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