Search in sources :

Example 81 with FlowLog

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

the class FlowService method getFlowState.

public FlowCheckResponse getFlowState(String flowId) {
    List<FlowLog> allByFlowIdOrderByCreatedDesc = flowLogDBService.findAllByFlowIdOrderByCreatedDesc(flowId);
    FlowCheckResponse flowCheckResponse = new FlowCheckResponse();
    flowCheckResponse.setFlowId(flowId);
    flowCheckResponse.setHasActiveFlow(!completed("Flow", flowId, List.of(), allByFlowIdOrderByCreatedDesc));
    flowCheckResponse.setLatestFlowFinalizedAndFailed(isFlowInFailedState(allByFlowIdOrderByCreatedDesc, failHandledEvents));
    return flowCheckResponse;
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) FlowLog(com.sequenceiq.flow.domain.FlowLog)

Example 82 with FlowLog

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

the class FlowService method getFlowChainStateSafe.

public FlowCheckResponse getFlowChainStateSafe(List<Long> resourceIdList, String chainId) {
    FlowCheckResponse flowCheckResponse = new FlowCheckResponse();
    flowCheckResponse.setFlowChainId(chainId);
    List<FlowChainLog> flowChains = flowChainLogService.findByFlowChainIdOrderByCreatedDesc(chainId);
    if (!flowChains.isEmpty()) {
        LOGGER.info("Checking if there is an active flow based on flow chain id {}", chainId);
        List<FlowChainLog> relatedChains = getRelatedFlowChainLogs(flowChains);
        Set<String> relatedChainIds = relatedChains.stream().map(FlowChainLog::getFlowChainId).collect(toSet());
        Set<String> relatedFlowIds = flowLogDBService.getFlowIdsByChainIds(relatedChainIds);
        List<FlowLog> relatedFlowLogs = flowLogDBService.getFlowLogsByFlowIdsCreatedDesc(relatedFlowIds);
        validateResourceId(relatedFlowLogs, resourceIdList);
        flowCheckResponse.setHasActiveFlow(!completed("Flow chain", chainId, relatedChains, relatedFlowLogs));
        flowCheckResponse.setLatestFlowFinalizedAndFailed(isFlowInFailedState(relatedFlowLogs, failHandledEvents));
        return flowCheckResponse;
    } else {
        flowCheckResponse.setHasActiveFlow(Boolean.FALSE);
        return flowCheckResponse;
    }
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Example 83 with FlowLog

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

the class FlowService method getFlowChainState.

public FlowCheckResponse getFlowChainState(String chainId) {
    FlowCheckResponse flowCheckResponse = new FlowCheckResponse();
    flowCheckResponse.setFlowChainId(chainId);
    List<FlowChainLog> flowChains = flowChainLogService.findByFlowChainIdOrderByCreatedDesc(chainId);
    if (!flowChains.isEmpty()) {
        LOGGER.info("Checking if there is an active flow based on flow chain id {}", chainId);
        List<FlowChainLog> relatedChains = getRelatedFlowChainLogs(flowChains);
        Set<String> relatedChainIds = relatedChains.stream().map(FlowChainLog::getFlowChainId).collect(toSet());
        Set<String> relatedFlowIds = flowLogDBService.getFlowIdsByChainIds(relatedChainIds);
        List<FlowLog> relatedFlowLogs = flowLogDBService.getFlowLogsByFlowIdsCreatedDesc(relatedFlowIds);
        flowCheckResponse.setHasActiveFlow(!completed("Flow chain", chainId, relatedChains, relatedFlowLogs));
        flowCheckResponse.setLatestFlowFinalizedAndFailed(isFlowInFailedState(relatedFlowLogs, failHandledEvents));
        return flowCheckResponse;
    } else {
        flowCheckResponse.setHasActiveFlow(Boolean.FALSE);
        return flowCheckResponse;
    }
}
Also used : FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Example 84 with FlowLog

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

the class FlowService method getLastFlowProgressByResourceCrn.

public FlowProgressResponse getLastFlowProgressByResourceCrn(String resourceCrn) {
    checkState(Crn.isCrn(resourceCrn));
    LOGGER.info("Getting flow logs (progress) by resource crn {}", resourceCrn);
    List<FlowLog> flowLogs = flowLogDBService.getFlowLogsByResourceCrnOrName(resourceCrn);
    FlowProgressResponse response = flowProgressResponseConverter.convert(flowLogs, resourceCrn);
    if (StringUtils.isBlank(response.getFlowId())) {
        throw new NotFoundException(String.format("Not found any historical flow data for requested resource (crn: %s)", resourceCrn));
    }
    return flowProgressResponseConverter.convert(flowLogs, resourceCrn);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 85 with FlowLog

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

the class FlowService method hasFinishedFlow.

private boolean hasFinishedFlow(String marker, String flowChainId, List<FlowChainLog> flowChainLogs, List<FlowLog> flowLogs) {
    boolean hasFinishedFlowLog = false;
    for (FlowLog flowLog : flowLogs) {
        String currentState = flowLog.getCurrentState();
        if (failHandledEvents.contains(flowLog.getNextEvent()) || (currentState != null && CANCELLED_TERMINATED_STATES.contains(currentState))) {
            LOGGER.info("{} {} marked as completed on {} flow log", marker, flowChainId, flowLog.minimizedString());
            return true;
        } else if (FlowConstants.INIT_STATE.equals(currentState)) {
            boolean hasEventInQueue = flowChainLogService.hasEventInFlowChainQueue(flowChainLogs);
            LOGGER.info("{} {} state. Finished {}, hasEventInQueue {}", marker, flowChainId, hasFinishedFlowLog, hasEventInQueue);
            return hasFinishedFlowLog && !hasEventInQueue;
        } else if (FlowConstants.FINISHED_STATE.equals(currentState)) {
            hasFinishedFlowLog = true;
        } else if (!hasFinishedFlowLog) {
            return false;
        }
    }
    LOGGER.info("{} {} marked as not completed", marker, flowChainId);
    return false;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

Aggregations

FlowLog (com.sequenceiq.flow.domain.FlowLog)92 Test (org.junit.jupiter.api.Test)25 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)21 List (java.util.List)13 FlowConfiguration (com.sequenceiq.flow.core.config.FlowConfiguration)12 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)11 Mockito.times (org.mockito.Mockito.times)11 Mockito.verify (org.mockito.Mockito.verify)11 Mockito.when (org.mockito.Mockito.when)11 HelloWorldFlowConfig (com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig)10 Map (java.util.Map)10 UUID (java.util.UUID)10 Collectors (java.util.stream.Collectors)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Clock (com.sequenceiq.cloudbreak.common.service.Clock)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)9 FlowRegister (com.sequenceiq.flow.core.FlowRegister)9 SecureRandom (java.security.SecureRandom)9 Random (java.util.Random)9