Search in sources :

Example 1 with ScalingFailedException

use of com.sequenceiq.cloudbreak.service.stack.flow.ScalingFailedException in project cloudbreak by hortonworks.

the class InstanceTerminationService method instanceTermination.

public void instanceTermination(InstanceTerminationContext context) {
    Stack stack = context.getStack();
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REMOVE_INSTANCE, "Removing instance");
    flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_REMOVING_INSTANCE, UPDATE_IN_PROGRESS.name());
    List<InstanceMetaData> instanceMetaDataList = context.getInstanceMetaDataList();
    for (InstanceMetaData instanceMetaData : instanceMetaDataList) {
        String hostName = instanceMetaData.getDiscoveryFQDN();
        if (stack.getCluster() != null) {
            HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), hostName);
            if (hostMetadata == null) {
                LOGGER.info("Nothing to remove since hostmetadata is null");
            } else if (HostMetadataState.HEALTHY.equals(hostMetadata.getHostMetadataState())) {
                throw new ScalingFailedException(String.format("Host (%s) is in HEALTHY state. Cannot be removed.", hostName));
            }
        }
        if (hostName != null) {
            String instanceGroupName = instanceMetaData.getInstanceGroup().getGroupName();
            flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_SCALING_TERMINATING_HOST_FROM_HOSTGROUP, UPDATE_IN_PROGRESS.name(), hostName, instanceGroupName);
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ScalingFailedException(com.sequenceiq.cloudbreak.service.stack.flow.ScalingFailedException) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 ScalingFailedException (com.sequenceiq.cloudbreak.service.stack.flow.ScalingFailedException)1