Search in sources :

Example 1 with RetryResponse

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

the class StackCommonService method retryInWorkspace.

public FlowIdentifier retryInWorkspace(NameOrCrn nameOrCrn, Long workspaceId) {
    Long stackId = stackService.getIdByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
    RetryResponse retry = flowRetryService.retry(stackId);
    eventService.fireCloudbreakEvent(stackId, Status.UPDATE_IN_PROGRESS.name(), STACK_RETRY_FLOW_START, List.of(retry.getName()));
    return retry.getFlowIdentifier();
}
Also used : RetryResponse(com.sequenceiq.flow.domain.RetryResponse)

Example 2 with RetryResponse

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

the class FreeIpaRetryServiceTest method testRetry.

@Test
public void testRetry() {
    Stack stack = new Stack();
    stack.setId(6L);
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "afda");
    when(flowRetryService.retry(stack.getId())).thenReturn(new RetryResponse("asdf", flowIdentifier));
    FlowIdentifier result = underTest.retry(ENV_CRN, ACCOUNT_ID);
    assertEquals(flowIdentifier, result);
}
Also used : RetryResponse(com.sequenceiq.flow.domain.RetryResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with RetryResponse

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

the class FreeIpaRetryService method retry.

public FlowIdentifier retry(String environmentCrn, String accountId) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountId(environmentCrn, accountId);
    MDCBuilder.buildMdcContext(stack);
    RetryResponse retry = flowRetryService.retry(stack.getId());
    return retry.getFlowIdentifier();
}
Also used : RetryResponse(com.sequenceiq.flow.domain.RetryResponse) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 4 with RetryResponse

use of com.sequenceiq.flow.domain.RetryResponse 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

RetryResponse (com.sequenceiq.flow.domain.RetryResponse)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 Stack (com.sequenceiq.freeipa.entity.Stack)2 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 RetryableStateResponse (com.sequenceiq.flow.domain.RetryableStateResponse)1 BadRequestException (javax.ws.rs.BadRequestException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 Test (org.junit.jupiter.api.Test)1