@Test public void testPopulateResourcesForMultipleHostMetricscPointInTime() throws Exception { setUpCommonMocks(); TestStreamProvider streamProvider = new TestStreamProvider(MULTIPLE_HOST_METRICS_FILE_PATH); 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.Host); AMSPropertyProvider propertyProvider = new AMSHostPropertyProvider( propertyIds, streamProvider, sslConfiguration, cacheProviderMock, metricHostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID ); Resource resource = new ResourceImpl(Resource.Type.Host); resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1"); resource.setProperty(HOST_NAME_PROPERTY_ID, "h1"); Map<String, TemporalInfo> temporalInfoMap = Collections.emptyMap(); Request request = PropertyHelper.getReadRequest( new HashSet<String>() {{ add(PROPERTY_ID1); add(PROPERTY_ID2); }}, 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,mem_free"); uriBuilder.addParameter("hostname", "h1"); uriBuilder.addParameter("appId", "HOST"); URIBuilder uriBuilder2 = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false); uriBuilder2.addParameter("metricNames", "mem_free,cpu_user"); uriBuilder2.addParameter("hostname", "h1"); uriBuilder2.addParameter("appId", "HOST"); Assert.assertTrue(uriBuilder.toString().equals(streamProvider.getLastSpec()) || uriBuilder2.toString().equals(streamProvider.getLastSpec())); Double val1 = (Double) res.getPropertyValue(PROPERTY_ID1); Assert.assertNotNull("No value for property " + PROPERTY_ID1, val1); Assert.assertEquals(41.088, val1, 0.001); Double val2 = (Double) res.getPropertyValue(PROPERTY_ID2); Assert.assertNotNull("No value for property " + PROPERTY_ID2, val2); Assert.assertEquals(2.47025664E8, val2, 0.1); }
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();  }