Search in sources :

Example 1 with ClusterDownscaleDetails

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();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) HashMap(java.util.HashMap) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) ClusterDownscaleDetails(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails)

Example 2 with ClusterDownscaleDetails

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);
        }
    };
}
Also used : ClusterDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleTriggerEvent) CollectDownscaleCandidatesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest) AbstractClusterAction(com.sequenceiq.cloudbreak.core.flow2.cluster.AbstractClusterAction) Map(java.util.Map) ClusterDownscaleDetails(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails) ClusterViewContext(com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext) Bean(org.springframework.context.annotation.Bean)

Example 3 with ClusterDownscaleDetails

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);
}
Also used : Set(java.util.Set) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) MultiHostgroupClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.MultiHostgroupClusterAndStackDownscaleTriggerEvent) Map(java.util.Map) ClusterDownscaleDetails(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails)

Example 4 with ClusterDownscaleDetails

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());
}
Also used : CollectDownscaleCandidatesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest) Event(reactor.bus.Event) CollectDownscaleCandidatesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult) ClusterDownscaleDetails(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 5 with ClusterDownscaleDetails

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);
}
Also used : MultiHostgroupClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.MultiHostgroupClusterAndStackDownscaleTriggerEvent) ClusterDownscaleDetails(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails)

Aggregations

ClusterDownscaleDetails (com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleDetails)7 MultiHostgroupClusterAndStackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.MultiHostgroupClusterAndStackDownscaleTriggerEvent)4 ClusterAndStackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent)3 Set (java.util.Set)3 CollectDownscaleCandidatesRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 AbstractClusterAction (com.sequenceiq.cloudbreak.core.flow2.cluster.AbstractClusterAction)1 ClusterViewContext (com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext)1 ClusterDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleTriggerEvent)1 StackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 CollectDownscaleCandidatesResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1