Search in sources :

Example 6 with AcceptResult

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);
}
Also used : Promise(reactor.rx.Promise) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 7 with AcceptResult

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());
    }
}
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 8 with AcceptResult

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);
}
Also used : Promise(reactor.rx.Promise) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Aggregations

AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)8 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)8 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)4 Promise (reactor.rx.Promise)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 BaseFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseFlowEvent)3 Test (org.junit.Test)3 Event (reactor.bus.Event)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)1 Payload (com.sequenceiq.cloudbreak.common.event.Payload)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 FlowNotAcceptedException (com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)1 FlowsAlreadyRunningException (com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException)1 NestedSleepChainTriggerEvent (com.sequenceiq.flow.component.sleep.event.NestedSleepChainTriggerEvent)1 SleepChainTriggerEvent (com.sequenceiq.flow.component.sleep.event.SleepChainTriggerEvent)1 SleepConfig (com.sequenceiq.flow.component.sleep.event.SleepConfig)1