@Test public void testPopulateResourcesForHostComponentMetricsForMultipleHosts() throws Exception { setUpCommonMocks(); TestStreamProviderForHostComponentMultipleHostsMetricsTest streamProvider = new TestStreamProviderForHostComponentMultipleHostsMetricsTest(null); injectCacheEntryFactoryWithStreamProvider(streamProvider); TestMetricHostProvider metricHostProvider = new TestMetricHostProvider("h1"); 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); 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_ID4, new TemporalInfoImpl(1416445244801L, 1416448936464L, 1L)); Request request = PropertyHelper.getReadRequest( new HashSet<String>() {{ add(PROPERTY_ID4); add("params/padding/NONE"); }}, temporalInfoMap); AMSPropertyProvider propertyProvider = new AMSHostComponentPropertyProvider( propertyIds, streamProvider, sslConfiguration, cacheProviderMock, metricHostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID ); Set<Resource> resources1 = propertyProvider.populateResources(Collections.singleton(resource), request, null); Assert.assertEquals(1, resources1.size()); Resource res1 = resources1.iterator().next(); Map<String, Object> properties = PropertyHelper.getProperties(resources1.iterator().next()); Assert.assertNotNull(properties); metricHostProvider = new TestMetricHostProvider("h2"); cacheProviderMock = EasyMock.createMock(TimelineMetricCacheProvider.class); cacheMock = EasyMock.createMock(TimelineMetricCache.class); expect(cacheProviderMock.getTimelineMetricsCache()).andReturn(cacheMock).anyTimes(); resource = new ResourceImpl(Resource.Type.Host); resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1"); resource.setProperty(HOST_NAME_PROPERTY_ID, "h2"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "DATANODE"); temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(PROPERTY_ID4, new TemporalInfoImpl(1416445244801L, 1416448936464L, 1L)); request = PropertyHelper.getReadRequest( new HashSet<String>() {{ add(PROPERTY_ID4); add("params/padding/NONE"); }}, temporalInfoMap); propertyProvider = new AMSHostComponentPropertyProvider( propertyIds, streamProvider, sslConfiguration, cacheProviderMock, metricHostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID ); resource.setProperty(HOST_NAME_PROPERTY_ID, "h2"); Set<Resource> resources2 = propertyProvider.populateResources(Collections.singleton(resource), request, null); Assert.assertEquals(1, resources2.size()); Resource res2 = resources2.iterator().next(); properties = PropertyHelper.getProperties(resources2.iterator().next()); Assert.assertNotNull(properties); Set<String> specs = streamProvider.getAllSpecs(); Assert.assertEquals(2, specs.size()); URIBuilder uriBuilder1 = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false); Number[][] val; for (String spec : specs) { Assert.assertNotNull(spec); if (spec.contains("h2")) { uriBuilder1.setParameter("metricNames", "dfs.datanode.blocks_removed"); uriBuilder1.setParameter("hostname", "h2"); uriBuilder1.setParameter("appId", "DATANODE"); uriBuilder1.setParameter("startTime", "1416445244801"); uriBuilder1.setParameter("endTime", "1416448936464"); Assert.assertEquals(uriBuilder1.toString(), spec); val = (Number[][]) res2.getPropertyValue(PROPERTY_ID4); Assert.assertNotNull("No value for property " + PROPERTY_ID4, val); Assert.assertEquals(9, val.length); } else { uriBuilder1.setParameter("metricNames", "dfs.datanode.blocks_removed"); uriBuilder1.setParameter("hostname", "h1"); uriBuilder1.setParameter("appId", "DATANODE"); uriBuilder1.setParameter("startTime", "1416445244801"); uriBuilder1.setParameter("endTime", "1416448936464"); Assert.assertEquals(uriBuilder1.toString(), spec); val = (Number[][]) res1.getPropertyValue(PROPERTY_ID4); Assert.assertNotNull("No value for property " + PROPERTY_ID4, 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();  }