Search in sources :

Example 1 with FlowNotTriggerableException

use of com.sequenceiq.flow.core.exception.FlowNotTriggerableException in project cloudbreak by hortonworks.

the class Flow2Handler method doAccept.

private void doAccept(Event<? extends Payload> event, String key, Payload payload, String flowChainId, String flowChainType, FlowParameters flowParameters) {
    try {
        if (FLOW_CANCEL.equals(key)) {
            cancelRunningFlows(payload.getResourceId());
        } else if (FLOW_FINAL.equals(key)) {
            finalizeFlow(flowParameters, flowChainId, payload.getResourceId(), getContextParams(event));
        } else if (flowParameters.getFlowId() == null) {
            AcceptResult result = handleNewFlowRequest(key, payload, flowParameters, flowChainId, flowChainType, getContextParams(event));
            LOGGER.info("Create new flow result {}", result);
            if (isAcceptablePayload(payload)) {
                ((Acceptable) payload).accepted().accept(result);
            }
        } else {
            handleFlowControlEvent(key, payload, flowParameters, flowChainId);
        }
    } catch (FlowNotTriggerableException e) {
        LOGGER.error("Failed to handle flow event.", e);
        if (isAcceptablePayload(payload)) {
            ((Acceptable) payload).accepted().onError(e);
        } else {
            throw e;
        }
    } catch (CloudbreakServiceException e) {
        LOGGER.error("Failed to handle flow event.", e);
        throw e;
    } catch (Exception e) {
        LOGGER.error("Failed to handle flow event.", e);
        throw new CloudbreakServiceException(e);
    }
}
Also used : FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) FlowNotFoundException(com.sequenceiq.flow.core.exception.FlowNotFoundException) FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 2 with FlowNotTriggerableException

use of com.sequenceiq.flow.core.exception.FlowNotTriggerableException in project cloudbreak by hortonworks.

the class Flow2HandlerTest method testFlowChainFailureOnNotTriggerableFlowCreatesFailedFlow.

@Test
public void testFlowChainFailureOnNotTriggerableFlowCreatesFailedFlow() throws TransactionExecutionException {
    Map<String, Object> headers = new HashMap<>();
    headers.put(FlowConstants.FLOW_CHAIN_ID, FLOW_CHAIN_ID);
    headers.put(FlowConstants.FLOW_TRIGGER_USERCRN, FLOW_TRIGGER_USERCRN);
    dummyEvent = new Event<>(new Headers(headers), payload);
    dummyEvent.setKey("KEY");
    BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
    given(flowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
    given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(new FlowTriggerConditionResult("Not triggerable."));
    FlowNotTriggerableException exception = assertThrows(FlowNotTriggerableException.class, () -> underTest.accept(dummyEvent));
    assertEquals("Not triggerable.", exception.getMessage());
    flowLogService.save(any(), eq(FLOW_CHAIN_ID), any(), eq(payload), any(), eq(flowConfig.getClass()), eq(FlowStateConstants.INIT_STATE));
    flowLogService.close(eq(payload.getResourceId()), any(), eq(true));
    flowChains.removeFullFlowChain(FLOW_CHAIN_ID, false);
}
Also used : FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) HashMap(java.util.HashMap) Headers(reactor.bus.Event.Headers) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with FlowNotTriggerableException

use of com.sequenceiq.flow.core.exception.FlowNotTriggerableException in project cloudbreak by hortonworks.

the class UpgradeCcmFlowIntegrationTest method testCcmUpgradeTriggerNotAllowed.

@Test
public void testCcmUpgradeTriggerNotAllowed() {
    StackStatus stackStatus = new StackStatus(stack, Status.CREATE_FAILED, "no reason at all", DetailedStackStatus.PROVISION_FAILED);
    stack.setStackStatus(stackStatus);
    FlowNotTriggerableException actualException = Assertions.assertThrows(FlowNotTriggerableException.class, this::triggerFlow);
    Assertions.assertTrue(actualException.getMessage().contains("Cluster Connectivity Manager upgrade could not " + "be triggered, because the cluster's state is not available."), "FlowNotTriggerableException exception message is not right");
}
Also used : FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Test(org.junit.jupiter.api.Test)

Example 4 with FlowNotTriggerableException

use of com.sequenceiq.flow.core.exception.FlowNotTriggerableException in project cloudbreak by hortonworks.

the class CcmUpgradeFlowIntegrationTest method testCcmUpgradeTriggerNotAllowed.

@Test
public void testCcmUpgradeTriggerNotAllowed() {
    StackStatus stackStatus = new StackStatus(stack, Status.CREATE_FAILED, "no reason at all", DetailedStackStatus.PROVISION_FAILED);
    stack.setStackStatus(stackStatus);
    FlowNotTriggerableException actualException = Assertions.assertThrows(FlowNotTriggerableException.class, () -> triggerFlow());
    Assertions.assertTrue(actualException.getMessage().contains("Cluster Connectivity Manager upgrade could not " + "be triggered, because the cluster's state is not available."), "FlowNotTriggerableException exception message is not right");
}
Also used : FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Test(org.junit.jupiter.api.Test)

Aggregations

FlowNotTriggerableException (com.sequenceiq.flow.core.exception.FlowNotTriggerableException)4 Test (org.junit.jupiter.api.Test)3 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)2 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)2 AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)1 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)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 FlowNotFoundException (com.sequenceiq.flow.core.exception.FlowNotFoundException)1 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)1 HashMap (java.util.HashMap)1 BadRequestException (javax.ws.rs.BadRequestException)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Headers (reactor.bus.Event.Headers)1