Search in sources :

Example 1 with FlowNotAcceptedException

use of com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException 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));
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 2 with FlowNotAcceptedException

use of com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException in project cloudbreak by hortonworks.

the class ReactorNotifier method checkFlowStatus.

private FlowIdentifier checkFlowStatus(Event<? extends Acceptable> event, String identifier) {
    try {
        FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        if (accepted == null) {
            LOGGER.error("Event not accepted: {}", event);
            reactorReporter.logErrorReport();
            throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for stack %s.", identifier));
        }
        switch(accepted.getResultType()) {
            case ALREADY_EXISTING_FLOW:
                reactorReporter.logErrorReport();
                throw new FlowsAlreadyRunningException(String.format("Request not allowed, 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(), e);
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 3 with FlowNotAcceptedException

use of com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException 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());
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Aggregations

FlowNotAcceptedException (com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)3 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)2 FlowsAlreadyRunningException (com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException)2 AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)1 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)1