ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject ambari git commit: AMBARI-11568. Metric dropdown appends aggregation to each metric.
Date Sun, 31 May 2015 15:25:45 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 4024cf366 -> 8c569a8b0


AMBARI-11568. Metric dropdown appends aggregation to each metric.


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

Branch: refs/heads/trunk
Commit: 8c569a8b0c661a10effca68f4b1b5da98fb8079d
Parents: 4024cf3
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Sun May 31 08:25:40 2015 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Sun May 31 08:25:40 2015 -0700

----------------------------------------------------------------------
 ambari-server/pom.xml                           |  5 ++
 .../internal/StackArtifactResourceProvider.java | 67 +++++++++++++++++++-
 .../StackArtifactResourceProviderTest.java      |  2 +-
 3 files changed, 71 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8c569a8b/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index ca13c7a..af37093 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1463,6 +1463,11 @@
       <artifactId>commons-csv</artifactId>
     </dependency>
     <dependency>
+      <groupId>uk.com.robust-it</groupId>
+      <artifactId>cloning</artifactId>
+      <version>1.9.2</version>
+    </dependency>
+    <dependency>
       <groupId>com.google.inject.extensions</groupId>
       <artifactId>guice-assistedinject</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8c569a8b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
index 62209e2..3dbe0a8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.controller.internal;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 import com.google.inject.Inject;
+import com.rits.cloning.Cloner;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.StackAccessException;
 import org.apache.ambari.server.StaticallyInject;
@@ -43,6 +44,7 @@ import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
 import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptorFactory;
+import org.apache.ambari.server.state.stack.Metric;
 import org.apache.ambari.server.state.stack.MetricDefinition;
 import org.apache.ambari.server.state.stack.WidgetLayout;
 import org.apache.commons.lang.StringUtils;
@@ -56,6 +58,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -330,11 +333,13 @@ public class StackArtifactResourceProvider extends AbstractControllerResourcePro
           if (stackService != null) {
             if (componentName == null) {
               // Service
-              serviceMetrics = metaInfo.getServiceMetrics(stackName, stackVersion, stackService);
+              serviceMetrics = removeAggregateFunctions(metaInfo.getServiceMetrics(stackName,
+                      stackVersion, stackService));
               descriptor = Collections.singletonMap(stackService, (Object) serviceMetrics);
             } else {
               // Component
-              componentMetrics = metaInfo.getMetrics(stackName, stackVersion, stackService,
componentName, Resource.Type.Component.name());
+              componentMetrics = removeAggregateFunctions(metaInfo.getMetrics(stackName,
+                      stackVersion, stackService, componentName, Resource.Type.Component.name()));
               descriptor = Collections.singletonMap(componentName, (Object) componentMetrics);
             }
           } else {
@@ -593,4 +598,62 @@ public class StackArtifactResourceProvider extends AbstractControllerResourcePro
     return serviceDescriptors;
   }
 
+  private Map<String, Map<String, List<MetricDefinition>>> removeAggregateFunctions(
+          Map<String, Map<String, List<MetricDefinition>>> serviceMetrics
 ) {
+    Map<String, Map<String, List<MetricDefinition>>> filteredServiceMetrics
= null;
+    if (serviceMetrics != null) {
+      Cloner cloner = new Cloner();
+      filteredServiceMetrics = cloner.deepClone(serviceMetrics);
+      // For every Component
+      for (Map<String, List<MetricDefinition>> componentMetricDef :  filteredServiceMetrics.values())
{
+        // For every Component / HostComponent category
+        for (Map.Entry<String, List<MetricDefinition>> metricDefEntry : componentMetricDef.entrySet())
{
+          //For every metric definition
+          for (MetricDefinition metricDefinition : metricDefEntry.getValue()) {
+            // Metrics System metrics only
+            if (metricDefinition.getType().equals("ganglia")) {
+              // Create a new map for each category
+              for (Map<String, Metric> metricByCategory : metricDefinition.getMetricsByCategory().values())
{
+                Iterator<Map.Entry<String, Metric>> iterator = metricByCategory.entrySet().iterator();
+                while (iterator.hasNext()) {
+                  Map.Entry<String, Metric> entry = iterator.next();
+                  String metricName = entry.getKey();
+                  if (PropertyHelper.hasAggregateFunctionSuffix(metricName)) {
+                    iterator.remove();
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+    return filteredServiceMetrics;
+  }
+
+  private List<MetricDefinition> removeAggregateFunctions(List<MetricDefinition>
componentMetrics) {
+    List<MetricDefinition> filteredComponentMetrics = null;
+    if (componentMetrics != null) {
+      Cloner cloner = new Cloner();
+      filteredComponentMetrics = cloner.deepClone(componentMetrics);
+      // For every metric definition
+      for (MetricDefinition metricDefinition : filteredComponentMetrics) {
+        // Metrics System metrics only
+        if (metricDefinition.getType().equals("ganglia")) {
+          // Create a new map for each category
+          for (Map<String, Metric> metricByCategory : metricDefinition.getMetricsByCategory().values())
{
+            Iterator<Map.Entry<String, Metric>> iterator = metricByCategory.entrySet().iterator();
+            while (iterator.hasNext()) {
+              Map.Entry<String, Metric> entry = iterator.next();
+              String metricName = entry.getKey();
+              if (PropertyHelper.hasAggregateFunctionSuffix(metricName)) {
+                iterator.remove();
+              }
+            }
+          }
+        }
+      }
+    }
+    return  filteredComponentMetrics;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8c569a8b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
index af2cbc4..f4c212c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
@@ -123,7 +123,7 @@ public class StackArtifactResourceProviderTest {
 
     Metric m1 = md.getMetrics().get("metrics/dfs/datanode/heartBeats_avg_time");
     Metric m2 = md.getMetrics().get("metrics/rpc/closeRegion_num_ops");
-    Assert.assertEquals(1630, md.getMetrics().size());
+    Assert.assertEquals(326, md.getMetrics().size());
     Assert.assertTrue(m1.isAmsHostMetric());
     Assert.assertEquals("unitless", m1.getUnit());
     Assert.assertFalse(m2.isAmsHostMetric());


Mime
View raw message