You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2016/04/19 17:10:32 UTC

ambari git commit: AMBARI-15967. JMX related parse exception on the perf cluster need to be looked at (aonishuk)

Repository: ambari
Updated Branches:
  refs/heads/trunk 77477c69c -> 0a5a721f1


AMBARI-15967. JMX related parse exception on the perf cluster need to be looked at (aonishuk)


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

Branch: refs/heads/trunk
Commit: 0a5a721f1ca6e685210a55cdf938a7d14551a0d7
Parents: 77477c6
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Tue Apr 19 18:10:11 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Tue Apr 19 18:10:11 2016 +0300

----------------------------------------------------------------------
 .../ThreadPoolEnabledPropertyProvider.java      | 21 +++++++-
 .../ThreadPoolEnabledPropertyProviderTest.java  | 51 ++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0a5a721f/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProvider.java
index fba1ef5..6f4a6ea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProvider.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller.metrics;
 
+import com.google.common.base.Throwables;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import org.apache.ambari.server.configuration.Configuration;
@@ -224,6 +225,20 @@ public abstract class ThreadPoolEnabledPropertyProvider extends AbstractProperty
     return request.getPropertyIds().isEmpty() || propertyId.startsWith(requestedPropertyId);
   }
 
+  protected static String getCacheKeyForException(final Throwable throwable) {
+    if (throwable == null) {
+      return "";
+    }
+    StringBuilder sb = new StringBuilder();
+    for (Throwable t : Throwables.getCausalChain(throwable)) {
+      if (t != null) {
+        sb.append(t.getClass().getName());
+      }
+      sb.append('\n');
+    }
+    return sb.toString();
+  }
+
   /**
    * Log an error for the given exception.
    *
@@ -234,11 +249,15 @@ public abstract class ThreadPoolEnabledPropertyProvider extends AbstractProperty
   protected static String logException(final Throwable throwable) {
     final String msg = "Caught exception getting JMX metrics : " + throwable.getLocalizedMessage();
 
+    // JsonParseException includes InputStream's hash code into the message.
+    // getMessage and printStackTrace returns a different String every time.
+    String cacheKey = getCacheKeyForException(throwable);
+
     if (LOG.isDebugEnabled()) {
       LOG.debug(msg, throwable);
     } else {
       try {
-        exceptionsCache.get(msg, new Callable<Throwable>() {
+        exceptionsCache.get(cacheKey, new Callable<Throwable>() {
           @Override
           public Throwable call() {
             LOG.error(msg + ", skipping same exceptions for next 5 minutes", throwable);

http://git-wip-us.apache.org/repos/asf/ambari/blob/0a5a721f/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProviderTest.java
new file mode 100644
index 0000000..8743fa5
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ThreadPoolEnabledPropertyProviderTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.server.controller.metrics;
+
+import org.apache.ambari.server.controller.jmx.JMXMetricHolder;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.ObjectReader;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ThreadPoolEnabledPropertyProviderTest {
+
+  @Test
+  public void testGetCacheKeyForException() throws Exception {
+    ObjectMapper jmxObjectMapper = new ObjectMapper();
+    jmxObjectMapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false);
+    ObjectReader jmxObjectReader = jmxObjectMapper.reader(JMXMetricHolder.class);
+
+    List<Exception> exceptions = new ArrayList<>();
+    for (int i = 0; i < 2; i++) {
+      try{
+        jmxObjectReader.readValue("Invalid string");
+      } catch (Exception e) {
+        // Exception messages will be different with each iteration.
+        exceptions.add(e);
+      }
+    }
+    Assert.assertEquals(ThreadPoolEnabledPropertyProvider.getCacheKeyForException(exceptions.get(0)),
+        ThreadPoolEnabledPropertyProvider.getCacheKeyForException(exceptions.get(1)));
+  }
+}