Search in sources :

Example 16 with FlowChainLog

use of com.sequenceiq.flow.domain.FlowChainLog 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 17 with FlowChainLog

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

the class FlowChainLogService method collectRelatedFlowChains.

public List<FlowChainLog> collectRelatedFlowChains(FlowChainLog flowChain) {
    LOGGER.info("Finding out master flow chain based on chain id {}", flowChain.getFlowChainId());
    FlowChainLog rootFlowChain = collectRootFlowChain(flowChain);
    LOGGER.info("Collecting child flow chains based on master chain id {}", rootFlowChain.getFlowChainId());
    Map<String, FlowChainLog> flowChains = new HashMap<>();
    flowChains.put(rootFlowChain.getFlowChainId(), rootFlowChain);
    collectChildFlowChains(flowChains, rootFlowChain);
    LOGGER.info("Collected flow chain ids for checking: {}", Joiner.on(",").join(flowChains.keySet()));
    return flowChains.values().stream().sorted(comparing(FlowChainLog::getCreated)).collect(toList());
}
Also used : HashMap(java.util.HashMap) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Example 18 with FlowChainLog

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

the class FlowChains method getRootTriggerEvent.

public Optional<Pair<String, Payload>> getRootTriggerEvent(String flowChainId) {
    String rootFlowChainId = getRootFlowChainId(flowChainId);
    FlowTriggerEventQueue flowTriggerEventQueue = flowChainMap.get(rootFlowChainId);
    if (flowTriggerEventQueue != null) {
        return Optional.of(Pair.of(rootFlowChainId, flowTriggerEventQueue.getTriggerEvent()));
    }
    Optional<FlowChainLog> initFlowChainLog = flowChainLogService.findRootInitFlowChainLog(flowChainId);
    if (initFlowChainLog.isEmpty()) {
        return Optional.empty();
    }
    LOGGER.info("Found root init flow chain log {} for flow chain {}", initFlowChainLog.get(), flowChainId);
    Payload triggerEvent = FlowLogUtil.tryDeserializeTriggerEvent(initFlowChainLog.get());
    if (triggerEvent == null) {
        return Optional.empty();
    } else {
        return Optional.of(Pair.of(initFlowChainLog.get().getFlowChainId(), triggerEvent));
    }
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Payload(com.sequenceiq.cloudbreak.common.event.Payload) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Aggregations

FlowChainLog (com.sequenceiq.flow.domain.FlowChainLog)18 FlowLog (com.sequenceiq.flow.domain.FlowLog)6 Test (org.junit.Test)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)3 SdxContext (com.sequenceiq.datalake.flow.SdxContext)3 FlowCheckResponse (com.sequenceiq.flow.api.model.FlowCheckResponse)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 Optional (java.util.Optional)3 Payload (com.sequenceiq.cloudbreak.common.event.Payload)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)2 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)2 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)2 List (java.util.List)2 Map (java.util.Map)2 Queue (java.util.Queue)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Sets (com.google.common.collect.Sets)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CrnParseException (com.sequenceiq.cloudbreak.auth.crn.CrnParseException)1