@Test public void updateAppAggregatesFromHostMetricTest() { long cacheSliceIntervalMillis = 30000L; long startTime = getRoundedCheckPointTimeMillis(System.currentTimeMillis(), cacheSliceIntervalMillis); long seconds = 1000; TreeMap<Long, Double> metricValues = new TreeMap<Long, Double>(); List<TimelineMetric> timelineMetrics = new ArrayList<>(); TimelineMetric timelineMetric; metricValues = new TreeMap<>(); metricValues.put(startTime + 15*seconds, 1.0); metricValues.put(startTime + 55*seconds, 2.0); timelineMetric = new TimelineMetric("host_metric", "host1", HOST_APP_ID, "instance1"); timelineMetric.setMetricValues(metricValues); timelineMetrics.add(timelineMetric); metricValues = new TreeMap<>(); metricValues.put(startTime + 45*seconds, 3.0); metricValues.put(startTime + 85*seconds, 4.0); timelineMetric = new TimelineMetric("app_metric", "host1", "appIdForHostsAggr", "instance1"); timelineMetric.setMetricValues(metricValues); timelineMetrics.add(timelineMetric); metricValues = new TreeMap<>(); metricValues.put(startTime + 85*seconds, 5.0); timelineMetric = new TimelineMetric("host_metric", "host1", HOST_APP_ID, "instance1"); timelineMetric.setMetricValues(metricValues); timelineMetrics.add(timelineMetric); metricValues = new TreeMap<>(); metricValues.put(startTime + 85*seconds, 6.0); timelineMetric = new TimelineMetric("host_metric", "host2", HOST_APP_ID, "instance1"); timelineMetric.setMetricValues(metricValues); timelineMetrics.add(timelineMetric); timelineMetricsIgniteCache.putMetrics(timelineMetrics); Map<TimelineClusterMetric, MetricClusterAggregate> aggregateMap = timelineMetricsIgniteCache.evictMetricAggregates(startTime, startTime + 120*seconds); Assert.assertEquals(aggregateMap.size(), 6); TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(timelineMetric.getMetricName(), timelineMetric.getAppId(), timelineMetric.getInstanceId(), startTime + 90*seconds); Assert.assertTrue(aggregateMap.containsKey(timelineClusterMetric)); Assert.assertEquals(11.0, aggregateMap.get(timelineClusterMetric).getSum()); timelineClusterMetric = new TimelineClusterMetric("app_metric", "appIdForHostsAggr", "instance1", startTime + 90*seconds); Assert.assertTrue(aggregateMap.containsKey(timelineClusterMetric)); Assert.assertEquals(4.0, aggregateMap.get(timelineClusterMetric).getSum()); timelineClusterMetric = new TimelineClusterMetric("host_metric", "appIdForHostsAggr", "instance1", startTime + 90*seconds); Assert.assertTrue(aggregateMap.containsKey(timelineClusterMetric)); Assert.assertEquals(5.0, aggregateMap.get(timelineClusterMetric).getSum()); Assert.assertEquals(0d, timelineMetricsIgniteCache.getPointInTimeCacheMetrics().get("Cluster_KeySize")); }
private void updateAppAggregatesFromHostMetric(TimelineClusterMetric key, MetricClusterAggregate newMetricClusterAggregate, TimelineMetricHostMetadata timelineMetricHostMetadata) { for (String appId : timelineMetricHostMetadata.getHostedApps().keySet()) { if (appIdsToAggregate.contains(appId)) { TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(key.getMetricName(), appId, key.getInstanceId(), key.getTimestamp()); TimelineMetricMetadataKey metadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId()); TimelineMetricMetadata metricMetadata = metricMetadataManager.getMetadataCacheValue(metadataKey); if (metricMetadata == null || metricMetadata.getUuid() == null) { TimelineMetricMetadataKey metricMetadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), HOST_APP_ID, timelineClusterMetric.getInstanceId()); metricMetadata = metricMetadataManager.getMetadataCacheValue(metricMetadataKey); if (metricMetadata != null) { TimelineMetricMetadata timelineMetricMetadata = new TimelineMetricMetadata(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), metricMetadata.getUnits(), metricMetadata.getType(), metricMetadata.getSeriesStartTime(), metricMetadata.isSupportsAggregates(), TimelineMetricsFilter.acceptMetric(timelineClusterMetric.getMetricName(), appId)); byte[] uuid = metricMetadataManager.getUuid(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), StringUtils.EMPTY, true); timelineMetricMetadata.setUuid(uuid); metricMetadataManager.putIfModifiedTimelineMetricMetadata(timelineMetricMetadata); } } putMetricIntoCache(timelineClusterMetric, newMetricClusterAggregate); } } }
TimelineMetricsIgniteCache implements TimelineMetricDistributedCache { private void updateAppAggregatesFromHostMetric(TimelineClusterMetric key, MetricClusterAggregate newMetricClusterAggregate, TimelineMetricHostMetadata timelineMetricHostMetadata) { for (String appId : timelineMetricHostMetadata.getHostedApps().keySet()) { if (appIdsToAggregate.contains(appId)) { TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(key.getMetricName(), appId, key.getInstanceId(), key.getTimestamp()); TimelineMetricMetadataKey metadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId()); TimelineMetricMetadata metricMetadata = metricMetadataManager.getMetadataCacheValue(metadataKey); if (metricMetadata == null || metricMetadata.getUuid() == null) { TimelineMetricMetadataKey metricMetadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), HOST_APP_ID, timelineClusterMetric.getInstanceId()); metricMetadata = metricMetadataManager.getMetadataCacheValue(metricMetadataKey); if (metricMetadata != null) { TimelineMetricMetadata timelineMetricMetadata = new TimelineMetricMetadata(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), metricMetadata.getUnits(), metricMetadata.getType(), metricMetadata.getSeriesStartTime(), metricMetadata.isSupportsAggregates(), TimelineMetricsFilter.acceptMetric(timelineClusterMetric.getMetricName(), appId)); byte[] uuid = metricMetadataManager.getUuid(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), StringUtils.EMPTY, true); timelineMetricMetadata.setUuid(uuid); metricMetadataManager.putIfModifiedTimelineMetricMetadata(timelineMetricMetadata); } } putMetricIntoCache(timelineClusterMetric, newMetricClusterAggregate); } } } }
TimelineMetricsIgniteCache implements TimelineMetricDistributedCache { private void updateAppAggregatesFromHostMetric(TimelineClusterMetric key, MetricClusterAggregate newMetricClusterAggregate, TimelineMetricHostMetadata timelineMetricHostMetadata) { for (String appId : timelineMetricHostMetadata.getHostedApps().keySet()) { if (appIdsToAggregate.contains(appId)) { TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(key.getMetricName(), appId, key.getInstanceId(), key.getTimestamp()); TimelineMetricMetadataKey metadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId()); TimelineMetricMetadata metricMetadata = metricMetadataManager.getMetadataCacheValue(metadataKey); if (metricMetadata == null || metricMetadata.getUuid() == null) { TimelineMetricMetadataKey metricMetadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), HOST_APP_ID, timelineClusterMetric.getInstanceId()); metricMetadata = metricMetadataManager.getMetadataCacheValue(metricMetadataKey); if (metricMetadata != null) { TimelineMetricMetadata timelineMetricMetadata = new TimelineMetricMetadata(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), metricMetadata.getUnits(), metricMetadata.getType(), metricMetadata.getSeriesStartTime(), metricMetadata.isSupportsAggregates(), TimelineMetricsFilter.acceptMetric(timelineClusterMetric.getMetricName(), appId)); byte[] uuid = metricMetadataManager.getUuid(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), StringUtils.EMPTY, true); timelineMetricMetadata.setUuid(uuid); metricMetadataManager.putIfModifiedTimelineMetricMetadata(timelineMetricMetadata); } } putMetricIntoCache(timelineClusterMetric, newMetricClusterAggregate); } } } TimelineMetricsIgniteCache(TimelineMetricMetadataManager metricMetadataManager); }
TimelineMetricsIgniteCache implements TimelineMetricDistributedCache { private void updateAppAggregatesFromHostMetric(TimelineClusterMetric key, MetricClusterAggregate newMetricClusterAggregate, TimelineMetricHostMetadata timelineMetricHostMetadata) { for (String appId : timelineMetricHostMetadata.getHostedApps().keySet()) { if (appIdsToAggregate.contains(appId)) { TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(key.getMetricName(), appId, key.getInstanceId(), key.getTimestamp()); TimelineMetricMetadataKey metadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId()); TimelineMetricMetadata metricMetadata = metricMetadataManager.getMetadataCacheValue(metadataKey); if (metricMetadata == null || metricMetadata.getUuid() == null) { TimelineMetricMetadataKey metricMetadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), HOST_APP_ID, timelineClusterMetric.getInstanceId()); metricMetadata = metricMetadataManager.getMetadataCacheValue(metricMetadataKey); if (metricMetadata != null) { TimelineMetricMetadata timelineMetricMetadata = new TimelineMetricMetadata(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), metricMetadata.getUnits(), metricMetadata.getType(), metricMetadata.getSeriesStartTime(), metricMetadata.isSupportsAggregates(), TimelineMetricsFilter.acceptMetric(timelineClusterMetric.getMetricName(), appId)); byte[] uuid = metricMetadataManager.getUuid(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), StringUtils.EMPTY, true); timelineMetricMetadata.setUuid(uuid); metricMetadataManager.putIfModifiedTimelineMetricMetadata(timelineMetricMetadata); } } putMetricIntoCache(timelineClusterMetric, newMetricClusterAggregate); } } } TimelineMetricsIgniteCache(TimelineMetricMetadataManager metricMetadataManager); @Override Map<TimelineClusterMetric, MetricClusterAggregate> evictMetricAggregates(Long startTime, Long endTime); @Override void putMetrics(Collection<TimelineMetric> elements); @Override Map<String, Double> getPointInTimeCacheMetrics(); }
TimelineMetricsIgniteCache implements TimelineMetricDistributedCache { private void updateAppAggregatesFromHostMetric(TimelineClusterMetric key, MetricClusterAggregate newMetricClusterAggregate, TimelineMetricHostMetadata timelineMetricHostMetadata) { for (String appId : timelineMetricHostMetadata.getHostedApps().keySet()) { if (appIdsToAggregate.contains(appId)) { TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(key.getMetricName(), appId, key.getInstanceId(), key.getTimestamp()); TimelineMetricMetadataKey metadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId()); TimelineMetricMetadata metricMetadata = metricMetadataManager.getMetadataCacheValue(metadataKey); if (metricMetadata == null || metricMetadata.getUuid() == null) { TimelineMetricMetadataKey metricMetadataKey = new TimelineMetricMetadataKey(timelineClusterMetric.getMetricName(), HOST_APP_ID, timelineClusterMetric.getInstanceId()); metricMetadata = metricMetadataManager.getMetadataCacheValue(metricMetadataKey); if (metricMetadata != null) { TimelineMetricMetadata timelineMetricMetadata = new TimelineMetricMetadata(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), metricMetadata.getUnits(), metricMetadata.getType(), metricMetadata.getSeriesStartTime(), metricMetadata.isSupportsAggregates(), TimelineMetricsFilter.acceptMetric(timelineClusterMetric.getMetricName(), appId)); byte[] uuid = metricMetadataManager.getUuid(timelineClusterMetric.getMetricName(), appId, timelineClusterMetric.getInstanceId(), StringUtils.EMPTY, true); timelineMetricMetadata.setUuid(uuid); metricMetadataManager.putIfModifiedTimelineMetricMetadata(timelineMetricMetadata); } } putMetricIntoCache(timelineClusterMetric, newMetricClusterAggregate); } } } TimelineMetricsIgniteCache(TimelineMetricMetadataManager metricMetadataManager); @Override Map<TimelineClusterMetric, MetricClusterAggregate> evictMetricAggregates(Long startTime, Long endTime); @Override void putMetrics(Collection<TimelineMetric> elements); @Override Map<String, Double> getPointInTimeCacheMetrics();  }