Search in sources :

Example 1 with HealthCheck

use of com.sequenceiq.cloudbreak.common.type.HealthCheck 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 HealthCheck

use of com.sequenceiq.cloudbreak.common.type.HealthCheck in project cloudbreak by hortonworks.

the class VmStatusCheckerConclusionStep method checkCMForInstanceStatuses.

private Conclusion checkCMForInstanceStatuses(ClusterApi connector, Set<InstanceMetaData> runningInstances, Long clusterId) {
    ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(clusterId));
    Map<HostName, Set<HealthCheck>> hostStatuses = extendedHostStatuses.getHostsHealth();
    Map<String, String> unhealthyHosts = hostStatuses.keySet().stream().filter(hostName -> !extendedHostStatuses.isHostHealthy(hostName)).collect(Collectors.toMap(StringType::value, extendedHostStatuses::statusReasonForHost));
    Set<String> noReportHosts = runningInstances.stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).filter(discoveryFQDN -> !hostStatuses.containsKey(hostName(discoveryFQDN))).collect(toSet());
    if (!unhealthyHosts.isEmpty() || !noReportHosts.isEmpty()) {
        String conclusion = String.format("Unhealthy and/or unknown VMs found based on CM status. Unhealthy VMs: %s, unknown VMs: %s. " + "Please check the instances on your cloud provider for further details.", unhealthyHosts, noReportHosts);
        String details = String.format("Unhealthy and/or unknown VMs found based on CM status. Unhealthy VMs: %s, unknown VMs: %s", unhealthyHosts, noReportHosts);
        LOGGER.warn(details);
        return failed(conclusion, details);
    } else {
        return succeeded();
    }
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Inject(javax.inject.Inject) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) StackInstanceStatusChecker(com.sequenceiq.cloudbreak.service.stack.StackInstanceStatusChecker) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) RuntimeVersionService(com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService) Set(java.util.Set) StringType(com.sequenceiq.cloudbreak.cloud.model.generic.StringType) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) List(java.util.List) Component(org.springframework.stereotype.Component) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceSyncState(com.sequenceiq.cloudbreak.service.stack.flow.InstanceSyncState) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) Objects(java.util.Objects) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Example 3 with HealthCheck

use of com.sequenceiq.cloudbreak.common.type.HealthCheck in project cloudbreak by hortonworks.

the class StackStatusCheckerJobTest method internalTestInstanceSyncStopStart.

private void internalTestInstanceSyncStopStart(String instanceHgName, InstanceStatus instanceStatus, DetailedStackStatus expected) throws JobExecutionException {
    setupForCM();
    Set<HealthCheck> healthChecks = Sets.newHashSet(new HealthCheck(HealthCheckType.HOST, HealthCheckResult.UNHEALTHY, Optional.empty()), new HealthCheck(HealthCheckType.CERT, HealthCheckResult.UNHEALTHY, Optional.empty()));
    ExtendedHostStatuses extendedHostStatuses = new ExtendedHostStatuses(Map.of(HostName.hostName("host1"), healthChecks));
    when(clusterStatusService.getExtendedHostStatuses(any())).thenReturn(extendedHostStatuses);
    when(instanceMetaData.getInstanceStatus()).thenReturn(instanceStatus);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.datahub()).thenReturn(regionAwareInternalCrnGenerator);
    when(instanceMetaData.getDiscoveryFQDN()).thenReturn("host1");
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(instanceHgName);
    when(instanceMetaData.getInstanceGroup()).thenReturn(instanceGroup);
    when(clusterApiConnectors.getConnector(stack)).thenReturn(clusterApi);
    when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
    when(stackUtil.stopStartScalingEntitlementEnabled(any())).thenReturn(true);
    Set<String> computeGroups = new HashSet<>();
    computeGroups.add("compute");
    when(cmTemplateProcessor.getComputeHostGroups(any())).thenReturn(computeGroups);
    underTest.executeTracedJob(jobExecutionContext);
    verify(clusterOperationService, times(1)).reportHealthChange(any(), any(), anySet());
    verify(stackInstanceStatusChecker).queryInstanceStatuses(eq(stack), any());
    verify(clusterService, times(1)).updateClusterCertExpirationState(stack.getCluster(), true);
    verify(clusterService, times(1)).updateClusterStatusByStackId(stack.getId(), expected);
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) HashSet(java.util.HashSet)

Example 4 with HealthCheck

use of com.sequenceiq.cloudbreak.common.type.HealthCheck in project cloudbreak by hortonworks.

the class StackStatusCheckerJobTest method testInstanceSyncCMRunningNodeStopped.

@Test
public void testInstanceSyncCMRunningNodeStopped() throws JobExecutionException {
    setupForCM();
    Set<HealthCheck> healthChecks = Sets.newHashSet(new HealthCheck(HealthCheckType.HOST, HealthCheckResult.UNHEALTHY, Optional.empty()), new HealthCheck(HealthCheckType.CERT, HealthCheckResult.UNHEALTHY, Optional.empty()));
    ExtendedHostStatuses extendedHostStatuses = new ExtendedHostStatuses(Map.of(HostName.hostName("host1"), healthChecks));
    when(clusterStatusService.getExtendedHostStatuses(any())).thenReturn(extendedHostStatuses);
    when(instanceMetaData.getInstanceStatus()).thenReturn(InstanceStatus.STOPPED);
    when(instanceMetaData.getDiscoveryFQDN()).thenReturn("host1");
    when(clusterApiConnectors.getConnector(stack)).thenReturn(clusterApi);
    when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.datahub()).thenReturn(regionAwareInternalCrnGenerator);
    underTest.executeTracedJob(jobExecutionContext);
    verify(clusterOperationService, times(1)).reportHealthChange(any(), any(), anySet());
    verify(stackInstanceStatusChecker).queryInstanceStatuses(eq(stack), any());
    verify(clusterService, times(1)).updateClusterCertExpirationState(stack.getCluster(), true);
    verify(clusterService, times(1)).updateClusterStatusByStackId(stack.getId(), DetailedStackStatus.NODE_FAILURE);
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) Test(org.junit.Test)

Example 5 with HealthCheck

use of com.sequenceiq.cloudbreak.common.type.HealthCheck in project cloudbreak by hortonworks.

the class ClusterServiceTest method setupClusterApi.

private void setupClusterApi(Stack stack, HealthCheckResult healthCheckResult, String statusReason) {
    ClusterApi connector = mock(ClusterApi.class);
    ClusterStatusService clusterStatusService = mock(ClusterStatusService.class);
    when(clusterStatusService.isClusterManagerRunning()).thenReturn(true);
    when(connector.clusterStatusService()).thenReturn(clusterStatusService);
    Map<HostName, Set<HealthCheck>> clusterManagerStateMap = new HashMap<>();
    if (healthCheckResult != null) {
        clusterManagerStateMap.put(HostName.hostName(FQDN1), Sets.newHashSet(new HealthCheck(HealthCheckType.HOST, healthCheckResult, Optional.ofNullable(statusReason))));
    }
    ExtendedHostStatuses extendedHostStatuses = new ExtendedHostStatuses(clusterManagerStateMap);
    when(clusterStatusService.getExtendedHostStatuses(any())).thenReturn(extendedHostStatuses);
    when(clusterApiConnectors.getConnector(stack)).thenReturn(connector);
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Set(java.util.Set) HashMap(java.util.HashMap) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ClusterStatusService(com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Aggregations

ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)7 HealthCheck (com.sequenceiq.cloudbreak.common.type.HealthCheck)7 HostName (com.sequenceiq.cloudbreak.cloud.model.HostName)4 Set (java.util.Set)4 HashMap (java.util.HashMap)3 HostName.hostName (com.sequenceiq.cloudbreak.cloud.model.HostName.hostName)2 ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)2 ClusterStatusService (com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 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