Search in sources :

Example 1 with ApiHealthCheck

use of com.cloudera.api.swagger.model.ApiHealthCheck in project cloudbreak by hortonworks.

the class ClouderaManagerClusterStatusService method getCertCheck.

private static Optional<HealthCheck> getCertCheck(ApiHost apiHost) {
    Optional<ApiHealthCheck> healthCheck = emptyIfNull(apiHost.getHealthChecks()).stream().filter(health -> HOST_AGENT_CERTIFICATE_EXPIRY.equals(health.getName())).findFirst();
    if (healthCheck.isPresent()) {
        HealthCheckResult result = ApiHealthSummary.BAD.equals(healthCheck.get().getSummary()) || ApiHealthSummary.CONCERNING.equals(healthCheck.get().getSummary()) ? HealthCheckResult.UNHEALTHY : HealthCheckResult.HEALTHY;
        Optional<String> reason = Optional.ofNullable(healthCheck.get().getSummary()).map(apiSum -> "Cert health on CM: " + apiSum.getValue());
        return Optional.of(new HealthCheck(HealthCheckType.CERT, result, reason));
    }
    return Optional.empty();
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HealthCheckResult(com.sequenceiq.cloudbreak.common.type.HealthCheckResult) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRole(com.cloudera.api.swagger.model.ApiRole) StringUtils(org.apache.commons.lang3.StringUtils) ApiException(com.cloudera.api.swagger.client.ApiException) ClusterCommandType(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommandType) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) BigDecimal(java.math.BigDecimal) Collectors.toMap(java.util.stream.Collectors.toMap) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) SyncApiCommandRetriever(com.sequenceiq.cloudbreak.cm.commands.SyncApiCommandRetriever) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Set(java.util.Set) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) ApiVersionInfo(com.cloudera.api.swagger.model.ApiVersionInfo) Collectors.joining(java.util.stream.Collectors.joining) Sets(com.google.common.collect.Sets) ClusterStatus(com.sequenceiq.cloudbreak.cluster.status.ClusterStatus) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) CollectionUtils.emptyIfNull(org.apache.commons.collections4.CollectionUtils.emptyIfNull) Joiner(com.google.common.base.Joiner) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ApiClient(com.cloudera.api.swagger.client.ApiClient) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClusterStatusResult(com.sequenceiq.cloudbreak.cluster.status.ClusterStatusResult) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) HashMap(java.util.HashMap) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) Service(org.springframework.stereotype.Service) ApiHost(com.cloudera.api.swagger.model.ApiHost) Collectors.mapping(java.util.stream.Collectors.mapping) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) ApiServiceState(com.cloudera.api.swagger.model.ApiServiceState) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) HealthCheckType(com.sequenceiq.cloudbreak.common.type.HealthCheckType) Logger(org.slf4j.Logger) ClusterStatusService(com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService) TimeUnit(java.util.concurrent.TimeUnit) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) Collectors.toList(java.util.stream.Collectors.toList) ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) RetryTemplate(org.springframework.retry.support.RetryTemplate) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) HealthCheckResult(com.sequenceiq.cloudbreak.common.type.HealthCheckResult)

Example 2 with ApiHealthCheck

use of com.cloudera.api.swagger.model.ApiHealthCheck in project cloudbreak by hortonworks.

the class ClouderaManagerClusterStatusServiceTest method filtersAppropriateHealthCheckForHost.

@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)));
    assertTrue(subject.getExtendedHostStatuses(Optional.of("7.2.12")).isHostHealthy(hostName("host")));
}
Also used : ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 3 with ApiHealthCheck

use of com.cloudera.api.swagger.model.ApiHealthCheck in project cloudbreak by hortonworks.

the class ClouderaManagerClusterStatusServiceTest method collectsExtendedHostHealthIfAvailable.

@Test
public void collectsExtendedHostHealthIfAvailable() throws ApiException {
    hostsAre(new ApiHost().hostname("host1").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.GOOD)).addHealthChecksItem(new ApiHealthCheck().name(HOST_AGENT_CERTIFICATE_EXPIRY).summary(ApiHealthSummary.GOOD)), new ApiHost().hostname("host2").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.CONCERNING)).addHealthChecksItem(new ApiHealthCheck().name(HOST_AGENT_CERTIFICATE_EXPIRY).summary(ApiHealthSummary.CONCERNING).explanation("in 30 days")), new ApiHost().hostname("host3").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.BAD).explanation("explanation.")).addHealthChecksItem(new ApiHealthCheck().name(HOST_AGENT_CERTIFICATE_EXPIRY).summary(ApiHealthSummary.BAD).explanation("in 2 days")), 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)), new ApiHost().hostname("host7").maintenanceMode(true).addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.GOOD)).addHealthChecksItem(new ApiHealthCheck().name(HOST_AGENT_CERTIFICATE_EXPIRY).summary(ApiHealthSummary.GOOD)));
    ExtendedHostStatuses extendedHostStatuses = subject.getExtendedHostStatuses(Optional.of("7.2.12"));
    assertEquals("explanation. Cert health on CM: BAD", extendedHostStatuses.statusReasonForHost(hostName("host3")));
    assertTrue(extendedHostStatuses.isAnyCertExpiring());
    assertTrue(extendedHostStatuses.isHostHealthy(hostName("host1")));
    assertTrue(extendedHostStatuses.isHostHealthy(hostName("host2")));
    assertFalse(extendedHostStatuses.isHostHealthy(hostName("host3")));
    assertFalse(extendedHostStatuses.isHostHealthy(hostName("host7")));
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 4 with ApiHealthCheck

use of com.cloudera.api.swagger.model.ApiHealthCheck in project cloudbreak by hortonworks.

the class ClouderaManagerClusterStatusServiceTest method testServiceBadHealth.

@Test
public void testServiceBadHealth() throws ApiException {
    hostsAre(new ApiHost().hostname("host1").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.BAD).explanation("explanation")).addHealthChecksItem(new ApiHealthCheck().name(HOST_AGENT_CERTIFICATE_EXPIRY).summary(ApiHealthSummary.GOOD)).addRoleRefsItem(roleRef("badservice", ApiHealthSummary.BAD)), new ApiHost().hostname("host2").addHealthChecksItem(new ApiHealthCheck().name(HOST_SCM_HEALTH).summary(ApiHealthSummary.GOOD)).addHealthChecksItem(new ApiHealthCheck().name(HOST_AGENT_CERTIFICATE_EXPIRY).summary(ApiHealthSummary.GOOD).explanation("in 30 days")).addRoleRefsItem(roleRef("badservice2", ApiHealthSummary.BAD)).addRoleRefsItem(roleRef("badservice3", ApiHealthSummary.BAD)));
    ExtendedHostStatuses extendedHostStatuses = subject.getExtendedHostStatuses(Optional.of("7.2.12"));
    assertFalse(extendedHostStatuses.isAnyCertExpiring());
    assertFalse(extendedHostStatuses.isHostHealthy(hostName("host1")));
    assertFalse(extendedHostStatuses.isHostHealthy(hostName("host2")));
    assertEquals("explanation. The following services are in bad health: badservice.", extendedHostStatuses.statusReasonForHost(hostName("host1")));
    assertEquals("The following services are in bad health: badservice2, badservice3.", extendedHostStatuses.statusReasonForHost(hostName("host2")));
    extendedHostStatuses = subject.getExtendedHostStatuses(Optional.of("7.2.11"));
    assertFalse(extendedHostStatuses.isAnyCertExpiring());
    assertFalse(extendedHostStatuses.isHostHealthy(hostName("host1")));
    assertTrue(extendedHostStatuses.isHostHealthy(hostName("host2")));
    assertEquals("explanation.", extendedHostStatuses.statusReasonForHost(hostName("host1")));
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 5 with ApiHealthCheck

use of com.cloudera.api.swagger.model.ApiHealthCheck in project cloudbreak by hortonworks.

the class ClouderaManagerClusterStatusServiceTest method collectsHostHealthIfAvailable.

@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)));
    ExtendedHostStatuses extendedHostStatuses = subject.getExtendedHostStatuses(Optional.of("7.2.12"));
    assertFalse(extendedHostStatuses.isHostHealthy(hostName("host3")));
    assertTrue(extendedHostStatuses.isHostHealthy(hostName("host1")));
    assertTrue(extendedHostStatuses.isHostHealthy(hostName("host2")));
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Aggregations

ApiHealthCheck (com.cloudera.api.swagger.model.ApiHealthCheck)8 ApiHost (com.cloudera.api.swagger.model.ApiHost)8 Test (org.junit.Test)7 ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)6 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)1 ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)1 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)1 RolesResourceApi (com.cloudera.api.swagger.RolesResourceApi)1 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiException (com.cloudera.api.swagger.client.ApiException)1 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)1 ApiHealthSummary (com.cloudera.api.swagger.model.ApiHealthSummary)1 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)1 ApiRole (com.cloudera.api.swagger.model.ApiRole)1 ApiRoleRef (com.cloudera.api.swagger.model.ApiRoleRef)1 ApiRoleState (com.cloudera.api.swagger.model.ApiRoleState)1 ApiService (com.cloudera.api.swagger.model.ApiService)1 ApiServiceState (com.cloudera.api.swagger.model.ApiServiceState)1 ApiVersionInfo (com.cloudera.api.swagger.model.ApiVersionInfo)1