ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [3/8] ambari git commit: AMBARI-14729. API does not return host component metrics except for one host. (swagle)
Date Wed, 20 Jan 2016 17:04:01 GMT
AMBARI-14729. API does not return host component metrics except for one host. (swagle)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 2e6aaf58e31928721350b026b1c4e8da9e3c48f5
Parents: d32f36e
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Tue Jan 19 15:36:22 2016 -0800
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Tue Jan 19 15:36:22 2016 -0800

----------------------------------------------------------------------
 .../metrics/timeline/AMSPropertyProvider.java   | 57 ++++++++++++--------
 .../cache/TimelineAppMetricCacheKey.java        | 36 ++++++++-----
 .../cache/TimelineMetricsCacheSizeOfEngine.java |  4 +-
 3 files changed, 61 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2e6aaf58/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 b9f54db..acbf1cf 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
@@ -51,6 +51,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -67,6 +68,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
   private final TimelineMetricCache metricCache;
   private static AtomicInteger printSkipPopulateMsgHostCounter = new AtomicInteger(0);
   private static AtomicInteger printSkipPopulateMsgHostCompCounter = new AtomicInteger(0);
+  private static final Map<String, String> timelineAppIdCache = new ConcurrentHashMap<>(10);
 
   public AMSPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
                              URLStreamProvider streamProvider,
@@ -175,7 +177,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
       Long startTime = (metricCacheKey.getTemporalInfo() != null) ? metricCacheKey.getTemporalInfo().getStartTimeMillis():null;
       Long endTime = (metricCacheKey.getTemporalInfo() != null) ? metricCacheKey.getTemporalInfo().getEndTimeMillis():null;
 
-      return requestHelper.fetchTimelineMetrics(uriBuilder,startTime, endTime);
+      return requestHelper.fetchTimelineMetrics(uriBuilder, startTime, endTime);
     }
 
 
@@ -214,7 +216,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
           try {
             metricsResponse = getTimelineMetricsFromCache(
               getTimelineAppMetricCacheKey(hostComponentHostMetrics,
-                componentName, uriBuilder.toString()), componentName);
+                componentName, hostnames, uriBuilder.toString()), componentName);
           } catch (IOException e) {
             if (LOG.isDebugEnabled()) {
               LOG.debug("Caught exception fetching metric data.", e);
@@ -236,7 +238,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
           try {
             metricsResponse = getTimelineMetricsFromCache(
               getTimelineAppMetricCacheKey(nonHostComponentMetrics,
-                componentName, uriBuilder.toString()), componentName);
+                componentName, hostnames, uriBuilder.toString()), componentName);
           } catch (IOException e) {
             if (LOG.isDebugEnabled()) {
               LOG.debug("Caught exception fetching metric data.", e);
@@ -284,6 +286,33 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
       return Collections.emptySet();
     }
 
+    private String getTimelineAppId(String componentName) {
+      if (timelineAppIdCache.containsKey(componentName)) {
+        return timelineAppIdCache.get(componentName);
+      } else {
+        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){
+              timelineAppIdCache.put(componentName, timeLineAppId);
+              return timeLineAppId;
+            }
+          }
+        } catch (Exception e) {
+          e.printStackTrace();
+        }
+      }
+
+      return componentName;
+    }
+
     private void setQueryParams(String metricsParam, String hostname,
                                 boolean isHostMetric, String componentName) {
       // Reuse uriBuilder
@@ -303,23 +332,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
       } else {
         if (componentName != null && !componentName.isEmpty()
             && !componentName.equalsIgnoreCase("HOST")) {
-          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();
-          }
+          componentName = getTimelineAppId(componentName);
         }
         uriBuilder.setParameter("appId", componentName);
       }
@@ -426,10 +439,10 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider
{
 
     // Called when host component metrics are present
     private TimelineAppMetricCacheKey getTimelineAppMetricCacheKey(Set<String> metrics,
-        String componentName, String spec) {
+        String hostnames, String componentName, String spec) {
 
       TimelineAppMetricCacheKey metricCacheKey =
-        new TimelineAppMetricCacheKey(metrics, componentName, temporalInfo);
+        new TimelineAppMetricCacheKey(metrics, componentName, hostnames, temporalInfo);
 
       // Set Uri on the cache key so the only job of the cache update is
       // tweaking the params. Note: Passing UriBuilder reference is unsafe

http://git-wip-us.apache.org/repos/asf/ambari/blob/2e6aaf58/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineAppMetricCacheKey.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineAppMetricCacheKey.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineAppMetricCacheKey.java
index 76bc73b..a5a2168 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineAppMetricCacheKey.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineAppMetricCacheKey.java
@@ -32,16 +32,23 @@ import java.util.Set;
 public class TimelineAppMetricCacheKey {
   private final Set<String> metricNames;
   private final String appId;
+  private final String hostNames;
   private String spec;
   private TemporalInfo temporalInfo;
 
   public TimelineAppMetricCacheKey(Set<String> metricNames, String appId,
-                                   TemporalInfo temporalInfo) {
+                                   String hostNames, TemporalInfo temporalInfo) {
     this.metricNames = metricNames;
     this.appId = appId;
+    this.hostNames = hostNames;
     this.temporalInfo = temporalInfo;
   }
 
+  public TimelineAppMetricCacheKey(Set<String> metricNames, String appId,
+                                   TemporalInfo temporalInfo) {
+    this(metricNames, appId, null, temporalInfo);
+  }
+
   public Set<String> getMetricNames() {
     return metricNames;
   }
@@ -67,6 +74,10 @@ public class TimelineAppMetricCacheKey {
     return appId;
   }
 
+  public String getHostNames() {
+    return hostNames;
+  }
+
   /**
    * Actual http request Uri, this does not contribute to the key behavior,
    * it is used solely for interoperability between @AMSPropertyProvider.MetricsRequest
@@ -92,28 +103,27 @@ public class TimelineAppMetricCacheKey {
 
     TimelineAppMetricCacheKey that = (TimelineAppMetricCacheKey) o;
 
-    if (appId != null ? !appId.equals(that.appId) : that.appId != null)
-      return false;
-    if (metricNames != null ? !metricNames.equals(that.metricNames) : that.metricNames !=
null)
-      return false;
+    if (!metricNames.equals(that.metricNames)) return false;
+    if (!appId.equals(that.appId)) return false;
+    return !(hostNames != null ? !hostNames.equals(that.hostNames) : that.hostNames != null);
 
-    return true;
   }
 
   @Override
   public int hashCode() {
-    int result = metricNames != null ? metricNames.hashCode() : 0;
-    result = 31 * result + (appId != null ? appId.hashCode() : 0);
+    int result = metricNames.hashCode();
+    result = 31 * result + appId.hashCode();
+    result = 31 * result + (hostNames != null ? hostNames.hashCode() : 0);
     return result;
   }
 
   @Override
   public String toString() {
-    return "TimelineAppMetricCacheKey {" +
-      "metricNames = " + metricNames +
-      ", appId = '" + appId + '\'' +
-      ", temporalInfo = " + temporalInfo +
-      ", uriInfo = " + spec +
+    return "TimelineAppMetricCacheKey{" +
+      "metricNames=" + metricNames +
+      ", appId='" + appId + '\'' +
+      ", hostNames=" + hostNames +
+      ", spec='" + spec + '\'' +
       '}';
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/2e6aaf58/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricsCacheSizeOfEngine.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricsCacheSizeOfEngine.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricsCacheSizeOfEngine.java
index 2828a49..a1d29e4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricsCacheSizeOfEngine.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricsCacheSizeOfEngine.java
@@ -59,7 +59,7 @@ public class TimelineMetricsCacheSizeOfEngine implements SizeOfEngine {
       reflectionSizeOf.sizeOf(new Double(2.0));
 
     //SizeOfMapEntryOverhead = SizeOfMapWithOneEntry - (SizeOfEmptyMap + SizeOfOneEntry)
-    TreeMap<Long,Double> map = new TreeMap<>();
+    TreeMap<Long, Double> map = new TreeMap<>();
     long emptyMapSize = reflectionSizeOf.sizeOf(map);
     map.put(new Long(1), new Double(2.0));
     long sizeOfMapOneEntry = reflectionSizeOf.deepSizeOf(DEFAULT_MAX_DEPTH, DEFAULT_ABORT_WHEN_MAX_DEPTH_EXCEEDED,
map).getCalculated();
@@ -95,6 +95,8 @@ public class TimelineMetricsCacheSizeOfEngine implements SizeOfEngine {
       reflectionSizeOf.deepSizeOf(1000, false, key.getMetricNames()).getCalculated() : 0;
     size += key.getSpec() != null ?
       reflectionSizeOf.deepSizeOf(1000, false, key.getSpec()).getCalculated() : 0;
+    size += key.getHostNames() != null ?
+      reflectionSizeOf.deepSizeOf(1000, false, key.getHostNames()).getCalculated() : 0;
     // 4 fixed longs of @TemporalInfo + reference
     size += 40;
     size += 8; // Object overhead


Mime
View raw message