AMBARI-7009. BE: Configs recommendation API generates incorrect host-groups


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

Branch: refs/heads/branch-alerts-dev
Commit: 336a63dac9436d35532135e1e719fa3f8b6ac12f
Parents: 98660b9
Author: Srimanth Gunturi <sgunt...@hortonworks.com>
Authored: Mon Aug 25 17:18:01 2014 -0700
Committer: Srimanth Gunturi <sgunt...@hortonworks.com>
Committed: Mon Aug 25 17:41:24 2014 -0700

----------------------------------------------------------------------
 .../GetConfigurationRecommnedationCommand.java  |   5 +-
 ...tConfigurationRecommnedationCommandTest.java | 103 +++++++++++++++++++
 2 files changed, 105 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/336a63da/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommand.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommand.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommand.java
index 52df3d0..b20c966 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommand.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommand.java
@@ -63,10 +63,9 @@ public class GetConfigurationRecommnedationCommand extends
     return response;
   }
 
-  private Set<HostGroup> processHostGroups(StackAdvisorRequest request) {
-
+  protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) {
     Set<HostGroup> resultSet = new HashSet<HostGroup>();
-    for (Map.Entry<String, Set<String>> componentHost : 
request.getComponentHostsMap().entrySet()) {
+    for (Map.Entry<String, Set<String>> componentHost : 
request.getHostComponents().entrySet()) {
       String hostGroupName = componentHost.getKey();
       Set<String> components = componentHost.getValue();
       if (hostGroupName != null && components != null) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/336a63da/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommandTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommandTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommandTest.java
new file mode 100644
index 0000000..1bd66a4
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/GetConfigurationRecommnedationCommandTest.java
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.stackadvisor.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest;
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRunner;
+import 
org.apache.ambari.server.api.services.stackadvisor.recommendations.RecommendationResponse;
+import org.junit.Test;
+
+public class GetConfigurationRecommnedationCommandTest {
+
+  @Test
+  public void testProcessHostGroups() throws Exception {
+    StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
+    File file = mock(File.class);
+    AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
+    GetConfigurationRecommnedationCommand command = new 
GetConfigurationRecommnedationCommand(file, "script", 1, saRunner, metaInfo);
+
+    StackAdvisorRequest request = mock(StackAdvisorRequest.class);
+    Map<String, Set<String>> componentHostGroupMap = new HashMap<String, 
Set<String>>();
+    Set<String> components1 = new HashSet<String>();
+    components1.add("component1");
+    components1.add("component4");
+    components1.add("component5");
+    componentHostGroupMap.put("group1", components1);
+    Set<String> components2 = new HashSet<String>();
+    components2.add("component2");
+    components2.add("component3");
+    componentHostGroupMap.put("group2", components2);
+    doReturn(componentHostGroupMap).when(request).getHostComponents();
+    Set<RecommendationResponse.HostGroup> hostGroups = 
command.processHostGroups(request);
+
+    assertNotNull(hostGroups);
+    assertEquals(2, hostGroups.size());
+    Map<String, RecommendationResponse.HostGroup> hostGroupMap =
+        new HashMap<String, RecommendationResponse.HostGroup>();
+    for (RecommendationResponse.HostGroup hostGroup : hostGroups) {
+      hostGroupMap.put(hostGroup.getName(), hostGroup);
+    }
+    RecommendationResponse.HostGroup hostGroup1 = hostGroupMap.get("group1");
+    assertNotNull(hostGroup1);
+    Set<Map<String, String>> host1Components = hostGroup1.getComponents();
+    assertNotNull(host1Components);
+    assertEquals(3, host1Components.size());
+    Set<String> componentNames1 = new HashSet<String>();
+    for (Map<String, String> host1Component : host1Components) {
+      assertNotNull(host1Component);
+      assertEquals(1, host1Component.size());
+      String componentName = host1Component.get("name");
+      assertNotNull(componentName);
+      componentNames1.add(componentName);
+    }
+    assertEquals(3, componentNames1.size());
+    assertTrue(componentNames1.contains("component1"));
+    assertTrue(componentNames1.contains("component4"));
+    assertTrue(componentNames1.contains("component5"));
+    RecommendationResponse.HostGroup hostGroup2 = hostGroupMap.get("group2");
+    assertNotNull(hostGroup2);
+    Set<Map<String, String>> host2Components = hostGroup2.getComponents();
+    assertNotNull(host2Components);
+    assertEquals(2, host2Components.size());
+    Set<String> componentNames2 = new HashSet<String>();
+    for (Map<String, String> host2Component : host2Components) {
+      assertNotNull(host2Component);
+      assertEquals(1, host2Component.size());
+      String componentName = host2Component.get("name");
+      assertNotNull(componentName);
+      componentNames2.add(componentName);
+    }
+    assertEquals(2, componentNames2.size());
+    assertTrue(componentNames2.contains("component2"));
+    assertTrue(componentNames2.contains("component3"));
+  }
+}
\ No newline at end of file

Reply via email to