Browse Source

AMBARI-6700 Rest API Null Pointer Exception for non-existent host in HostRoles/host_name filter for host_components (rjaltare via jaoki)

Jun Aoki 10 years ago
parent
commit
148f5a9b8e

+ 3 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java

@@ -286,6 +286,9 @@ public class ClustersImpl implements Clusters {
     checkLoaded();
     r.lock();
     try {
+      if(!hostClusterMap.containsKey(hostname)){
+            throw new HostNotFoundException(hostname);
+      }
       if (LOG.isDebugEnabled()) {
         LOG.debug("Looking up clusters for hostname"
             + ", hostname=" + hostname

+ 8 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java

@@ -203,6 +203,7 @@ public class ClustersTest {
     String h1 = "h1";
     String h2 = "h2";
     String h3 = "h3";
+    String h4 = "h4";
 
     try {
       clusters.mapHostToCluster(h1, c1);
@@ -235,6 +236,13 @@ public class ClustersTest {
     clusters.getHost(h2).persist();
     clusters.getHost(h3).persist();
 
+    try {
+        clusters.getClustersForHost(h4);
+        fail("Expected exception for invalid host");
+    } catch (HostNotFoundException e) {
+          // Expected
+    }
+
     Set<Cluster> c = clusters.getClustersForHost(h3);
     Assert.assertEquals(0, c.size());