use of com.sequenceiq.flow.core.config.FlowProgressHolder in project cloudbreak by hortonworks.
the class FlowProgressResponseConverter method convert.
public FlowProgressResponse convert(List<FlowLog> flowLogs, String resourceCrn) {
FlowProgressResponse response = new FlowProgressResponse();
if (CollectionUtils.isNotEmpty(flowLogs)) {
FlowLog lastFlowLog = flowLogs.get(0);
Optional<String> flowTypeOpt = flowLogs.stream().filter(fl -> fl.getFlowType() != null).findFirst().map(fl -> fl.getFlowType().getClassValue().getName());
FlowLog firstFlowLog = flowLogs.get(flowLogs.size() - 1);
response.setFlowId(lastFlowLog.getFlowId());
response.setFlowChainId(lastFlowLog.getFlowChainId());
Integer prgoressFromSteps = flowTypeOpt.map(s -> flowProgressHolder.getProgressPercentageForState(s, lastFlowLog.getCurrentState())).orElse(UNKNOWN_PROGRESS_PERCENTAGE);
response.setProgress(prgoressFromSteps);
response.setMaxNumberOfTransitions(flowTypeOpt.map(flowProgressHolder::getTransitionsSize).orElse(null));
List<FlowLog> reversedFlowLogs = flowLogs.stream().sorted(Comparator.comparingLong(FlowLog::getCreated)).collect(Collectors.toList());
response.setTransitions(createFlowStateTransitions(reversedFlowLogs, firstFlowLog.getCreated()));
response.setFinalized(lastFlowLog.getFinalized());
response.setCreated(firstFlowLog.getCreated());
if (lastFlowLog.getFinalized()) {
response.setElapsedTimeInSeconds(getRoundedTimeInSeconds(firstFlowLog.getCreated(), lastFlowLog.getCreated()));
response.setProgress(FINISHED_PERCENTAGE);
} else {
response.setElapsedTimeInSeconds(getRoundedTimeInSeconds(firstFlowLog.getCreated(), new Date().getTime()));
}
response.setResourceCrn(resourceCrn);
}
return response;
}
Aggregations