AMSReportPropertyProvider extends MetricsReportPropertyProvider { @Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { Set<Resource> keepers = new HashSet<Resource>(); for (Resource resource : resources) { if (populateResource(resource, request, predicate)) { keepers.add(resource); } } return keepers; } AMSReportPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
                                   URLStreamProvider streamProvider,
                                 ComponentSSLConfiguration configuration,
                                 TimelineMetricCacheProvider cacheProvider,
                                 MetricHostProvider hostProvider,
                                 String clusterNamePropertyId); @Override Set<String> checkPropertyIds(Set<String> propertyIds); @Override Set<Resource> populateResources(Set<Resource> resources,
               Request request, Predicate predicate);  }
@Test public void testPopulateResources() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH); injectCacheEntryFactoryWithStreamProvider(streamProvider); TestMetricHostProvider metricHostProvider = new TestMetricHostProvider(); ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class); Map<String, Map<String, PropertyInfo>> propertyIds = PropertyHelper.getMetricPropertyIds(Resource.Type.Cluster); AMSReportPropertyProvider propertyProvider = new AMSReportPropertyProvider( propertyIds, streamProvider, sslConfiguration, cacheProvider, metricHostProvider, CLUSTER_NAME_PROPERTY_ID ); String propertyId = PropertyHelper.getPropertyId("metrics/cpu", "User"); Resource resource = new ResourceImpl(Resource.Type.Cluster); resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1"); Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(propertyId, new TemporalInfoImpl(1416445244800L, 1416448936474L, 1L)); Request request = PropertyHelper.getReadRequest( Collections.singleton(propertyId), temporalInfoMap); Set<Resource> resources = propertyProvider.populateResources(Collections.singleton(resource), request, null); Assert.assertEquals(1, resources.size()); Resource res = resources.iterator().next(); Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next()); Assert.assertNotNull(properties); URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false); uriBuilder.addParameter("metricNames", "cpu_user"); uriBuilder.addParameter("appId", "HOST"); uriBuilder.addParameter("startTime", "1416445244800"); uriBuilder.addParameter("endTime", "1416448936474"); Assert.assertEquals(uriBuilder.toString(), streamProvider.getLastSpec()); Number[][] val = (Number[][]) res.getPropertyValue("metrics/cpu/User"); Assert.assertEquals(111, val.length); }
@Test public void testPopulateResourceWithAggregateFunction() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider(AGGREGATE_CLUSTER_METRICS_FILE_PATH); injectCacheEntryFactoryWithStreamProvider(streamProvider); TestMetricHostProvider metricHostProvider = new TestMetricHostProvider(); ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class); Map<String, Map<String, PropertyInfo>> propertyIds = PropertyHelper.getMetricPropertyIds(Resource.Type.Cluster); AMSReportPropertyProvider propertyProvider = new AMSReportPropertyProvider( propertyIds, streamProvider, sslConfiguration, cacheProvider, metricHostProvider, CLUSTER_NAME_PROPERTY_ID ); String propertyId = PropertyHelper.getPropertyId("metrics/cpu", "User._sum"); Resource resource = new ResourceImpl(Resource.Type.Cluster); resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1"); Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(propertyId, new TemporalInfoImpl(1432033257812L, 1432035927922L, 1L)); Request request = PropertyHelper.getReadRequest( Collections.singleton(propertyId), temporalInfoMap); Set<Resource> resources = propertyProvider.populateResources(Collections.singleton(resource), request, null); Assert.assertEquals(1, resources.size()); Resource res = resources.iterator().next(); Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next()); Assert.assertNotNull(properties); URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false); uriBuilder.addParameter("metricNames", "cpu_user._sum"); uriBuilder.addParameter("appId", "HOST"); uriBuilder.addParameter("startTime", "1432033257812"); uriBuilder.addParameter("endTime", "1432035927922"); Assert.assertEquals(uriBuilder.toString(), streamProvider.getLastSpec()); Number[][] val = (Number[][]) res.getPropertyValue("metrics/cpu/User._sum"); Assert.assertEquals(90, val.length); }