@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); }
@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 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 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); }
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); }
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);  }