Search in sources :

Example 31 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandler method onApplicationEvent.

@Override
public void onApplicationEvent(ClusterStatusSyncEvent event) {
    long autoscaleClusterId = event.getClusterId();
    Cluster cluster = clusterService.findById(autoscaleClusterId);
    if (cluster == null) {
        return;
    }
    LoggingUtils.buildMdcContext(cluster);
    StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn());
    boolean clusterAvailable;
    if (Boolean.TRUE.equals(cluster.isStopStartScalingEnabled())) {
        clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false);
    // TODO CB-15146: This may need to change depending on the final form of how we check which operations are to be allowed
    // when there are some STOPPED instances
    } else {
        clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false) && Optional.ofNullable(statusResponse.getClusterStatus()).map(Status::isAvailable).orElse(false);
    }
    LOGGER.info("Computed clusterAvailable: {}", clusterAvailable);
    LOGGER.info("Analysing CBCluster Status '{}' for Cluster '{}. Available(Determined)={}' ", statusResponse, cluster.getStackCrn(), clusterAvailable);
    updateClusterState(cluster, statusResponse, clusterAvailable);
}
Also used : Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Cluster(com.sequenceiq.periscope.domain.Cluster) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)

Example 32 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class CreateExternalDatabaseHandler method accept.

@Override
public void accept(Event<CreateExternalDatabaseRequest> createExternalDatabaseRequest) {
    LOGGER.debug("In CreateExternalDatabaseHandler.accept");
    CreateExternalDatabaseRequest request = createExternalDatabaseRequest.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    Selectable result;
    try {
        String resourceCrn = null;
        if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested.", stack.getName());
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_STARTED, "External database creation in progress");
            LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
            DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
            environmentValidator.checkValidEnvironment(stack.getName(), externalDatabase, environment);
            provisionService.provisionDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.PROVISION_REQUESTED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.PROVISION_REQUESTED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED, "External database creation finished");
            resourceCrn = stack.getCluster().getDatabaseServerCrn();
        }
        result = new CreateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), stack.getName(), resourceCrn);
    } catch (UserBreakException e) {
        LOGGER.info("Database polling exited before timeout. Cause: ", e);
        result = createFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.info(String.format("Database poller stopped for stack: %s", stack.getName()), e);
        result = createFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.info(String.format("Database polling failed for stack: %s", stack.getName()), e);
        result = createFailedEvent(stack, e);
    } catch (Exception e) {
        LOGGER.error(String.format("Exception during DB creation for stack/cluster: %s", stack.getName()), e);
        result = createFailedEvent(stack, e);
    }
    LOGGER.debug("Sending reactor notification for selector {}", result.selector());
    eventBus.notify(result.selector(), new Event<>(createExternalDatabaseRequest.getHeaders(), result));
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CreateExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseRequest) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CreateExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseResult) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 33 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class TerminateExternalDatabaseHandler method accept.

@Override
public void accept(Event<TerminateExternalDatabaseRequest> terminateExternalDatabaseRequest) {
    LOGGER.debug("In TerminateExternalDatabaseHandler.accept");
    TerminateExternalDatabaseRequest request = terminateExternalDatabaseRequest.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    Selectable result;
    try {
        if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Termination is not necessary.", stack.getName());
            result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_STARTED, "External database deletion in progress");
            LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
            DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
            terminationService.terminateDatabase(stack.getCluster(), externalDatabase, environment, request.isForced());
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.AVAILABLE.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.AVAILABLE, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FINISHED, "External database deletion finished");
            result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.info("Database termination polling exited before timeout. Cause: ", e);
        result = terminateFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.info(String.format("Database termination poller stopped for stack: %s", stack.getName()), e);
        result = terminateFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.info(String.format("Database termination polling failed for stack: %s", stack.getName()), e);
        result = terminateFailedEvent(stack, e);
    } catch (Exception e) {
        LOGGER.error(String.format("Exception during DB termination for stack/cluster: %s", stack.getName()), e);
        result = terminateFailedEvent(stack, e);
    }
    LOGGER.debug("Sending reactor notification for selector {}", result.selector());
    eventBus.notify(result.selector(), new Event<>(terminateExternalDatabaseRequest.getHeaders(), result));
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) TerminateExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseResult) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) TerminateExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 34 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class StopExternalDatabaseHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StopExternalDatabaseRequest> event) {
    LOGGER.debug("In StopExternalDatabaseHandler.doAccept");
    StopExternalDatabaseRequest request = event.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Selectable result;
    try {
        if (StackType.WORKLOAD != stack.getType()) {
            LOGGER.debug("External database stop in Cloudbreak service is required for WORKLOAD stacks only.");
            result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
        } else if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Stop is not possible.", stack.getName());
            result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
        } else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
            LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
            result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_COMMANCED, "External database stop in progress");
            stopService.stopDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FINISHED, "External database stop finished");
            result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.error("Database 'stop' polling exited before timeout. Cause: ", e);
        result = stopFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.error(String.format("Database 'stop' poller stopped for stack: %s", stack.getName()), e);
        result = stopFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.error(String.format("Database 'stop' polling failed for stack: %s", stack.getName()), e);
        result = stopFailedEvent(stack, e);
    }
    return result;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StopExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseResult) StopExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 35 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.

the class StackCommonServiceTest method testStartInstancesInDefaultWorkspace.

@Test
public void testStartInstancesInDefaultWorkspace() {
    Stack stack = new Stack();
    stack.setType(StackType.WORKLOAD);
    when(stackService.findStackByNameOrCrnAndWorkspaceId(STACK_CRN, WORKSPACE_ID)).thenReturn(Optional.of(stack));
    CloudbreakUser cloudbreakUser = mock(CloudbreakUser.class);
    when(cloudbreakUser.getUserCrn()).thenReturn("crn:cdp:" + Crn.Service.AUTOSCALE.getName() + ":us-west-1:altus:user:__internal__actor__");
    when(restRequestThreadLocalService.getCloudbreakUser()).thenReturn(cloudbreakUser);
    when(stackUtil.stopStartScalingEntitlementEnabled(stack)).thenReturn(true);
    UpdateStackV4Request updateStackV4Request = new UpdateStackV4Request();
    updateStackV4Request.setWithClusterEvent(true);
    InstanceGroupAdjustmentV4Request instanceGroupAdjustmentV4Request = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustmentV4Request.setInstanceGroup("instanceGroup");
    instanceGroupAdjustmentV4Request.setScalingAdjustment(5);
    updateStackV4Request.setInstanceGroupAdjustment(instanceGroupAdjustmentV4Request);
    when(regionAwareInternalCrnGeneratorFactory.autoscale()).thenReturn(regionAwareInternalCrnGenerator);
    // Regular flow
    underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, ScalingStrategy.STOPSTART_FALLBACK_TO_REGULAR);
    verify(stackOperationService).updateNodeCountStartInstances(stack, updateStackV4Request.getInstanceGroupAdjustment(), true, ScalingStrategy.STOPSTART_FALLBACK_TO_REGULAR);
    // Null scaling strategy
    underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, null);
    verify(stackOperationService).updateNodeCountStartInstances(stack, updateStackV4Request.getInstanceGroupAdjustment(), true, ScalingStrategy.STOPSTART);
    // Status is set - Bad Request
    updateStackV4Request.setStatus(StatusRequest.FULL_SYNC);
    assertThrows(BadRequestException.class, () -> underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, null));
}
Also used : UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)23 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)22 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)18 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)12 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)9 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)6 Collection (java.util.Collection)6 List (java.util.List)6 Set (java.util.Set)6 Inject (javax.inject.Inject)6 PollerStoppedException (com.dyngr.exception.PollerStoppedException)5 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)5 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)5