ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnettle...@apache.org
Subject ambari git commit: AMBARI-14723. NPE when provisioning cluster with a Cluster template which doesn't contain all hostgroups defined in Blueprint. (Sandor Magyari via rnettleton)
Date Wed, 20 Jan 2016 18:41:42 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 362d4850e -> 8220dd883


AMBARI-14723. NPE when provisioning cluster with a Cluster template which doesn't contain
all hostgroups defined in Blueprint. (Sandor Magyari via rnettleton)


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

Branch: refs/heads/branch-2.2
Commit: 8220dd883a4b3b3909964f65b607d4376b219150
Parents: 362d485
Author: Bob Nettleton <rnettleton@hortonworks.com>
Authored: Wed Jan 20 13:40:56 2016 -0500
Committer: Bob Nettleton <rnettleton@hortonworks.com>
Committed: Wed Jan 20 13:40:56 2016 -0500

----------------------------------------------------------------------
 .../server/topology/ClusterTopologyImpl.java    |  7 ++++-
 .../topology/ClusterTopologyImplTest.java       | 28 +++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8220dd88/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
index 91965f1..05dc504 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
@@ -173,7 +173,12 @@ public class ClusterTopologyImpl implements ClusterTopology {
     Collection<String> hosts = new ArrayList<String>();
     Collection<String> hostGroups = getHostGroupsForComponent(component);
     for (String group : hostGroups) {
-      hosts.addAll(getHostGroupInfo().get(group).getHostNames());
+      HostGroupInfo hostGroupInfo = getHostGroupInfo().get(group);
+      if (hostGroupInfo != null) {
+        hosts.addAll(hostGroupInfo.getHostNames());
+      } else {
+        LOG.warn("HostGroup {} not found, when checking for hosts for component {}", group,
component);
+      }
     }
     return hosts;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8220dd88/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
index 7c68482..95e58ae 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
@@ -24,6 +24,7 @@ import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -101,6 +102,11 @@ public class ClusterTopologyImplTest {
     Set<Component> group1Components = new HashSet<Component>();
     group1Components.add(new Component("component1"));
     group1Components.add(new Component("component2"));
+
+    Set<String> group1ComponentNames = new HashSet<String>();
+    group1ComponentNames.add("component1");
+    group1ComponentNames.add("component2");
+
     Set<Component> group2Components = new HashSet<Component>();
     group2Components.add(new Component("component3"));
     Set<Component> group3Components = new HashSet<Component>();
@@ -123,6 +129,11 @@ public class ClusterTopologyImplTest {
     expect(group2.getComponents()).andReturn(group2Components).anyTimes();
     expect(group3.getComponents()).andReturn(group3Components).anyTimes();
     expect(group4.getComponents()).andReturn(group4Components).anyTimes();
+
+    expect(group1.getComponentNames()).andReturn(group1ComponentNames).anyTimes();
+    expect(group2.getComponentNames()).andReturn(Collections.singletonList("component3")).anyTimes();
+    expect(group3.getComponentNames()).andReturn(Collections.singletonList("component4")).anyTimes();
+    expect(group4.getComponentNames()).andReturn(Collections.singletonList("component5")).anyTimes();
   }
 
   @After
@@ -156,7 +167,7 @@ public class ClusterTopologyImplTest {
   }
 
   @Test
-  public void testCreate_validatorSuccess() throws Exception {
+     public void testCreate_validatorSuccess() throws Exception {
     TestTopologyRequest request = new TestTopologyRequest(TopologyRequest.Type.PROVISION);
 
     TopologyValidator validator = createStrictMock(TopologyValidator.class);
@@ -182,6 +193,21 @@ public class ClusterTopologyImplTest {
     new ClusterTopologyImpl(null, request);
   }
 
+  @Test
+  public void test_GetHostAssigmentForComponents() throws Exception {
+    TestTopologyRequest request = new TestTopologyRequest(TopologyRequest.Type.PROVISION);
+
+    TopologyValidator validator = createStrictMock(TopologyValidator.class);
+    topologyValidators.add(validator);
+
+    validator.validate((ClusterTopology) notNull());
+
+    replayAll();
+    replay(validator);
+
+    new ClusterTopologyImpl(null, request).getHostAssignmentsForComponent("component1");
+  }
+
   private class TestTopologyRequest implements TopologyRequest {
     private Type type;
 


Mime
View raw message