AMBARI-7650. RestMetricsPropertyProvider adds Storm metrics to all components 
(aonishuk)


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

Branch: refs/heads/branch-1.7.0
Commit: 8c1dc9514bcf02cf15d3a0238cfb4b432b6b1924
Parents: a70258b
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Mon Oct 6 19:54:51 2014 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Mon Oct 6 19:54:51 2014 +0300

----------------------------------------------------------------------
 .../internal/StackDefinedPropertyProvider.java   | 10 ++++++----
 .../metrics/RestMetricsPropertyProvider.java     | 19 +++++++++++++------
 2 files changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8c1dc951/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java
index 32411e9..4ecc2f0 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java
@@ -168,7 +168,8 @@ public class StackDefinedPropertyProvider implements 
PropertyProvider {
               pp = getDelegate(m,
                   streamProvider, metricsHostProvider,
                   clusterNamePropertyId, hostNamePropertyId,
-                  componentNamePropertyId, resourceStatePropertyId);
+                  componentNamePropertyId, resourceStatePropertyId,
+                  componentName);
             }
             if(pp != null) {
               additional.add(pp);
@@ -292,7 +293,8 @@ public class StackDefinedPropertyProvider implements 
PropertyProvider {
                                        String clusterNamePropertyId,
                                        String hostNamePropertyId,
                                        String componentNamePropertyId,
-                                       String statePropertyId) {
+                                       String statePropertyId,
+                                       String componentName) {
     Map<String, PropertyInfo> metrics = getPropertyInfo(definition);
     HashMap<String, Map<String, PropertyInfo>> componentMetrics =
         new HashMap<String, Map<String, PropertyInfo>>();
@@ -325,13 +327,13 @@ public class StackDefinedPropertyProvider implements 
PropertyProvider {
          */
         Constructor<?> ct = clz.getConstructor(Injector.class, Map.class,
             Map.class, StreamProvider.class, MetricsHostProvider.class,
-            String.class, String.class, String.class, String.class);
+            String.class, String.class, String.class, String.class, 
String.class);
         Object o = ct.newInstance(
             injector,
             definition.getProperties(), componentMetrics,
             streamProvider, metricsHostProvider,
             clusterNamePropertyId, hostNamePropertyId,
-            componentNamePropertyId, statePropertyId);
+            componentNamePropertyId, statePropertyId, componentName);
         return PropertyProvider.class.cast(o);
       } catch (Exception e) {
         LOG.info("Could not find contructor for type '" +

http://git-wip-us.apache.org/repos/asf/ambari/blob/8c1dc951/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProvider.java
index 48d06b8..e8b054f 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProvider.java
@@ -77,6 +77,7 @@ public class RestMetricsPropertyProvider extends 
MetricsProvider {
   private final String componentNamePropertyId;
   private final String statePropertyId;
   private MetricsHostProvider metricsHostProvider;
+  private final String componentName;
 
   private static final String DEFAULT_PORT_PROPERTY = "default_port";
   private static final String PORT_CONFIG_TYPE_PROPERTY = "port_config_type";
@@ -123,7 +124,8 @@ public class RestMetricsPropertyProvider extends 
MetricsProvider {
       String clusterNamePropertyId,
       String hostNamePropertyId,
       String componentNamePropertyId,
-      String statePropertyId) {
+      String statePropertyId,
+      String componentName){
 
     super(componentMetrics, hostNamePropertyId, metricsHostProvider);
     this.metricsProperties = metricsProperties;
@@ -133,6 +135,7 @@ public class RestMetricsPropertyProvider extends 
MetricsProvider {
     this.statePropertyId = statePropertyId;
     this.metricsHostProvider = metricsHostProvider;
     injector.injectMembers(this);
+    this.componentName = componentName;
   }
 
   // ----- MetricsProvider implementation ------------------------------------
@@ -155,6 +158,12 @@ public class RestMetricsPropertyProvider extends 
MetricsProvider {
     // Remove request properties that request temporal information
     Set<String> ids = getRequestPropertyIds(request, predicate);
     Set<String> temporalIds = new HashSet<String>();
+    String resourceComponentName = (String) 
resource.getPropertyValue(componentNamePropertyId);
+
+    if (!componentName.equals(resourceComponentName)) {
+      return resource;
+    }
+
     for (String id : ids) {
       if (request.getTemporalInfo(id) != null) {
         temporalIds.add(id);
@@ -176,8 +185,6 @@ public class RestMetricsPropertyProvider extends 
MetricsProvider {
       }
     }
 
-    String componentName = (String) 
resource.getPropertyValue(componentNamePropertyId);
-
     Map<String, PropertyInfo> propertyInfos =
         
getComponentMetrics().get(StackDefinedPropertyProvider.WRAPPED_METRICS_KEY);
     if (propertyInfos == null) {
@@ -190,14 +197,14 @@ public class RestMetricsPropertyProvider extends 
MetricsProvider {
     try {
       String clusterName = (String) 
resource.getPropertyValue(clusterNamePropertyId);
       Cluster cluster = clusters.getCluster(clusterName);
-      hostname = getHost(resource, clusterName, componentName);
+      hostname = getHost(resource, clusterName, resourceComponentName);
       if (hostname == null) {
         String msg = String.format("Unable to get component REST metrics. " +
-            "No host name for %s.", componentName);
+            "No host name for %s.", resourceComponentName);
         LOG.warn(msg);
         return resource;
       }
-      port = resolvePort(cluster, hostname, componentName, metricsProperties);
+      port = resolvePort(cluster, hostname, resourceComponentName, 
metricsProperties);
     } catch (Exception e) {
       rethrowSystemException(e);
     }

Reply via email to