Search in sources :

Example 6 with FlowProgressResponse

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

the class OperationDetailsPopulatorTest method createFlowProgressResponse.

private Optional<FlowProgressResponse> createFlowProgressResponse(String secondTransitionState, boolean finished) {
    FlowProgressResponse response = new FlowProgressResponse();
    List<FlowStateTransitionResponse> transitionResponseList = new ArrayList<>();
    FlowStateTransitionResponse transitionResponse1 = new FlowStateTransitionResponse();
    transitionResponse1.setState("state1");
    transitionResponse1.setNextEvent("nextEvent1");
    transitionResponse1.setStatus("SUCCESSFUL");
    FlowStateTransitionResponse transitionResponse2 = new FlowStateTransitionResponse();
    transitionResponse2.setStatus("state2");
    transitionResponse2.setNextEvent("nextEvent2");
    transitionResponse2.setStatus(secondTransitionState);
    transitionResponseList.add(transitionResponse1);
    transitionResponseList.add(transitionResponse2);
    response.setTransitions(transitionResponseList);
    if (finished) {
        response.setProgress(MAX_PROGRESS);
        response.setFinalized(false);
        response.setMaxNumberOfTransitions(transitionResponseList.size());
    } else {
        response.setProgress(IN_PROGRESS);
        response.setFinalized(true);
        response.setMaxNumberOfTransitions(transitionResponseList.size() + 1);
    }
    return Optional.of(response);
}
Also used : FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) ArrayList(java.util.ArrayList) FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse)

Example 7 with FlowProgressResponse

use of com.sequenceiq.flow.api.model.FlowProgressResponse 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)

Example 8 with FlowProgressResponse

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

the class OperationDetailsPopulator method calculateProgress.

private OperationProgressStatus calculateProgress(List<FlowProgressResponse> provisionFlows) {
    FlowProgressResponse lastFlowProgress = provisionFlows.get(provisionFlows.size() - 1);
    if (lastFlowProgress.getTransitions() == null) {
        return OperationProgressStatus.UNKNOWN;
    }
    OperationProgressStatus progressStatus = OperationProgressStatus.FINISHED;
    boolean hasCancelState = false;
    boolean hasFailedStatus = false;
    boolean hasPendingStatus = false;
    for (FlowStateTransitionResponse fsTransitionResp : lastFlowProgress.getTransitions()) {
        if (OperationProgressStatus.CANCELLED.name().equals(fsTransitionResp.getStatus())) {
            hasCancelState = true;
        } else if (StateStatus.FAILED.name().equals(fsTransitionResp.getStatus())) {
            hasFailedStatus = true;
        } else if (StateStatus.PENDING.name().equals(fsTransitionResp.getStatus())) {
            hasPendingStatus = true;
        }
    }
    if (hasFailedStatus) {
        progressStatus = OperationProgressStatus.FAILED;
    } else if (hasCancelState) {
        progressStatus = OperationProgressStatus.CANCELLED;
    } else if (hasPendingStatus) {
        progressStatus = OperationProgressStatus.RUNNING;
    }
    return progressStatus;
}
Also used : FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) OperationProgressStatus(com.sequenceiq.flow.api.model.operation.OperationProgressStatus) FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse)

Example 9 with FlowProgressResponse

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

the class OperationDetailsPopulator method populateOperationDetails.

private void populateOperationDetails(OperationView source, List<Optional<FlowProgressResponse>> operations, int expectedNumberOfFlows, Integer progressFromHistory) {
    int preProgress = 0;
    int overallProgress = 0;
    boolean foundFlow = false;
    boolean expectFlowChainId = operations.size() > 1;
    for (Optional<FlowProgressResponse> operationOpt : operations) {
        if (operationOpt.isPresent()) {
            if (!foundFlow) {
                overallProgress += preProgress;
                source.setOperationId(operationOpt.get().getFlowId());
            }
            foundFlow = true;
            FlowProgressResponse flowProgress = operationOpt.get();
            if (flowProgress.getProgress() != DEFAULT_PROGRESS) {
                overallProgress += flowProgress.getProgress();
            }
            source.getOperations().add(flowProgress);
        } else if (expectFlowChainId && !foundFlow) {
            preProgress += MAX_PROGRESS;
            operationOpt.ifPresent(flowProgressResponse -> source.setOperationId(flowProgressResponse.getFlowChainId()));
        }
    }
    setProgressAndStatus(source, expectedNumberOfFlows, progressFromHistory, overallProgress);
}
Also used : FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse) OperationProgressStatus(com.sequenceiq.flow.api.model.operation.OperationProgressStatus) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) StateStatus(com.sequenceiq.flow.api.model.StateStatus) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.springframework.stereotype.Component) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) Map(java.util.Map) OperationResource(com.sequenceiq.flow.api.model.operation.OperationResource) Optional(java.util.Optional) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse)

Example 10 with FlowProgressResponse

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

the class OperationDetailsPopulator method createOperationView.

public OperationView createOperationView(OperationFlowsView operationFlowsView, OperationResource resource, List<Class<?>> expectedTypeOrder) {
    OperationView response = new OperationView();
    response.setOperationType(operationFlowsView.getOperationType());
    response.setOperationResource(resource);
    response.setOperationId(operationFlowsView.getOperationId());
    List<String> typeOrderList = CollectionUtils.isNotEmpty(expectedTypeOrder) ? expectedTypeOrder.stream().map(Class::getCanonicalName).collect(Collectors.toList()) : operationFlowsView.getTypeOrderList();
    int expectedNumberOfFlows = typeOrderList.size();
    Map<String, FlowProgressResponse> flowTypeProgressMap = operationFlowsView.getFlowTypeProgressMap();
    List<Optional<FlowProgressResponse>> responseListToProcess = new ArrayList<>();
    for (String typeName : typeOrderList) {
        if (flowTypeProgressMap != null && flowTypeProgressMap.containsKey(typeName)) {
            responseListToProcess.add(Optional.of(flowTypeProgressMap.get(typeName)));
        } else {
            responseListToProcess.add(Optional.empty());
        }
    }
    populateOperationDetails(response, responseListToProcess, expectedNumberOfFlows, operationFlowsView.getProgressFromHistory());
    return response;
}
Also used : Optional(java.util.Optional) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) ArrayList(java.util.ArrayList)

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