Repository: ambari
Updated Branches:
  refs/heads/trunk 4ce716f8e -> 41abdbb01


AMBARI-16270. Blueprint processor should create ConfigGroup even with only one 
host registered. (stoader)


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

Branch: refs/heads/trunk
Commit: 41abdbb01d2af411e1c86a9e3424cd8b068abd54
Parents: 4ce716f
Author: Toader, Sebastian <[email protected]>
Authored: Fri May 6 16:40:10 2016 +0200
Committer: Toader, Sebastian <[email protected]>
Committed: Fri May 6 16:40:27 2016 +0200

----------------------------------------------------------------------
 .../ambari/server/topology/AmbariContext.java   | 28 ++++++++++-
 .../server/topology/AmbariContextTest.java      | 52 ++++++++++++++++++++
 2 files changed, 78 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/41abdbb0/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
index dd2b7c6..e3b51c0 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
@@ -76,6 +76,11 @@ import org.apache.ambari.server.utils.RetryHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.annotation.Nullable;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
+
 /**
  * Provides topology related information as well as access to the core Ambari 
functionality.
  */
@@ -615,9 +620,28 @@ public class AmbariContext {
       groupHosts = topology.getHostGroupInfo().
           get(groupName).getHostNames();
 
+      // remove hosts that are not assigned to the cluster yet
+      String clusterName = null;
+      try {
+        clusterName = getClusterName(topology.getClusterId());
+      } catch (AmbariException e) {
+        LOG.error("Cannot get cluster name for clusterId = " + 
topology.getClusterId(), e);
+        throw new RuntimeException(e);
+      }
+
+      final Map<String, Host> clusterHosts = 
getController().getClusters().getHostsForCluster(clusterName);
+      Iterable<String> filteredGroupHosts = Iterables.filter(groupHosts, new 
com.google.common.base.Predicate<String>() {
+        @Override
+        public boolean apply(@Nullable String groupHost) {
+          return clusterHosts.containsKey(groupHost);
+        }
+      });
+
+
+
       ConfigGroupRequest request = new ConfigGroupRequest(
-          null, getClusterName(topology.getClusterId()), absoluteGroupName, 
service, "Host Group Configuration",
-          new HashSet<String>(groupHosts), serviceConfigs);
+          null, clusterName, absoluteGroupName, service, "Host Group 
Configuration",
+        Sets.newHashSet(filteredGroupHosts), serviceConfigs);
 
       // get the config group provider and create config group resource
       ConfigGroupResourceProvider configGroupProvider = 
(ConfigGroupResourceProvider)

http://git-wip-us.apache.org/repos/asf/ambari/blob/41abdbb0/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
index c9182c1..6ef240d 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
@@ -72,6 +72,7 @@ import org.junit.Test;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
 
 /**
  * AmbariContext unit tests
@@ -200,6 +201,9 @@ public class AmbariContextTest {
     expect(clusters.getHost(HOST1)).andReturn(host1).anyTimes();
     expect(clusters.getHost(HOST2)).andReturn(host2).anyTimes();
 
+    Map<String, Host> clusterHosts = ImmutableMap.of(HOST1, host1, HOST2, 
host2);
+    
expect(clusters.getHostsForCluster(CLUSTER_NAME)).andReturn(clusterHosts).anyTimes();
+
     expect(cluster.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
     expect(cluster.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
 
@@ -359,6 +363,54 @@ public class AmbariContextTest {
   }
 
   @Test
+  public void 
testRegisterHostWithConfigGroup_createNewConfigGroupWithPendingHosts() throws 
Exception {
+    // test specific expectations
+    expect(cluster.getConfigGroups()).andReturn(Collections.<Long, 
ConfigGroup>emptyMap()).once();
+    
expect(clusterController.ensureResourceProvider(Resource.Type.ConfigGroup)).andReturn(configGroupResourceProvider).once();
+    //todo: for now not using return value so just returning null
+    
expect(configGroupResourceProvider.createResources(capture(configGroupRequestCapture))).andReturn(null).once();
+    configHelper.moveDeprecatedGlobals(stackId, 
group1Configuration.getFullProperties(1), CLUSTER_NAME);
+
+    reset(group1Info);
+    
expect(group1Info.getConfiguration()).andReturn(group1Configuration).anyTimes();
+    Collection<String> groupHosts = ImmutableList.of(HOST1, HOST2, 
"pending_host"); // pending_host is not registered with the cluster
+    expect(group1Info.getHostNames()).andReturn(groupHosts).anyTimes(); // 
there are 3 hosts for the host group
+    // replay all mocks
+    replayAll();
+
+    // test
+    context.registerHostWithConfigGroup(HOST1, topology, HOST_GROUP_1);
+
+    // assertions
+    Set<ConfigGroupRequest> configGroupRequests = 
configGroupRequestCapture.getValue();
+    assertEquals(1, configGroupRequests.size());
+    ConfigGroupRequest configGroupRequest = 
configGroupRequests.iterator().next();
+    assertEquals(CLUSTER_NAME, configGroupRequest.getClusterName());
+    assertEquals("testBP:group1", configGroupRequest.getGroupName());
+    assertEquals("service1", configGroupRequest.getTag());
+    assertEquals("Host Group Configuration", 
configGroupRequest.getDescription());
+    Collection<String> requestHosts = configGroupRequest.getHosts();
+
+    // we expect only HOST1 and HOST2 in the config group request as the third 
host "pending_host" hasn't registered yet with the cluster
+    assertEquals(2, requestHosts.size());
+    assertTrue(requestHosts.contains(HOST1));
+    assertTrue(requestHosts.contains(HOST2));
+
+    Map<String, Config> requestConfig = configGroupRequest.getConfigs();
+    assertEquals(1, requestConfig.size());
+    Config type1Config = requestConfig.get("type1");
+    //todo: other properties such as cluster name are not currently being 
explicitly set on config
+    assertEquals("type1", type1Config.getType());
+    assertEquals("group1", type1Config.getTag());
+    Map<String, String> requestProps = type1Config.getProperties();
+    assertEquals(3, requestProps.size());
+    // 1.2 is overridden value
+    assertEquals("val1.2", requestProps.get("prop1"));
+    assertEquals("val2", requestProps.get("prop2"));
+    assertEquals("val3", requestProps.get("prop3"));
+  }
+
+  @Test
   public void 
testRegisterHostWithConfigGroup_registerWithExistingConfigGroup() throws 
Exception {
     // test specific expectations
     expect(cluster.getConfigGroups()).andReturn(configGroups).once();

Reply via email to