ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpapirkovs...@apache.org
Subject [2/2] ambari git commit: AMBARI-15375. NPE while gathering JMX ports from configs. (mpapirkovskyy)
Date Fri, 11 Mar 2016 15:18:56 GMT
AMBARI-15375. NPE while gathering JMX ports from configs. (mpapirkovskyy)


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

Branch: refs/heads/trunk
Commit: 962a9730454f1b771d08ff3280f773a8a1251b7e
Parents: 39eded4
Author: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Authored: Thu Mar 10 17:00:31 2016 +0200
Committer: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Committed: Fri Mar 11 16:37:36 2016 +0200

----------------------------------------------------------------------
 .../internal/AbstractProviderModule.java        | 27 +++++++++++++-------
 .../internal/StackDefinedPropertyProvider.java  |  4 +--
 .../internal/JMXHostProviderTest.java           |  3 +++
 3 files changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/962a9730/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
index b96addb..30e5b9c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
@@ -66,6 +66,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import static org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService.GANGLIA;
 import static org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService.TIMELINE_METRICS;
@@ -199,8 +200,8 @@ public abstract class AbstractProviderModule implements ProviderModule,
   /**
    * JMX ports read from the configs
    */
-  private final Map<String, Map<String, Map<String, String>> >jmxPortMap
=
-      new HashMap<String, Map<String, Map<String, String>>>();
+  private final Map<String, ConcurrentMap<String, ConcurrentMap<String, String>>
>jmxPortMap =
+      Collections.synchronizedMap(new HashMap<String, ConcurrentMap<String, ConcurrentMap<String,
String>>>());
 
   private volatile boolean initialized = false;
 
@@ -494,12 +495,12 @@ public abstract class AbstractProviderModule implements ProviderModule,
   @Override
   public String getPort(String clusterName, String componentName, String hostName, boolean
httpsEnabled) throws SystemException {
     // Parent map need not be synchronized
-    Map<String, Map<String, String>> clusterJmxPorts = jmxPortMap.get(clusterName);
+    ConcurrentMap<String, ConcurrentMap<String, String>> clusterJmxPorts = jmxPortMap.get(clusterName);
     if (clusterJmxPorts == null) {
       synchronized (jmxPortMap) {
         clusterJmxPorts = jmxPortMap.get(clusterName);
         if (clusterJmxPorts == null) {
-          clusterJmxPorts = new ConcurrentHashMap<String, Map<String, String>>();
+          clusterJmxPorts = new ConcurrentHashMap<String, ConcurrentMap<String, String>>();
           jmxPortMap.put(clusterName, clusterJmxPorts);
         }
       }
@@ -547,20 +548,28 @@ public abstract class AbstractProviderModule implements ProviderModule,
             // this will trigger using the default port for the component
             String portString = getPortString(entry.getValue());
             if (null != portString) {
-              if(!clusterJmxPorts.containsKey(hostName)) {
-                clusterJmxPorts.put(hostName, new ConcurrentHashMap<String, String>());
-              }
+              clusterJmxPorts.putIfAbsent(hostName, new ConcurrentHashMap<String, String>());
               clusterJmxPorts.get(hostName).put(entry.getKey(), portString);
             }
           }
         }
       } catch (Exception e) {
-        LOG.error("Exception initializing jmx port maps. " + e);
+        LOG.error("Exception initializing jmx port maps. ", e);
       }
     }
 
     LOG.debug("jmxPortMap -> " + jmxPortMap);
-    return clusterJmxPorts.get(hostName).get(componentName);
+
+    ConcurrentMap<String, String> hostJmxPorts = clusterJmxPorts.get(hostName);
+    if (hostJmxPorts == null) {
+      LOG.debug("Jmx ports not loaded from properties: clusterName={}, componentName={},
hostName={}, " +
+          "clusterJmxPorts={}, jmxPortMap.get(clusterName)={}",
+          clusterName, componentName, hostName, clusterJmxPorts, jmxPortMap.get(clusterName));
+      //returning null is acceptable in cases when property with port not present
+      //or loading from property is not supported for specific component
+      return null;
+    }
+    return hostJmxPorts.get(componentName);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/962a9730/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 edd11c1..6c40d14 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
@@ -209,8 +209,8 @@ public class StackDefinedPropertyProvider implements PropertyProvider
{
     } catch (AuthorizationException e) {
       // Need to rethrow the catched 'AuthorizationException'.
       throw e;
-    }
-    catch (Exception e) {
+    } catch (Exception e) {
+      LOG.error("Error loading deferred resources", e);
       throw new SystemException("Error loading deferred resources", e);
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/962a9730/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
index 187e0a6..70e21d3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
@@ -543,6 +543,9 @@ public class JMXHostProviderTest {
     //Unrelated ports
     Assert.assertEquals("70070", providerModule.getPort("c1", "NAMENODE", "localhost"));
     Assert.assertEquals(null, providerModule.getPort("c1", "JOBTRACKER", "localhost"));
+
+    //test another host and component without property
+    Assert.assertNull(providerModule.getPort("c1", "HBASE_REGIONSERVER", "remotehost1"));
   }
 
   private static class JMXHostProviderModule extends AbstractProviderModule {


Mime
View raw message