Search in sources :

Example 6 with FlowAcceptResult

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

the class FlowComponentTest method retryPendingFlowFails.

@Test
public void retryPendingFlowFails() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepStartEvent sleepStartEvent = SleepStartEvent.neverFail(resourceId, SLEEP_TIME);
    FlowAcceptResult acceptResult = startSleepFlow(sleepStartEvent);
    assertRunningInFlow(acceptResult);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> flow2Handler.retryLastFailedFlow(resourceId, noOp()));
    assertEquals("Retry cannot be performed, because there is already an active flow.", exception.getMessage());
    waitFlowToComplete(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult);
}
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 7 with FlowAcceptResult

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

the class FlowComponentTest method startingFlowChainFailsWhenFlowIsAlreadyRunning.

@Test
public void startingFlowChainFailsWhenFlowIsAlreadyRunning() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    SleepStartEvent sleepStartEvent = SleepStartEvent.neverFail(resourceId, SLEEP_TIME);
    SleepChainTriggerEvent sleepChainTriggerEvent = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL), new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)));
    FlowAcceptResult acceptResult = startSleepFlow(sleepStartEvent);
    FlowAcceptResult rejectResult = startSleepFlowChain(sleepChainTriggerEvent);
    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) 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 8 with FlowAcceptResult

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

the class FlowComponentTest method startNestedFlowChainThenWaitForComplete.

@Test
public void startNestedFlowChainThenWaitForComplete() throws InterruptedException {
    long resourceId = RESOURCE_ID_SEC.incrementAndGet();
    Promise<AcceptResult> accepted1 = new Promise<>();
    SleepChainTriggerEvent sleepChainTriggerEvent1 = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)), accepted1);
    SleepChainTriggerEvent sleepChainTriggerEvent2 = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)), accepted1);
    NestedSleepChainTriggerEvent nestedSleepChainTriggerEvent1 = new NestedSleepChainTriggerEvent(resourceId, Lists.newArrayList(sleepChainTriggerEvent1, sleepChainTriggerEvent2), accepted1);
    Promise<AcceptResult> accepted2 = new Promise<>();
    SleepChainTriggerEvent sleepChainTriggerEvent3 = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)), accepted2);
    SleepChainTriggerEvent sleepChainTriggerEvent4 = new SleepChainTriggerEvent(resourceId, Lists.newArrayList(new SleepConfig(SLEEP_TIME, SleepStartEvent.NEVER_FAIL)), accepted2);
    NestedSleepChainTriggerEvent nestedSleepChainTriggerEvent2 = new NestedSleepChainTriggerEvent(resourceId, Lists.newArrayList(sleepChainTriggerEvent3, sleepChainTriggerEvent4), accepted2);
    FlowAcceptResult acceptResult1 = startNestedSleepFlowChain(nestedSleepChainTriggerEvent1);
    FlowAcceptResult acceptResult2 = startNestedSleepFlowChain(nestedSleepChainTriggerEvent2);
    assertRunningInFlowChain(acceptResult1);
    assertRunningInFlowChain(acceptResult2);
    waitFlowChainToComplete(SLEEP_TIME.multipliedBy(WAIT_FACTOR), acceptResult1);
}
Also used : Promise(reactor.rx.Promise) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) NestedSleepChainTriggerEvent(com.sequenceiq.flow.component.sleep.event.NestedSleepChainTriggerEvent) SleepChainTriggerEvent(com.sequenceiq.flow.component.sleep.event.SleepChainTriggerEvent) NestedSleepChainTriggerEvent(com.sequenceiq.flow.component.sleep.event.NestedSleepChainTriggerEvent) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) SleepConfig(com.sequenceiq.flow.component.sleep.event.SleepConfig) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with FlowAcceptResult

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

the class FreeIpaFlowManager method checkFlowOperationForResource.

private FlowIdentifier checkFlowOperationForResource(Event<? extends Acceptable> event) {
    try {
        Promise<AcceptResult> acceptPromise = event.getData().accepted();
        FlowAcceptResult accepted = (FlowAcceptResult) Benchmark.checkedMeasure(() -> acceptPromise.await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS), LOGGER, "Accepting flow event took {}ms");
        if (accepted == null) {
            reactorReporter.logErrorReport();
            throw new RuntimeException("FlowAcceptResult was null. Maybe flow is under operation, request not allowed.");
        }
        switch(accepted.getResultType()) {
            case RUNNING_IN_FLOW:
                return new FlowIdentifier(FlowType.FLOW, accepted.getAsFlowId());
            case RUNNING_IN_FLOW_CHAIN:
                return new FlowIdentifier(FlowType.FLOW_CHAIN, accepted.getAsFlowChainId());
            case ALREADY_EXISTING_FLOW:
                throw new FlowsAlreadyRunningException(String.format("Request not allowed, freeipa cluster already has a running operation. " + "Running operation(s): [%s]", flowNameFormatService.formatFlows(accepted.getAlreadyRunningFlows())));
            default:
                throw new IllegalStateException("Illegal resultType: " + accepted.getResultType());
        }
    } catch (InterruptedException e) {
        reactorReporter.logErrorReport();
        throw new RuntimeException(e.getMessage());
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult)

Example 10 with FlowAcceptResult

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

the class ReactorNotifier method checkFlowStatus.

private FlowIdentifier checkFlowStatus(Event<? extends Acceptable> event, String identifier) {
    try {
        FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        if (accepted == null) {
            LOGGER.error("Event not accepted: {}", event);
            reactorReporter.logErrorReport();
            throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for stack %s.", identifier));
        }
        switch(accepted.getResultType()) {
            case ALREADY_EXISTING_FLOW:
                reactorReporter.logErrorReport();
                throw new FlowsAlreadyRunningException(String.format("Request not allowed, 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(), e);
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

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