use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class StartExternalDatabaseHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StartExternalDatabaseRequest> event) {
LOGGER.debug("In StartExternalDatabaseHandler.doAccept");
StartExternalDatabaseRequest request = event.getData();
Stack stack = stackService.getById(request.getResourceId());
DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
Selectable result;
try {
if (StackType.WORKLOAD != stack.getType()) {
LOGGER.debug("External database start in Cloudbreak service is required for WORKLOAD stacks only.");
result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
} else if (externalDatabase.isEmbedded()) {
LOGGER.info("External database for stack {} is not requested. Start is not possible.", stack.getName());
result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
} else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
} else {
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_COMMANCED, "External database start in progress");
startService.startDatabase(stack.getCluster(), externalDatabase, environment);
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FINISHED, "External database start finished");
result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
}
} catch (UserBreakException e) {
LOGGER.error("Database 'start' polling exited before timeout. Cause: ", e);
result = startFailedEvent(stack, e);
} catch (PollerStoppedException e) {
LOGGER.error(String.format("Database 'start' poller stopped for stack: %s", stack.getName()), e);
result = startFailedEvent(stack, e);
} catch (PollerException e) {
LOGGER.error(String.format("Database 'start' polling failed for stack: %s", stack.getName()), e);
result = startFailedEvent(stack, e);
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class AbstractExternalDatabaseStopAction method createFlowContext.
@Override
protected ExternalDatabaseContext createFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStopState, ExternalDatabaseStopEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithClusterInTransaction(payload.getResourceId());
MDCBuilder.buildMdcContext(stack);
beforeReturnFlowContext(flowParameters, stateContext, payload);
return new ExternalDatabaseContext(flowParameters, stack);
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class StopExternalDatabaseHandler method defaultFailureEvent.
@Override
protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event<StopExternalDatabaseRequest> event) {
Stack stack = stackService.getById(event.getData().getResourceId());
LOGGER.error(String.format("Exception during DB 'stop' for stack/cluster: %s", stack.getName()), e);
return stopFailedEvent(stack, e);
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class CmDiagnosticsFlowService method executeCmDiagnosticOperation.
private void executeCmDiagnosticOperation(Long stackId, String operation, Set<String> excludeHosts, CmDiagnosticsFlowOperation func) throws CloudbreakOrchestratorFailedException {
LOGGER.debug("CM Diagnostics {} will be called only on the primary gateway address", operation);
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
String primaryGatewayIp = gatewayConfigService.getPrimaryGatewayIp(stack);
Set<String> hosts = Set.of(primaryGatewayIp);
OrchestratorMetadataFilter filter = OrchestratorMetadataFilter.Builder.newBuilder().includeHosts(hosts).exlcudeHosts(excludeHosts).build();
Set<Node> filteredNodes = filter.apply(stack.getAllNodes());
ClusterDeletionBasedExitCriteriaModel exitModel = new ClusterDeletionBasedExitCriteriaModel(stackId, stack.getCluster().getId());
if (filteredNodes.isEmpty()) {
LOGGER.debug("CM Diagnostics {} has been skipped. (no target minions)", operation);
} else {
LOGGER.debug("CM Diagnostics operation '{}' has been started.", operation);
func.apply(gatewayConfigs, filteredNodes, exitModel);
LOGGER.debug("CM Diagnostics operation '{}' has been finished.", operation);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ExternalDatabaseTerminationActions method externalDatabaseTermination.
@Bean(name = "WAIT_FOR_EXTERNAL_DATABASE_TERMINATION_STATE")
public Action<?, ?> externalDatabaseTermination() {
return new AbstractExternalDatabaseTerminationAction<>(TerminationEvent.class) {
@Override
protected void doExecute(ExternalDatabaseContext context, TerminationEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
TerminateExternalDatabaseRequest request = new TerminateExternalDatabaseRequest(stack.getId(), "TerminateExternalDatabaseRequest", stack.getName(), stack.getResourceCrn(), payload.getTerminationType().isForced());
sendEvent(context, request);
}
};
}
Aggregations