ClouderaManagerImpl extends AbstractSoftwareManager implements SoftwareManager { @Override public ClusterReport queryClusterStatus(ClusterBlueprint blueprint) throws SoftwareManagementPluginException { if (blueprint == null) { logger.info("Empty blueprint is passed to query cluster status. Return null."); return null; } try { CmClusterDef cluster = new CmClusterDef(blueprint); syncHostsId(cluster); boolean allStarted = true; boolean allStopped = true; for (ApiService apiService : apiResourceRootV6.getClustersResource() .getServicesResource(cluster.getName()).readServices(DataView.SUMMARY)) { ApiServiceState serviceState = apiService.getServiceState(); if (!ApiServiceState.STARTED.equals(serviceState)) { allStarted = false; } else { allStopped = false; } } if (allStopped) { logger.debug("Cluster " + blueprint.getName() + " services are stopped."); cluster.getCurrentReport().setStatus(ServiceStatus.STOPPED); } else if (allStarted) { ApiHealthSummary summary = getExistingServiceHealthStatus(cluster.getName()); switch (summary) { case GOOD: cluster.getCurrentReport().setStatus(ServiceStatus.STARTED); logger.debug("Cluster " + blueprint.getName() + " is healthy."); break; case BAD: case CONCERNING: cluster.getCurrentReport().setStatus(ServiceStatus.ALERT); logger.debug("Cluster " + blueprint.getName() + " is concerning."); break; default: cluster.getCurrentReport().setStatus(ServiceStatus.STARTED); logger.debug("Cluster " + blueprint.getName() + " healthy is unavailable."); break; } } else { cluster.getCurrentReport().setStatus(ServiceStatus.ALERT); logger.debug("Cluster " + blueprint.getName() + " services are not all started yet."); } queryNodesStatus(cluster); return cluster.getCurrentReport().clone(); } catch (Exception e) { throw SoftwareManagementPluginException.QUERY_CLUSTER_STATUS_FAILED( blueprint.getName(), e); } } ClouderaManagerImpl();  ClouderaManagerImpl(String cmServerHost, int port, String user,
         String password, String privateKey);  ClouderaManagerImpl(URL url, String user, String password,
         String privateKey); RootResourceV6 getApiResourceRootV6(); @Override boolean validateServerVersion(); @Override String getName(); @Override String getDescription(); @Override String getType(); @Override List<HadoopStack> getSupportedStacks(); @Override String getSupportedConfigs(HadoopStack hadoopStack); @Override boolean validateBlueprint(ClusterBlueprint blueprint); @Override boolean createCluster(ClusterBlueprint blueprint,
         ClusterReportQueue reportQueue); @Override /** * @TODO better use a event-listener mode to decouple the reportQueue. lixl */ boolean reconfigCluster(ClusterBlueprint blueprint,
         ClusterReportQueue reportQueue); @Override boolean scaleOutCluster(ClusterBlueprint blueprint, List<String> addedNodeNames,
         ClusterReportQueue reportQueue, boolean forceScaleOut); @Override boolean deleteCluster(ClusterBlueprint clusterBlueprint,
         ClusterReportQueue reports); @Override boolean onStopCluster(ClusterBlueprint clusterBlueprint,
         ClusterReportQueue reportQueue); @Override boolean onDeleteCluster(ClusterBlueprint clusterBlueprint,
         ClusterReportQueue reports); @Override boolean onDeleteNodes(ClusterBlueprint blueprint, List<String> nodeNames); @Override boolean decomissionNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override void decommissionNode(ClusterBlueprint blueprint, String nodeGroupName, String nodeName, ClusterReportQueue reportQueue); @Override boolean recomissionNode(String clusterName, NodeInfo node, ClusterReportQueue reportQueue); @Override boolean comissionNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override boolean startNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override boolean stopNodes(String clusterName, List<NodeInfo> nodes,
         ClusterReportQueue reports); @Override String exportBlueprint(String clusterName); @Override ClusterReport queryClusterStatus(ClusterBlueprint blueprint); @Override boolean echo(); @Override HealthStatus getStatus(); boolean startCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reportQueue); @Override boolean startCluster(ClusterBlueprint clusterBlueprint, ClusterReportQueue reportQueue, boolean forceStart); String getCmServerHostId(); @Override List<String> validateRolesForScaleOut(NodeGroupInfo group); void validateRolesForShrink(NodeGroupInfo groupInfo); @Override void updateInfrastructure(ClusterBlueprint blueprint); @Override boolean hasHbase(ClusterBlueprint blueprint); @Override boolean hasMgmtRole(List<String> roles); @Override boolean isComputeOnlyRoles(List<String> roles); @Override boolean twoDataDisksRequired(NodeGroupInfo group); @Override boolean hasComputeMasterGroup(ClusterBlueprint blueprint); @Override String getVersion(); @Override HadoopStack getDefaultStack(); @Override boolean hasMountPointStartwithDatax(String clusterName); @Override void restartClusterRequiredServices(ClusterBlueprint blueprint,
         ClusterReportQueue reports); final String MIN_SUPPORTED_VERSION; }
@Test( groups = { "TestClouderaManagerImpl" }, dependsOnMethods = { "testCreateCluster" }) public void testQueryClusterStatus() { blueprint.getHadoopStack().setDistro("CDH-5.0.1"); ApiHostList hostList = rootResourceV6.getHostsResource().readHosts(DataView.SUMMARY); List<ApiHost> hosts = hostList.getHosts(); hosts.get(0).setHealthSummary(ApiHealthSummary.BAD); hosts.get(1).setHealthSummary(ApiHealthSummary.CONCERNING); hosts.get(2).setHealthSummary(ApiHealthSummary.GOOD); hosts.get(3).setHealthSummary(ApiHealthSummary.NOT_AVAILABLE); List<ApiRoleRef> roleRefs = new ArrayList<>(); String hdfsServiceName = blueprint.getName() + "_HDFS"; String yarnServiceName = blueprint.getName() + "_YARN"; ApiRoleList roleList = rootResourceV6.getClustersResource() .getServicesResource(blueprint.getName()) .getRolesResource(hdfsServiceName).readRoles(); for (ApiRole role : roleList.getRoles()) { if (role.getHostRef().getHostId().equals(hosts.get(2).getHostId())) { ApiRoleRef roleRef = new ApiRoleRef(); roleRef.setClusterName(blueprint.getName()); roleRef.setServiceName(hdfsServiceName); roleRef.setRoleName(role.getName()); roleRefs.add(roleRef); } } roleList = rootResourceV6.getClustersResource() .getServicesResource(blueprint.getName()) .getRolesResource(yarnServiceName).readRoles(); for (ApiRole role : roleList.getRoles()) { if (role.getHostRef().getHostId().equals(hosts.get(2).getHostId())) { ApiRoleRef roleRef = new ApiRoleRef(); roleRef.setClusterName(blueprint.getName()); roleRef.setServiceName(yarnServiceName); roleRef.setRoleName(role.getName()); roleRefs.add(roleRef); } } hosts.get(2).setRoleRefs(roleRefs); ClusterReport report = provider.queryClusterStatus(blueprint); Assert.assertTrue(report.getStatus() != null && report.getStatus() == ServiceStatus.STOPPED, "Status should be stopped, but got " + report.getStatus()); System.out.println("Status: " + report.getStatus()); }