Search in sources :

Example 16 with ExternalDatabaseStatus

use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus 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 17 with ExternalDatabaseStatus

use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.

the class StartDatabaseServerHandler method accept.

@Override
public void accept(Event<StartDatabaseServerRequest> event) {
    LOGGER.debug("Received event: {}", event);
    StartDatabaseServerRequest 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 != STARTED) {
            LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STARTED);
            connector.resources().startDatabaseServer(ac, request.getDbStack());
        } else {
            LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STARTED);
        }
        RedbeamsEvent success = new StartDatabaseServerSuccess(request.getResourceId());
        eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success));
        LOGGER.debug("Starting the database server successfully finished for {}", cloudContext);
    } catch (Exception e) {
        StartDatabaseServerFailed failure = new StartDatabaseServerFailed(request.getResourceId(), e);
        LOGGER.warn("Error starting the database server:", e);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : StartDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerSuccess) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) StartDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerRequest) Event(reactor.bus.Event) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) StartDatabaseServerFailed(com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerFailed) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)

Aggregations

ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)17 Test (org.junit.jupiter.api.Test)13 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 SQLAdmin (com.google.api.services.sqladmin.SQLAdmin)7 InstancesListResponse (com.google.api.services.sqladmin.model.InstancesListResponse)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 DatabaseServer (com.sequenceiq.cloudbreak.cloud.model.DatabaseServer)7 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)7 DatabaseInstance (com.google.api.services.sqladmin.model.DatabaseInstance)6 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)4 Settings (com.google.api.services.sqladmin.model.Settings)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 DetailedDBStackStatus (com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus)2 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)2 Event (reactor.bus.Event)2 Status (com.sequenceiq.redbeams.api.model.common.Status)1 StartDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerFailed)1 StartDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerRequest)1 StartDatabaseServerSuccess (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerSuccess)1 StopDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.stop.event.StopDatabaseServerFailed)1