Search in sources :

Example 1 with AllocateDatabaseServerSuccess

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

the class RedbeamsProvisionActionsTest method updateDatabaseServerRegistrationTestDoExecute.

@Test
void updateDatabaseServerRegistrationTestDoExecute() throws Exception {
    when(cloudContext.getId()).thenReturn(RESOURCE_ID);
    when(cloudResourceStatus.getCloudResource()).thenReturn(cloudResource);
    when(dbResourceService.getAllAsCloudResourceStatus(RESOURCE_ID)).thenReturn(List.of(cloudResourceStatus));
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    AllocateDatabaseServerSuccess payload = new AllocateDatabaseServerSuccess(RESOURCE_ID);
    new AbstractActionTestSupport<>(getUpdateDatabaseServerRegistrationAction()).doExecute(context, payload, Map.of());
    verify(dbStackStatusUpdater).updateStatus(RESOURCE_ID, DetailedDBStackStatus.PROVISIONED);
    verify(reactorEventFactory).createEvent(anyMap(), payloadArgumentCaptor.capture());
    verify(eventBus).notify("UPDATEDATABASESERVERREGISTRATIONREQUEST", event);
    Object responsePayload = payloadArgumentCaptor.getValue();
    assertThat(responsePayload).isInstanceOf(UpdateDatabaseServerRegistrationRequest.class);
    UpdateDatabaseServerRegistrationRequest updateDatabaseServerRegistrationRequest = (UpdateDatabaseServerRegistrationRequest) responsePayload;
    assertThat(updateDatabaseServerRegistrationRequest.getResourceId()).isEqualTo(RESOURCE_ID);
    assertThat(updateDatabaseServerRegistrationRequest.getCloudContext()).isSameAs(cloudContext);
    assertThat(updateDatabaseServerRegistrationRequest.getCloudCredential()).isSameAs(cloudCredential);
    assertThat(updateDatabaseServerRegistrationRequest.getDatabaseStack()).isSameAs(databaseStack);
    assertThat(updateDatabaseServerRegistrationRequest.getDbResources()).isEqualTo(List.of(cloudResource));
}
Also used : UpdateDatabaseServerRegistrationRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationRequest) AllocateDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess) Test(org.junit.jupiter.api.Test)

Example 2 with AllocateDatabaseServerSuccess

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

the class RedbeamsProvisionActions method updateDatabaseServerRegistration.

@Bean(name = "UPDATE_DATABASE_SERVER_REGISTRATION_STATE")
public Action<?, ?> updateDatabaseServerRegistration() {
    return new AbstractRedbeamsProvisionAction<>(AllocateDatabaseServerSuccess.class) {

        @Override
        protected void doExecute(RedbeamsContext context, AllocateDatabaseServerSuccess payload, Map<Object, Object> variables) {
            dbStackStatusUpdater.updateStatus(payload.getResourceId(), DetailedDBStackStatus.PROVISIONED);
            List<CloudResourceStatus> dbResourcesList = dbResourceService.getAllAsCloudResourceStatus(payload.getResourceId());
            sendEvent(context, new UpdateDatabaseServerRegistrationRequest(context.getCloudContext(), context.getCloudCredential(), context.getDatabaseStack(), ResourceLists.transform(dbResourcesList)));
        }
    };
}
Also used : UpdateDatabaseServerRegistrationRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationRequest) AllocateDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AbstractRedbeamsProvisionAction(com.sequenceiq.redbeams.flow.redbeams.provision.AbstractRedbeamsProvisionAction) RedbeamsContext(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 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<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 AllocateDatabaseServerSuccess

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

the class AllocateDatabaseServerHandlerTest method doAcceptTestWhenSuccessWithPolling.

@Test
void doAcceptTestWhenSuccessWithPolling() throws Exception {
    initCommon();
    when(statusCheckFactory.newPollResourcesStateTask(eq(authenticatedContext), anyList(), eq(true))).thenReturn(task);
    when(task.completed(any(ResourcesStatePollerResult.class))).thenReturn(false);
    when(syncPollingScheduler.schedule(task)).thenReturn(statePollerResult);
    CloudResourceStatus cloudResourceStatus = new CloudResourceStatus(null, ResourceStatus.CREATED, STATUS_REASON_ERROR, PRIVATE_ID_1);
    when(statePollerResult.getResults()).thenReturn(List.of(cloudResourceStatus));
    Selectable selectable = new ExceptionCatcherEventHandlerTestSupport<>(underTest).doAccept(event);
    assertThat(selectable).isInstanceOf(AllocateDatabaseServerSuccess.class);
    AllocateDatabaseServerSuccess allocateDatabaseServerSuccess = (AllocateDatabaseServerSuccess) selectable;
    assertThat(allocateDatabaseServerSuccess.getResourceId()).isEqualTo(RESOURCE_ID);
    verify(syncPollingScheduler).schedule(task);
    verify(databaseServerSslCertificatePrescriptionService).prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack);
}
Also used : AllocateDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with AllocateDatabaseServerSuccess

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

the class AllocateDatabaseServerHandlerTest method doAcceptTestWhenSuccessWithoutPolling.

@Test
void doAcceptTestWhenSuccessWithoutPolling() throws Exception {
    initCommon();
    when(statusCheckFactory.newPollResourcesStateTask(eq(authenticatedContext), anyList(), eq(true))).thenReturn(task);
    when(task.completed(any(ResourcesStatePollerResult.class))).thenReturn(true);
    Selectable selectable = new ExceptionCatcherEventHandlerTestSupport<>(underTest).doAccept(event);
    assertThat(selectable).isInstanceOf(AllocateDatabaseServerSuccess.class);
    AllocateDatabaseServerSuccess allocateDatabaseServerSuccess = (AllocateDatabaseServerSuccess) selectable;
    assertThat(allocateDatabaseServerSuccess.getResourceId()).isEqualTo(RESOURCE_ID);
    verify(syncPollingScheduler, never()).schedule(task);
    verify(databaseServerSslCertificatePrescriptionService).prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack);
}
Also used : AllocateDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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