Stack stack = stackRepository.findOne(stackId);
MDCBuilder.buildMdcContext(stack);
Status stackStatus = stack.getStatus();
if (status.equals(StatusRequest.STARTED)) {
if (!Status.STOPPED.equals(stackStatus)) {
throw new BadRequestException(String.format("Cannot update the status of stack '%s' to STARTED, because it isn't in STOPPED state.", stackId));
}
stack.setStatus(Status.START_IN_PROGRESS);
stackRepository.save(stack);
LOGGER.info("Publishing {} event", ReactorConfig.STACK_STATUS_UPDATE_EVENT);
reactor.notify(ReactorConfig.STACK_STATUS_UPDATE_EVENT,
Event.wrap(new StackStatusUpdateRequest(stack.getTemplate().cloudPlatform(), stack.getId(), status)));
} else {
Status clusterStatus = clusterRepository.findOneWithLists(stack.getCluster().getId()).getStatus();
if (Status.STOP_IN_PROGRESS.equals(clusterStatus)) {
stack.setStatus(Status.STOP_REQUESTED);
stackRepository.save(stack);
} else {
if (!Status.AVAILABLE.equals(stackStatus)) {
throw new BadRequestException(
String.format("Cannot update the status of stack '%s' to STOPPED, because it isn't in AVAILABLE state.", stackId));
}
if (!Status.STOPPED.equals(clusterStatus)) {
throw new BadRequestException(
String.format("Cannot update the status of stack '%s' to STOPPED, because the cluster is not in STOPPED state.", stackId));
}
LOGGER.info("Publishing {} event.", ReactorConfig.STACK_STATUS_UPDATE_EVENT);
reactor.notify(ReactorConfig.STACK_STATUS_UPDATE_EVENT,
Event.wrap(new StackStatusUpdateRequest(stack.getTemplate().cloudPlatform(), stack.getId(), status)));