Search in sources :

Example 1 with FlowStateTransitionResponse

use of com.sequenceiq.flow.api.model.FlowStateTransitionResponse 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 2 with FlowStateTransitionResponse

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

the class FlowProgressResponseConverter method createFlowStateTransitions.

private List<FlowStateTransitionResponse> createFlowStateTransitions(List<FlowLog> reversedFlowLogs, Long currentCreatedTime) {
    List<FlowStateTransitionResponse> transitions = new ArrayList<>();
    for (int flowLogIndex = 0; flowLogIndex < reversedFlowLogs.size(); flowLogIndex++) {
        FlowLog fl = reversedFlowLogs.get(flowLogIndex);
        Double elapsedTime = null;
        if (!fl.getFinalized() && flowLogIndex == reversedFlowLogs.size() - 1) {
            elapsedTime = getRoundedTimeInSeconds(currentCreatedTime, new Date().getTime());
        } else {
            elapsedTime = getRoundedTimeInSeconds(currentCreatedTime, fl.getCreated());
        }
        currentCreatedTime = fl.getCreated();
        transitions.add(convertToFlowTransitionResponse(fl, elapsedTime));
    }
    return transitions;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) ArrayList(java.util.ArrayList) FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse) Date(java.util.Date)

Example 3 with FlowStateTransitionResponse

use of com.sequenceiq.flow.api.model.FlowStateTransitionResponse 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 4 with FlowStateTransitionResponse

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

the class FlowProgressResponseConverter method convertToFlowTransitionResponse.

private FlowStateTransitionResponse convertToFlowTransitionResponse(FlowLog fl, Double elapsedTime) {
    FlowStateTransitionResponse transition = new FlowStateTransitionResponse();
    transition.setState(fl.getCurrentState());
    transition.setNextEvent(fl.getNextEvent());
    transition.setStatus(fl.getStateStatus().name());
    transition.setElapsedTimeInSeconds(elapsedTime);
    return transition;
}
Also used : FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse)

Aggregations

FlowStateTransitionResponse (com.sequenceiq.flow.api.model.FlowStateTransitionResponse)4 FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)2 ArrayList (java.util.ArrayList)2 OperationProgressStatus (com.sequenceiq.flow.api.model.operation.OperationProgressStatus)1 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 Date (java.util.Date)1