Search in sources :

Example 1 with ExtendedHostStatuses

use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses in project cloudbreak by hortonworks.

the class StackStatusCheckerJob method doSync.

private void doSync(Stack stack) {
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    Set<InstanceMetaData> runningInstances = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
    try {
        if (isClusterManagerRunning(stack, connector)) {
            ExtendedHostStatuses extendedHostStatuses = getExtendedHostStatuses(stack, connector);
            Map<HostName, Set<HealthCheck>> hostStatuses = extendedHostStatuses.getHostsHealth();
            LOGGER.debug("Cluster '{}' state check, host certicates expiring: [{}], cm running, hoststates: {}", stack.getId(), extendedHostStatuses.isAnyCertExpiring(), hostStatuses);
            reportHealthAndSyncInstances(stack, runningInstances, getFailedInstancesInstanceMetadata(extendedHostStatuses, runningInstances), getNewHealthyHostNames(extendedHostStatuses, runningInstances), extendedHostStatuses.isAnyCertExpiring());
        } else {
            syncInstances(stack, runningInstances, false);
        }
    } catch (RuntimeException e) {
        LOGGER.warn("Error during sync", e);
        syncInstances(stack, runningInstances, false);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Collectors.toSet(java.util.stream.Collectors.toSet) EnumSet(java.util.EnumSet) Set(java.util.Set) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Example 2 with ExtendedHostStatuses

use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses in project cloudbreak by hortonworks.

the class ClusterService method updateClusterMetadata.

public Cluster updateClusterMetadata(Long stackId) {
    Stack stack = stackService.getById(stackId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    if (!connector.clusterStatusService().isClusterManagerRunning()) {
        Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
        InstanceMetaData cmInstance = updateClusterManagerHostStatus(notTerminatedInstanceMetaDatas);
        eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), CLUSTER_HOST_STATUS_UPDATED, Arrays.asList(cmInstance.getDiscoveryFQDN(), cmInstance.getInstanceStatus().name()));
        return stack.getCluster();
    } else {
        ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(stack.getCluster().getId()));
        updateClusterCertExpirationState(stack.getCluster(), extendedHostStatuses.isAnyCertExpiring());
        try {
            return transactionService.required(() -> {
                Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
                List<InstanceMetaData> updatedInstanceMetaData = updateInstanceStatuses(notTerminatedInstanceMetaDatas, extendedHostStatuses);
                instanceMetaDataService.saveAll(updatedInstanceMetaData);
                fireHostStatusUpdateNotification(stack, updatedInstanceMetaData);
                return stack.getCluster();
            });
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 3 with ExtendedHostStatuses

use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses 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 4 with ExtendedHostStatuses

use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses 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 5 with ExtendedHostStatuses

use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses 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)

Aggregations

ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)16 ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)6 HealthCheck (com.sequenceiq.cloudbreak.common.type.HealthCheck)6 Test (org.junit.Test)6 ApiHealthCheck (com.cloudera.api.swagger.model.ApiHealthCheck)5 ApiHost (com.cloudera.api.swagger.model.ApiHost)5 Set (java.util.Set)5 HostName (com.sequenceiq.cloudbreak.cloud.model.HostName)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)3 HealthCheckResult (com.sequenceiq.cloudbreak.common.type.HealthCheckResult)2 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)2 RuntimeVersionService (com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService)2 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)2 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2