ClusterManager { public Map<String, String> getRackTopology(String clusterName, String topology) { ClusterRead cluster = clusterEntityMgr.findClusterWithNodes(clusterName, false); Set<String> hosts = new HashSet<String>(); List<NodeRead> nodes = new ArrayList<NodeRead>(); for (NodeGroupRead nodeGroup : cluster.getNodeGroups()) { for (NodeRead node : nodeGroup.getInstances()) { if (node.getMoId() != null) { hosts.add(node.getHostName()); nodes.add(node); } } } if (CommonUtil.isBlank(topology)) { topology = cluster.getTopologyPolicy().toString(); } AuAssert.check(hosts.size() > 0); clusterConfigMgr.validateRackTopologyUploaded(hosts, topology); return clusterConfigMgr.buildTopology(nodes, topology); }  JobManager getJobManager(); void setJobManager(JobManager jobManager); ClusterConfigManager getClusterConfigMgr(); void setClusterConfigMgr(ClusterConfigManager clusterConfigMgr); INetworkService getNetworkManager(); void setNetworkManager(INetworkService networkManager); IResourceService getResMgr(); @Autowired void setResMgr(IResourceService resMgr); IClusterEntityManager getClusterEntityMgr(); @Autowired void setClusterEntityMgr(IClusterEntityManager clusterEntityMgr); RackInfoManager getRackInfoMgr(); @Autowired void setRackInfoMgr(RackInfoManager rackInfoMgr); IClusteringService getClusteringService(); @Autowired void setClusteringService(IClusteringService clusteringService); IClusterHealService getClusterHealService(); @Autowired void setClusterHealService(IClusterHealService clusterHealService); IExecutionService getExecutionService(); @Autowired void setExecutionService(IExecutionService executionService); @Autowired void setSoftwareManagerCollector(SoftwareManagerCollector softwareManagerCollector); @Autowired void setShrinkManager(ShrinkManager shrinkManager); Map<String, Object> getClusterConfigManifest(String clusterName,
         List<String> targets, boolean needAllocIp); File writeClusterSpecFile(String targetName, File workDir,
         boolean needAllocIp); ClusterRead getClusterByName(String clusterName, boolean realTime); ClusterCreate getClusterSpec(String clusterName); List<ClusterRead> getClusters(Boolean realTime); @ClusterManagerPointcut Long createCluster(ClusterCreate createSpec, org.apache.commons.configuration.Configuration newParams); @ClusterManagerPointcut Long configCluster(String clusterName, ClusterCreate createSpec); long enableLdap(String clusterName); Long resumeClusterCreation(String clusterName, org.apache.commons.configuration.Configuration newParams); @ClusterManagerPointcut Long deleteClusterByName(String clusterName); @ClusterManagerPointcut Long upgradeClusterByName(String clusterName); Long startCluster(String clusterName, boolean force); @ClusterManagerPointcut Long stopCluster(String clusterName); @ClusterManagerPointcut Long resizeCluster(String clusterName, String nodeGroupName,
         int instanceNum, boolean force, org.apache.commons.configuration.Configuration newParams); @SuppressWarnings("unchecked") List<String> syncSetParam(String clusterName,
         Integer activeComputeNodeNum, Integer minComputeNodeNum, Integer maxComputeNodeNum,
         Boolean enableAuto, Priority ioPriority); @ClusterManagerPointcut Long asyncSetParam(String clusterName, Integer activeComputeNodeNum,
         Integer minComputeNodeNum, Integer maxComputeNodeNum, Boolean enableAuto,
         Priority ioPriority); @ClusterManagerPointcut @Transactional void updateCluster(ClusterCreate clusterUpdate, boolean ignoreWarning, boolean appendResource); void prioritizeCluster(String clusterName, Priority ioShares); @ClusterManagerPointcut Long fixDiskFailures(String clusterName, String groupName); Map<String, String> getRackTopology(String clusterName, String topology); HadoopStack filterDistroFromAppManager(
         SoftwareManager softwareManager, String distroName); @ClusterManagerPointcut Long expandCluster(String clusterName,
                          NodeGroupCreate[] nodeGroupsAdd); Long clusterExpandExecute(String clusterName, NodeGroupCreate[] nodeGroupsAdd, ClusterCreate clusterSpec); void recoverClusters(List<VcClusterMap> clstMaps);  }
@Test(groups = { "TestClusterManager" }, dependsOnMethods = "testAsyncSetParamAutoElasticitySuccess") public void testGetRackTopology() { IClusterEntityManager iclusterEntityManager = new MockUp<IClusterEntityManager>() { @Mock public ClusterRead findClusterWithNodes(String clusterName, boolean includeVolumns) { ClusterRead cluster = new ClusterRead(); cluster.setTopologyPolicy(TopologyType.NONE); List<NodeGroupRead> nodeGroups = new ArrayList<NodeGroupRead>(); NodeGroupRead nodeGroup = new NodeGroupRead(); List<NodeRead> nodes = new ArrayList<NodeRead>(); NodeRead node = new NodeRead(); node.setMoId("vm-01"); node.setRack("rack1"); node.setHostName("host1.com"); Map<NetTrafficType, List<IpConfigInfo>> ipConfigs = new HashMap<NetTrafficType, List<IpConfigInfo>>(); IpConfigInfo ipConfigInfo1 = new IpConfigInfo(NetTrafficType.MGT_NETWORK, "nw1", "portgroup1", "192.168.1.100"); List<IpConfigInfo> ipConfigInfos1 = new ArrayList<IpConfigInfo>(); ipConfigInfos1.add(ipConfigInfo1); IpConfigInfo ipConfigInfo2 = new IpConfigInfo(NetTrafficType.HDFS_NETWORK, "nw2", "portgroup2", "192.168.2.100"); IpConfigInfo ipConfigInfo3 = new IpConfigInfo(NetTrafficType.HDFS_NETWORK, "nw3", "portgroup3", "192.168.3.100"); List<IpConfigInfo> ipConfigInfos2 = new ArrayList<IpConfigInfo>(); ipConfigInfos2.add(ipConfigInfo2); ipConfigInfos2.add(ipConfigInfo3); ipConfigs.put(NetTrafficType.MGT_NETWORK, ipConfigInfos1); ipConfigs.put(NetTrafficType.HDFS_NETWORK, ipConfigInfos2); node.setIpConfigs(ipConfigs); nodes.add(node); nodeGroup.setInstances(nodes); nodeGroups.add(nodeGroup); cluster.setNodeGroups(nodeGroups); return cluster; } }.getMockInstance(); new MockUp<ClusterConfigManager>() { @Mock public boolean validateRackTopologyUploaded(Set<String> hosts, String topology) { return true; } @Mock public Map<String, String> buildTopology(List<NodeRead> nodes, String topology) { Map<String, String> rackTopology = new HashMap<String, String>(); Iterator<Map.Entry<ClusterNetConfigInfo.NetTrafficType, List<IpConfigInfo>>> ipConfigIt = nodes.get(0).getIpConfigs().entrySet().iterator(); while (ipConfigIt.hasNext()) { Entry<NetTrafficType, List<IpConfigInfo>> entry = ipConfigIt.next(); for (IpConfigInfo ipConfig : entry.getValue()) { rackTopology.put(ipConfig.getIpAddress(), nodes.get(0).getRack()); } } return rackTopology; } }; clusterMgr.setClusterEntityMgr(iclusterEntityManager); Map<String, String> racksTopology = clusterMgr.getRackTopology(TEST_CLUSTER_NAME, "HOST_AS_RACK"); assertEquals("rack1", racksTopology.get("192.168.1.100")); }