@Test public void testProcessHostGroups() throws Exception { StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class); File file = mock(File.class); AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class); ConfigurationRecommendationCommand command = new ConfigurationRecommendationCommand(file, "1w", "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")); }
protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) { Set<HostGroup> resultSet = new HashSet<HostGroup>(); for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) { String hostGroupName = componentHost.getKey(); Set<String> components = componentHost.getValue(); if (hostGroupName != null && components != null) { HostGroup hostGroup = new HostGroup(); Set<Map<String, String>> componentsSet = new HashSet<Map<String, String>>(); for (String component : components) { Map<String, String> componentMap = new HashMap<String, String>(); componentMap.put("name", component); componentsSet.add(componentMap); } hostGroup.setComponents(componentsSet); hostGroup.setName(hostGroupName); resultSet.add(hostGroup); } } return resultSet; }
ConfigurationRecommendationCommand extends
    StackAdvisorCommand<RecommendationResponse> { protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) { Set<HostGroup> resultSet = new HashSet<HostGroup>(); for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) { String hostGroupName = componentHost.getKey(); Set<String> components = componentHost.getValue(); if (hostGroupName != null && components != null) { HostGroup hostGroup = new HostGroup(); Set<Map<String, String>> componentsSet = new HashSet<Map<String, String>>(); for (String component : components) { Map<String, String> componentMap = new HashMap<String, String>(); componentMap.put("name", component); componentsSet.add(componentMap); } hostGroup.setComponents(componentsSet); hostGroup.setName(hostGroupName); resultSet.add(hostGroup); } } return resultSet; } }
ConfigurationRecommendationCommand extends
    StackAdvisorCommand<RecommendationResponse> { protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) { Set<HostGroup> resultSet = new HashSet<HostGroup>(); for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) { String hostGroupName = componentHost.getKey(); Set<String> components = componentHost.getValue(); if (hostGroupName != null && components != null) { HostGroup hostGroup = new HostGroup(); Set<Map<String, String>> componentsSet = new HashSet<Map<String, String>>(); for (String component : components) { Map<String, String> componentMap = new HashMap<String, String>(); componentMap.put("name", component); componentsSet.add(componentMap); } hostGroup.setComponents(componentsSet); hostGroup.setName(hostGroupName); resultSet.add(hostGroup); } } return resultSet; } ConfigurationRecommendationCommand(File recommendationsDir, String recommendationsArtifactsLifetime, String stackAdvisorScript, int requestId,
                                            StackAdvisorRunner saRunner, AmbariMetaInfo metaInfo); }
ConfigurationRecommendationCommand extends
    StackAdvisorCommand<RecommendationResponse> { protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) { Set<HostGroup> resultSet = new HashSet<HostGroup>(); for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) { String hostGroupName = componentHost.getKey(); Set<String> components = componentHost.getValue(); if (hostGroupName != null && components != null) { HostGroup hostGroup = new HostGroup(); Set<Map<String, String>> componentsSet = new HashSet<Map<String, String>>(); for (String component : components) { Map<String, String> componentMap = new HashMap<String, String>(); componentMap.put("name", component); componentsSet.add(componentMap); } hostGroup.setComponents(componentsSet); hostGroup.setName(hostGroupName); resultSet.add(hostGroup); } } return resultSet; } ConfigurationRecommendationCommand(File recommendationsDir, String recommendationsArtifactsLifetime, String stackAdvisorScript, int requestId,
                                            StackAdvisorRunner saRunner, AmbariMetaInfo metaInfo);  }
ConfigurationRecommendationCommand extends
    StackAdvisorCommand<RecommendationResponse> { protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) { Set<HostGroup> resultSet = new HashSet<HostGroup>(); for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) { String hostGroupName = componentHost.getKey(); Set<String> components = componentHost.getValue(); if (hostGroupName != null && components != null) { HostGroup hostGroup = new HostGroup(); Set<Map<String, String>> componentsSet = new HashSet<Map<String, String>>(); for (String component : components) { Map<String, String> componentMap = new HashMap<String, String>(); componentMap.put("name", component); componentsSet.add(componentMap); } hostGroup.setComponents(componentsSet); hostGroup.setName(hostGroupName); resultSet.add(hostGroup); } } return resultSet; } ConfigurationRecommendationCommand(File recommendationsDir, String recommendationsArtifactsLifetime, String stackAdvisorScript, int requestId,
                                            StackAdvisorRunner saRunner, AmbariMetaInfo metaInfo);   }