Search in sources :

Example 1 with FlowCheckResponse

use of com.sequenceiq.flow.api.model.FlowCheckResponse in project cloudbreak by hortonworks.

the class LoadBalancerPollerServiceTest method setupActiveFlowCheckResponse.

private FlowCheckResponse setupActiveFlowCheckResponse() {
    FlowCheckResponse flowCheckResponse = new FlowCheckResponse();
    flowCheckResponse.setHasActiveFlow(true);
    return flowCheckResponse;
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse)

Example 2 with FlowCheckResponse

use of com.sequenceiq.flow.api.model.FlowCheckResponse in project cloudbreak by hortonworks.

the class FlowUtil method waitForFlow.

private void waitForFlow(FlowPublicEndpoint flowEndpoint, String crn, String flowChainId, String flowId, RunningParameter runningParameter) {
    boolean flowRunning = true;
    boolean flowFailed = false;
    int retryCount = 0;
    int failureCount = 0;
    long pollingInterval = getPollingInterval();
    while (flowRunning && retryCount < maxRetry) {
        sleep(pollingInterval, crn, flowChainId, flowId);
        try {
            if (StringUtils.isNotBlank(flowChainId)) {
                LOGGER.info("Waiting for flow chain: '{}' at resource: '{}', retry count: '{}'", flowChainId, crn, retryCount);
                FlowCheckResponse flowCheckResponse = flowEndpoint.hasFlowRunningByChainId(flowChainId, crn);
                flowRunning = flowCheckResponse.getHasActiveFlow();
                flowFailed = flowCheckResponse.getLatestFlowFinalizedAndFailed();
            } else if (StringUtils.isNoneBlank(flowId)) {
                LOGGER.info("Waiting for flow: '{}' at resource: '{}', retry count: '{}'", flowId, crn, retryCount);
                FlowCheckResponse flowCheckResponse = flowEndpoint.hasFlowRunningByFlowId(flowId, crn);
                flowRunning = flowCheckResponse.getHasActiveFlow();
                flowFailed = flowCheckResponse.getLatestFlowFinalizedAndFailed();
            } else {
                LOGGER.info("Flow id and flow chain id are empty so flow is not running at resource: '{}'", crn);
                flowRunning = false;
            }
        } catch (Exception ex) {
            if (failureCount >= maxFailureRetry) {
                LOGGER.error("Error during polling flow. Crn={}, FlowId={}, FlowChainId={}, Message={}", crn, flowId, flowChainId, ex.getMessage(), ex);
                throw new TestFailException(String.format(" Error during polling flow. Crn=%s, FlowId=%s , FlowChainId=%s, Message=%s ", crn, flowId, flowChainId, ex.getMessage()));
            } else {
                LOGGER.info("Retrying after failure. Failure count {}", ++failureCount);
            }
        }
        retryCount++;
    }
    if (retryCount >= maxRetry) {
        String errorMessage = String.format("Test timed out, flow did not finish in time. Crn=%s, FlowId=%s, FlowChainId=%s", crn, flowId, flowChainId);
        LOGGER.error(errorMessage);
        throw new TestFailException(errorMessage);
    }
    if (flowFailed && runningParameter.isWaitForFlowSuccess()) {
        LOGGER.error("Flow has been finalized with failed status. Crn={}, FlowId={}, FlowChainId={}", crn, flowId, flowChainId);
        throw new TestFailException(String.format(" Flow has been finalized with failed status. Crn=%s, FlowId=%s , FlowChainId=%s ", crn, flowId, flowChainId));
    }
    if (!flowFailed && runningParameter.isWaitForFlowFail()) {
        LOGGER.error("Flow has been finalized with success status. Crn={}, FlowId={}, FlowChainId={}", crn, flowId, flowChainId);
        throw new TestFailException(String.format(" Flow has been finalized with success status but it was expected to fail. Crn=%s, FlowId=%s , FlowChainId=%s ", crn, flowId, flowChainId));
    }
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) FlowPublicEndpoint(com.sequenceiq.flow.api.FlowPublicEndpoint) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 3 with FlowCheckResponse

use of com.sequenceiq.flow.api.model.FlowCheckResponse in project cloudbreak by hortonworks.

the class UnboundRestartPatchServiceTest method setFlowState.

private void setFlowState(boolean finished, boolean failed) {
    FlowCheckResponse flowCheckResponse = new FlowCheckResponse();
    flowCheckResponse.setHasActiveFlow(!finished);
    flowCheckResponse.setLatestFlowFinalizedAndFailed(failed);
    when(flowService.getFlowState(POLLABLE_ID)).thenReturn(flowCheckResponse);
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse)

Example 4 with FlowCheckResponse

use of com.sequenceiq.flow.api.model.FlowCheckResponse in project cloudbreak by hortonworks.

the class FlowServiceTest method testNoFlowRunningByFlowId.

@Test
public void testNoFlowRunningByFlowId() {
    setUpFlow(FLOW_ID, List.of(flowLog(FlowConstants.FINISHED_STATE, NO_NEXT_EVENT, 2), flowLog(FlowConstants.INIT_STATE, NEXT_EVENT, 1)));
    FlowCheckResponse flowCheckResponse = underTest.getFlowState(FLOW_ID);
    assertFalse(flowCheckResponse.getHasActiveFlow());
    assertNotNull(flowCheckResponse.getFlowId());
    verify(flowLogDBService).findAllByFlowIdOrderByCreatedDesc(anyString());
    verify(flowChainLogService).hasEventInFlowChainQueue(List.of());
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) Test(org.junit.Test)

Example 5 with FlowCheckResponse

use of com.sequenceiq.flow.api.model.FlowCheckResponse in project cloudbreak by hortonworks.

the class FlowServiceTest method testRunningFlowChainWithPendingFlowLog.

@Test
public void testRunningFlowChainWithPendingFlowLog() {
    setUpFlowChain(flowChainLog(), false, List.of(pendingFlowLog(INTERMEDIATE_STATE, NEXT_EVENT, 4), flowLog(FlowConstants.FINISHED_STATE, NO_NEXT_EVENT, 3), flowLog(INTERMEDIATE_STATE, FAIL_HANDLED_NEXT_EVENT, 2), flowLog(FlowConstants.INIT_STATE, NEXT_EVENT, 1)));
    FlowCheckResponse flowCheckResponse = underTest.getFlowChainState(FLOW_CHAIN_ID);
    assertTrue(flowCheckResponse.getHasActiveFlow());
    assertEquals(FLOW_CHAIN_ID, flowCheckResponse.getFlowChainId());
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) Test(org.junit.Test)

Aggregations

FlowCheckResponse (com.sequenceiq.flow.api.model.FlowCheckResponse)23 Test (org.junit.Test)10 FlowLog (com.sequenceiq.flow.domain.FlowLog)3 FlowChainLog (com.sequenceiq.flow.domain.FlowChainLog)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 FlowPublicEndpoint (com.sequenceiq.flow.api.FlowPublicEndpoint)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 NotFoundException (javax.ws.rs.NotFoundException)1 Test (org.junit.jupiter.api.Test)1