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