@Test public void testPopulateResourcesForHostComponentHostMetrics() throws Exception { setUpCommonMocks(); TestStreamProviderForHostComponentHostMetricsTest streamProvider = new TestStreamProviderForHostComponentHostMetricsTest(null); injectCacheEntryFactoryWithStreamProvider(streamProvider); TestMetricHostProvider metricHostProvider = new TestMetricHostProvider(); ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class); TimelineMetricCacheProvider cacheProviderMock = EasyMock.createMock(TimelineMetricCacheProvider.class); TimelineMetricCache cacheMock = EasyMock.createMock(TimelineMetricCache.class); expect(cacheProviderMock.getTimelineMetricsCache()).andReturn(cacheMock).anyTimes(); Map<String, Map<String, PropertyInfo>> propertyIds = PropertyHelper.getMetricPropertyIds(Resource.Type.HostComponent); AMSPropertyProvider propertyProvider = new AMSHostComponentPropertyProvider( propertyIds, streamProvider, sslConfiguration, cacheProviderMock, metricHostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID ); Resource resource = new ResourceImpl(Resource.Type.Host); resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1"); resource.setProperty(HOST_NAME_PROPERTY_ID, "h1"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "DATANODE"); Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(PROPERTY_ID1, new TemporalInfoImpl(1416445244801L, 1416448936464L, 1L)); temporalInfoMap.put(PROPERTY_ID3, new TemporalInfoImpl(1416445244801L, 1416448936464L, 1L)); Request request = PropertyHelper.getReadRequest( new HashSet<String>() {{ add(PROPERTY_ID1); add(PROPERTY_ID3); add("params/padding/NONE"); }}, 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); Set<String> specs = streamProvider.getAllSpecs(); Assert.assertEquals(2, specs.size()); String hostMetricSpec = null; String hostComponentMetricsSpec = null; for (String spec : specs) { if (spec.contains("HOST")) { hostMetricSpec = spec; } else { hostComponentMetricsSpec = spec; } } Assert.assertNotNull(hostMetricSpec); Assert.assertNotNull(hostComponentMetricsSpec); URIBuilder uriBuilder1 = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false); uriBuilder1.addParameter("metricNames", "dfs.datanode.BlocksReplicated"); uriBuilder1.addParameter("hostname", "h1"); uriBuilder1.addParameter("appId", "DATANODE"); uriBuilder1.addParameter("startTime", "1416445244801"); uriBuilder1.addParameter("endTime", "1416448936464"); Assert.assertEquals(uriBuilder1.toString(), hostComponentMetricsSpec); URIBuilder uriBuilder2 = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false); uriBuilder2.addParameter("metricNames", "cpu_user"); uriBuilder2.addParameter("hostname", "h1"); uriBuilder2.addParameter("appId", "HOST"); uriBuilder2.addParameter("startTime", "1416445244801"); uriBuilder2.addParameter("endTime", "1416448936464"); Assert.assertEquals(uriBuilder2.toString(), hostMetricSpec); Number[][] val = (Number[][]) res.getPropertyValue(PROPERTY_ID1); Assert.assertEquals(111, val.length); val = (Number[][]) res.getPropertyValue(PROPERTY_ID3); Assert.assertNotNull("No value for property " + PROPERTY_ID3, val); Assert.assertEquals(8, val.length); }
static URIBuilder getAMSUriBuilder(String hostname, int port, boolean httpsEnabled) { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(httpsEnabled ? "https" : "http"); uriBuilder.setHost(hostname); uriBuilder.setPort(port); uriBuilder.setPath("/ws/v1/timeline/metrics"); return uriBuilder; }
AMSPropertyProvider extends MetricsPropertyProvider { static URIBuilder getAMSUriBuilder(String hostname, int port, boolean httpsEnabled) { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(httpsEnabled ? "https" : "http"); uriBuilder.setHost(hostname); uriBuilder.setPort(port); uriBuilder.setPath("/ws/v1/timeline/metrics"); return uriBuilder; } }
AMSPropertyProvider extends MetricsPropertyProvider { static URIBuilder getAMSUriBuilder(String hostname, int port, boolean httpsEnabled) { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(httpsEnabled ? "https" : "http"); uriBuilder.setHost(hostname); uriBuilder.setPort(port); uriBuilder.setPath("/ws/v1/timeline/metrics"); return uriBuilder; } AMSPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
                             URLStreamProvider streamProvider,
                             ComponentSSLConfiguration configuration,
                             TimelineMetricCacheProvider cacheProvider,
                             MetricHostProvider hostProvider,
                             String clusterNamePropertyId,
                             String hostNamePropertyId,
                             String componentNamePropertyId); }
AMSPropertyProvider extends MetricsPropertyProvider { static URIBuilder getAMSUriBuilder(String hostname, int port, boolean httpsEnabled) { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(httpsEnabled ? "https" : "http"); uriBuilder.setHost(hostname); uriBuilder.setPort(port); uriBuilder.setPath("/ws/v1/timeline/metrics"); return uriBuilder; } AMSPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
                             URLStreamProvider streamProvider,
                             ComponentSSLConfiguration configuration,
                             TimelineMetricCacheProvider cacheProvider,
                             MetricHostProvider hostProvider,
                             String clusterNamePropertyId,
                             String hostNamePropertyId,
                             String componentNamePropertyId); @Override Set<String> checkPropertyIds(Set<String> propertyIds); @Override Set<Resource> populateResourcesWithProperties(Set<Resource> resources,
               Request request, Set<String> propertyIds); @Override Map<String, Map<String, PropertyInfo>> getComponentMetrics(); }
AMSPropertyProvider extends MetricsPropertyProvider { static URIBuilder getAMSUriBuilder(String hostname, int port, boolean httpsEnabled) { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(httpsEnabled ? "https" : "http"); uriBuilder.setHost(hostname); uriBuilder.setPort(port); uriBuilder.setPath("/ws/v1/timeline/metrics"); return uriBuilder; } AMSPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
                             URLStreamProvider streamProvider,
                             ComponentSSLConfiguration configuration,
                             TimelineMetricCacheProvider cacheProvider,
                             MetricHostProvider hostProvider,
                             String clusterNamePropertyId,
                             String hostNamePropertyId,
                             String componentNamePropertyId); @Override Set<String> checkPropertyIds(Set<String> propertyIds); @Override Set<Resource> populateResourcesWithProperties(Set<Resource> resources,
               Request request, Set<String> propertyIds); @Override Map<String, Map<String, PropertyInfo>> getComponentMetrics();  }