Search in sources :

Example 1 with RetryableStateResponse

use of com.sequenceiq.flow.domain.RetryableStateResponse in project cloudbreak by hortonworks.

the class FlowRetryService method retry.

public RetryResponse retry(Long stackId) {
    RetryableStateResponse retryableStateResponse = getRetryableStateResponse(stackId);
    switch(retryableStateResponse.getState()) {
        case FLOW_PENDING:
            String flowPendingMessage = "Retry cannot be performed, because there is already an active flow.";
            LOGGER.info(flowPendingMessage + " stackId: {}", stackId);
            throw new BadRequestException(flowPendingMessage);
        case LAST_NOT_FAILED_OR_NOT_RETRYABLE:
            String notFailedOrNotRetryableMessage = "Retry cannot be performed. The last flow did not fail or not retryable." + retryableStateResponse.getLastKnownStateMessage();
            LOGGER.info(notFailedOrNotRetryableMessage + " stackId: {}", stackId);
            throw new BadRequestException(notFailedOrNotRetryableMessage);
        case NO_SUCCESSFUL_STATE:
            String noSuccessfulStateMessage = "Cannot restart previous flow because there is no successful state in the flow.";
            LOGGER.info(noSuccessfulStateMessage + " stackId: {}", stackId);
            throw new BadRequestException(noSuccessfulStateMessage);
        case RETRYABLE:
            FlowLog lastSuccessfulStateFlowLog = retryableStateResponse.getLastSuccessfulStateFlowLog();
            flow2Handler.restartFlow(lastSuccessfulStateFlowLog);
            if (lastSuccessfulStateFlowLog.getFlowChainId() != null) {
                return new RetryResponse(retryableStateResponse.getName(), new FlowIdentifier(FlowType.FLOW_CHAIN, lastSuccessfulStateFlowLog.getFlowChainId()));
            } else {
                return new RetryResponse(retryableStateResponse.getName(), new FlowIdentifier(FlowType.FLOW, lastSuccessfulStateFlowLog.getFlowId()));
            }
        default:
            throw new NotImplementedException("Retry state handling is not implemented: " + retryableStateResponse.getState());
    }
}
Also used : RetryResponse(com.sequenceiq.flow.domain.RetryResponse) FlowLog(com.sequenceiq.flow.domain.FlowLog) RetryableStateResponse(com.sequenceiq.flow.domain.RetryableStateResponse) NotImplementedException(org.apache.commons.lang3.NotImplementedException) BadRequestException(javax.ws.rs.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Aggregations

FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 RetryResponse (com.sequenceiq.flow.domain.RetryResponse)1 RetryableStateResponse (com.sequenceiq.flow.domain.RetryableStateResponse)1 BadRequestException (javax.ws.rs.BadRequestException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1