ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpapirkovs...@apache.org
Subject [1/2] ambari git commit: AMBARI-15375. NPE while gathering JMX ports from configs. (mpapirkovskyy)
Date Fri, 11 Mar 2016 15:18:32 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 fe2462876 -> 3b5a96d27


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/3b5a96d2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3b5a96d2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3b5a96d2

Branch: refs/heads/branch-2.2
Commit: 3b5a96d272423740a856411eb57a4f7f29626062
Parents: 161cbd0
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:47:04 2016 +0200

----------------------------------------------------------------------
 .../internal/AbstractProviderModule.java        | 27 +++++++++++++-------
 .../internal/StackDefinedPropertyProvider.java  |  2 +-
 .../internal/JMXHostProviderTest.java           |  3 +++
 3 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3b5a96d2/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 ff9b4e4..7747753 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/3b5a96d2/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 a1b4f3f..228ce01 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
@@ -207,7 +207,7 @@ public class StackDefinedPropertyProvider implements PropertyProvider
{
       }
 
     } catch (Exception e) {
-      e.printStackTrace();
+      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/3b5a96d2/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 8894ef8..029720e 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
@@ -537,6 +537,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