Search in sources :

Example 1 with FlowProgressHolder

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;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse) Date(java.util.Date) DecimalFormat(java.text.DecimalFormat) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.springframework.stereotype.Component) FlowProgressHolder(com.sequenceiq.flow.core.config.FlowProgressHolder) Optional(java.util.Optional) Comparator(java.util.Comparator) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) FlowLog(com.sequenceiq.flow.domain.FlowLog) Date(java.util.Date)

Aggregations

FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)1 FlowStateTransitionResponse (com.sequenceiq.flow.api.model.FlowStateTransitionResponse)1 FlowProgressHolder (com.sequenceiq.flow.core.config.FlowProgressHolder)1 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 Component (org.springframework.stereotype.Component)1