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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations