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));
}
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)));
}
};
}
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;
}
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);
}
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);
}
Aggregations