Search in sources :

Example 1 with OperationType

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

the class OperationService method getOperationProgressByResourceCrn.

public OperationView getOperationProgressByResourceCrn(String resourceCrn, boolean detailed) {
    OperationView stackOperationView = new OperationView();
    try {
        OperationResource operationResource = OperationResource.fromCrn(Crn.safeFromString(resourceCrn));
        Optional<OperationFlowsView> operationFlowsViewOpt = flowService.getLastFlowOperationByResourceCrn(resourceCrn);
        if (operationFlowsViewOpt.isPresent()) {
            OperationFlowsView operationFlowsView = operationFlowsViewOpt.get();
            OperationType operationType = operationFlowsView.getOperationType();
            if (OperationType.PROVISION.equals(operationType)) {
                stackOperationView = handleProvisionOperation(resourceCrn, operationResource, operationFlowsView, detailed);
            } else {
                stackOperationView = operationDetailsPopulator.createOperationView(operationFlowsView, operationResource);
            }
        }
    } catch (Exception e) {
        LOGGER.debug(String.format("Could not fetch remote database details for stack with crn %s", resourceCrn), e);
    }
    return stackOperationView;
}
Also used : OperationView(com.sequenceiq.flow.api.model.operation.OperationView) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) OperationResource(com.sequenceiq.flow.api.model.operation.OperationResource)

Example 2 with OperationType

use of com.sequenceiq.flow.api.model.operation.OperationType 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 3 with OperationType

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

the class FlowChainOperationTypeConfig method init.

@PostConstruct
public void init() {
    for (FlowEventChainFactory<?> flowEventChainFactory : flowChainFactories) {
        String flowType = flowEventChainFactory.getName();
        OperationType operationType = flowEventChainFactory.getFlowOperationType();
        if (flowTypeOperationTypeMap.get(flowType) != null) {
            throw new UnsupportedOperationException("Flow type already registered: " + flowType);
        }
        flowTypeOperationTypeMap.put(flowType, operationType);
    }
}
Also used : OperationType(com.sequenceiq.flow.api.model.operation.OperationType) PostConstruct(javax.annotation.PostConstruct)

Example 4 with OperationType

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

the class FlowOperationStatisticsService method save.

public synchronized void save(FlowStat flowStat) {
    if (OperationType.UNKNOWN.equals(flowStat.getOperationType()) || flowStat.getPayloadContext() == null) {
        return;
    }
    if (flowStat.isRestored()) {
        LOGGER.debug("Flow was restored, so statistics won't be saved about that. (operation: {})", flowStat.getOperationType());
        return;
    }
    try {
        OperationType operationType = flowStat.getOperationType();
        PayloadContext payloadContext = flowStat.getPayloadContext();
        Optional<FlowOperationStats> flowOpStatOpt = flowOperationStatsRepository.findFirstByOperationTypeAndCloudPlatform(operationType, payloadContext.getCloudPlatform());
        final FlowOperationStats flowOperationStats;
        if (flowOpStatOpt.isPresent()) {
            flowOperationStats = flowOpStatOpt.get();
        } else {
            flowOperationStats = new FlowOperationStats();
            flowOperationStats.setOperationType(operationType);
            flowOperationStats.setCloudPlatform(payloadContext.getCloudPlatform());
        }
        String durationHistory = flowOperationStats.getDurationHistory();
        Queue<Double> durationHistoryQueue = EvictingQueue.create(MAX_FLOW_STAT_SIZE);
        if (StringUtils.isNotBlank(durationHistory)) {
            Splitter.on(",").splitToList(durationHistory).forEach(s -> {
                durationHistoryQueue.add(Double.parseDouble(s));
            });
        }
        Double elapsedOperationTime = getRoundedTimeInSeconds(flowStat.getStartTime(), new Date().getTime());
        durationHistoryQueue.add(elapsedOperationTime);
        durationHistory = StringUtils.join(durationHistoryQueue.stream().map(Object::toString).collect(Collectors.toList()), ",");
        flowOperationStats.setDurationHistory(durationHistory);
        transactionService.required(() -> flowOperationStatsRepository.save(flowOperationStats));
    } catch (TransactionService.TransactionExecutionException e) {
        LOGGER.warn("Cannot store flow operation statistics.", e);
    } catch (Exception e) {
        LOGGER.warn("Unexpected error happened during storing flow operation statistics", e);
    }
}
Also used : PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) FlowOperationStats(com.sequenceiq.flow.domain.FlowOperationStats) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) Date(java.util.Date)

Example 5 with OperationType

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

the class FlowLogDBService method finalize.

private FlowLog finalize(Long resourceId, String flowId, String state, boolean failed) throws TransactionExecutionException {
    return transactionService.required(() -> {
        flowLogRepository.finalizeByFlowId(flowId);
        Optional<FlowLog> lastFlowLogOpt = getLastFlowLog(flowId);
        OperationType operationType = OperationType.UNKNOWN;
        if (lastFlowLogOpt.isPresent()) {
            FlowLog lastFlowLog = lastFlowLogOpt.get();
            updateLastFlowLogStatus(lastFlowLog, failed);
            operationType = lastFlowLog.getOperationType();
        }
        FlowLog flowLog = new FlowLog(resourceId, flowId, state, Boolean.TRUE, StateStatus.SUCCESSFUL, operationType);
        flowLog.setCloudbreakNodeId(nodeConfig.getId());
        return flowLogRepository.save(flowLog);
    });
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) OperationType(com.sequenceiq.flow.api.model.operation.OperationType)

Aggregations

OperationType (com.sequenceiq.flow.api.model.operation.OperationType)8 OperationFlowsView (com.sequenceiq.flow.api.model.operation.OperationFlowsView)4 OperationView (com.sequenceiq.flow.api.model.operation.OperationView)3 PayloadContext (com.sequenceiq.cloudbreak.common.event.PayloadContext)2 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 FlowLog (com.sequenceiq.flow.domain.FlowLog)2 FlowOperationStats (com.sequenceiq.flow.domain.FlowOperationStats)2 Date (java.util.Date)2 Queue (java.util.Queue)2 Splitter (com.google.common.base.Splitter)1 EvictingQueue (com.google.common.collect.EvictingQueue)1 Payload (com.sequenceiq.cloudbreak.common.event.Payload)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)1 OperationResource (com.sequenceiq.flow.api.model.operation.OperationResource)1 FlowProgressResponseConverter (com.sequenceiq.flow.converter.FlowProgressResponseConverter)1 PayloadContextProvider (com.sequenceiq.flow.core.PayloadContextProvider)1 FlowStat (com.sequenceiq.flow.core.cache.FlowStat)1 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)1 FlowChainLog (com.sequenceiq.flow.domain.FlowChainLog)1