Search in sources :

Example 46 with DatabaseStack

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

the class AllocateDatabaseServerHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<AllocateDatabaseServerRequest> 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();
        DBStack dbStack = dbStackService.getById(request.getResourceId());
        databaseServerSslCertificatePrescriptionService.prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, 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());
        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);
    }
    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) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) 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)

Example 47 with DatabaseStack

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

the class AbstractRedbeamsStopAction method createFlowContext.

@Override
protected RedbeamsStopContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStopState, RedbeamsStopEvent> stateContext, P payload) {
    DBStack dbStack = dbStackService.getById(payload.getResourceId());
    MDCBuilder.buildMdcContext(dbStack);
    Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
    String userName = dbStack.getOwnerCrn().getUserId();
    String accountId = dbStack.getOwnerCrn().getAccountId();
    CloudContext cloudContext = CloudContext.Builder.builder().withId(dbStack.getId()).withName(dbStack.getName()).withCrn(dbStack.getResourceCrn()).withPlatform(dbStack.getCloudPlatform()).withVariant(dbStack.getPlatformVariant()).withLocation(location).withUserName(userName).withAccountId(accountId).build();
    Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    DatabaseStack databaseStack = databaseStackConverter.convert(dbStack);
    return new RedbeamsStopContext(flowParameters, cloudContext, cloudCredential, databaseStack);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.redbeams.dto.Credential) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) RedbeamsStopContext(com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 48 with DatabaseStack

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

DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)48 Test (org.junit.jupiter.api.Test)34 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)24 DatabaseServer (com.sequenceiq.cloudbreak.cloud.model.DatabaseServer)24 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)22 SQLAdmin (com.google.api.services.sqladmin.SQLAdmin)16 InstancesListResponse (com.google.api.services.sqladmin.model.InstancesListResponse)13 DatabaseInstance (com.google.api.services.sqladmin.model.DatabaseInstance)12 PersistenceNotifier (com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier)12 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)11 DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 Network (com.sequenceiq.cloudbreak.cloud.model.Network)9 ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)8 Json (com.sequenceiq.cloudbreak.common.json.Json)8 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)7 Network (com.sequenceiq.redbeams.domain.stack.Network)7