use of com.sequenceiq.cloudbreak.common.event.AcceptResult in project cloudbreak by hortonworks.
the class ReactorNotifierTest method testAcceptedReturnFalse.
@Test(expected = FlowsAlreadyRunningException.class)
public void testAcceptedReturnFalse() throws InterruptedException {
Stack stack = TestUtil.stack();
stack.setCluster(TestUtil.cluster());
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);
when(accepted.await(10L, TimeUnit.SECONDS)).thenReturn(FlowAcceptResult.alreadyExistingFlow(Collections.EMPTY_SET));
underTest.notify(1L, "RANDOM", data, stackService::getByIdWithTransaction);
verify(reactorReporter, times(1)).logInfoReport();
verify(reactorReporter, times(1)).logErrorReport();
verify(reactor, times(1)).notify(eq("RANDOM"), eq(event));
verify(accepted, times(1)).await(10L, TimeUnit.SECONDS);
}
use of com.sequenceiq.cloudbreak.common.event.AcceptResult 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());
}
}
use of com.sequenceiq.cloudbreak.common.event.AcceptResult 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);
}
Aggregations