Search in sources :

Example 1 with FlowChainLog

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

the class FlowChainHandler method restoreFlowChain.

public void restoreFlowChain(String flowChainId) {
    Optional<FlowChainLog> chainLog = flowLogService.findFirstByFlowChainIdOrderByCreatedDesc(flowChainId);
    if (chainLog.isPresent()) {
        String flowChainType = chainLog.get().getFlowChainType();
        Queue<Selectable> queue = (Queue<Selectable>) JsonReader.jsonToJava(chainLog.get().getChain());
        Payload triggerEvent = tryDeserializeTriggerEvent(chainLog.get());
        FlowTriggerEventQueue chain = new FlowTriggerEventQueue(flowChainType, triggerEvent, queue);
        if (chainLog.get().getParentFlowChainId() != null) {
            chain.setParentFlowChainId(chainLog.get().getParentFlowChainId());
        }
        flowChains.putFlowChain(flowChainId, chainLog.get().getParentFlowChainId(), chain);
        Selectable selectable = queue.peek();
        if (selectable != null) {
            OperationType operationType = flowChainOperationTypeConfig.getFlowTypeOperationTypeMap().getOrDefault(flowChainType, OperationType.UNKNOWN);
            flowStatCache.putByFlowChainId(flowChainId, selectable.getResourceId(), operationType.name(), true);
        }
        if (chainLog.get().getParentFlowChainId() != null) {
            restoreFlowChain(chainLog.get().getParentFlowChainId());
        }
    }
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Payload(com.sequenceiq.cloudbreak.common.event.Payload) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Queue(java.util.Queue)

Example 2 with FlowChainLog

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

the class FlowLogDBService method saveChain.

@Override
public void saveChain(String flowChainId, String parentFlowChainId, FlowTriggerEventQueue chain, String flowTriggerUserCrn) {
    String chainType = chain.getFlowChainName();
    String chainJson = JsonWriter.objectToJson(chain.getQueue());
    String triggerEventJson = null;
    if (chain.getTriggerEvent() != null) {
        triggerEventJson = JsonWriter.objectToJson(chain.getTriggerEvent(), writeOptions);
    }
    FlowChainLog chainLog = new FlowChainLog(chainType, flowChainId, parentFlowChainId, chainJson, flowTriggerUserCrn, triggerEventJson);
    flowChainLogService.save(chainLog);
}
Also used : FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Example 3 with FlowChainLog

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

the class FlowService method getRelatedFlowChainLogs.

private List<FlowChainLog> getRelatedFlowChainLogs(List<FlowChainLog> sourceFlowChains) {
    Optional<FlowChainLog> flowChainWithParent = sourceFlowChains.stream().filter(flowChainLog -> StringUtils.isNotBlank(flowChainLog.getParentFlowChainId())).findFirst();
    FlowChainLog lastFlowChain = sourceFlowChains.stream().max(Comparator.comparing(FlowChainLog::getCreated)).get();
    FlowChainLog inputFlowChain = flowChainWithParent.orElse(lastFlowChain);
    return flowChainLogService.collectRelatedFlowChains(inputFlowChain);
}
Also used : AbstractFlowConfiguration(com.sequenceiq.flow.core.config.AbstractFlowConfiguration) FlowProgressResponseConverter(com.sequenceiq.flow.converter.FlowProgressResponseConverter) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) FlowChainLogService(com.sequenceiq.flow.service.flowlog.FlowChainLogService) FlowOperationStatisticsService(com.sequenceiq.flow.core.stats.FlowOperationStatisticsService) Service(org.springframework.stereotype.Service) FlowConstants(com.sequenceiq.flow.core.FlowConstants) FlowLogResponse(com.sequenceiq.flow.api.model.FlowLogResponse) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) FlowCheckResponse(com.sequenceiq.flow.api.model.FlowCheckResponse) Collectors.toSet(java.util.stream.Collectors.toSet) StateStatus(com.sequenceiq.flow.domain.StateStatus) FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) Set(java.util.Set) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) CrnParseException(com.sequenceiq.cloudbreak.auth.crn.CrnParseException) FlowLogUtil.isFlowInFailedState(com.sequenceiq.cloudbreak.service.flowlog.FlowLogUtil.isFlowInFailedState) Optional(java.util.Optional) FlowLogDBService(com.sequenceiq.flow.service.flowlog.FlowLogDBService) ClassValue(com.sequenceiq.flow.domain.ClassValue) Comparator(java.util.Comparator) FlowLogConverter(com.sequenceiq.flow.converter.FlowLogConverter) Collections(java.util.Collections) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Example 4 with FlowChainLog

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

the class FlowChainLogService method hasEventInFlowChainQueue.

public boolean hasEventInFlowChainQueue(List<FlowChainLog> flowChains) {
    Map<String, List<FlowChainLog>> byFlowChainId = flowChains.stream().collect(Collectors.groupingBy(FlowChainLog::getFlowChainId, toList()));
    return byFlowChainId.entrySet().stream().anyMatch(entry -> {
        FlowChainLog latestFlowChain = entry.getValue().stream().sorted(comparing(FlowChainLog::getCreated).reversed()).findFirst().get();
        LOGGER.debug("Checking if chain with id {} has any event in it's queue", latestFlowChain.getFlowChainId());
        LOGGER.trace("Chain string in db: {}", latestFlowChain.getChain());
        Queue<Selectable> chain = (Queue<Selectable>) JsonReader.jsonToJava(latestFlowChain.getChain());
        return !chain.isEmpty();
    });
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) Queue(java.util.Queue)

Example 5 with FlowChainLog

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

the class FlowServiceTest method flowChainLog.

private FlowChainLog flowChainLog() {
    FlowChainLog flowChainLog = new FlowChainLog();
    flowChainLog.setFlowChainId(FLOW_CHAIN_ID);
    return flowChainLog;
}
Also used : 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