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);
}
}
}
Aggregations