StageUtils { public static Map<String, Set<String>> getClusterHostInfo(Cluster cluster) throws AmbariException { Set<String> hostsSet = new LinkedHashSet<String>(); List<Integer> portsList = new ArrayList<Integer>(); List<String> rackList = new ArrayList<String>(); List<String> ipV4List = new ArrayList<String>(); Collection<Host> allHosts = cluster.getHosts(); for (Host host : allHosts) { hostsSet.add(host.getHostName()); Integer currentPingPort = host.getCurrentPingPort(); portsList.add(currentPingPort == null ? DEFAULT_PING_PORT : currentPingPort); String rackInfo = host.getRackInfo(); rackList.add(StringUtils.isEmpty(rackInfo) ? DEFAULT_RACK : rackInfo ); String iPv4 = host.getIPv4(); ipV4List.add(StringUtils.isEmpty(iPv4) ? DEFAULT_IPV4_ADDRESS : iPv4 ); } Map<String, Collection<String>> pendingHostComponents = topologyManager.getPendingHostComponents(); for (String hostname : pendingHostComponents.keySet()) { if (!hostsSet.contains(hostname)) { hostsSet.add(hostname); portsList.add(DEFAULT_PING_PORT); rackList.add(DEFAULT_RACK); ipV4List.add(DEFAULT_IPV4_ADDRESS); } } List<String> hostsList = new ArrayList<String>(hostsSet); Map<String, String> additionalComponentToClusterInfoKeyMap = new HashMap<String, String>(); Map<String, SortedSet<Integer>> hostRolesInfo = new HashMap<String, SortedSet<Integer>>(); for (Map.Entry<String, Service> serviceEntry : cluster.getServices().entrySet()) { Service service = serviceEntry.getValue(); for (Map.Entry<String, ServiceComponent> serviceComponentEntry : service.getServiceComponents().entrySet()) { ServiceComponent serviceComponent = serviceComponentEntry.getValue(); String componentName = serviceComponent.getName(); String roleName = componentToClusterInfoKeyMap.get(componentName); if(null == roleName) { roleName = additionalComponentToClusterInfoKeyMap.get(componentName); } if (null == roleName && !serviceComponent.isClientComponent()) { roleName = componentName.toLowerCase() + "_hosts"; additionalComponentToClusterInfoKeyMap.put(componentName, roleName); } String decomRoleName = decommissionedToClusterInfoKeyMap.get(componentName); if (roleName == null && decomRoleName == null) { continue; } for (String hostName : serviceComponent.getServiceComponentHosts().keySet()) { if (roleName != null) { SortedSet<Integer> hostsForComponentsHost = hostRolesInfo.get(roleName); if (hostsForComponentsHost == null) { hostsForComponentsHost = new TreeSet<Integer>(); hostRolesInfo.put(roleName, hostsForComponentsHost); } int hostIndex = hostsList.indexOf(hostName); hostsForComponentsHost.add(hostIndex); } if (decomRoleName != null) { ServiceComponentHost scHost = serviceComponent.getServiceComponentHost(hostName); if (scHost.getComponentAdminState() == HostComponentAdminState.DECOMMISSIONED) { SortedSet<Integer> hostsForComponentsHost = hostRolesInfo.get(decomRoleName); if (hostsForComponentsHost == null) { hostsForComponentsHost = new TreeSet<Integer>(); hostRolesInfo.put(decomRoleName, hostsForComponentsHost); } int hostIndex = hostsList.indexOf(hostName); hostsForComponentsHost.add(hostIndex); } } } } } for (Map.Entry<String, Collection<String>> entry : pendingHostComponents.entrySet()) { String hostname = entry.getKey(); Collection<String> hostComponents = entry.getValue(); for (String hostComponent : hostComponents) { String roleName = componentToClusterInfoKeyMap.get(hostComponent); if (null == roleName) { roleName = additionalComponentToClusterInfoKeyMap.get(hostComponent); } if (null == roleName) { for (Service service : cluster.getServices().values()) { for (ServiceComponent sc : service.getServiceComponents().values()) { if (!sc.isClientComponent() && sc.getName().equals(hostComponent)) { roleName = hostComponent.toLowerCase() + "_hosts"; additionalComponentToClusterInfoKeyMap.put(hostComponent, roleName); } } } } if (roleName != null) { SortedSet<Integer> hostsForComponentsHost = hostRolesInfo.get(roleName); if (hostsForComponentsHost == null) { hostsForComponentsHost = new TreeSet<Integer>(); hostRolesInfo.put(roleName, hostsForComponentsHost); } int hostIndex = hostsList.indexOf(hostname); if (hostIndex != -1) { if (!hostsForComponentsHost.contains(hostIndex)) { hostsForComponentsHost.add(hostIndex); } } else { throw new RuntimeException("Unable to get host index for host: " + hostname); } } } } Map<String, Set<String>> clusterHostInfo = new HashMap<String, Set<String>>(); for (Map.Entry<String, SortedSet<Integer>> entry : hostRolesInfo.entrySet()) { TreeSet<Integer> sortedSet = new TreeSet<Integer>(entry.getValue()); Set<String> replacedRangesSet = replaceRanges(sortedSet); clusterHostInfo.put(entry.getKey(), replacedRangesSet); } clusterHostInfo.put(HOSTS_LIST, hostsSet); clusterHostInfo.put(PORTS, replaceMappedRanges(portsList)); clusterHostInfo.put(IPV4_ADDRESSES, replaceMappedRanges(ipV4List)); clusterHostInfo.put(RACKS, replaceMappedRanges(rackList)); clusterHostInfo.put(AMBARI_SERVER_HOST, Sets.newHashSet(getHostName())); boolean serverUseSsl = configuration.getApiSSLAuthentication(); int port = serverUseSsl ? configuration.getClientSSLApiPort() : configuration.getClientApiPort(); clusterHostInfo.put(AMBARI_SERVER_PORT, Sets.newHashSet(Integer.toString(port))); clusterHostInfo.put(AMBARI_SERVER_USE_SSL, Sets.newHashSet(Boolean.toString(serverUseSsl))); return clusterHostInfo; } @Inject  StageUtils(StageFactory stageFactory); static Gson getGson(); static void setGson(Gson gson); static void setTopologyManager(TopologyManager topologyManager); static void setConfiguration(Configuration configuration); static String getActionId(long requestId, long stageId); static Map<String, String> getComponentToClusterInfoKeyMap(); static long[] getRequestStage(String actionId); static Stage getATestStage(long requestId, long stageId, String clusterHostInfo, String commandParamsStage, String hostParamsStage); @Inject static Stage getATestStage(long requestId, long stageId, String hostname, String clusterHostInfo, String commandParamsStage, String hostParamsStage); static String jaxbToString(Object jaxbObj); static T fromJson(String json, Class<T> clazz); static Map<String, String> getCommandParamsStage(ActionExecutionContext actionExecContext); static Map<String, Set<String>> getClusterHostInfo(Cluster cluster); static Map<String, Set<String>> substituteHostIndexes(Map<String, Set<String>> clusterHostInfo); static Set<String> replaceRanges(SortedSet<Integer> set); static Set<String> replaceMappedRanges(List<T> values); static String getHostName(); static final Integer DEFAULT_PING_PORT; static final String DEFAULT_RACK; static final String DEFAULT_IPV4_ADDRESS; }
@Test public void testGetClusterHostInfo() throws Exception { final HashMap<String, String> hostAttributes = new HashMap<String, String>() {{ put("os_family", "redhat"); put("os_release_version", "5.9"); }}; final Clusters clusters = createNiceMock(Clusters.class); List<Host> hosts = new ArrayList<Host>(); List<String> hostNames = new ArrayList<String>(); List<Integer> pingPorts = Arrays.asList(StageUtils.DEFAULT_PING_PORT, StageUtils.DEFAULT_PING_PORT, StageUtils.DEFAULT_PING_PORT, 8671, 8671, null, 8672, 8672, null, 8673); for (int i = 0; i < 10; i++) { String hostname = String.format("h%d", i); Host host = createNiceMock(Host.class); expect(host.getHostName()).andReturn(hostname).anyTimes(); expect(host.getHostAttributes()).andReturn(hostAttributes).anyTimes(); expect(host.getCurrentPingPort()).andReturn(pingPorts.get(i)).anyTimes(); hosts.add(host); hostNames.add(hostname); expect(clusters.getHost(hostname)).andReturn(host).anyTimes(); } final ServiceComponentHost nnh0ServiceComponentHost = createMock(ServiceComponentHost.class); expect(nnh0ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost snnh1ServiceComponentHost = createMock(ServiceComponentHost.class); expect(snnh1ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh0ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh0ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh1ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh1ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh2ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh2ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh3ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh3ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh5ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh5ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh7ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh7ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh8ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh8ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost dnh9ServiceComponentHost = createMock(ServiceComponentHost.class); expect(dnh9ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost hbm5ServiceComponentHost = createMock(ServiceComponentHost.class); expect(hbm5ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost hbrs1ServiceComponentHost = createMock(ServiceComponentHost.class); expect(hbrs1ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost hbrs3ServiceComponentHost = createMock(ServiceComponentHost.class); expect(hbrs3ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost hbrs5ServiceComponentHost = createMock(ServiceComponentHost.class); expect(hbrs5ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost hbrs8ServiceComponentHost = createMock(ServiceComponentHost.class); expect(hbrs8ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost hbrs9ServiceComponentHost = createMock(ServiceComponentHost.class); expect(hbrs9ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost mrjt5ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrjt5ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost mrtt1ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrtt1ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost mrtt2ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrtt2ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.DECOMMISSIONED).anyTimes(); final ServiceComponentHost mrtt3ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrtt3ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.DECOMMISSIONED).anyTimes(); final ServiceComponentHost mrtt4ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrtt4ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost mrtt5ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrtt5ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost mrtt7ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrtt7ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost mrtt9ServiceComponentHost = createMock(ServiceComponentHost.class); expect(mrtt9ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); final ServiceComponentHost nns7ServiceComponentHost = createMock(ServiceComponentHost.class); expect(nns7ServiceComponentHost.getComponentAdminState()).andReturn(HostComponentAdminState.INSERVICE).anyTimes(); Map<String, Collection<String>> projectedTopology = new HashMap<String, Collection<String>>(); final HashMap<String, ServiceComponentHost> nnServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h0", nnh0ServiceComponentHost); } }; insertTopology(projectedTopology, "NAMENODE", nnServiceComponentHosts.keySet()); final HashMap<String, ServiceComponentHost> snnServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h1", snnh1ServiceComponentHost); } }; insertTopology(projectedTopology, "SECONDARY_NAMENODE", snnServiceComponentHosts.keySet()); final Map<String, ServiceComponentHost> dnServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h0", dnh0ServiceComponentHost); put("h1", dnh1ServiceComponentHost); put("h2", dnh2ServiceComponentHost); put("h3", dnh3ServiceComponentHost); put("h5", dnh5ServiceComponentHost); put("h7", dnh7ServiceComponentHost); put("h8", dnh8ServiceComponentHost); put("h9", dnh9ServiceComponentHost); } }; insertTopology(projectedTopology, "DATANODE", dnServiceComponentHosts.keySet()); final Map<String, ServiceComponentHost> hbmServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h5", hbm5ServiceComponentHost); } }; insertTopology(projectedTopology, "HBASE_MASTER", hbmServiceComponentHosts.keySet()); final Map<String, ServiceComponentHost> hbrsServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h1", hbrs1ServiceComponentHost); put("h3", hbrs3ServiceComponentHost); put("h5", hbrs5ServiceComponentHost); put("h8", hbrs8ServiceComponentHost); put("h9", hbrs9ServiceComponentHost); } }; insertTopology(projectedTopology, "HBASE_REGIONSERVER", hbrsServiceComponentHosts.keySet()); final Map<String, ServiceComponentHost> mrjtServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h5", mrjt5ServiceComponentHost); } }; insertTopology(projectedTopology, "JOBTRACKER", mrjtServiceComponentHosts.keySet()); final Map<String, ServiceComponentHost> mrttServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h1", mrtt1ServiceComponentHost); put("h2", mrtt2ServiceComponentHost); put("h3", mrtt3ServiceComponentHost); put("h4", mrtt4ServiceComponentHost); put("h5", mrtt5ServiceComponentHost); put("h7", mrtt7ServiceComponentHost); put("h9", mrtt9ServiceComponentHost); } }; insertTopology(projectedTopology, "TASKTRACKER", mrttServiceComponentHosts.keySet()); final Map<String, ServiceComponentHost> nnsServiceComponentHosts = new HashMap<String, ServiceComponentHost>() { { put("h7", nns7ServiceComponentHost); } }; insertTopology(projectedTopology, "NONAME_SERVER", nnsServiceComponentHosts.keySet()); final ServiceComponent nnComponent = createMock(ServiceComponent.class); expect(nnComponent.getName()).andReturn("NAMENODE").anyTimes(); expect(nnComponent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return nnServiceComponentHosts.get(args[0]); } }).anyTimes(); expect(nnComponent.getServiceComponentHosts()).andReturn(nnServiceComponentHosts).anyTimes(); expect(nnComponent.isClientComponent()).andReturn(false).anyTimes(); final ServiceComponent snnComponent = createMock(ServiceComponent.class); expect(snnComponent.getName()).andReturn("SECONDARY_NAMENODE").anyTimes(); expect(snnComponent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return snnServiceComponentHosts.get(args[0]); } }).anyTimes(); expect(snnComponent.getServiceComponentHosts()).andReturn(snnServiceComponentHosts).anyTimes(); expect(snnComponent.isClientComponent()).andReturn(false).anyTimes(); final ServiceComponent dnComponent = createMock(ServiceComponent.class); expect(dnComponent.getName()).andReturn("DATANODE").anyTimes(); expect(dnComponent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return dnServiceComponentHosts.get(args[0]); } }).anyTimes(); expect(dnComponent.getServiceComponentHosts()).andReturn(dnServiceComponentHosts).anyTimes(); expect(dnComponent.isClientComponent()).andReturn(false).anyTimes(); final ServiceComponent hbmComponent = createMock(ServiceComponent.class); expect(hbmComponent.getName()).andReturn("HBASE_MASTER").anyTimes(); expect(hbmComponent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return hbmServiceComponentHosts.get(args[0]); } }).anyTimes(); expect(hbmComponent.getServiceComponentHosts()).andReturn(hbmServiceComponentHosts).anyTimes(); expect(hbmComponent.isClientComponent()).andReturn(false).anyTimes(); final ServiceComponent hbrsComponent = createMock(ServiceComponent.class); expect(hbrsComponent.getName()).andReturn("HBASE_REGIONSERVER").anyTimes(); expect(hbrsComponent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return hbrsServiceComponentHosts.get(args[0]); } }).anyTimes(); Map<String, ServiceComponentHost> hbrsHosts = Maps.filterKeys(hbrsServiceComponentHosts, new Predicate<String>() { @Override public boolean apply(String s) { return s.equals("h1"); } }); expect(hbrsComponent.getServiceComponentHosts()).andReturn(hbrsServiceComponentHosts).anyTimes(); expect(hbrsComponent.isClientComponent()).andReturn(false).anyTimes(); final ServiceComponent mrjtComponent = createMock(ServiceComponent.class); expect(mrjtComponent.getName()).andReturn("JOBTRACKER").anyTimes(); expect(mrjtComponent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return mrjtServiceComponentHosts.get(args[0]); } }).anyTimes(); expect(mrjtComponent.getServiceComponentHosts()).andReturn(mrjtServiceComponentHosts).anyTimes(); expect(mrjtComponent.isClientComponent()).andReturn(false).anyTimes(); final ServiceComponent mrttCompomnent = createMock(ServiceComponent.class); expect(mrttCompomnent.getName()).andReturn("TASKTRACKER").anyTimes(); expect(mrttCompomnent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return mrttServiceComponentHosts.get(args[0]); } }).anyTimes(); expect(mrttCompomnent.getServiceComponentHosts()).andReturn(mrttServiceComponentHosts).anyTimes(); expect(mrttCompomnent.isClientComponent()).andReturn(false).anyTimes(); final ServiceComponent nnsComponent = createMock(ServiceComponent.class); expect(nnsComponent.getName()).andReturn("NONAME_SERVER").anyTimes(); expect(nnsComponent.getServiceComponentHost(anyObject(String.class))) .andAnswer(new IAnswer<ServiceComponentHost>() { @Override public ServiceComponentHost answer() throws Throwable { Object[] args = getCurrentArguments(); return nnsServiceComponentHosts.get(args[0]); } }).anyTimes(); expect(nnsComponent.getServiceComponentHosts()).andReturn(nnsServiceComponentHosts).anyTimes(); expect(nnsComponent.isClientComponent()).andReturn(false).anyTimes(); final Service hdfsService = createMock(Service.class); expect(hdfsService.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>() {{ put("NAMENODE", nnComponent); put("SECONDARY_NAMENODE", snnComponent); put("DATANODE", dnComponent); }}).anyTimes(); final Service hbaseService = createMock(Service.class); expect(hbaseService.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>() {{ put("HBASE_MASTER", hbmComponent); put("HBASE_REGIONSERVER", hbrsComponent); }}).anyTimes(); final Service mrService = createMock(Service.class); expect(mrService.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>() { { put("JOBTRACKER", mrjtComponent); put("TASKTRACKER", mrttCompomnent); } }).anyTimes(); final Service nnService = createMock(Service.class); expect(nnService.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>() { { put("NONAME_SERVER", nnsComponent); } }).anyTimes(); Cluster cluster = createMock(Cluster.class); expect(cluster.getHosts()).andReturn(hosts).anyTimes(); expect(cluster.getServices()).andReturn(new HashMap<String, Service>() {{ put("HDFS", hdfsService); put("HBASE", hbaseService); put("MAPREDUCE", mrService); put("NONAME", nnService); }}).anyTimes(); final TopologyManager topologyManager = injector.getInstance(TopologyManager.class); topologyManager.getPendingHostComponents(); expectLastCall().andReturn(projectedTopology).once(); replayAll(); injector.getInstance(AmbariMetaInfo.class).init(); Map<String, Set<String>> info = StageUtils.getClusterHostInfo(cluster); verifyAll(); Set<String> allHosts = info.get(StageUtils.HOSTS_LIST); assertEquals(hosts.size(), allHosts.size()); for (Host host : hosts) { assertTrue(allHosts.contains(host.getHostName())); } checkServiceHostIndexes(info, "DATANODE", "slave_hosts", projectedTopology, hostNames); checkServiceHostIndexes(info, "NAMENODE", "namenode_host", projectedTopology, hostNames); checkServiceHostIndexes(info, "SECONDARY_NAMENODE", "snamenode_host", projectedTopology, hostNames); checkServiceHostIndexes(info, "HBASE_MASTER", "hbase_master_hosts", projectedTopology, hostNames); checkServiceHostIndexes(info, "HBASE_REGIONSERVER", "hbase_rs_hosts", projectedTopology, hostNames); checkServiceHostIndexes(info, "JOBTRACKER", "jtnode_host", projectedTopology, hostNames); checkServiceHostIndexes(info, "TASKTRACKER", "mapred_tt_hosts", projectedTopology, hostNames); checkServiceHostIndexes(info, "NONAME_SERVER", "noname_server_hosts", projectedTopology, hostNames); Set<String> actualPingPorts = info.get(StageUtils.PORTS); if (pingPorts.contains(null)) { assertEquals(new HashSet<Integer>(pingPorts).size(), actualPingPorts.size() + 1); } else { assertEquals(new HashSet<Integer>(pingPorts).size(), actualPingPorts.size()); } List<Integer> pingPortsActual = getRangeMappedDecompressedSet(actualPingPorts); List<Integer> reindexedPorts = getReindexedList(pingPortsActual, new ArrayList<String>(allHosts), hostNames); List<Integer> expectedPingPorts = new ArrayList<Integer>(pingPorts); for (int i = 0; i < expectedPingPorts.size(); i++) { if (expectedPingPorts.get(i) == null) { expectedPingPorts.set(i, StageUtils.DEFAULT_PING_PORT); } } assertEquals(expectedPingPorts, reindexedPorts); assertTrue(info.containsKey("decom_tt_hosts")); Set<String> decommissionedHosts = info.get("decom_tt_hosts"); assertEquals(2, decommissionedHosts.toString().split(",").length); assertTrue(info.containsKey(StageUtils.AMBARI_SERVER_HOST)); Set<String> serverHost = info.get(StageUtils.AMBARI_SERVER_HOST); assertEquals(1, serverHost.size()); assertEquals(StageUtils.getHostName(), serverHost.iterator().next()); assertTrue(getDecompressedSet(info.get("hbase_rs_hosts")).contains(9)); info = StageUtils.substituteHostIndexes(info); checkServiceHostNames(info, "DATANODE", "slave_hosts", projectedTopology); checkServiceHostNames(info, "NAMENODE", "namenode_host", projectedTopology); checkServiceHostNames(info, "SECONDARY_NAMENODE", "snamenode_host", projectedTopology); checkServiceHostNames(info, "HBASE_MASTER", "hbase_master_hosts", projectedTopology); checkServiceHostNames(info, "HBASE_REGIONSERVER", "hbase_rs_hosts", projectedTopology); checkServiceHostNames(info, "JOBTRACKER", "jtnode_host", projectedTopology); checkServiceHostNames(info, "TASKTRACKER", "mapred_tt_hosts", projectedTopology); checkServiceHostNames(info, "NONAME_SERVER", "noname_server_hosts", projectedTopology); }