Search in sources :

Example 1 with FlowOperationStats

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

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

the class FlowOperationStatisticsServiceTest method createFlowStats.

private Optional<FlowOperationStats> createFlowStats() {
    FlowOperationStats flowOperationStats = new FlowOperationStats();
    flowOperationStats.setCloudPlatform(CloudPlatform.AWS.name());
    flowOperationStats.setOperationType(OperationType.PROVISION);
    flowOperationStats.setDurationHistory("66,69");
    return Optional.of(flowOperationStats);
}
Also used : FlowOperationStats(com.sequenceiq.flow.domain.FlowOperationStats)

Example 3 with FlowOperationStats

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

the class FlowOperationStatisticsService method getExpectedAverageTimeForOperation.

private Double getExpectedAverageTimeForOperation(OperationType operationType, String cloudPlatform) {
    Optional<FlowOperationStats> flowOpStats = flowOperationStatsRepository.findFirstByOperationTypeAndCloudPlatform(operationType, cloudPlatform);
    if (flowOpStats.isPresent()) {
        FlowOperationStats flowOperationStats = flowOpStats.get();
        String durationHistory = flowOperationStats.getDurationHistory();
        if (StringUtils.isNotBlank(durationHistory)) {
            return Splitter.on(",").splitToList(durationHistory).stream().mapToDouble(Double::parseDouble).average().orElse(0.0);
        }
    }
    return DEFAULT_GUESSED_AVG_TIME_SEC;
}
Also used : FlowOperationStats(com.sequenceiq.flow.domain.FlowOperationStats)

Aggregations

FlowOperationStats (com.sequenceiq.flow.domain.FlowOperationStats)3 PayloadContext (com.sequenceiq.cloudbreak.common.event.PayloadContext)1 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)1 OperationType (com.sequenceiq.flow.api.model.operation.OperationType)1 Date (java.util.Date)1