private void storeFlowMetrics(byte[] rowKey, Set<TimelineMetric> metrics, Attribute... attributes) throws IOException { for (TimelineMetric metric : metrics) { byte[] metricColumnQualifier = stringKeyConverter.encode(metric.getId()); Map<Long, Number> timeseries = metric.getValues(); for (Map.Entry<Long, Number> timeseriesEntry : timeseries.entrySet()) { Long timestamp = timeseriesEntry.getKey(); ColumnRWHelper.store(rowKey, flowRunTable, FlowRunColumnPrefix.METRIC, metricColumnQualifier, timestamp, timeseriesEntry.getValue(), attributes); } } }
/** * stores the {@linkplain TimelineMetric} information from the * {@linkplain TimelineEvent} object. */ private <T extends BaseTable<T>> void storeMetrics( byte[] rowKey, Set<TimelineMetric> metrics, ColumnPrefix<T> columnPrefix, TypedBufferedMutator<T> table) throws IOException { if (metrics != null) { for (TimelineMetric metric : metrics) { byte[] metricColumnQualifier = stringKeyConverter.encode(metric.getId()); Map<Long, Number> timeseries = metric.getValues(); for (Map.Entry<Long, Number> timeseriesEntry : timeseries.entrySet()) { Long timestamp = timeseriesEntry.getKey(); ColumnRWHelper.store(rowKey, table, columnPrefix, metricColumnQualifier, timestamp, timeseriesEntry.getValue()); } } } }
TimelineMetric aggregatedMetric = aggregatedEntity.getMetrics().iterator().next(); assertEquals(750L, aggregatedMetric.getValues().values().iterator().next()); assertEquals(TimelineMetricOperation.SUM, aggregatedMetric.getRealtimeAggregationOp()); assertTrue(aggregatedMetric.getValues().isEmpty()); assertEquals(TimelineMetricOperation.NOP, aggregatedMetric.getRealtimeAggregationOp()); assertEquals(150L, aggregatedMetric.getValues().values().iterator().next()); assertEquals(TimelineMetricOperation.SUM, aggregatedMetric.getRealtimeAggregationOp());
Assert.assertEquals(TimelineMetric.Type.TIME_SERIES, metric1.getType()); Iterator<Map.Entry<Long, Number>> itr = metric1.getValues().entrySet().iterator(); Map.Entry<Long, Number> entry = itr.next(); Assert.assertEquals(new Long(3L), entry.getKey()); Assert.assertEquals(TimelineMetric.Type.SINGLE_VALUE, metric2.getType()); Assert.assertTrue( metric2.getValues().values().iterator().next() instanceof Short); Map<Long, Number> points = new HashMap<>(); points.put(4L, 4.0D);