Search in sources :

Example 1 with StopRestrictionReason

use of com.sequenceiq.cloudbreak.domain.StopRestrictionReason in project cloudbreak by hortonworks.

the class StackService method isStopNeeded.

private boolean isStopNeeded(Stack stack) {
    boolean result = true;
    StopRestrictionReason reason = stack.isInfrastructureStoppable();
    if (stack.isStopped()) {
        String statusDesc = cloudbreakMessagesService.getMessage(Msg.STACK_STOP_IGNORED.code());
        LOGGER.info(statusDesc);
        eventService.fireCloudbreakEvent(stack.getId(), STOPPED.name(), statusDesc);
        result = false;
    } else if (reason != StopRestrictionReason.NONE) {
        throw new BadRequestException(String.format("Cannot stop a stack '%s'. Reason: %s", stack.getName(), reason.getReason()));
    } else if (!stack.isAvailable() && !stack.isStopFailed()) {
        throw new BadRequestException(String.format("Cannot update the status of stack '%s' to STOPPED, because it isn't in AVAILABLE state.", stack.getName()));
    }
    return result;
}
Also used : StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 2 with StopRestrictionReason

use of com.sequenceiq.cloudbreak.domain.StopRestrictionReason in project cloudbreak by hortonworks.

the class AmbariClusterService method stop.

private void stop(Stack stack, Cluster cluster) {
    StopRestrictionReason reason = stack.isInfrastructureStoppable();
    if (cluster.isStopped()) {
        String statusDesc = cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_STOP_IGNORED.code());
        LOGGER.info(statusDesc);
        eventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), statusDesc);
    } else if (reason != StopRestrictionReason.NONE) {
        throw new BadRequestException(String.format("Cannot stop a cluster '%s'. Reason: %s", cluster.getId(), reason.getReason()));
    } else if (!cluster.isClusterReadyForStop() && !cluster.isStopFailed()) {
        throw new BadRequestException(String.format("Cannot update the status of cluster '%s' to STOPPED, because it isn't in AVAILABLE state.", cluster.getId()));
    } else if (!stack.isStackReadyForStop() && !stack.isStopFailed()) {
        throw new BadRequestException(String.format("Cannot update the status of cluster '%s' to STARTED, because the stack is not AVAILABLE", cluster.getId()));
    } else if (cluster.isAvailable() || cluster.isStopFailed()) {
        updateClusterStatusByStackId(stack.getId(), STOP_REQUESTED);
        flowManager.triggerClusterStop(stack.getId());
    }
}
Also used : StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 StopRestrictionReason (com.sequenceiq.cloudbreak.domain.StopRestrictionReason)2