Search in sources :

Example 1 with StopStartDownscaleTriggerEvent

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

the class StopStartDownscaleFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(ClusterAndStackDownscaleTriggerEvent event) {
    StackView stackView = stackService.getViewByIdWithoutAuth(event.getResourceId());
    Map<String, Set<Long>> hostGroupsWithPrivateIds = event.getHostGroupsWithPrivateIds();
    Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
    // TODO CB-14929: Is a stack sync really required here. What does it do ? (As of now it also serves to accept the event)
    addStackSyncTriggerEvent(event, flowEventChain);
    if (hostGroupsWithPrivateIds.keySet().size() > 1) {
        throw new BadRequestException("Start stop downscale flow was intended to handle only 1 hostgroup.");
    }
    for (Map.Entry<String, Set<Long>> hostGroupWithPrivateIds : hostGroupsWithPrivateIds.entrySet()) {
        StopStartDownscaleTriggerEvent te = new StopStartDownscaleTriggerEvent(StopStartDownscaleEvent.STOPSTART_DOWNSCALE_TRIGGER_EVENT.event(), stackView.getId(), hostGroupWithPrivateIds.getKey(), hostGroupWithPrivateIds.getValue());
        flowEventChain.add(te);
    }
    return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
Also used : Set(java.util.Set) StopStartDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartDownscaleTriggerEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Map(java.util.Map)

Example 2 with StopStartDownscaleTriggerEvent

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

the class StopStartDownscaleActionsTest method testDecommissionViaCmAction.

@Test
void testDecommissionViaCmAction() throws Exception {
    AbstractStopStartDownscaleActions<StopStartDownscaleTriggerEvent> action = (AbstractStopStartDownscaleActions<StopStartDownscaleTriggerEvent>) underTest.decommissionViaCmAction();
    initActionPrivateFields(action);
    List<InstanceMetaData> instancesActionableStarted = generateInstances(10, 100, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_ACTIONABLE);
    Set<Long> instanceIdsToRemove = instancesActionableStarted.stream().limit(5).map(InstanceMetaData::getId).collect(Collectors.toUnmodifiableSet());
    StopStartDownscaleContext stopStartDownscaleContext = createContext(instanceIdsToRemove);
    StopStartDownscaleTriggerEvent payload = new StopStartDownscaleTriggerEvent(SELECTOR, STACK_ID, INSTANCE_GROUP_NAME_ACTIONABLE, instanceIdsToRemove);
    mockStackEtc();
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(action).doExecute(stopStartDownscaleContext, payload, Collections.emptyMap());
    verify(stopStartDownscaleFlowService).clusterDownscaleStarted(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), eq(instanceIdsToRemove));
    verifyNoMoreInteractions(stopStartDownscaleFlowService);
    ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
    verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
    verify(eventBus).notify("STOPSTARTDOWNSCALEDECOMMISSIONVIACMREQUEST", event);
    assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartDownscaleDecommissionViaCMRequest.class);
    StopStartDownscaleDecommissionViaCMRequest req = (StopStartDownscaleDecommissionViaCMRequest) argumentCaptor.getValue();
    Assert.assertEquals(instanceIdsToRemove, req.getInstanceIdsToDecommission());
    Assert.assertEquals(INSTANCE_GROUP_NAME_ACTIONABLE, req.getHostGroupName());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StopStartDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartDownscaleTriggerEvent) StopStartDownscaleDecommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest) AbstractStopStartDownscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleActions.AbstractStopStartDownscaleActions) Test(org.junit.jupiter.api.Test)

Aggregations

StopStartDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StopStartDownscaleTriggerEvent)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 AbstractStopStartDownscaleActions (com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleActions.AbstractStopStartDownscaleActions)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 StopStartDownscaleDecommissionViaCMRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest)1 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 Test (org.junit.jupiter.api.Test)1