Search in sources :

Example 1 with StackStatus

use of com.sequenceiq.cloudbreak.domain.stack.StackStatus in project cloudbreak by hortonworks.

the class CcmUpgradeFlowIntegrationTest method mockStack.

private Stack mockStack() {
    stack = new Stack();
    stack.setId(STACK_ID);
    stack.setName("stackname");
    StackStatus stackStatus = new StackStatus(stack, Status.AVAILABLE, "no reason at all", DetailedStackStatus.AVAILABLE);
    stack.setStackStatus(stackStatus);
    stack.setCluster(new Cluster());
    return stack;
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with StackStatus

use of com.sequenceiq.cloudbreak.domain.stack.StackStatus in project cloudbreak by hortonworks.

the class StackUpdater method doUpdateStackStatus.

private Stack doUpdateStackStatus(Long stackId, Status newStatus, DetailedStackStatus newDetailedStatus, String statusReason) {
    Stack stack = stackService.getByIdWithTransaction(stackId);
    StackStatus actualStackStatus = stack.getStackStatus();
    LOGGER.info("Update stack status from: {}/{} to: {}/{} stack: {} reason: {}", actualStackStatus.getStatus(), actualStackStatus.getDetailedStackStatus(), newStatus, newDetailedStatus, stackId, statusReason);
    if (actualStackStatus.getStatus().equals(newStatus)) {
        LOGGER.debug("New status is the same as previous status {}/{}, skip status update.", actualStackStatus.getStatus(), actualStackStatus.getDetailedStackStatus());
        return stack;
    } else if (!stack.isDeleteCompleted()) {
        stack.setStackStatus(new StackStatus(stack, newStatus, statusReason, newDetailedStatus));
        Cluster cluster = stack.getCluster();
        if (newStatus.isRemovableStatus()) {
            InMemoryStateStore.deleteStack(stackId);
            if (cluster != null) {
                InMemoryStateStore.deleteCluster(cluster.getId());
            }
        } else {
            InMemoryStateStore.putStack(stackId, statusToPollGroupConverter.convert(newStatus));
            if (cluster != null) {
                InMemoryStateStore.putCluster(cluster.getId(), statusToPollGroupConverter.convert(newStatus));
            }
        }
        stack = stackService.save(stack);
        saveDeprecatedClusterStatus(statusReason, stack, newStatus);
        usageLoggingUtil.logClusterStatusChangeUsageEvent(actualStackStatus.getStatus(), newStatus, cluster);
    } else {
        LOGGER.info("Stack is in DELETE_COMPLETED status, cannot update status.");
    }
    return stack;
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 3 with StackStatus

use of com.sequenceiq.cloudbreak.domain.stack.StackStatus in project cloudbreak by hortonworks.

the class TerminationTriggerServiceTest method stackWithStatus.

private Stack stackWithStatus(Status status) {
    Stack stack = new Stack();
    stack.setId(1L);
    stack.setEnvironmentCrn("envcrn");
    stack.setName("stackname");
    StackStatus stackStatus = new StackStatus();
    stackStatus.setStatus(status);
    stack.setStackStatus(stackStatus);
    return stack;
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 4 with StackStatus

use of com.sequenceiq.cloudbreak.domain.stack.StackStatus in project cloudbreak by hortonworks.

the class StackStatusIntegrationTest method availableStackInstancesAreHealthy.

@Test
@DisplayName("GIVEN an available stack " + "WHEN all instances are healthy " + "THEN stack is still available")
void availableStackInstancesAreHealthy() throws JobExecutionException {
    setUpClusterStatus(ClusterStatus.STARTED);
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.AVAILABLE));
    setUpHealthForInstance(INSTANCE_1, HealthCheckResult.HEALTHY);
    setUpHealthForInstance(INSTANCE_2, HealthCheckResult.HEALTHY);
    setUpCloudVmInstanceStatuses(Map.of(INSTANCE_1, com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.STARTED, INSTANCE_2, com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.STARTED));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:datahub:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.datahub()).thenReturn(regionAwareInternalCrnGenerator);
    underTest.executeTracedJob(jobExecutionContext);
    verify(instanceMetaDataService, never()).findHostInStack(eq(STACK_ID), any());
    verify(hostGroupService, never()).getRepairViewByClusterIdAndName(anyLong(), anyString());
    verify(flowManager, never()).triggerClusterRepairFlow(anyLong(), any(), anyBoolean());
    verify(instanceMetaDataService, never()).saveAll(any());
    verify(clusterService, never()).updateClusterStatusByStackId(any(), any(), any());
    verify(clusterService).updateClusterCertExpirationState(stack.getCluster(), false);
    verify(instanceMetaDataService, never()).save(any());
    verify(stackUpdater, never()).updateStackStatus(eq(STACK_ID), any(DetailedStackStatus.class));
    verify(stackUpdater, never()).updateStackStatus(eq(STACK_ID), any(), any());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with StackStatus

use of com.sequenceiq.cloudbreak.domain.stack.StackStatus in project cloudbreak by hortonworks.

the class StackStatusIntegrationTest method availableStackAllInstancesGoesDown.

@Test
@DisplayName("GIVEN an available stack " + "WHEN all instances go down " + "THEN stack is no more available")
void availableStackAllInstancesGoesDown() throws JobExecutionException {
    setUpClusterStatus(ClusterStatus.STARTED);
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.AVAILABLE));
    setUpHealthForInstance(INSTANCE_1, HealthCheckResult.HEALTHY);
    setUpHealthForInstance(INSTANCE_2, HealthCheckResult.UNHEALTHY);
    setUpCloudVmInstanceStatuses(Map.of(INSTANCE_1, com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.TERMINATED_BY_PROVIDER, INSTANCE_2, com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.TERMINATED_BY_PROVIDER));
    when(instanceMetaDataService.findNotTerminatedAndNotZombieForStackWithoutInstanceGroups(STACK_ID)).thenReturn(Set.of());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.datahub()).thenReturn(regionAwareInternalCrnGenerator);
    underTest.executeTracedJob(jobExecutionContext);
    verify(instanceMetaDataService, never()).findHostInStack(eq(STACK_ID), any());
    verify(hostGroupService, never()).getRepairViewByClusterIdAndName(anyLong(), anyString());
    verify(flowManager, never()).triggerClusterRepairFlow(anyLong(), any(), anyBoolean());
    verify(instanceMetaDataService, never()).saveAll(any());
    verify(clusterService, never()).updateClusterStatusByStackId(any(), any(), any());
    verify(clusterService).updateClusterCertExpirationState(stack.getCluster(), false);
    assertInstancesSavedWithStatuses(Map.of(INSTANCE_1, InstanceStatus.DELETED_BY_PROVIDER, INSTANCE_2, InstanceStatus.DELETED_BY_PROVIDER));
    verify(stackUpdater).updateStackStatus(eq(STACK_ID), eq(DetailedStackStatus.DELETED_ON_PROVIDER_SIDE), any());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)81 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)61 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)58 Test (org.junit.jupiter.api.Test)41 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)25 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)12 Test (org.junit.Test)12 Supplier (java.util.function.Supplier)5 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)4 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)4 InstanceGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)3 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)3 CertificatesRotationV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request)3 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)3 StackIdView (com.sequenceiq.cloudbreak.domain.projection.StackIdView)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 DisplayName (org.junit.jupiter.api.DisplayName)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)2