Search in sources :

Example 1 with StackDownscaleTriggerEvent

use of com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent in project cloudbreak by hortonworks.

the class ReactorFlowManager method triggerStackDownscale.

public void triggerStackDownscale(Long stackId, InstanceGroupAdjustmentJson instanceGroupAdjustment) {
    String selector = STACK_DOWNSCALE_EVENT.event();
    Acceptable stackScaleTriggerEvent = new StackDownscaleTriggerEvent(selector, stackId, instanceGroupAdjustment.getInstanceGroup(), instanceGroupAdjustment.getScalingAdjustment());
    notify(selector, stackScaleTriggerEvent);
}
Also used : ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) Acceptable(com.sequenceiq.cloudbreak.cloud.Acceptable)

Example 2 with StackDownscaleTriggerEvent

use of com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent in project cloudbreak by hortonworks.

the class AbstractStackDownscaleAction method extractAdjustment.

private Integer extractAdjustment(P payload, Map<Object, Object> variables) {
    if (payload instanceof StackDownscaleTriggerEvent) {
        StackDownscaleTriggerEvent ssc = (StackDownscaleTriggerEvent) payload;
        Integer adjustment = ssc.getHostNames() == null ? ssc.getAdjustment() : -ssc.getHostNames().size();
        variables.put(ADJUSTMENT, adjustment);
        return adjustment;
    }
    return getAdjustment(variables);
}
Also used : StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)

Example 3 with StackDownscaleTriggerEvent

use of com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent in project cloudbreak by hortonworks.

the class AbstractStackDownscaleAction method extractInstanceIds.

private Set<String> extractInstanceIds(P payload, Map<Object, Object> variables, Stack stack) {
    if (payload instanceof StackDownscaleTriggerEvent) {
        StackDownscaleTriggerEvent ssc = (StackDownscaleTriggerEvent) payload;
        Set<String> instanceIds;
        if (ssc.getHostNames() == null || ssc.getHostNames().isEmpty()) {
            Map<String, String> unusedInstanceIds = stackScalingService.getUnusedInstanceIds(ssc.getInstanceGroup(), ssc.getAdjustment(), stack);
            instanceIds = new HashSet<>(unusedInstanceIds.keySet());
        } else {
            Set<InstanceMetaData> imds = stack.getInstanceGroupByInstanceGroupName(ssc.getInstanceGroup()).getInstanceMetaData();
            instanceIds = imds.stream().filter(imd -> ssc.getHostNames().contains(imd.getDiscoveryFQDN())).map(InstanceMetaData::getInstanceId).collect(Collectors.toSet());
        }
        variables.put(INSTANCEIDS, instanceIds);
        return instanceIds;
    }
    return getInstanceIds(variables);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) StateContext(org.springframework.statemachine.StateContext) AbstractAction(com.sequenceiq.cloudbreak.core.flow2.AbstractAction) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CredentialToCloudCredentialConverter(com.sequenceiq.cloudbreak.converter.spi.CredentialToCloudCredentialConverter) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackScalingService(com.sequenceiq.cloudbreak.service.stack.flow.StackScalingService) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)

Example 4 with StackDownscaleTriggerEvent

use of com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent 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)

Example 5 with StackDownscaleTriggerEvent

use of com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent in project cloudbreak by hortonworks.

the class DownscaleFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public Queue<Selectable> createFlowTriggerEventQueue(ClusterAndStackDownscaleTriggerEvent event) {
    Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
    ClusterScaleTriggerEvent cste;
    cste = event.getHostNames() == null ? new ClusterDownscaleTriggerEvent(DECOMMISSION_EVENT.event(), event.getStackId(), event.getHostGroupName(), event.getAdjustment(), event.accepted()) : new ClusterDownscaleTriggerEvent(DECOMMISSION_EVENT.event(), event.getStackId(), event.getHostGroupName(), event.getHostNames(), event.accepted());
    flowEventChain.add(cste);
    if (event.getScalingType() == ScalingType.DOWNSCALE_TOGETHER) {
        StackView stackView = stackService.getByIdView(event.getStackId());
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stackView.getClusterView().getId(), event.getHostGroupName());
        Constraint hostGroupConstraint = hostGroup.getConstraint();
        String instanceGroupName = Optional.ofNullable(hostGroupConstraint.getInstanceGroup()).map(InstanceGroup::getGroupName).orElse(null);
        StackScaleTriggerEvent sste;
        sste = event.getHostNames() == null ? new StackDownscaleTriggerEvent(STACK_DOWNSCALE_EVENT.event(), event.getStackId(), instanceGroupName, event.getAdjustment()) : new StackDownscaleTriggerEvent(STACK_DOWNSCALE_EVENT.event(), event.getStackId(), instanceGroupName, event.getHostNames());
        flowEventChain.add(sste);
    }
    return flowEventChain;
}
Also used : ClusterDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleTriggerEvent) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) ClusterScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterScaleTriggerEvent) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StackView(com.sequenceiq.cloudbreak.domain.view.StackView)

Aggregations

StackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)5 Selectable (com.sequenceiq.cloudbreak.cloud.event.Selectable)2 ClusterAndStackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent)2 StackScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 Map (java.util.Map)2 Acceptable (com.sequenceiq.cloudbreak.cloud.Acceptable)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 Payload (com.sequenceiq.cloudbreak.cloud.event.Payload)1 DownscaleStackCollectResourcesRequest (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest)1 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)1 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)1 CredentialToCloudCredentialConverter (com.sequenceiq.cloudbreak.converter.spi.CredentialToCloudCredentialConverter)1