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