Search in sources :

Example 11 with FlowAcceptResult

use of com.sequenceiq.flow.core.model.FlowAcceptResult in project cloudbreak by hortonworks.

the class SdxReactorFlowManager method notify.

private FlowIdentifier notify(String selector, SdxEvent acceptable, String identifier) {
    Map<String, Object> flowTriggerUserCrnHeader = Map.of(FlowConstants.FLOW_TRIGGER_USERCRN, acceptable.getUserId());
    Event<Acceptable> event = eventFactory.createEventWithErrHandler(flowTriggerUserCrnHeader, acceptable);
    reactor.notify(selector, event);
    try {
        FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        if (accepted == null) {
            throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for sdx cluster %s.", event.getData().getResourceId()));
        } else {
            switch(accepted.getResultType()) {
                case ALREADY_EXISTING_FLOW:
                    throw new FlowsAlreadyRunningException(String.format("Request not allowed, datalake cluster '%s' already has a running operation. " + "Running operation(s): [%s]", identifier, flowNameFormatService.formatFlows(accepted.getAlreadyRunningFlows())));
                case RUNNING_IN_FLOW:
                    return new FlowIdentifier(FlowType.FLOW, accepted.getAsFlowId());
                case RUNNING_IN_FLOW_CHAIN:
                    return new FlowIdentifier(FlowType.FLOW_CHAIN, accepted.getAsFlowChainId());
                default:
                    throw new IllegalStateException("Unsupported accept result type: " + accepted.getClass());
            }
        }
    } catch (InterruptedException e) {
        throw new CloudbreakApiException(e.getMessage());
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 12 with FlowAcceptResult

use of com.sequenceiq.flow.core.model.FlowAcceptResult in project cloudbreak by hortonworks.

the class ReactorNotifierTest method testAccepted.

@Test
public void testAccepted() throws InterruptedException {
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    stack.setStackStatus(new StackStatus(stack, AVAILABLE));
    when(stackService.getByIdWithTransaction(1L)).thenReturn(stack);
    Acceptable data = mock(Acceptable.class);
    Promise<AcceptResult> accepted = (Promise<AcceptResult>) mock(Promise.class);
    when(data.accepted()).thenReturn(accepted);
    when(data.getResourceId()).thenReturn(1L);
    Event<Acceptable> event = new Event<>(data);
    when(eventFactory.createEventWithErrHandler(anyMap(), any(Acceptable.class))).thenReturn(event);
    FlowAcceptResult acceptResult = FlowAcceptResult.runningInFlow("flowid");
    when(accepted.await(10L, TimeUnit.SECONDS)).thenReturn(acceptResult);
    underTest.notify(1L, "RANDOM", data, stackService::getByIdWithTransaction);
    verify(reactorReporter, times(1)).logInfoReport();
    verify(reactor, times(1)).notify(eq("RANDOM"), eq(event));
    verify(accepted, times(1)).await(10L, TimeUnit.SECONDS);
}
Also used : Promise(reactor.rx.Promise) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 13 with FlowAcceptResult

use of com.sequenceiq.flow.core.model.FlowAcceptResult in project cloudbreak by hortonworks.

the class FlowComponentTest method retryCompletedFlowFails.

@Test
public void retryCompletedFlowFails() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepStartEvent sleepStartEvent = SleepStartEvent.neverFail(resourceId, SLEEP_TIME);
    FlowAcceptResult acceptResult = startSleepFlow(sleepStartEvent);
    assertRunningInFlow(acceptResult);
    waitFlowToComplete(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> flow2Handler.retryLastFailedFlow(resourceId, noOp()));
    assertEquals("Retry cannot be performed, because the last action was successful.", exception.getMessage());
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) SleepStartEvent(com.sequenceiq.flow.component.sleep.event.SleepStartEvent) BadRequestException(javax.ws.rs.BadRequestException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with FlowAcceptResult

use of com.sequenceiq.flow.core.model.FlowAcceptResult in project cloudbreak by hortonworks.

the class FlowComponentTest method startingDifferentFlowChainFailsBeforeFirstCompletes.

@Test
public void startingDifferentFlowChainFailsBeforeFirstCompletes() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepChainTriggerEvent sleepChainTriggerEvent1 = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL), new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)));
    SleepChainTriggerEvent sleepChainTriggerEvent2 = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.ALWAYS_FAIL), new SleepConfig(SLEEP_TIME, SleepStartEvent.ALWAYS_FAIL)));
    FlowAcceptResult acceptResult = startSleepFlowChain(sleepChainTriggerEvent1);
    FlowAcceptResult rejectResult = startSleepFlowChain(sleepChainTriggerEvent2);
    assertRunningInFlowChain(acceptResult);
    assertRejected(rejectResult);
    waitFlowChainToComplete(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) SleepChainTriggerEvent(com.sequenceiq.flow.component.sleep.event.SleepChainTriggerEvent) NestedSleepChainTriggerEvent(com.sequenceiq.flow.component.sleep.event.NestedSleepChainTriggerEvent) SleepConfig(com.sequenceiq.flow.component.sleep.event.SleepConfig) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with FlowAcceptResult

use of com.sequenceiq.flow.core.model.FlowAcceptResult in project cloudbreak by hortonworks.

the class FlowComponentTest method startFlowChainWhenSecondFlowTriggerConditionFailsItShouldFail.

@Test
public void startFlowChainWhenSecondFlowTriggerConditionFailsItShouldFail() throws InterruptedException {
    reset(sleepTriggerCondition);
    when(sleepTriggerCondition.isFlowTriggerable(anyLong())).thenReturn(FlowTriggerConditionResult.OK).thenReturn(new FlowTriggerConditionResult("Error"));
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepChainTriggerEvent sleepChainTriggerEvent = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL), new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)));
    FlowAcceptResult acceptResult = startSleepFlowChain(sleepChainTriggerEvent);
    assertRunningInFlowChain(acceptResult);
    waitFlowChainToFail(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) SleepChainTriggerEvent(com.sequenceiq.flow.component.sleep.event.SleepChainTriggerEvent) NestedSleepChainTriggerEvent(com.sequenceiq.flow.component.sleep.event.NestedSleepChainTriggerEvent) FlowTriggerConditionResult(com.sequenceiq.flow.core.FlowTriggerConditionResult) SleepConfig(com.sequenceiq.flow.component.sleep.event.SleepConfig) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)21 Test (org.junit.jupiter.api.Test)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 SleepStartEvent (com.sequenceiq.flow.component.sleep.event.SleepStartEvent)10 NestedSleepChainTriggerEvent (com.sequenceiq.flow.component.sleep.event.NestedSleepChainTriggerEvent)7 SleepChainTriggerEvent (com.sequenceiq.flow.component.sleep.event.SleepChainTriggerEvent)7 SleepConfig (com.sequenceiq.flow.component.sleep.event.SleepConfig)7 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)6 AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)4 FlowNotAcceptedException (com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)3 FlowsAlreadyRunningException (com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException)3 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)2 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)2 BadRequestException (javax.ws.rs.BadRequestException)2 Promise (reactor.rx.Promise)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 FlowTriggerConditionResult (com.sequenceiq.flow.core.FlowTriggerConditionResult)1 BaseFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseFlowEvent)1