Search in sources :

Example 6 with AllocateDatabaseServerSuccess

use of com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess in project cloudbreak by hortonworks.

the class AllocateDatabaseServerHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent handlerEvent) {
    Event<AllocateDatabaseServerRequest> event = handlerEvent.getEvent();
    LOGGER.debug("Received event: {}", event);
    AllocateDatabaseServerRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    Selectable response;
    try {
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        CloudCredential cloudCredential = request.getCloudCredential();
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
        DatabaseStack databaseStack = request.getDatabaseStack();
        databaseServerSslCertificatePrescriptionService.prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, request.getDbStack(), databaseStack);
        List<CloudResourceStatus> resourceStatuses = connector.resources().launchDatabaseServer(ac, databaseStack, persistenceNotifier);
        List<CloudResource> resources = ResourceLists.transform(resourceStatuses);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatuses);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        validateResourcesState(cloudContext, statePollerResult);
        response = new AllocateDatabaseServerSuccess(request.getResourceId());
        // request.getResult().onNext(success);
        LOGGER.debug("Launching the database stack successfully finished for {}", cloudContext);
    } catch (Exception e) {
        response = new AllocateDatabaseServerFailed(request.getResourceId(), e);
        LOGGER.warn("Error launching the database stack:", e);
    // request.getResult().onNext(failure);
    }
    return response;
}
Also used : AllocateDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess) AllocateDatabaseServerFailed(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AllocateDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Aggregations

AllocateDatabaseServerSuccess (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess)6 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)4 Test (org.junit.jupiter.api.Test)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)2 OperationException (com.sequenceiq.cloudbreak.service.OperationException)2 AllocateDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed)2 AllocateDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest)2 UpdateDatabaseServerRegistrationRequest (com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationRequest)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1 RedbeamsContext (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext)1 AbstractRedbeamsProvisionAction (com.sequenceiq.redbeams.flow.redbeams.provision.AbstractRedbeamsProvisionAction)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1