HBaseTimelineMetricStore extends AbstractService implements TimelineMetricStore { static Multimap<String, List<Function>> parseMetricNamesToAggregationFunctions(List<String> metricNames) { Multimap<String, List<Function>> metricsFunctions = ArrayListMultimap.create(); for (String metricName : metricNames){ Function function = Function.DEFAULT_VALUE_FUNCTION; String cleanMetricName = metricName; try { function = Function.fromMetricName(metricName); int functionStartIndex = metricName.indexOf("._"); if (functionStartIndex > 0) { cleanMetricName = metricName.substring(0, functionStartIndex); } } catch (Function.FunctionFormatException ffe){ } List<Function> functionsList = new ArrayList<>(); functionsList.add(function); metricsFunctions.put(cleanMetricName, functionsList); } return metricsFunctions; } HBaseTimelineMetricStore(TimelineMetricConfiguration configuration); @Override TimelineMetrics getTimelineMetrics(List<String> metricNames,
      List<String> hostnames, String applicationId, String instanceId,
      Long startTime, Long endTime, Precision precision, Integer limit,
      boolean groupedByHosts, TopNConfig topNConfig, String seriesAggregateFunction); @Override TimelinePutResponse putMetrics(TimelineMetrics metrics); @Override TimelinePutResponse putContainerMetrics(List<ContainerMetric> metrics); @Override Map<String, List<TimelineMetricMetadata>> getTimelineMetricMetadata(String query); @Override Map<String, Set<String>> getHostAppsMetadata(); @Override List<String> getLiveInstances();  }
@Test public void testParseMetricNamesToAggregationFunctions() throws Exception { List<String> metricNames = Arrays.asList( MEM_METRIC + "._avg", MEM_METRIC + "._sum", MEM_METRIC + "._rate._avg", BYTES_IN_METRIC, BYTES_NOT_AFUNCTION_METRIC); Multimap<String, List<Function>> multimap = HBaseTimelineMetricStore.parseMetricNamesToAggregationFunctions(metricNames); Assert.assertEquals(multimap.keySet().size(), 3); Assert.assertTrue(multimap.containsKey(MEM_METRIC)); Assert.assertTrue(multimap.containsKey(BYTES_IN_METRIC)); Assert.assertTrue(multimap.containsKey(BYTES_NOT_AFUNCTION_METRIC)); List<List<Function>> metricEntry = (List<List<Function>>) multimap.get(MEM_METRIC); HashMap<String, List<Function>> mfm = new HashMap<String, List<Function>>(); mfm.put(MEM_METRIC, metricEntry.get(0)); assertThat(mfm.get(MEM_METRIC)).containsOnly( new Function(AVG, null)); mfm = new HashMap<String, List<Function>>(); mfm.put(MEM_METRIC, metricEntry.get(1)); assertThat(mfm.get(MEM_METRIC)).containsOnly( new Function(SUM, null)); mfm = new HashMap<String, List<Function>>(); mfm.put(MEM_METRIC, metricEntry.get(2)); assertThat(mfm.get(MEM_METRIC)).containsOnly( new Function(AVG, RATE)); metricEntry = (List<List<Function>>) multimap.get(BYTES_IN_METRIC); mfm = new HashMap<String, List<Function>>(); mfm.put(BYTES_IN_METRIC, metricEntry.get(0)); assertThat(mfm.get(BYTES_IN_METRIC)) .contains(Function.DEFAULT_VALUE_FUNCTION); metricEntry = (List<List<Function>>) multimap.get(BYTES_NOT_AFUNCTION_METRIC); mfm = new HashMap<String, List<Function>>(); mfm.put(BYTES_NOT_AFUNCTION_METRIC, metricEntry.get(0)); assertThat(mfm.get(BYTES_NOT_AFUNCTION_METRIC)) .contains(Function.DEFAULT_VALUE_FUNCTION); }