Search in sources :

Example 6 with FlowCheckResponse

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

the class FlowServiceTest method testRunningFlowChainWhenHasEventInQueue.

@Test
public void testRunningFlowChainWhenHasEventInQueue() {
    setUpFlowChain(flowChainLog(), true, List.of(flowLog(FlowConstants.FINISHED_STATE, NO_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)

Example 7 with FlowCheckResponse

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

the class FlowServiceTest method testRunningFlowChainWithoutFinishedState.

@Test
public void testRunningFlowChainWithoutFinishedState() {
    setUpFlowChain(flowChainLog(), false, List.of(flowLog(INTERMEDIATE_STATE, 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)

Example 8 with FlowCheckResponse

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

the class CloudbreakFlowServiceTest method testFlowCheckBasedOnFlowId.

@Test
public void testFlowCheckBasedOnFlowId() {
    when(flowCheckResponseToFlowStatusConverter.convert(any())).thenCallRealMethod();
    SdxCluster cluster = new SdxCluster();
    cluster.setLastCbFlowId(FLOW_ID);
    cluster.setInitiatorUserCrn(USER_CRN);
    cluster.setClusterName(CLUSTER_NAME);
    FlowCheckResponse flowCheckResponse = new FlowCheckResponse();
    flowCheckResponse.setHasActiveFlow(TRUE);
    when(flowEndpoint.hasFlowRunningByFlowId(anyString())).thenReturn(flowCheckResponse);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    assertEquals(FlowState.RUNNING, underTest.getLastKnownFlowState(cluster));
    verify(flowEndpoint).hasFlowRunningByFlowId(FLOW_ID);
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Test(org.junit.jupiter.api.Test)

Example 9 with FlowCheckResponse

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

the class CloudbreakFlowService method getLastKnownFlowStateByFlowId.

public FlowState getLastKnownFlowStateByFlowId(String flowId) {
    LOGGER.info("Checking cloudbreak {} {}", FlowType.FLOW, flowId);
    FlowCheckResponse flowCheckResponse = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> flowEndpoint.hasFlowRunningByFlowId(flowId));
    logCbFlowStatus(flowId, flowCheckResponse.getHasActiveFlow());
    return flowCheckResponseToFlowStateConverter.convert(flowCheckResponse);
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse)

Example 10 with FlowCheckResponse

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

the class CloudbreakFlowService method getLastKnownFlowState.

public FlowState getLastKnownFlowState(SdxCluster sdxCluster) {
    try {
        if (sdxCluster.getLastCbFlowChainId() != null) {
            LOGGER.info("Checking cloudbreak {} {}", FlowType.FLOW_CHAIN, sdxCluster.getLastCbFlowChainId());
            FlowCheckResponse flowCheckResponse = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> flowEndpoint.hasFlowRunningByChainId(sdxCluster.getLastCbFlowChainId()));
            logCbFlowChainStatus(sdxCluster.getLastCbFlowChainId(), flowCheckResponse.getHasActiveFlow());
            return flowCheckResponseToFlowStateConverter.convert(flowCheckResponse);
        } else if (sdxCluster.getLastCbFlowId() != null) {
            return getLastKnownFlowStateByFlowId(sdxCluster.getLastCbFlowId());
        }
        return FlowState.UNKNOWN;
    } catch (NotFoundException e) {
        LOGGER.error("Flow chain id or resource {} not found in CB: {}, so there is no active flow!", sdxCluster.getClusterName(), e.getMessage());
        return FlowState.UNKNOWN;
    } catch (Exception e) {
        LOGGER.error("Exception occured during checking if there is a flow for cluster {} in CB: {}", sdxCluster.getClusterName(), e.getMessage());
        return FlowState.UNKNOWN;
    }
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) NotFoundException(javax.ws.rs.NotFoundException) NotFoundException(javax.ws.rs.NotFoundException)

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