Repository: ambari Updated Branches: refs/heads/trunk 81f311baf -> 23faabc4a
http://git-wip-us.apache.org/repos/asf/ambari/blob/23faabc4/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java index c50ccba..b6af863 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java @@ -72,14 +72,14 @@ public class RestMetricsPropertyProviderTest { metricsProperties.put("port_config_type", "storm-site"); metricsProperties.put("port_property_name", "storm.port"); metricsProperties.put("protocol", "http"); - componentMetrics.put("metrics/api/cluster/summary/tasks.total", new Metric("/api/cluster/summary##tasks.total", false, false)); - componentMetrics.put("metrics/api/cluster/summary/slots.total", new Metric("/api/cluster/summary##slots.total", false, false)); - componentMetrics.put("metrics/api/cluster/summary/slots.free", new Metric("/api/cluster/summary##slots.free", false, false)); - componentMetrics.put("metrics/api/cluster/summary/supervisors", new Metric("/api/cluster/summary##supervisors", false, false)); - componentMetrics.put("metrics/api/cluster/summary/executors.total", new Metric("/api/cluster/summary##executors.total", false, false)); - componentMetrics.put("metrics/api/cluster/summary/slots.used", new Metric("/api/cluster/summary##slots.used", false, false)); - componentMetrics.put("metrics/api/cluster/summary/topologies", new Metric("/api/cluster/summary##topologies", false, false)); - componentMetrics.put("metrics/api/cluster/summary/nimbus.uptime", new Metric("/api/cluster/summary##nimbus.uptime", false, false)); + componentMetrics.put("metrics/api/cluster/summary/tasks.total", new Metric("/api/cluster/summary##tasks.total", false, false, false)); + componentMetrics.put("metrics/api/cluster/summary/slots.total", new Metric("/api/cluster/summary##slots.total", false, false, false)); + componentMetrics.put("metrics/api/cluster/summary/slots.free", new Metric("/api/cluster/summary##slots.free", false, false, false)); + componentMetrics.put("metrics/api/cluster/summary/supervisors", new Metric("/api/cluster/summary##supervisors", false, false, false)); + componentMetrics.put("metrics/api/cluster/summary/executors.total", new Metric("/api/cluster/summary##executors.total", false, false, false)); + componentMetrics.put("metrics/api/cluster/summary/slots.used", new Metric("/api/cluster/summary##slots.used", false, false, false)); + componentMetrics.put("metrics/api/cluster/summary/topologies", new Metric("/api/cluster/summary##topologies", false, false, false)); + componentMetrics.put("metrics/api/cluster/summary/nimbus.uptime", new Metric("/api/cluster/summary##nimbus.uptime", false, false, false)); } http://git-wip-us.apache.org/repos/asf/ambari/blob/23faabc4/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/TestStreamProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/TestStreamProvider.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/TestStreamProvider.java index f6ac02b..07fa7c7 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/TestStreamProvider.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/TestStreamProvider.java @@ -24,8 +24,8 @@ import java.io.IOException; import java.io.InputStream; public class TestStreamProvider implements StreamProvider { - - private final String fileName; + // Allow for filename to be set at runtime + protected String fileName; private String lastSpec; private boolean isLastSpecUpdated; http://git-wip-us.apache.org/repos/asf/ambari/blob/23faabc4/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java index 4e2ed98..052f86c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java @@ -33,6 +33,8 @@ import org.junit.Assert; import org.junit.Test; import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -46,6 +48,7 @@ import static org.mockito.Mockito.mock; public class AMSPropertyProviderTest { private static final String PROPERTY_ID1 = PropertyHelper.getPropertyId("metrics/cpu", "cpu_user"); private static final String PROPERTY_ID2 = PropertyHelper.getPropertyId("metrics/memory", "mem_free"); + private static final String PROPERTY_ID3 = PropertyHelper.getPropertyId("metrics/dfs/datanode", "blocks_replicated"); private static final String CLUSTER_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "cluster_name"); private static final String HOST_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "host_name"); private static final String COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name"); @@ -98,8 +101,7 @@ public class AMSPropertyProviderTest { } @Test - public void testPopulateResourcesForSingleHostMetricPointInTime() throws - Exception { + public void testPopulateResourcesForSingleHostMetricPointInTime() throws Exception { // given TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH); @@ -176,7 +178,6 @@ public class AMSPropertyProviderTest { uriBuilder2.addParameter("metricNames", "mem_free,cpu_user"); uriBuilder2.addParameter("hostname", "h1"); uriBuilder2.addParameter("appId", "HOST"); - System.out.println(streamProvider.getLastSpec()); Assert.assertTrue(uriBuilder.toString().equals(streamProvider.getLastSpec()) || uriBuilder2.toString().equals(streamProvider.getLastSpec())); Double val1 = (Double) res.getPropertyValue(PROPERTY_ID1); @@ -185,7 +186,6 @@ public class AMSPropertyProviderTest { Assert.assertEquals(2.47025664E8, val2, 0.1); } - @Test public void testPopulateResourcesForMultipleHostMetrics() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider(MULTIPLE_HOST_METRICS_FILE_PATH); @@ -236,7 +236,6 @@ public class AMSPropertyProviderTest { Assert.assertEquals(86, val.length); } - @Test public void testPopulateResourcesForRegexpMetrics() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider(MULTIPLE_COMPONENT_REGEXP_METRICS_FILE_PATH); @@ -369,6 +368,103 @@ public class AMSPropertyProviderTest { Assert.assertEquals(188, val.length); } + static class TestStreamProviderForHostComponentHostMetricsTest extends TestStreamProvider { + String hostMetricFilePath = FILE_PATH_PREFIX + "single_host_metric.json"; + String hostComponentMetricFilePath = FILE_PATH_PREFIX + "single_host_component_metrics.json"; + Set<String> specs = new HashSet<String>(); + + public TestStreamProviderForHostComponentHostMetricsTest(String fileName) { + super(fileName); + } + + @Override + public InputStream readFrom(String spec) throws IOException { + if (spec.contains("HOST")) { + this.fileName = hostMetricFilePath; + } else { + this.fileName = hostComponentMetricFilePath; + } + + specs.add(spec); + + return super.readFrom(spec); + } + + public Set<String> getAllSpecs() { + return specs; + } + } + + @Test + public void testPopulateResourcesForHostComponentHostMetrics() throws Exception { + TestStreamProviderForHostComponentHostMetricsTest streamProvider = + new TestStreamProviderForHostComponentHostMetricsTest(null); + TestMetricHostProvider metricHostProvider = new TestMetricHostProvider(); + ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class); + + Map<String, Map<String, PropertyInfo>> propertyIds = PropertyHelper.getMetricPropertyIds(Resource.Type.HostComponent); + AMSPropertyProvider propertyProvider = new AMSHostComponentPropertyProvider( + propertyIds, + streamProvider, + sslConfiguration, + metricHostProvider, + CLUSTER_NAME_PROPERTY_ID, + HOST_NAME_PROPERTY_ID, + COMPONENT_NAME_PROPERTY_ID + ); + + Resource resource = new ResourceImpl(Resource.Type.Host); + 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(1416445244701L, 1416445251802L, 1L)); + temporalInfoMap.put(PROPERTY_ID3, new TemporalInfoImpl(1416445244701L, 1416445251802L, 1L)); + Request request = PropertyHelper.getReadRequest( + new HashSet<String>() {{ add(PROPERTY_ID1); add(PROPERTY_ID3); }}, + 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); + // Verify calls + URIBuilder uriBuilder1 = AMSPropertyProvider.getAMSUriBuilder("localhost", 8188); + uriBuilder1.addParameter("metricNames", "dfs.datanode.BlocksReplicated"); + uriBuilder1.addParameter("hostname", "h1"); + uriBuilder1.addParameter("appId", "DATANODE"); + uriBuilder1.addParameter("startTime", "1416445244701"); + uriBuilder1.addParameter("endTime", "1416445251802"); + Assert.assertEquals(uriBuilder1.toString(), hostComponentMetricsSpec); + + URIBuilder uriBuilder2 = AMSPropertyProvider.getAMSUriBuilder("localhost", 8188); + uriBuilder2.addParameter("metricNames", "cpu_user"); + uriBuilder2.addParameter("hostname", "h1"); + uriBuilder2.addParameter("appId", "HOST"); + uriBuilder2.addParameter("startTime", "1416445244701"); + uriBuilder2.addParameter("endTime", "1416445251802"); + Assert.assertEquals(uriBuilder2.toString(), hostMetricSpec); + + Number[][] val = (Number[][]) res.getPropertyValue(PROPERTY_ID1); + Assert.assertEquals(111, val.length); + val = (Number[][]) res.getPropertyValue(PROPERTY_ID3); + Assert.assertEquals(8, val.length); + } + public static class TestMetricHostProvider implements MetricHostProvider { @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/23faabc4/ambari-server/src/test/resources/ams/single_host_component_metrics.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/resources/ams/single_host_component_metrics.json b/ambari-server/src/test/resources/ams/single_host_component_metrics.json new file mode 100644 index 0000000..f3e6554 --- /dev/null +++ b/ambari-server/src/test/resources/ams/single_host_component_metrics.json @@ -0,0 +1,21 @@ +{ + "metrics": [ + { + "timestamp": 1416445244801, + "type": "Long", + "metricname": "dfs.datanode.BlocksReplicated", + "appid": "datanode", + "hostname": "c6402.ambari.apache.org", + "starttime": 1416445244801, + "metrics": { + "1416445244801": 0.0, + "1416445245801": 0.0, + "1416445246801": 0.0, + "1416445247801": 0.0, + "1416445248801": 0.0, + "1416445249801": 0.0, + "1416445250801": 0.0, + "1416445251801": 0.0 + } + } +]} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/23faabc4/ambari-server/src/test/resources/ams/single_host_metric.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/resources/ams/single_host_metric.json b/ambari-server/src/test/resources/ams/single_host_metric.json index e8b7c14..83f2cdf 100644 --- a/ambari-server/src/test/resources/ams/single_host_metric.json +++ b/ambari-server/src/test/resources/ams/single_host_metric.json @@ -1,122 +1,124 @@ -{"metrics": [ - { - "timestamp": 1416445244801, - "metricname": "cpu_user", - "appid": "HOST", - "starttime": 1416445244801, - "metrics": { - "1416445244801": 4006.085, - "1416445259801": 4006.29, - "1416445274801": 4006.6475, - "1416445289801": 4006.9474999999998, - "1416445304801": 4007.1025, - "1416445319801": 4007.21, - "1416445364801": 4007.8375, - "1416445379801": 4008.0425000000005, - "1416445394801": 4008.37, - "1416445409801": 4008.9474999999998, - "1416445424801": 4009.08, - "1416445439801": 4009.185, - "1416445484801": 4009.9525, - "1416445499801": 4010.19, - "1416445514801": 4010.8725, - "1416445529801": 4011.3424999999997, - "1416445544801": 4011.4975000000004, - "1416445559801": 4011.665, - "1416445604801": 4012.57, - "1416445619801": 4012.9325, - "1416445634801": 4013.3424999999997, - "1416445649801": 4013.9225, - "1416445664801": 4014.1949999999997, - "1416445679801": 4014.58, - "1416445724801": 4015.73, - "1416445739801": 4015.8599999999997, - "1416445964801": 4020.1075, - "1416445979801": 4020.2975, - "1416445994801": 4020.4624999999996, - "1416446009801": 4020.825, - "1416446024801": 4020.96, - "1416446084801": 4021.9725, - "1416446099801": 4022.2, - "1416446114801": 4022.3775, - "1416446129801": 4022.7275, - "1416446144801": 4022.98, - "1416446204801": 4023.9425, - "1416446219801": 4024.245, - "1416446234801": 4024.5275, - "1416446249801": 4024.925, - "1416446264801": 4025.03, - "1416446324801": 4026.2075, - "1416446339801": 4026.4125, - "1416446354801": 4026.5275, - "1416446369801": 4026.915, - "1416446384801": 4027.0550000000003, - "1416446444801": 4028.0975, - "1416446459801": 4028.2799999999997, - "1416446474801": 4028.4275, - "1416446489801": 4028.8375, - "1416446504801": 4028.98, - "1416446564801": 4030.005, - "1416446579801": 4030.1800000000003, - "1416446594801": 4030.365, - "1416446609801": 4030.745, - "1416446624801": 4030.895, - "1416446684801": 4031.7825, - "1416446699801": 4032.0175, - "1416446714801": 4032.2025, - "1416446729801": 4032.5525, - "1416446744801": 4032.82, - "1416446804801": 4033.7475, - "1416446819801": 4033.9700000000003, - "1416446834801": 4034.1425, - "1416446849801": 4034.4725, - "1416446864801": 4034.635, - "1416446924801": 4035.54, - "1416446939801": 4035.7175, - "1416446954801": 4035.885, - "1416446969801": 4036.255, - "1416446984801": 4036.435, - "1416447044801": 4037.8475, - "1416447059801": 4038.045, - "1416447074801": 4038.2025, - "1416447089801": 4038.7, - "1416447104801": 4038.855, - "1416447164801": 4039.7375, - "1416447179801": 4039.9025, - "1416447194801": 4040.08, - "1416447209801": 4040.42, - "1416447224801": 4040.59, - "1416447284801": 4041.51, - "1416447299801": 4041.85, - "1416447314801": 4042.6525, - "1416447329801": 4043.1025, - "1416447344801": 4043.29, - "1416447404801": 4044.265, - "1416447419801": 4044.52, - "1416447434801": 4044.705, - "1416447449801": 4045.09, - "1416447464801": 4045.325, - "1416447524801": 4046.2525, - "1416447539801": 4046.3975, - "1416447554801": 4046.55, - "1416447569801": 4046.865, - "1416447584801": 4047.0550000000003, - "1416447644801": 4049.255, - "1416448681363": 4105.1125, - "1416448696363": 4105.3625, - "1416448711363": 4105.6875, - "1416448726363": 4105.842500000001, - "1416448741363": 4105.9574999999995, - "1416448756363": 4106.07, - "1416448801363": 4106.74, - "1416448816363": 4106.9175, - "1416448831363": 4107.2, - "1416448846363": 4107.3525, - "1416448861363": 4107.545, - "1416448876363": 4107.65, - "1416448921363": 4109.2625, - "1416448936363": 4109.4, - "1416448936464": 4108.2 - } +{ + "metrics": [ + { + "timestamp": 1416445244801, + "metricname": "cpu_user", + "appid": "HOST", + "hostname": "c6402.ambari.apache.org", + "starttime": 1416445244801, + "metrics": { + "1416445244801": 4006.085, + "1416445259801": 4006.29, + "1416445274801": 4006.6475, + "1416445289801": 4006.9474999999998, + "1416445304801": 4007.1025, + "1416445319801": 4007.21, + "1416445364801": 4007.8375, + "1416445379801": 4008.0425000000005, + "1416445394801": 4008.37, + "1416445409801": 4008.9474999999998, + "1416445424801": 4009.08, + "1416445439801": 4009.185, + "1416445484801": 4009.9525, + "1416445499801": 4010.19, + "1416445514801": 4010.8725, + "1416445529801": 4011.3424999999997, + "1416445544801": 4011.4975000000004, + "1416445559801": 4011.665, + "1416445604801": 4012.57, + "1416445619801": 4012.9325, + "1416445634801": 4013.3424999999997, + "1416445649801": 4013.9225, + "1416445664801": 4014.1949999999997, + "1416445679801": 4014.58, + "1416445724801": 4015.73, + "1416445739801": 4015.8599999999997, + "1416445964801": 4020.1075, + "1416445979801": 4020.2975, + "1416445994801": 4020.4624999999996, + "1416446009801": 4020.825, + "1416446024801": 4020.96, + "1416446084801": 4021.9725, + "1416446099801": 4022.2, + "1416446114801": 4022.3775, + "1416446129801": 4022.7275, + "1416446144801": 4022.98, + "1416446204801": 4023.9425, + "1416446219801": 4024.245, + "1416446234801": 4024.5275, + "1416446249801": 4024.925, + "1416446264801": 4025.03, + "1416446324801": 4026.2075, + "1416446339801": 4026.4125, + "1416446354801": 4026.5275, + "1416446369801": 4026.915, + "1416446384801": 4027.0550000000003, + "1416446444801": 4028.0975, + "1416446459801": 4028.2799999999997, + "1416446474801": 4028.4275, + "1416446489801": 4028.8375, + "1416446504801": 4028.98, + "1416446564801": 4030.005, + "1416446579801": 4030.1800000000003, + "1416446594801": 4030.365, + "1416446609801": 4030.745, + "1416446624801": 4030.895, + "1416446684801": 4031.7825, + "1416446699801": 4032.0175, + "1416446714801": 4032.2025, + "1416446729801": 4032.5525, + "1416446744801": 4032.82, + "1416446804801": 4033.7475, + "1416446819801": 4033.9700000000003, + "1416446834801": 4034.1425, + "1416446849801": 4034.4725, + "1416446864801": 4034.635, + "1416446924801": 4035.54, + "1416446939801": 4035.7175, + "1416446954801": 4035.885, + "1416446969801": 4036.255, + "1416446984801": 4036.435, + "1416447044801": 4037.8475, + "1416447059801": 4038.045, + "1416447074801": 4038.2025, + "1416447089801": 4038.7, + "1416447104801": 4038.855, + "1416447164801": 4039.7375, + "1416447179801": 4039.9025, + "1416447194801": 4040.08, + "1416447209801": 4040.42, + "1416447224801": 4040.59, + "1416447284801": 4041.51, + "1416447299801": 4041.85, + "1416447314801": 4042.6525, + "1416447329801": 4043.1025, + "1416447344801": 4043.29, + "1416447404801": 4044.265, + "1416447419801": 4044.52, + "1416447434801": 4044.705, + "1416447449801": 4045.09, + "1416447464801": 4045.325, + "1416447524801": 4046.2525, + "1416447539801": 4046.3975, + "1416447554801": 4046.55, + "1416447569801": 4046.865, + "1416447584801": 4047.0550000000003, + "1416447644801": 4049.255, + "1416448681363": 4105.1125, + "1416448696363": 4105.3625, + "1416448711363": 4105.6875, + "1416448726363": 4105.842500000001, + "1416448741363": 4105.9574999999995, + "1416448756363": 4106.07, + "1416448801363": 4106.74, + "1416448816363": 4106.9175, + "1416448831363": 4107.2, + "1416448846363": 4107.3525, + "1416448861363": 4107.545, + "1416448876363": 4107.65, + "1416448921363": 4109.2625, + "1416448936363": 4109.4, + "1416448936464": 4108.2 } + } ]} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/23faabc4/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/metrics.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/metrics.json b/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/metrics.json index bb9dca9..0040926 100644 --- a/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/metrics.json +++ b/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/metrics.json @@ -2777,7 +2777,8 @@ "metrics/dfs/datanode/heartBeats_avg_time": { "metric": "dfs.datanode.HeartbeatsAvgTime", "pointInTime": true, - "temporal": true + "temporal": true, + "amsHostMetric":true }, "metrics/rpc/closeRegion_num_ops": { "metric": "rpc.rpc.closeRegion_num_ops",