### Question:
ClouderaManagerClusterStatusService implements ClusterStatusService { @Override public Map<HostName, ClusterManagerState.ClusterManagerStatus> getHostStatuses() { return convertHealthSummary(getHostHealthSummary(), ClouderaManagerClusterStatusService::healthSummaryToState); } ClouderaManagerClusterStatusService(Stack stack, HttpClientConfig clientConfig); @PostConstruct void initApiClient(); @Override ClusterStatusResult getStatus(boolean blueprintPresent); @Override ExtendedHostStatuses getExtendedHostStatuses(); @Override Map<HostName, ClusterManagerState.ClusterManagerStatus> getHostStatuses(); @Override Map<HostName, String> getHostStatusesRaw(); @Override boolean isClusterManagerRunning();  }### Answer:
@Test public void collectsHostHealthIfAvailable() throws ApiException { hostsAre( new ApiHost().hostname("host1").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.GOOD)), new ApiHost().hostname("host2").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.CONCERNING)), new ApiHost().hostname("host3").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.BAD)), new ApiHost().hostname("host4").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.NOT_AVAILABLE)), new ApiHost().hostname("host5").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.HISTORY_NOT_AVAILABLE)), new ApiHost().hostname("host6").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.DISABLED)) ); Map<HostName, ClusterManagerState.ClusterManagerStatus> expected = ImmutableMap.of( hostName("host1"), ClusterManagerState.ClusterManagerStatus.HEALTHY, hostName("host2"), ClusterManagerState.ClusterManagerStatus.HEALTHY, hostName("host3"), ClusterManagerState.ClusterManagerStatus.UNHEALTHY ); Map<HostName, ClusterManagerState.ClusterManagerStatus> actual = new TreeMap<>(subject.getHostStatuses()); assertEquals(expected, actual); }
@Test public void filtersAppropriateHealthCheckForHost() throws ApiException { hostsAre( new ApiHost().hostname("host") .addHealthChecksItem(new ApiHealthCheck().name("fake_check").summary(ApiHealthSummary.BAD)) .addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.CONCERNING)) .addHealthChecksItem(new ApiHealthCheck().name("another").summary(ApiHealthSummary.BAD)) ); Map<HostName, ClusterManagerStatus> expected = Collections.singletonMap(hostName("host"), ClusterManagerStatus.HEALTHY); assertEquals(expected, subject.getHostStatuses()); }
@Test public void ignoresHostsWithoutHealthChecks() throws ApiException { hostsAre(new ApiHost().hostname("hostY")); assertEquals(Collections.emptyMap(), subject.getHostStatuses()); }
@Test public void ignoresHostsWithoutAppropriateHealthCheck() throws ApiException { hostsAre(new ApiHost().hostname("hostY").addHealthChecksItem(new ApiHealthCheck().name("fake_check").summary(ApiHealthSummary.GOOD))); assertEquals(Collections.emptyMap(), subject.getHostStatuses()); }