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