Search in sources :

Example 6 with StackScalingFlowContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext in project cloudbreak by hortonworks.

the class StackDownscaleActions method stackDownscaleCollectResourcesAction.

@Bean(name = "DOWNSCALE_COLLECT_RESOURCES_STATE")
public Action<?, ?> stackDownscaleCollectResourcesAction() {
    return new AbstractStackDownscaleAction<StackDownscaleTriggerEvent>(StackDownscaleTriggerEvent.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, StackDownscaleTriggerEvent payload, Map<Object, Object> variables) {
            stackDownscaleService.startStackDownscale(context, payload);
            Stack stack = context.getStack();
            LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
            List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
            variables.put(RESOURCES, resources);
            List<CloudInstance> instances = new ArrayList<>();
            InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
            for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
                if (context.getInstanceIds().contains(metaData.getInstanceId())) {
                    CloudInstance cloudInstance = metadataConverter.convert(metaData);
                    instances.add(cloudInstance);
                }
            }
            variables.put(INSTANCES, instances);
            Selectable request = new DownscaleStackCollectResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), resources, instances);
            sendEvent(context.getFlowId(), request);
        }
    };
}
Also used : DownscaleStackCollectResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

StackScalingFlowContext (com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext)5 Map (java.util.Map)5 Bean (org.springframework.context.annotation.Bean)5 Selectable (com.sequenceiq.cloudbreak.cloud.event.Selectable)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)1 GetSSHFingerprintsRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest)1 DownscaleStackCollectResourcesRequest (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest)1 UpscaleStackRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 StackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)1 StackScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent)1 BootstrapNewNodesRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesRequest)1