Search in sources :

Example 16 with FlowProgressResponse

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

the class FlowOperationStatisticsService method createOperationResponse.

public Optional<OperationFlowsView> createOperationResponse(String resourceCrn, List<FlowLog> flowLogs) {
    Double avgProgressTime = 0.0d;
    OperationType operationType;
    if (flowLogs.isEmpty()) {
        operationType = OperationType.UNKNOWN;
    } else {
        FlowLog flowLog = flowLogs.get(0);
        operationType = flowLog.getOperationType();
        if (!operationType.equals(OperationType.UNKNOWN)) {
            PayloadContext payloadContext = payloadContextProvider.getPayloadContext(flowLog.getResourceId());
            avgProgressTime = getExpectedAverageTimeForOperation(operationType, payloadContext.getCloudPlatform());
        }
    }
    Map<String, List<FlowLog>> flowLogsPerType = flowLogs.stream().filter(fl -> fl.getFlowType() != null).collect(groupingBy(fl -> fl.getFlowType().getName()));
    Map<String, FlowProgressResponse> response = new HashMap<>();
    Map<Long, String> createdMap = new TreeMap<>();
    Integer progressFromHistory = DEFAULT_PROGRESS;
    for (Map.Entry<String, List<FlowLog>> entry : flowLogsPerType.entrySet()) {
        FlowProgressResponse progressResponse = flowProgressResponseConverter.convert(entry.getValue(), resourceCrn);
        response.put(entry.getKey(), progressResponse);
        createdMap.put(progressResponse.getCreated(), entry.getKey());
    }
    List<String> typeOrderList = new ArrayList<>(createdMap.values());
    if (!createdMap.isEmpty()) {
        Long operationCreated = createdMap.keySet().stream().mapToLong(v -> v).min().getAsLong();
        progressFromHistory = getProgressFromHistory(avgProgressTime, operationCreated);
    }
    if (CollectionUtils.isEmpty(response.entrySet())) {
        LOGGER.debug("Not found any historical flow data for requested resource (crn: {})", resourceCrn);
        return Optional.empty();
    }
    return Optional.of(OperationFlowsView.Builder.newBuilder().withOperationType(operationType).withFlowTypeProgressMap(response).withTypeOrderList(typeOrderList).withProgressFromHistory(progressFromHistory).build());
}
Also used : FlowProgressResponseConverter(com.sequenceiq.flow.converter.FlowProgressResponseConverter) Date(java.util.Date) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) FlowOperationStats(com.sequenceiq.flow.domain.FlowOperationStats) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) EvictingQueue(com.google.common.collect.EvictingQueue) Map(java.util.Map) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) Splitter(com.google.common.base.Splitter) FlowStat(com.sequenceiq.flow.core.cache.FlowStat) FlowOperationStatsRepository(com.sequenceiq.flow.repository.FlowOperationStatsRepository) PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) Logger(org.slf4j.Logger) PayloadContextProvider(com.sequenceiq.flow.core.PayloadContextProvider) DecimalFormat(java.text.DecimalFormat) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) TreeMap(java.util.TreeMap) Optional(java.util.Optional) Queue(java.util.Queue) FlowLog(com.sequenceiq.flow.domain.FlowLog) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) ArrayList(java.util.ArrayList) List(java.util.List) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)16 Test (org.junit.jupiter.api.Test)7 OperationFlowsView (com.sequenceiq.flow.api.model.operation.OperationFlowsView)5 OperationView (com.sequenceiq.flow.api.model.operation.OperationView)5 ArrayList (java.util.ArrayList)5 FlowStateTransitionResponse (com.sequenceiq.flow.api.model.FlowStateTransitionResponse)4 FlowLog (com.sequenceiq.flow.domain.FlowLog)4 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 Date (java.util.Date)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CollectionUtils (org.apache.commons.collections4.CollectionUtils)3 Component (org.springframework.stereotype.Component)3 OperationProgressStatus (com.sequenceiq.flow.api.model.operation.OperationProgressStatus)2 TestFlowConfig (com.sequenceiq.flow.core.config.TestFlowConfig)2 DecimalFormat (java.text.DecimalFormat)2 Map (java.util.Map)2 Splitter (com.google.common.base.Splitter)1 EvictingQueue (com.google.common.collect.EvictingQueue)1