Search in sources :

Example 6 with StopStartDownscaleStopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult in project cloudbreak by hortonworks.

the class StopStartDownscaleStopInstancesHandler method accept.

@Override
public void accept(Event<StopStartDownscaleStopInstancesRequest> event) {
    StopStartDownscaleStopInstancesRequest request = event.getData();
    LOGGER.info("StopStartDownscaleStopInstancesHandler: {}", event.getData().getResourceId());
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector<?> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = getAuthenticatedContext(request, cloudContext, connector);
        List<CloudInstance> cloudInstancesToStop = request.getCloudInstancesToStop();
        List<CloudVmInstanceStatus> cloudVmInstanceStatusList = Collections.emptyList();
        if (cloudInstancesToStop.size() > 0) {
            LOGGER.info("Attempting to stop instances with a timebound of {}ms. count={}, instances=[{}]", STOP_POLL_TIMEBOUND_MS, cloudInstancesToStop.size(), cloudInstancesToStop.stream().map(CloudInstance::getInstanceId).collect(Collectors.toList()));
            // TODO CB-15132: CB-15342 In case of a failure in this step, the nodes stay in a DECOMMISSIONED state,
            // even if the services are started via CM. The StackStatusChckerJob appears to ignore a bunch of CM states.
            // TODO CB-15132: What happens if the cloud provider does not know about an instance for which a STOP was requested. How does the API
            // behave.
            cloudVmInstanceStatusList = connector.instances().stopWithLimitedRetry(ac, null, cloudInstancesToStop, STOP_POLL_TIMEBOUND_MS);
        } else {
            LOGGER.info("No cloud VM instances to stop. Succeeding flow step with no action taken");
        }
        LOGGER.trace("CloudVMInstanceStatusesPostStop={}", cloudVmInstanceStatusList);
        // TODO CB-15132: If we fail to STOP all instances - one potential path for error handling would be to allow a subsequent upscale operation
        // to consider nodes which are in DECOMMISSIONED state, but RUNNING - as candidates for UPSCALE.
        StopStartDownscaleStopInstancesResult result = new StopStartDownscaleStopInstancesResult(request.getResourceId(), request, cloudVmInstanceStatusList);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    } catch (Exception e) {
        // TODO CB-15132: Try propagating specific information in the error, so that a later step can potentially attempt
        // to recover from this, or proceed with a reduced set of nodes.
        String message = "Failed while attempting to stop some instances";
        LOGGER.error(message, e);
        StopStartDownscaleStopInstancesResult result = new StopStartDownscaleStopInstancesResult(message, e, request.getResourceId(), request);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    }
}
Also used : StopStartDownscaleStopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) StopStartDownscaleStopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Event(reactor.bus.Event)

Aggregations

StopStartDownscaleStopInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult)6 StopStartDownscaleStopInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest)5 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)3 Test (org.junit.jupiter.api.Test)3 Event (reactor.bus.Event)3 AbstractStopStartDownscaleActions (com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleActions.AbstractStopStartDownscaleActions)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1