ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jai...@apache.org
Subject ambari git commit: AMBARI-11250. Publishing graphs/widgets for a new service requires ambari server code change. (Ivan via Jaimin)
Date Wed, 27 May 2015 18:42:25 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk e28a9c073 -> 90eae672d


AMBARI-11250. Publishing graphs/widgets for a new service requires ambari server code change.
(Ivan via Jaimin)


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

Branch: refs/heads/trunk
Commit: 90eae672d26bc2f9f773e948c4cf0e40e330fde3
Parents: e28a9c0
Author: Jaimin Jetly <jaimin@hortonworks.com>
Authored: Wed May 27 11:41:29 2015 -0700
Committer: Jaimin Jetly <jaimin@hortonworks.com>
Committed: Wed May 27 11:41:29 2015 -0700

----------------------------------------------------------------------
 .../metrics/timeline/AMSPropertyProvider.java   | 23 ++++-
 .../ambari/server/state/ComponentInfo.java      | 11 +++
 .../AMBARI_METRICS/0.1.0/metainfo.xml           |  1 +
 .../HBASE/0.96.0.2.0/metainfo.xml               |  2 +
 .../timeline/AMSPropertyProviderTest.java       | 96 ++++++++++++++++++++
 5 files changed, 131 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/90eae672/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 1963d8d..d7d4c0a 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
@@ -17,7 +17,10 @@
  */
 package org.apache.ambari.server.controller.metrics.timeline;
 
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.AmbariServer;
 import org.apache.ambari.server.controller.internal.PropertyInfo;
 import org.apache.ambari.server.controller.metrics.MetricHostProvider;
 import org.apache.ambari.server.controller.metrics.MetricsPropertyProvider;
@@ -27,6 +30,7 @@ import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.TemporalInfo;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
+import org.apache.ambari.server.state.StackId;
 import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetrics;
@@ -317,8 +321,23 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
       } else {
         String componentName = getComponentName(resource);
         if (componentName != null && !componentName.isEmpty()) {
-          if (TIMELINE_APPID_MAP.containsKey(componentName)) {
-            componentName = TIMELINE_APPID_MAP.get(componentName);
+          String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId);
+          StackId stackId;
+          try {
+            AmbariManagementController managementController = AmbariServer.getController();
+            stackId = managementController.getClusters().getCluster(clusterName).getCurrentStackVersion();
+            if (stackId != null) {
+              String stackName = stackId.getStackName();
+              String version = stackId.getStackVersion();
+              AmbariMetaInfo ambariMetaInfo = managementController.getAmbariMetaInfo();
+              String serviceName = ambariMetaInfo.getComponentToService(stackName,version,componentName);
+              String timeLineAppId = ambariMetaInfo.getComponent(stackName, version, serviceName,
componentName).getTimelineAppid();
+              if (timeLineAppId != null){
+                componentName = timeLineAppId;
+              }
+            }
+          } catch (Exception e) {
+            e.printStackTrace();
           }
           uriBuilder.setParameter("appId", componentName);
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/90eae672/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
index 05c0df7..fd68060 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
@@ -90,6 +90,8 @@ public class ComponentInfo {
   @XmlElement(name="auto-deploy")
   private AutoDeployInfo autoDeploy;
 
+  private String timelineAppid;
+
   public ComponentInfo() {
   }
 
@@ -109,6 +111,7 @@ public class ComponentInfo {
     autoDeploy = prototype.autoDeploy;
     configDependencies = prototype.configDependencies;
     clientConfigFiles = prototype.clientConfigFiles;
+    timelineAppid = prototype.timelineAppid;
   }
 
   public String getName() {
@@ -252,6 +255,14 @@ public class ComponentInfo {
     this.clientsToUpdateConfigs = clientsToUpdateConfigs;
   }
 
+  public String getTimelineAppid() {
+    return timelineAppid;
+  }
+
+  public void setTimelineAppid(String timelineAppid) {
+    this.timelineAppid = timelineAppid;
+  }
+
   @Override
   public boolean equals(Object o) {
     if (this == o) return true;

http://git-wip-us.apache.org/repos/asf/ambari/blob/90eae672/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/metainfo.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/metainfo.xml
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/metainfo.xml
index 6c5dd32..039cf4d 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/metainfo.xml
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/metainfo.xml
@@ -31,6 +31,7 @@
           <category>MASTER</category>
           <cardinality>1</cardinality>
           <versionAdvertised>false</versionAdvertised>
+          <timelineAppid>AMS-HBASE</timelineAppid>
           <dependencies>
             <dependency>
               <name>ZOOKEEPER/ZOOKEEPER_SERVER</name>

http://git-wip-us.apache.org/repos/asf/ambari/blob/90eae672/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metainfo.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metainfo.xml
b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metainfo.xml
index 1032024..e0d8ba2 100644
--- a/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metainfo.xml
+++ b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metainfo.xml
@@ -32,6 +32,7 @@
           <category>MASTER</category>
           <cardinality>1+</cardinality>
           <versionAdvertised>true</versionAdvertised>
+          <timelineAppid>HBASE</timelineAppid>
           <dependencies>
             <dependency>
               <name>HDFS/HDFS_CLIENT</name>
@@ -72,6 +73,7 @@
           <category>SLAVE</category>
           <cardinality>1+</cardinality>
           <versionAdvertised>true</versionAdvertised>
+          <timelineAppid>HBASE</timelineAppid>
           <commandScript>
             <script>scripts/hbase_regionserver.py</script>
             <scriptType>PYTHON</scriptType>

http://git-wip-us.apache.org/repos/asf/ambari/blob/90eae672/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 dc1ae2d..923f2f7 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
@@ -17,7 +17,11 @@
  */
 package org.apache.ambari.server.controller.metrics.timeline;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.AmbariServer;
 import org.apache.ambari.server.controller.internal.PropertyInfo;
 import org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.internal.TemporalInfoImpl;
@@ -28,9 +32,17 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.TemporalInfo;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.StackId;
 import org.apache.http.client.utils.URIBuilder;
 import org.junit.Assert;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 import java.io.File;
 import java.io.IOException;
@@ -43,9 +55,14 @@ import java.util.Map;
 import java.util.Set;
 
 import static org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService;
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
 import static org.mockito.Mockito.mock;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({AMSPropertyProvider.class, AmbariServer.class})
 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");
@@ -64,6 +81,7 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateResourcesForSingleHostMetric() throws Exception {
+    setUpCommonMocks();
     TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
     ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
@@ -102,6 +120,7 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateResourcesForSingleHostMetricPointInTime() throws Exception {
+    setUpCommonMocks();
 
     // given
     TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH);
@@ -144,6 +163,7 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateResourcesForMultipleHostMetricscPointInTime() throws Exception
{
+    setUpCommonMocks();
     TestStreamProvider streamProvider = new TestStreamProvider(MULTIPLE_HOST_METRICS_FILE_PATH);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
     ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
@@ -188,6 +208,7 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateResourcesForMultipleHostMetrics() throws Exception {
+    setUpCommonMocks();
     TestStreamProvider streamProvider = new TestStreamProvider(MULTIPLE_HOST_METRICS_FILE_PATH);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
     ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
@@ -238,6 +259,7 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateResourcesForRegexpMetrics() throws Exception {
+    setUpCommonMocks();
     TestStreamProvider streamProvider = new TestStreamProvider(MULTIPLE_COMPONENT_REGEXP_METRICS_FILE_PATH);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
     ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
@@ -286,6 +308,7 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateResourcesForSingleComponentMetric() throws Exception {
+    setUpCommonMocks();
     TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_COMPONENT_METRICS_FILE_PATH);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
     ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
@@ -328,6 +351,29 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateMetricsForEmbeddedHBase() throws Exception {
+    AmbariManagementController ams = createNiceMock(AmbariManagementController.class);
+    PowerMock.mockStatic(AmbariServer.class);
+    expect(AmbariServer.getController()).andReturn(ams);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
+    StackId stackId= new StackId("HDP","2.2");
+    expect(ams.getClusters()).andReturn(clusters).anyTimes();
+    try {
+      expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster).anyTimes();
+    } catch (AmbariException e) {
+      e.printStackTrace();
+    }
+    expect(cluster.getCurrentStackVersion()).andReturn(stackId).anyTimes();
+    expect(ams.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(ambariMetaInfo.getComponentToService("HDP", "2.2", "METRICS_COLLECTOR")).andReturn("AMS").anyTimes();
+    expect(ambariMetaInfo.getComponent("HDP", "2.2", "AMS", "METRICS_COLLECTOR"))
+            .andReturn(componentInfo).anyTimes();
+    expect(componentInfo.getTimelineAppid()).andReturn("AMS-HBASE");
+    replay(ams, clusters, cluster, ambariMetaInfo, componentInfo);
+    PowerMock.replayAll();
+
     TestStreamProvider streamProvider = new TestStreamProvider(EMBEDDED_METRICS_FILE_PATH);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
     ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
@@ -370,6 +416,29 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testAggregateFunctionForComponentMetrics() throws Exception {
+    AmbariManagementController ams = createNiceMock(AmbariManagementController.class);
+    PowerMock.mockStatic(AmbariServer.class);
+    expect(AmbariServer.getController()).andReturn(ams);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
+    StackId stackId= new StackId("HDP","2.2");
+    expect(ams.getClusters()).andReturn(clusters).anyTimes();
+    try {
+      expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster).anyTimes();
+    } catch (AmbariException e) {
+      e.printStackTrace();
+    }
+    expect(cluster.getCurrentStackVersion()).andReturn(stackId).anyTimes();
+    expect(ams.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(ambariMetaInfo.getComponentToService("HDP", "2.2", "HBASE_REGIONSERVER")).andReturn("HBASE").anyTimes();
+    expect(ambariMetaInfo.getComponent("HDP", "2.2", "HBASE", "HBASE_REGIONSERVER"))
+            .andReturn(componentInfo).anyTimes();
+    expect(componentInfo.getTimelineAppid()).andReturn("HBASE");
+    replay(ams, clusters, cluster, ambariMetaInfo, componentInfo);
+    PowerMock.replayAll();
+
     TestStreamProvider streamProvider = new TestStreamProvider(AGGREGATE_METRICS_FILE_PATH);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
     ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
@@ -439,6 +508,7 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateResourcesForHostComponentHostMetrics() throws Exception {
+    setUpCommonMocks();
     TestStreamProviderForHostComponentHostMetricsTest streamProvider =
       new TestStreamProviderForHostComponentHostMetricsTest(null);
     TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
@@ -535,4 +605,30 @@ public class AMSPropertyProviderTest {
       return true;
     }
   }
+
+  private void setUpCommonMocks() throws AmbariException {
+    AmbariManagementController ams = createNiceMock(AmbariManagementController.class);
+    PowerMock.mockStatic(AmbariServer.class);
+    expect(AmbariServer.getController()).andReturn(ams);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
+    StackId stackId= new StackId("HDP","2.2");
+    expect(ams.getClusters()).andReturn(clusters).anyTimes();
+    try {
+      expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster).anyTimes();
+    } catch (AmbariException e) {
+      e.printStackTrace();
+    }
+    expect(cluster.getCurrentStackVersion()).andReturn(stackId).anyTimes();
+    expect(ams.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(ambariMetaInfo.getComponentToService(anyObject(String.class),
+            anyObject(String.class), anyObject(String.class))).andReturn("HDFS").anyTimes();
+    expect(ambariMetaInfo.getComponent(anyObject(String.class),anyObject(String.class),
+            anyObject(String.class), anyObject(String.class)))
+            .andReturn(componentInfo).anyTimes();
+    replay(ams, clusters, cluster, ambariMetaInfo);
+    PowerMock.replayAll();
+  }
 }


Mime
View raw message