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