Search in sources :

Example 1 with AllocateDatabaseServerRequest

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

the class RedbeamsProvisionActionsTest method allocateDatabaseServerTestCreateRequest.

@Test
void allocateDatabaseServerTestCreateRequest() {
    when(cloudContext.getId()).thenReturn(RESOURCE_ID);
    Selectable request = new AbstractActionTestSupport<>(getAllocateDatabaseServerAction()).createRequest(context);
    assertThat(request).isInstanceOf(AllocateDatabaseServerRequest.class);
    AllocateDatabaseServerRequest allocateDatabaseServerRequest = (AllocateDatabaseServerRequest) request;
    assertThat(allocateDatabaseServerRequest.getResourceId()).isEqualTo(RESOURCE_ID);
    assertThat(allocateDatabaseServerRequest.getCloudContext()).isSameAs(cloudContext);
    assertThat(allocateDatabaseServerRequest.getCloudCredential()).isSameAs(cloudCredential);
    assertThat(allocateDatabaseServerRequest.getDatabaseStack()).isSameAs(databaseStack);
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) AllocateDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest) Test(org.junit.jupiter.api.Test)

Example 2 with AllocateDatabaseServerRequest

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

the class AllocateDatabaseServerHandlerTest method initCommon.

private void initCommon() {
    when(cloudContext.getId()).thenReturn(RESOURCE_ID);
    when(cloudContext.getPlatformVariant()).thenReturn(cloudPlatformVariant);
    AllocateDatabaseServerRequest request = new AllocateDatabaseServerRequest(cloudContext, cloudCredential, databaseStack);
    when(event.getData()).thenReturn(request);
    when(cloudPlatformConnectors.get(cloudPlatformVariant)).thenReturn(cloudConnector);
    when(cloudConnector.authentication()).thenReturn(authenticator);
    when(authenticator.authenticate(cloudContext, cloudCredential)).thenReturn(authenticatedContext);
    when(cloudConnector.resources()).thenReturn(resourceConnector);
}
Also used : AllocateDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest)

Example 3 with AllocateDatabaseServerRequest

use of com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest 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 4 with AllocateDatabaseServerRequest

use of com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest 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

AllocateDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)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 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)2 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)2 OperationException (com.sequenceiq.cloudbreak.service.OperationException)2 AllocateDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed)2 AllocateDatabaseServerSuccess (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess)2 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1 Test (org.junit.jupiter.api.Test)1