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());
}
Aggregations