use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class RedbeamsStartService method startDatabaseServer.
public void startDatabaseServer(String crn) {
DBStack dbStack = dbStackService.getByCrn(crn);
MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Start called for: {}", dbStack);
}
if (dbStack.getStatus().isStartInProgressOrCompleted()) {
LOGGER.debug("DatabaseServer with crn {} is already being started", dbStack.getResourceCrn());
return;
}
dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.START_REQUESTED);
flowManager.notify(RedbeamsStartEvent.REDBEAMS_START_EVENT.selector(), new RedbeamsEvent(RedbeamsStartEvent.REDBEAMS_START_EVENT.selector(), dbStack.getId()));
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class RedbeamsStopService method stopDatabaseServer.
public void stopDatabaseServer(String crn) {
DBStack dbStack = dbStackService.getByCrn(crn);
MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Stop called for: {}", dbStack);
}
if (dbStack.getStatus().isStopInProgressOrCompleted()) {
LOGGER.debug("DatabaseServer with crn {} is already being stopped", dbStack.getResourceCrn());
return;
}
dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.STOP_REQUESTED);
flowManager.notify(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), new RedbeamsEvent(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), dbStack.getId()));
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class RedbeamsProvisionActions method provisionFailed.
@Bean(name = "REDBEAMS_PROVISION_FAILED_STATE")
public Action<?, ?> provisionFailed() {
return new AbstractRedbeamsProvisionAction<>(RedbeamsFailureEvent.class) {
// A lot here - some of this could go into some sort of failure handler class
// compare to core StackCreationService::handleStackCreationFailure
@Override
protected void prepareExecution(RedbeamsFailureEvent payload, Map<Object, Object> variables) {
Exception failureException = payload.getException();
LOGGER.info("Error during database stack creation 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.PROVISION_FAILED, errorReason);
metricService.incrementMetricCounter(MetricType.DB_PROVISION_FAILED, dbStack);
}
}
@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsProvisionState, RedbeamsProvisionEvent> stateContext, RedbeamsFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected Selectable createRequest(RedbeamsContext context) {
return new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_FAILURE_HANDLED_EVENT.event(), 0L);
}
};
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class StopDatabaseServerHandler method accept.
@Override
public void accept(Event<StopDatabaseServerRequest> event) {
LOGGER.debug("Received event: {}", event);
StopDatabaseServerRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
ExternalDatabaseStatus status = connector.resources().getDatabaseServerStatus(ac, request.getDbStack());
if (status != null && status.isTransient()) {
LOGGER.debug("Database server '{}' is in '{}' status. Start waiting for a permanent status.", request.getDbStack(), status);
PollTask<ExternalDatabaseStatus> task = statusCheckFactory.newPollPermanentExternalDatabaseStateTask(ac, request.getDbStack());
status = externalDatabaseStatusPollingScheduler.schedule(task);
}
if (status != STOPPED) {
LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STOPPED);
connector.resources().stopDatabaseServer(ac, request.getDbStack());
} else {
LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STOPPED);
}
RedbeamsEvent success = new StopDatabaseServerSuccess(request.getResourceId());
eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success));
LOGGER.debug("Stopping the database server successfully finished for {}", cloudContext);
} catch (Exception e) {
StopDatabaseServerFailed failure = new StopDatabaseServerFailed(request.getResourceId(), e);
LOGGER.warn("Error stopping the database server:", e);
eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
}
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent 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;
}
Aggregations