ClusterDefinition { public String getHostState(String hostName) { for (Map.Entry<String, Map<String, Set<String>>> entry : hostComponents.entrySet()) { Map<String, Set<String>> serviceHostComponents = entry.getValue(); for (Map.Entry<String, Set<String>> hostEntry : serviceHostComponents.entrySet()) { if (hostEntry.getKey().equals(hostName)) { Set<String> componentNames = hostEntry.getValue(); for (String componentName : componentNames) { if (isClientOnlyComponent(componentName)) continue; if (stateProvider.getRunningState(hostName, componentName) != StateProvider.State.Running) { return "UNHEALTHY"; } } } } } return "HEALTHY"; } ClusterDefinition(StateProvider stateProvider,
                           ClusterDefinitionProvider definitionProvider,
                           HostInfoProvider hostInfoProvider); Integer getMajorStackVersion(); Integer getMinorStackVersion(); String getClusterName(); String getVersionId(); Set<String> getServices(); Set<String> getHosts(); HostInfoProvider getHostInfoProvider(); Set<String> getComponents(String service); Set<String> getHostComponents(String service, String host); String getHostState(String hostName); String getServiceState(String serviceName); int setServiceState(String serviceName, String state); String getComponentState(String serviceName, String componentName); int setComponentState(String serviceName, String componentName, String state); String getHostComponentState(String hostName, String componentName); int setHostComponentState(String hostName, String componentName, String state); StateProvider.Process getProcess(Integer id); Set<Resource> getRequestResources(); Set<Resource> getTaskResources();  }
@Test public void testGetHostState() throws Exception { TestStateProvider stateProvider = new TestStateProvider(); TestClusterDefinitionProvider definitionProvider = new TestClusterDefinitionProvider(); TestHostInfoProvider hostInfoProvider = new TestHostInfoProvider(); ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, definitionProvider, hostInfoProvider); Assert.assertEquals("HEALTHY", clusterDefinition.getHostState("NAMENODE_MASTER.acme.com")); stateProvider.setState(StateProvider.State.Stopped); Assert.assertEquals("UNHEALTHY", clusterDefinition.getHostState("NAMENODE_MASTER.acme.com")); stateProvider.setState(StateProvider.State.Paused); Assert.assertEquals("UNHEALTHY", clusterDefinition.getHostState("NAMENODE_MASTER.acme.com")); stateProvider.setState(StateProvider.State.Unknown); Assert.assertEquals("UNHEALTHY", clusterDefinition.getHostState("NAMENODE_MASTER.acme.com")); }