Search in sources :

Example 6 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class RedbeamsStartService method startDatabaseServer.

public void startDatabaseServer(String crn) {
    DBStack dbStack = dbStackService.getByCrn(crn);
    MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Start called for: {}", dbStack);
    }
    if (dbStack.getStatus().isStartInProgressOrCompleted()) {
        LOGGER.debug("DatabaseServer with crn {} is already being started", dbStack.getResourceCrn());
        return;
    }
    dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.START_REQUESTED);
    flowManager.notify(RedbeamsStartEvent.REDBEAMS_START_EVENT.selector(), new RedbeamsEvent(RedbeamsStartEvent.REDBEAMS_START_EVENT.selector(), dbStack.getId()));
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Example 7 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class RedbeamsStopService method stopDatabaseServer.

public void stopDatabaseServer(String crn) {
    DBStack dbStack = dbStackService.getByCrn(crn);
    MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Stop called for: {}", dbStack);
    }
    if (dbStack.getStatus().isStopInProgressOrCompleted()) {
        LOGGER.debug("DatabaseServer with crn {} is already being stopped", dbStack.getResourceCrn());
        return;
    }
    dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.STOP_REQUESTED);
    flowManager.notify(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), new RedbeamsEvent(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), dbStack.getId()));
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Example 8 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class RedbeamsProvisionActions method provisionFailed.

@Bean(name = "REDBEAMS_PROVISION_FAILED_STATE")
public Action<?, ?> provisionFailed() {
    return new AbstractRedbeamsProvisionAction<>(RedbeamsFailureEvent.class) {

        // A lot here - some of this could go into some sort of failure handler class
        // compare to core StackCreationService::handleStackCreationFailure
        @Override
        protected void prepareExecution(RedbeamsFailureEvent payload, Map<Object, Object> variables) {
            Exception failureException = payload.getException();
            LOGGER.info("Error during database stack creation flow:", failureException);
            if (failureException instanceof CancellationException || ExceptionUtils.getRootCause(failureException) instanceof CancellationException) {
                LOGGER.debug("The flow has been cancelled");
            } else {
                // StackCreationActions / StackCreationService only update status if stack isn't mid-deletion
                String errorReason = failureException == null ? "Unknown error" : failureException.getMessage();
                Optional<DBStack> dbStack = dbStackStatusUpdater.updateStatus(payload.getResourceId(), DetailedDBStackStatus.PROVISION_FAILED, errorReason);
                metricService.incrementMetricCounter(MetricType.DB_PROVISION_FAILED, dbStack);
            }
        }

        @Override
        protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsProvisionState, RedbeamsProvisionEvent> stateContext, RedbeamsFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected Selectable createRequest(RedbeamsContext context) {
            return new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_FAILURE_HANDLED_EVENT.event(), 0L);
        }
    };
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) StateContext(org.springframework.statemachine.StateContext) AbstractRedbeamsProvisionAction(com.sequenceiq.redbeams.flow.redbeams.provision.AbstractRedbeamsProvisionAction) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Flow(com.sequenceiq.flow.core.Flow) RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) Map(java.util.Map) RedbeamsContext(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext) Bean(org.springframework.context.annotation.Bean)

Example 9 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class StopDatabaseServerHandler method accept.

@Override
public void accept(Event<StopDatabaseServerRequest> event) {
    LOGGER.debug("Received event: {}", event);
    StopDatabaseServerRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        ExternalDatabaseStatus status = connector.resources().getDatabaseServerStatus(ac, request.getDbStack());
        if (status != null && status.isTransient()) {
            LOGGER.debug("Database server '{}' is in '{}' status. Start waiting for a permanent status.", request.getDbStack(), status);
            PollTask<ExternalDatabaseStatus> task = statusCheckFactory.newPollPermanentExternalDatabaseStateTask(ac, request.getDbStack());
            status = externalDatabaseStatusPollingScheduler.schedule(task);
        }
        if (status != STOPPED) {
            LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STOPPED);
            connector.resources().stopDatabaseServer(ac, request.getDbStack());
        } else {
            LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STOPPED);
        }
        RedbeamsEvent success = new StopDatabaseServerSuccess(request.getResourceId());
        eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success));
        LOGGER.debug("Stopping the database server successfully finished for {}", cloudContext);
    } catch (Exception e) {
        StopDatabaseServerFailed failure = new StopDatabaseServerFailed(request.getResourceId(), e);
        LOGGER.warn("Error stopping the database server:", e);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : StopDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.stop.event.StopDatabaseServerSuccess) StopDatabaseServerFailed(com.sequenceiq.redbeams.flow.redbeams.stop.event.StopDatabaseServerFailed) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) StopDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.stop.event.StopDatabaseServerRequest) Event(reactor.bus.Event) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)

Example 10 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class RedbeamsTerminationService method terminate.

private DatabaseServerConfig terminate(DatabaseServerConfig server, boolean force) {
    String crn = server.getResourceCrn().toString();
    if (server.getResourceStatus() != ResourceStatus.SERVICE_MANAGED) {
        return databaseServerConfigService.deleteByCrn(crn);
    }
    DBStack dbStack = dbStackService.getByCrn(crn);
    MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Terminate called for: {} with force: {}", dbStack, force);
    }
    if (dbStack.getStatus().isDeleteInProgressOrCompleted() && !deletetedOnProviderSide(server, dbStack)) {
        LOGGER.debug("DatabaseServer with crn {} is already being deleted", dbStack.getResourceCrn());
        return server;
    }
    dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.DELETE_REQUESTED);
    // re-fetch to see new status
    server = databaseServerConfigService.getByCrn(crn);
    cancelService.cancelRunningFlows(dbStack.getId());
    flowManager.notify(RedbeamsTerminationEvent.REDBEAMS_TERMINATION_EVENT.selector(), new RedbeamsEvent(RedbeamsTerminationEvent.REDBEAMS_TERMINATION_EVENT.selector(), dbStack.getId(), force));
    return server;
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Aggregations

RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)17 Test (org.junit.jupiter.api.Test)8 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)6 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)2 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)2 RedbeamsContext (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext)2 Event (reactor.bus.Event)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 RedbeamsFailureEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent)1 AbstractRedbeamsProvisionAction (com.sequenceiq.redbeams.flow.redbeams.provision.AbstractRedbeamsProvisionAction)1 RedbeamsStartContext (com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext)1 StartDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerFailed)1 StartDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerRequest)1