Search in sources :

Example 1 with PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.

the class FlowStatCache method putByFlowChainId.

public void putByFlowChainId(String flowChainId, Long resourceId, String operationType, boolean restored) {
    if (!flowChainIdStatCache.containsKey(flowChainId)) {
        PayloadContext payloadContext = payloadContextProvider.getPayloadContext(resourceId);
        if (payloadContext != null) {
            FlowStat flowStat = new FlowStat();
            flowStat.setFlowChainId(flowChainId);
            flowStat.setResourceId(resourceId);
            flowStat.setStartTime(new Date().getTime());
            flowStat.setOperationType(OperationType.valueOf(operationType));
            flowStat.setPayloadContext(payloadContext);
            flowStat.setRestored(restored);
            flowChainIdStatCache.put(flowChainId, flowStat);
            if (StringUtils.isNotBlank(payloadContext.getEnvironmentCrn())) {
                resourceCrnFlowChainStatCache.put(payloadContext.getEnvironmentCrn(), flowStat);
            }
            resourceCrnFlowChainStatCache.put(payloadContext.getResourceCrn(), flowStat);
        }
    }
}
Also used : PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) Date(java.util.Date)

Example 2 with PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.

the class FlowStatCache method remove.

public void remove(String flowId, boolean store) {
    if (flowIdStatCache.containsKey(flowId)) {
        FlowStat flowStat = flowIdStatCache.get(flowId);
        if (store && StringUtils.isBlank(flowStat.getFlowChainId())) {
            flowOperationStatisticsService.save(flowStat);
        }
        PayloadContext payloadContext = flowStat.getPayloadContext();
        resourceCrnFlowStatCache.remove(payloadContext.getResourceCrn());
        if (StringUtils.isNotBlank(payloadContext.getEnvironmentCrn())) {
            resourceCrnFlowStatCache.remove(payloadContext.getEnvironmentCrn());
        }
        flowIdStatCache.remove(flowId);
    }
}
Also used : PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext)

Example 3 with PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.

the class FlowStatCache method put.

public void put(String flowId, String flowChainId, Long resourceId, String operationType, Class<? extends FlowConfiguration<?>> flowConfigType, boolean restored) {
    PayloadContext payloadContext = payloadContextProvider.getPayloadContext(resourceId);
    if (payloadContext != null) {
        FlowStat flowStat = new FlowStat();
        flowStat.setFlowId(flowId);
        flowStat.setFlowChainId(flowChainId);
        flowStat.setResourceId(resourceId);
        flowStat.setStartTime(new Date().getTime());
        flowStat.setFlowType(flowConfigType);
        flowStat.setOperationType(OperationType.valueOf(operationType));
        flowStat.setPayloadContext(payloadContext);
        flowStat.setRestored(restored);
        flowIdStatCache.put(flowId, flowStat);
        if (StringUtils.isNotBlank(payloadContext.getEnvironmentCrn())) {
            resourceCrnFlowStatCache.put(payloadContext.getEnvironmentCrn(), flowStat);
        }
        resourceCrnFlowStatCache.put(payloadContext.getResourceCrn(), flowStat);
    }
}
Also used : PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) Date(java.util.Date)

Example 4 with PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext 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 PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.

the class FlowStatCacheTest method createFlowStat.

private FlowStat createFlowStat(String flowId, String flowChainId, String crn, boolean old) {
    FlowStat flowStat = new FlowStat();
    flowStat.setFlowId(flowId);
    flowStat.setFlowChainId(flowChainId);
    PayloadContext payloadContext = PayloadContext.create(crn, SAMPLE_CLOUD_PLATFORM);
    flowStat.setPayloadContext(payloadContext);
    if (old) {
        flowStat.setStartTime(OLD_DATE.getTime());
    } else {
        flowStat.setStartTime(new Date().getTime());
    }
    return flowStat;
}
Also used : PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) Date(java.util.Date)

Aggregations

PayloadContext (com.sequenceiq.cloudbreak.common.event.PayloadContext)8 Date (java.util.Date)5 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 OperationType (com.sequenceiq.flow.api.model.operation.OperationType)2 FlowOperationStats (com.sequenceiq.flow.domain.FlowOperationStats)2 Splitter (com.google.common.base.Splitter)1 EvictingQueue (com.google.common.collect.EvictingQueue)1 FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)1 OperationFlowsView (com.sequenceiq.flow.api.model.operation.OperationFlowsView)1 FlowProgressResponseConverter (com.sequenceiq.flow.converter.FlowProgressResponseConverter)1 PayloadContextProvider (com.sequenceiq.flow.core.PayloadContextProvider)1 FlowStat (com.sequenceiq.flow.core.cache.FlowStat)1 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 FlowOperationStatsRepository (com.sequenceiq.flow.repository.FlowOperationStatsRepository)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1