Search in sources :

Example 1 with FlowAcceptResult

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

the class EventSender method doSend.

private FlowIdentifier doSend(BaseFlowEvent event, Event.Headers headers, String resourceName) {
    Event<BaseFlowEvent> eventWithErrHandler = eventFactory.createEventWithErrHandler(new HashMap<>(headers.asMap()), event);
    reactor.notify(event.selector(), eventWithErrHandler);
    Promise<AcceptResult> accepted = eventWithErrHandler.getData().accepted();
    String resourceCrn = event.getResourceCrn();
    if (accepted != null) {
        try {
            FlowAcceptResult acceptResult = (FlowAcceptResult) accepted.await(TIMEOUT, TimeUnit.SECONDS);
            return createFlowIdentifier(acceptResult, resourceCrn);
        } catch (InterruptedException e) {
            throw new IllegalStateException(e.getMessage());
        }
    }
    if (headers.contains(FLOW_ID)) {
        return new FlowIdentifier(FlowType.FLOW, headers.get(FLOW_ID));
    } else if (headers.contains(FLOW_CHAIN_ID)) {
        return new FlowIdentifier(FlowType.FLOW_CHAIN, headers.get(FLOW_CHAIN_ID));
    }
    LOGGER.error("Accepted is null, header does not contains flow or flow chain id, event: {}, header: {}", event, headers);
    reactorReporter.logErrorReport();
    throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for stack %s.", resourceCrn));
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 2 with FlowAcceptResult

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

the class FlowComponentTest method startIdempotentFlowChainWhileTheOtherIsRunningReturnsOriginalFlowChainId.

@Test
public void startIdempotentFlowChainWhileTheOtherIsRunningReturnsOriginalFlowChainId() 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.NEVER_FAIL), new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)));
    FlowAcceptResult acceptResult1 = startSleepFlowChain(sleepChainTriggerEvent1);
    FlowAcceptResult acceptResult2 = startSleepFlowChain(sleepChainTriggerEvent2);
    assertRunningInFlowChain(acceptResult1);
    assertRunningInFlowChain(acceptResult2);
    waitFlowChainToComplete(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult2);
}
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 3 with FlowAcceptResult

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

the class FlowComponentTest method startFlowThenWaitForFail.

@Test
public void startFlowThenWaitForFail() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepStartEvent sleepStartEvent = SleepStartEvent.alwaysFail(resourceId, SLEEP_TIME);
    FlowAcceptResult acceptResult = startSleepFlow(sleepStartEvent);
    assertRunningInFlow(acceptResult);
    waitFlowToFail(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) SleepStartEvent(com.sequenceiq.flow.component.sleep.event.SleepStartEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with FlowAcceptResult

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

the class FlowComponentTest method retryFailedFlowAllowedMultipleTimes.

@Test
public void retryFailedFlowAllowedMultipleTimes() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepStartEvent sleepStartEvent = SleepStartEvent.alwaysFail(resourceId, SLEEP_TIME);
    FlowAcceptResult acceptResult = startSleepFlow(sleepStartEvent);
    assertRunningInFlow(acceptResult);
    waitFlowToFail(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
    FlowIdentifier flowIdentifier = flow2Handler.retryLastFailedFlow(resourceId, noOp());
    assertEquals(FlowType.FLOW, flowIdentifier.getType());
    assertEquals(acceptResult.getAsFlowId(), flowIdentifier.getPollableId());
    waitFlowToFail(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
    flowIdentifier = flow2Handler.retryLastFailedFlow(resourceId, noOp());
    assertEquals(FlowType.FLOW, flowIdentifier.getType());
    assertEquals(acceptResult.getAsFlowId(), flowIdentifier.getPollableId());
    waitFlowToFail(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) SleepStartEvent(com.sequenceiq.flow.component.sleep.event.SleepStartEvent) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with FlowAcceptResult

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

the class FlowComponentTest method startingDifferentFlowFailsBeforeFirstCompletes.

@Test
public void startingDifferentFlowFailsBeforeFirstCompletes() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepStartEvent sleepStartEvent1 = SleepStartEvent.neverFail(resourceId, SLEEP_TIME);
    SleepStartEvent sleepStartEvent2 = SleepStartEvent.alwaysFail(resourceId, SLEEP_TIME);
    FlowAcceptResult acceptResult = startSleepFlow(sleepStartEvent1);
    FlowAcceptResult rejectResult = startSleepFlow(sleepStartEvent2);
    assertRunningInFlow(acceptResult);
    assertRejected(rejectResult);
    waitFlowToComplete(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) SleepStartEvent(com.sequenceiq.flow.component.sleep.event.SleepStartEvent) 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