use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class RedbeamsTerminationActions method failedAction.
@Bean(name = "REDBEAMS_TERMINATION_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractRedbeamsTerminationAction<>(RedbeamsFailureEvent.class, false) {
// A lot here - some of this could go into some sort of failure handler class
// compare to core StackCreationService::handleStackCreationFailure
@Override
protected void doExecute(RedbeamsContext context, RedbeamsFailureEvent payload, Map<Object, Object> variables) {
Exception failureException = payload.getException();
LOGGER.info("Error during database stack termination flow:", failureException);
if (failureException instanceof CancellationException || ExceptionUtils.getRootCause(failureException) instanceof CancellationException) {
LOGGER.debug("The flow has been cancelled");
} else {
// StackCreationActions / StackCreationService only update status if stack isn't mid-deletion
String errorReason = failureException == null ? "Unknown error" : failureException.getMessage();
Optional<DBStack> dbStack = dbStackStatusUpdater.updateStatus(payload.getResourceId(), DetailedDBStackStatus.DELETE_FAILED, errorReason);
metricService.incrementMetricCounter(MetricType.DB_TERMINATION_FAILED, dbStack);
}
sendEvent(context, REDBEAMS_TERMINATION_FAILURE_HANDLED_EVENT.event(), payload);
}
@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, RedbeamsFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected Object getFailurePayload(RedbeamsFailureEvent payload, Optional<RedbeamsContext> flowContext, Exception ex) {
return payload;
}
};
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class RedbeamsTerminationService method terminate.
private DatabaseServerConfig terminate(DatabaseServerConfig server, boolean force) {
String crn = server.getResourceCrn().toString();
if (server.getResourceStatus() != ResourceStatus.SERVICE_MANAGED) {
return databaseServerConfigService.deleteByCrn(crn);
}
DBStack dbStack = dbStackService.getByCrn(crn);
MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Terminate called for: {} with force: {}", dbStack, force);
}
if (dbStack.getStatus().isDeleteInProgressOrCompleted() && !deletetedOnProviderSide(server, dbStack)) {
LOGGER.debug("DatabaseServer with crn {} is already being deleted", dbStack.getResourceCrn());
return server;
}
dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.DELETE_REQUESTED);
// re-fetch to see new status
server = databaseServerConfigService.getByCrn(crn);
cancelService.cancelRunningFlows(dbStack.getId());
flowManager.notify(RedbeamsTerminationEvent.REDBEAMS_TERMINATION_EVENT.selector(), new RedbeamsEvent(RedbeamsTerminationEvent.REDBEAMS_TERMINATION_EVENT.selector(), dbStack.getId(), force));
return server;
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DeregisterDatabaseServerHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<DeregisterDatabaseServerRequest> event) {
DeregisterDatabaseServerRequest request = event.getData();
DBStack dbStack = dbStackService.getById(request.getResourceId());
try {
databaseServerConfigService.getByCrn(Crn.safeFromString(dbStack.getResourceCrn())).ifPresent(dsc -> databaseServerConfigService.delete(dsc));
return new DeregisterDatabaseServerSuccess(request.getResourceId());
} catch (Exception e) {
LOGGER.warn("Error deregistering database:", e);
return new DeregisterDatabaseServerFailed(request.getResourceId(), e);
}
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class AbstractRedbeamsProvisionAction method createFlowContext.
@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsProvisionState, RedbeamsProvisionEvent> stateContext, P payload) {
DBStack dbStack = dbStackService.getById(payload.getResourceId());
MDCBuilder.buildMdcContext(dbStack);
Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
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(dbStack.getUserName()).withAccountId(accountId).build();
Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
CloudCredential cloudCredential = credentialConverter.convert(credential);
DatabaseStack databaseStack = databaseStackConverter.convert(dbStack);
return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack);
}
use of com.sequenceiq.redbeams.domain.stack.DBStack 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;
}
Aggregations