ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject git commit: AMBARI-5939. Slider view should report the list of ganglia metrics an app supports.
Date Fri, 30 May 2014 01:52:14 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.6.0.slider 1d22431b6 -> ac738258a


AMBARI-5939. Slider view should report the list of ganglia metrics an app supports.


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

Branch: refs/heads/branch-1.6.0.slider
Commit: ac738258a45ea8983257d8d764f1ceaf13bab4e1
Parents: 1d22431
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Thu May 29 18:52:06 2014 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Thu May 29 18:52:06 2014 -0700

----------------------------------------------------------------------
 .../ambari/view/slider/MetricsHolder.java       | 44 +++++++++
 .../ambari/view/slider/SliderAppType.java       | 32 +------
 .../slider/SliderAppsViewControllerImpl.java    | 22 +++--
 .../rest/client/SliderAppMasterClient.java      | 98 +++++++++++---------
 4 files changed, 113 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ac738258/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/MetricsHolder.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/MetricsHolder.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/MetricsHolder.java
new file mode 100644
index 0000000..29f35b0
--- /dev/null
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/MetricsHolder.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.view.slider;
+
+import org.apache.ambari.view.slider.rest.client.Metric;
+
+import java.util.Map;
+
+public class MetricsHolder {
+  private Map<String, Map<String, Map<String, Metric>>> jmxMetrics;
+  private Map<String, Map<String, Map<String, Metric>>> gangliaMetrics;
+
+  public Map<String, Map<String, Map<String, Metric>>> getJmxMetrics()
{
+    return jmxMetrics;
+  }
+
+  public void setJmxMetrics(Map<String, Map<String, Map<String, Metric>>>
jmxMetrics) {
+    this.jmxMetrics = jmxMetrics;
+  }
+
+  public Map<String, Map<String, Map<String, Metric>>> getGangliaMetrics()
{
+    return gangliaMetrics;
+  }
+
+  public void setGangliaMetrics(Map<String, Map<String, Map<String, Metric>>>
gangliaMetrics) {
+    this.gangliaMetrics = gangliaMetrics;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/ac738258/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppType.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppType.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppType.java
index d290680..82386af 100644
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppType.java
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppType.java
@@ -18,14 +18,9 @@
 
 package org.apache.ambari.view.slider;
 
-import org.apache.ambari.view.slider.rest.client.Metric;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-
 import java.util.List;
 import java.util.Map;
 
-@JsonIgnoreProperties({ "jmxMetrics", "gangliaMetrics" })
 public class SliderAppType {
   private String id;
   private String typeName;
@@ -34,31 +29,8 @@ public class SliderAppType {
   private Map<String, String> typeConfigs;
   private List<SliderAppTypeComponent> typeComponents;
   private String typePackageFileName;
-  @JsonIgnore
-  private Map<String, Map<String, Map<String, Metric>>> jmxMetrics;
-  @JsonIgnore
-  private Map<String, Map<String, Map<String, Metric>>> gangliaMetrics;
   private List<String> supportedMetrics;
 
-
-  @JsonIgnore
-  public Map<String, Map<String, Map<String, Metric>>> getJmxMetrics()
{
-    return jmxMetrics;
-  }
-
-  public void setJmxMetrics(Map<String, Map<String, Map<String, Metric>>>
jmxMetrics) {
-    this.jmxMetrics = jmxMetrics;
-  }
-
-  @JsonIgnore
-  public Map<String, Map<String, Map<String, Metric>>> getGangliaMetrics()
{
-    return gangliaMetrics;
-  }
-
-  public void setGangliaMetrics(Map<String, Map<String, Map<String, Metric>>>
gangliaMetrics) {
-    this.gangliaMetrics = gangliaMetrics;
-  }
-
   public List<String> getSupportedMetrics() {
     return supportedMetrics;
   }
@@ -123,4 +95,8 @@ public class SliderAppType {
     this.typePackageFileName = typePackageFileName;
   }
 
+  public String uniqueName() {
+    return getTypeName() + "-" + getTypeVersion();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/ac738258/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java
index 3f3f24f..f04c4a7 100644
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java
@@ -94,7 +94,7 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
   private AmbariClient ambariClient;
   private List<SliderAppType> appTypes;
   private Integer createAppCounter = -1;
-
+  private Map<String, MetricsHolder> appMetrics = new HashMap<String, MetricsHolder>();
   private String getAppsFolderPath() {
     return viewContext
         .getAmbariProperty(org.apache.ambari.server.configuration.Configuration.RESOURCES_DIR_KEY)
@@ -350,8 +350,8 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
               if (quickLinks != null && quickLinks.containsKey("JMX")) {
                 String jmxUrl = quickLinks.get("JMX");
                 if (matchedAppType != null) {
-                  app.setJmx(sliderAppClient.getJmx(jmxUrl, viewContext,
-                      matchedAppType));
+                  MetricsHolder metricsHolder = appMetrics.get(matchedAppType.uniqueName());
+                  app.setJmx(sliderAppClient.getJmx(jmxUrl, viewContext, matchedAppType,
metricsHolder));
                 }
               }
               Map<String, Map<String, String>> configs = sliderAppClient
@@ -444,8 +444,9 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
         }
         if (quickLinks != null && quickLinks.containsKey("Metrics")) {
           String metricsUrl = quickLinks.get("Metrics");
-          app.setMetrics(sliderAppClient.getGangliaMetrics(metricsUrl,
-              gangliaMetrics, null, viewContext, matchedAppType));
+          MetricsHolder metricsHolder = appMetrics.get(matchedAppType.uniqueName());
+          app.setMetrics(
+              sliderAppClient.getGangliaMetrics(metricsUrl, gangliaMetrics, null, viewContext,
matchedAppType, metricsHolder));
         }
       }
     }
@@ -715,11 +716,12 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
                 appTypeComponentList.add(appTypeComponent);
               }
 
-              appType.setJmxMetrics(readMetrics(zipFile, "jmx_metrics.json"));
-              appType.setGangliaMetrics(readMetrics(zipFile,
-                  "ganglia_metrics.json"));
-              appType.setSupportedMetrics(getSupportedMetrics(appType
-                  .getGangliaMetrics()));
+              MetricsHolder metricsHolder = new MetricsHolder();
+              metricsHolder.setJmxMetrics(readMetrics(zipFile, "jmx_metrics.json"));
+              metricsHolder.setGangliaMetrics(readMetrics(zipFile,
+                                                    "ganglia_metrics.json"));
+              appType.setSupportedMetrics(getSupportedMetrics(metricsHolder.getGangliaMetrics()));
+              appMetrics.put(appType.uniqueName(), metricsHolder);
 
               appType.setTypeComponents(appTypeComponentList);
               appTypes.add(appType);

http://git-wip-us.apache.org/repos/asf/ambari/blob/ac738258/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
index 7cfc4b1..15a7d2d 100644
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
@@ -24,6 +24,7 @@ import org.apache.ambari.server.controller.ganglia.GangliaMetric;
 import org.apache.ambari.server.controller.spi.TemporalInfo;
 import org.apache.ambari.view.URLStreamProvider;
 import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.slider.MetricsHolder;
 import org.apache.ambari.view.slider.SliderAppType;
 import org.apache.ambari.view.slider.SliderAppTypeComponent;
 import org.apache.commons.httpclient.HttpException;
@@ -150,57 +151,62 @@ public class SliderAppMasterClient extends BaseHttpClient {
   }
 
   public Map<String, Number[][]> getGangliaMetrics(String gangliaUrl,
-                                               Set<String> metricsRequested,
-                                               TemporalInfo temporalInfo,
-                                               ViewContext context,
-                                               SliderAppType appType) {
+                                                   Set<String> metricsRequested,
+                                                   TemporalInfo temporalInfo,
+                                                   ViewContext context,
+                                                   SliderAppType appType,
+                                                   MetricsHolder metricHolder) {
+
     Map<String, Number[][]> retVal = new HashMap<String, Number[][]>();
-    Map<String, GangliaMetric> receivedMetrics = null;
-    List<String> components = new ArrayList<String>();
-    for (SliderAppTypeComponent appTypeComponent : appType.getTypeComponents()) {
-      components.add(appTypeComponent.getName());
-    }
 
-    Map<String, Map<String, Map<String, Metric>>> metrics = appType.getGangliaMetrics();
-    Map<String, Metric> relevantMetrics = getRelevantMetrics(metrics, components);
-    Set<String> metricsToRead = new HashSet<String>();
-    Map<String, String> reverseNameLookup = new HashMap<String, String>();
-    for (String key : relevantMetrics.keySet()) {
-      if (metricsRequested.contains(key)) {
-        String metricName = relevantMetrics.get(key).getMetric();
-        metricsToRead.add(metricName);
-        reverseNameLookup.put(metricName, key);
+    if (metricHolder != null && metricHolder.getGangliaMetrics() != null) {
+      Map<String, GangliaMetric> receivedMetrics = null;
+      List<String> components = new ArrayList<String>();
+      for (SliderAppTypeComponent appTypeComponent : appType.getTypeComponents()) {
+        components.add(appTypeComponent.getName());
       }
-    }
 
-    if (metricsToRead.size() != 0) {
-      try {
-        String specWithParams = SliderAppGangliaHelper.getSpec(gangliaUrl, metricsToRead,
temporalInfo);
-        logger.info("Using spec: " + specWithParams);
-        if (specWithParams != null) {
+      Map<String, Map<String, Map<String, Metric>>> metrics = metricHolder.getGangliaMetrics();
+      Map<String, Metric> relevantMetrics = getRelevantMetrics(metrics, components);
+      Set<String> metricsToRead = new HashSet<String>();
+      Map<String, String> reverseNameLookup = new HashMap<String, String>();
+      for (String key : relevantMetrics.keySet()) {
+        if (metricsRequested.contains(key)) {
+          String metricName = relevantMetrics.get(key).getMetric();
+          metricsToRead.add(metricName);
+          reverseNameLookup.put(metricName, key);
+        }
+      }
 
-          String spec = null;
-          String params = null;
-          String[] tokens = specWithParams.split("\\?", 2);
+      if (metricsToRead.size() != 0) {
+        try {
+          String specWithParams = SliderAppGangliaHelper.getSpec(gangliaUrl, metricsToRead,
temporalInfo);
+          logger.info("Using spec: " + specWithParams);
+          if (specWithParams != null) {
 
-          try {
-            spec = tokens[0];
-            params = tokens[1];
-          } catch (ArrayIndexOutOfBoundsException e) {
-            logger.info(e.toString());
-          }
+            String spec = null;
+            String params = null;
+            String[] tokens = specWithParams.split("\\?", 2);
+
+            try {
+              spec = tokens[0];
+              params = tokens[1];
+            } catch (ArrayIndexOutOfBoundsException e) {
+              logger.info(e.toString());
+            }
 
-          receivedMetrics = SliderAppGangliaHelper.getGangliaMetrics(context, spec, params);
+            receivedMetrics = SliderAppGangliaHelper.getGangliaMetrics(context, spec, params);
+          }
+        } catch (Exception e) {
+          logger.warn("Unable to retrieve ganglia metrics. " + e.getMessage());
         }
-      } catch (Exception e) {
-        logger.warn("Unable to retrieve ganglia metrics. " + e.getMessage());
       }
-    }
 
-    if (receivedMetrics != null) {
-      for (GangliaMetric metric : receivedMetrics.values()) {
-        if (reverseNameLookup.containsKey(metric.getMetric_name())) {
-          retVal.put(reverseNameLookup.get(metric.getMetric_name()), metric.getDatapoints());
+      if (receivedMetrics != null) {
+        for (GangliaMetric metric : receivedMetrics.values()) {
+          if (reverseNameLookup.containsKey(metric.getMetric_name())) {
+            retVal.put(reverseNameLookup.get(metric.getMetric_name()), metric.getDatapoints());
+          }
         }
       }
     }
@@ -215,10 +221,12 @@ public class SliderAppMasterClient extends BaseHttpClient {
    *
    * @return
    */
-  public Map<String, String> getJmx(String jmxUrl, ViewContext context,
-                                    SliderAppType appType) {
+  public Map<String, String> getJmx(String jmxUrl,
+                                    ViewContext context,
+                                    SliderAppType appType,
+                                    MetricsHolder metricsHolder) {
     Map<String, String> jmxProperties = new HashMap<String, String>();
-    if (appType == null || appType.getJmxMetrics() == null) {
+    if (appType == null || metricsHolder == null || metricsHolder.getJmxMetrics() == null)
{
       logger
           .info("AppType must be provided and it must contain jmx_metrics.json to extract
jmx properties");
       return jmxProperties;
@@ -229,7 +237,7 @@ public class SliderAppMasterClient extends BaseHttpClient {
       components.add(appTypeComponent.getName());
     }
 
-    Map<String, Map<String, Map<String, Metric>>> metrics = appType.getJmxMetrics();
+    Map<String, Map<String, Map<String, Metric>>> metrics = metricsHolder.getJmxMetrics();
     Map<String, Metric> relevantMetrics = getRelevantMetrics(metrics, components);
     if (relevantMetrics.size() == 0) {
       logger.info("No metrics found for components defined in the app.");


Mime
View raw message