ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-17914 Request for HBase metrics making a call to Namenode and Nimbus for that metric (dsen)
Date Thu, 28 Jul 2016 16:16:43 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 25c5f26b6 -> 7586bdae2


AMBARI-17914 Request for HBase metrics making a call to Namenode and Nimbus for that metric
(dsen)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7586bdae
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7586bdae
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7586bdae

Branch: refs/heads/trunk
Commit: 7586bdae28e68cd8fa17998c18d5c738c14cc804
Parents: 25c5f26
Author: Dmytro Sen <dsen@apache.org>
Authored: Thu Jul 28 19:16:36 2016 +0300
Committer: Dmytro Sen <dsen@apache.org>
Committed: Thu Jul 28 19:16:36 2016 +0300

----------------------------------------------------------------------
 .../metrics/timeline/AMSPropertyProvider.java   | 16 +++++-
 .../timeline/AMSPropertyProviderTest.java       | 57 ++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7586bdae/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java
index 7ad1192..9e81df4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java
@@ -43,6 +43,7 @@ import org.apache.http.client.utils.URIBuilder;
 import java.io.IOException;
 import java.net.SocketTimeoutException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -134,6 +135,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
     // Basically a host metric to be returned for a hostcomponent
     private final Set<String> hostComponentHostMetrics = new HashSet<String>();
     private String clusterName;
+    private Map<String, Set<String>> componentMetricMap = new HashMap<>();
 
     private MetricsRequest(TemporalInfo temporalInfo, URIBuilder uriBuilder,
                            String clusterName) {
@@ -211,7 +213,10 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
 
         TimelineMetrics timelineMetrics = new TimelineMetrics();
 
-        Set<String> nonHostComponentMetrics = new HashSet<String>(metrics.keySet());
+        Set<String> nonHostComponentMetrics = componentMetricMap.get(componentName);
+        if (nonHostComponentMetrics == null) {
+          nonHostComponentMetrics = new HashSet<>();
+        }
         nonHostComponentMetrics.removeAll(hostComponentHostMetrics);
         Set<String> hostNamesBatches = splitHostNamesInBatches(getHostnames(resources.get(componentName)),
HOST_NAMES_BATCH_REQUEST_SIZE);
         Map<String, Set<TimelineMetric>> metricsMap = new HashMap<>();
@@ -444,6 +449,14 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
 
       return metricCacheKey;
     }
+
+    public void linkResourceToMetric(String componentName, String metric) {
+      if (componentMetricMap.get(componentName) == null) {
+        componentMetricMap.put(componentName, new HashSet<>(Arrays.asList(metric)));
+      } else {
+        componentMetricMap.get(componentName).add(metric);
+      }
+    }
   }
 
   private List<String> getHostnames(Set<Resource> resources) {
@@ -653,6 +666,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
             metricsRequest.putPropertyId(
               preprocessPropertyId(propertyInfo.getPropertyId(), getComponentName(resource)),
               propertyId);
+            metricsRequest.linkResourceToMetric(getComponentName(resource), preprocessPropertyId(propertyInfo.getPropertyId(),
getComponentName(resource)));
             // If request is for a host metric we need to create multiple requests
             if (propertyInfo.isAmsHostMetric()) {
               metricsRequest.putHosComponentHostMetric(propertyInfo.getPropertyId());

http://git-wip-us.apache.org/repos/asf/ambari/blob/7586bdae/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 291512a..c32e517 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
@@ -68,6 +68,7 @@ import java.lang.reflect.Method;
 import java.net.HttpURLConnection;
 import java.net.SocketTimeoutException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -137,6 +138,7 @@ public class AMSPropertyProviderTest {
     testPopulateResourcesForHostComponentHostMetrics();
     testPopulateResourcesForHostComponentMetricsForMultipleHosts();
     testPopulateResourcesHostBatches();
+    testPopulateResourcesForMultipleComponentsMetric();
   }
 
   @Test
@@ -156,6 +158,7 @@ public class AMSPropertyProviderTest {
     testPopulateResourcesForHostComponentHostMetrics();
     testPopulateResourcesForHostComponentMetricsForMultipleHosts();
     testPopulateResourcesHostBatches();
+    testPopulateResourcesForMultipleComponentsMetric();
   }
 
   @Test
@@ -175,6 +178,7 @@ public class AMSPropertyProviderTest {
     testPopulateResourcesForHostComponentHostMetrics();
     testPopulateResourcesForHostComponentMetricsForMultipleHosts();
     testPopulateResourcesHostBatches();
+    testPopulateResourcesForMultipleComponentsMetric();
   }
 
   @Test(expected = AuthorizationException.class)
@@ -196,6 +200,7 @@ public class AMSPropertyProviderTest {
     testPopulateResourcesForHostComponentHostMetrics();
     testPopulateResourcesForHostComponentMetricsForMultipleHosts();
     testPopulateResourcesHostBatches();
+    testPopulateResourcesForMultipleComponentsMetric();
   }
 
   public void testPopulateResourcesForSingleHostMetric() throws Exception {
@@ -511,6 +516,58 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(238, val.length);
   }
 
+  public void testPopulateResourcesForMultipleComponentsMetric() throws Exception {
+    setUpCommonMocks();
+    TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_COMPONENT_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.Component);
+
+    AMSPropertyProvider propertyProvider = new AMSComponentPropertyProvider(
+            propertyIds,
+            streamProvider,
+            sslConfiguration,
+            cacheProviderMock,
+            metricHostProvider,
+            CLUSTER_NAME_PROPERTY_ID,
+            COMPONENT_NAME_PROPERTY_ID
+    );
+    Set<String> requestedPropertyIds = new HashSet<>(Arrays.asList("metrics/hbase/master",
"metrics/cpu/cpu_wio"));
+    Resource resource = new ResourceImpl(Resource.Type.Component);
+    resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
+    resource.setProperty(HOST_NAME_PROPERTY_ID, "h1");
+    resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "METRICS_COLLECTOR");
+    Resource namenodeResource = new ResourceImpl(Resource.Type.Component);
+    namenodeResource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
+    namenodeResource.setProperty(HOST_NAME_PROPERTY_ID, "h1");
+    namenodeResource.setProperty(COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
+
+    Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
+    for (String propertyId : requestedPropertyIds) {
+      temporalInfoMap.put(propertyId, new TemporalInfoImpl(1416528759233L, 1416531129231L,
1L));
+    }
+    Request request = PropertyHelper.getReadRequest(
+            requestedPropertyIds, temporalInfoMap);
+    Set<Resource> resources =
+            propertyProvider.populateResources(new HashSet<>(Arrays.asList(resource,
namenodeResource)), request, null);
+    Assert.assertEquals(2, resources.size());
+    Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next());
+    Assert.assertNotNull(properties);
+    URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false);
+    uriBuilder.addParameter("metricNames", "cpu_wio");
+    uriBuilder.addParameter("appId", "NAMENODE");
+    uriBuilder.addParameter("startTime", "1416528759233");
+    uriBuilder.addParameter("endTime", "1416531129231");
+    Assert.assertTrue(streamProvider.getAllSpecs().contains(uriBuilder.toString()));
+    List<String> allSpecs = new ArrayList<>(streamProvider.getAllSpecs());
+    Assert.assertEquals(2, allSpecs.size());
+  }
+
   public void testPopulateMetricsForEmbeddedHBase() throws Exception {
     AmbariManagementController ams = createNiceMock(AmbariManagementController.class);
     PowerMock.mockStatic(AmbariServer.class);


Mime
View raw message