use of com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails in project cloudbreak by hortonworks.
the class ClusterRepairFlowEventChainFactory method downscaleEvent.
private StackEvent downscaleEvent(boolean singlePrimaryGW, ClusterRepairTriggerEvent event, Map<String, Set<String>> groupsWithHostNames) {
Set<InstanceMetaData> instanceMetaData = instanceMetaDataService.getAllInstanceMetadataWithoutInstanceGroupByStackId(event.getStackId());
Map<String, Set<Long>> groupsWithPrivateIds = new HashMap<>();
Map<String, Integer> groupsWithAdjustment = new HashMap<>();
for (Entry<String, Set<String>> groupWithHostNames : groupsWithHostNames.entrySet()) {
Set<String> hostNames = groupWithHostNames.getValue();
String group = groupWithHostNames.getKey();
Set<Long> privateIdsForHostNames = stackService.getPrivateIdsForHostNames(instanceMetaData, hostNames);
groupsWithPrivateIds.put(group, privateIdsForHostNames);
int size = hostNames != null ? hostNames.size() : 0;
groupsWithAdjustment.put(group, size);
}
LOGGER.info("Downscale groups with adjustments: {}", groupsWithAdjustment);
LOGGER.info("Downscale groups with privateIds: {}", groupsWithPrivateIds);
if (!singlePrimaryGW) {
LOGGER.info("Full downscale for the following: {}", groupsWithHostNames);
return new ClusterAndStackDownscaleTriggerEvent(FlowChainTriggers.FULL_DOWNSCALE_TRIGGER_EVENT, event.getResourceId(), groupsWithAdjustment, groupsWithPrivateIds, groupsWithHostNames, ScalingType.DOWNSCALE_TOGETHER, event.accepted(), new ClusterDownscaleDetails(true, true));
} else {
LOGGER.info("Stack downscale for the following: {}", groupsWithHostNames);
return new StackDownscaleTriggerEvent(STACK_DOWNSCALE_EVENT.event(), event.getResourceId(), groupsWithAdjustment, groupsWithPrivateIds, groupsWithHostNames, event.getTriggeredStackVariant(), event.accepted()).setRepair();
}
}
use of com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails in project cloudbreak by hortonworks.
the class ClusterDownscaleActions method collectCandidatesAction.
@Bean(name = "COLLECT_CANDIDATES_STATE")
public Action<?, ?> collectCandidatesAction() {
return new AbstractClusterAction<>(ClusterDownscaleTriggerEvent.class) {
@Override
protected void doExecute(ClusterViewContext context, ClusterDownscaleTriggerEvent payload, Map<Object, Object> variables) {
ClusterDownscaleDetails clusterDownscaleDetails = payload.getDetails();
variables.put(REPAIR, clusterDownscaleDetails == null ? Boolean.FALSE : Boolean.valueOf(payload.getDetails().isRepair()));
clusterDownscaleService.clusterDownscaleStarted(context.getStackId(), payload.getHostGroupsWithAdjustment(), payload.getHostGroupsWithPrivateIds(), payload.getDetails());
CollectDownscaleCandidatesRequest request = new CollectDownscaleCandidatesRequest(context.getStackId(), payload.getHostGroupsWithAdjustment(), payload.getHostGroupsWithPrivateIds(), payload.getDetails());
sendEvent(context, request.selector(), request);
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails in project cloudbreak by hortonworks.
the class ReactorFlowManager method triggerStopStartStackDownscale.
public FlowIdentifier triggerStopStartStackDownscale(Long stackId, Map<String, Set<Long>> instanceIdsByHostgroupMap, boolean forced) {
// TODO CB-14929: stop-start is not meant for multiple hostGroups - set up a different API for this.
LOGGER.debug("triggerStopStartStackDownscale with instanceIdsByHostgroupMap={}", instanceIdsByHostgroupMap);
if (instanceIdsByHostgroupMap.size() != 1) {
throw new RuntimeException("Expected instancesIdsToHostGroupMap to contain exactly 1 host group. Found" + instanceIdsByHostgroupMap.size());
}
Map.Entry<String, Set<Long>> entry = instanceIdsByHostgroupMap.entrySet().iterator().next();
String hostGroup = entry.getKey();
Set<Long> privateIds = entry.getValue();
LOGGER.debug("ids to remove(stop). size:{}, ids:{}", privateIds.size(), privateIds);
String selector = FlowChainTriggers.STOPSTART_DOWNSCALE_CHAIN_TRIGGER_EVENT;
ClusterDownscaleDetails details = new ClusterDownscaleDetails(forced, false);
ClusterAndStackDownscaleTriggerEvent event = new ClusterAndStackDownscaleTriggerEvent(selector, stackId, Collections.singletonMap(hostGroup, privateIds), ScalingType.DOWNSCALE_TOGETHER, new Promise<>(), details);
return reactorNotifier.notify(stackId, selector, event);
}
use of com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails in project cloudbreak by hortonworks.
the class CollectDownscaleCandidatesHandlerTest method downScaleForcedForced.
@Test
public void downScaleForcedForced() {
// given
Stack stack = generateStackData();
Event<CollectDownscaleCandidatesRequest> event = generateTestDataEvent(Collections.singleton(PRIVATE_ID), new ClusterDownscaleDetails(true, false));
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
// when
testedClass.accept(event);
// then
ArgumentCaptor<Event<CollectDownscaleCandidatesResult>> capturedEvent = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify((Object) any(), capturedEvent.capture());
Event<CollectDownscaleCandidatesResult> submittedEvent = capturedEvent.getValue();
CollectDownscaleCandidatesResult submittedResult = submittedEvent.getData();
assertNotNull(submittedResult);
assertTrue(submittedResult.getRequest().getDetails().isForced());
}
use of com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails in project cloudbreak by hortonworks.
the class ReactorFlowManager method triggerStackRemoveInstances.
public FlowIdentifier triggerStackRemoveInstances(Long stackId, Map<String, Set<Long>> instanceIdsByHostgroupMap, boolean forced) {
String selector = FlowChainTriggers.FULL_DOWNSCALE_MULTIHOSTGROUP_TRIGGER_EVENT;
ClusterDownscaleDetails details = new ClusterDownscaleDetails(forced, false);
MultiHostgroupClusterAndStackDownscaleTriggerEvent event = new MultiHostgroupClusterAndStackDownscaleTriggerEvent(selector, stackId, instanceIdsByHostgroupMap, details, ScalingType.DOWNSCALE_TOGETHER, new Promise<>());
return reactorNotifier.notify(stackId, selector, event);
}
Aggregations