Search in sources :

Example 1 with GetJobsByOffsetQueryParameters

use of org.ovirt.engine.core.common.queries.GetJobsByOffsetQueryParameters in project ovirt-engine by oVirt.

the class TaskListModel method syncSearch.

@Override
protected void syncSearch() {
    AsyncQuery<QueryReturnValue> asyncQuery = new AsyncQuery<>(returnValue -> {
        List<Job> taskList = returnValue.getReturnValue();
        if (taskList.size() == 0) {
            detailedTaskMap.clear();
        }
        List<Job> taskListWithCorrelationFilter = new ArrayList<>();
        Map<String, Map.Entry<Job, ArrayList<Job>>> correlationTaskMap = new HashMap<>();
        for (Job task : taskList) {
            if (task.getCorrelationId().startsWith(WEBADMIN)) {
                if (!correlationTaskMap.containsKey(task.getCorrelationId())) {
                    Job rootTask = new Job();
                    rootTask.setCorrelationId(task.getCorrelationId());
                    Map.Entry<Job, ArrayList<Job>> entry = new TaskEntry(rootTask);
                    entry.setValue(new ArrayList<Job>());
                    correlationTaskMap.put(rootTask.getCorrelationId(), entry);
                    String[] taskDescreptionArray = // $NON-NLS-1$ //$NON-NLS-2$
                    rootTask.getCorrelationId().replace(WEBADMIN, "").split("_");
                    StringBuilder taskDesc = new StringBuilder();
                    for (int i = 1; i < taskDescreptionArray.length; i++) {
                        // $NON-NLS-1$
                        taskDesc.append(taskDescreptionArray[i]).append(" ");
                    }
                    rootTask.setId(task.getId());
                    rootTask.setDescription(taskDesc.toString());
                    taskListWithCorrelationFilter.add(rootTask);
                }
                Map.Entry<Job, ArrayList<Job>> entry = correlationTaskMap.get(task.getCorrelationId());
                entry.getValue().add(task);
            } else {
                taskListWithCorrelationFilter.add(task);
            }
        }
        for (Map.Entry<Job, ArrayList<Job>> entry : correlationTaskMap.values()) {
            entry.getKey().setStatus(JobExecutionStatus.UNKNOWN);
            boolean hasFailedStatus = false;
            boolean hasStartedStatus = false;
            boolean hasAbortedStatus = false;
            int finishedCount = 0;
            for (Job task : entry.getValue()) {
                switch(task.getStatus()) {
                    case STARTED:
                        hasStartedStatus = true;
                        break;
                    case FINISHED:
                        finishedCount++;
                        break;
                    case FAILED:
                        hasFailedStatus = true;
                        break;
                    case ABORTED:
                        hasAbortedStatus = true;
                        break;
                    case UNKNOWN:
                        break;
                    default:
                        break;
                }
                if (entry.getKey().getLastUpdateTime() == null || (entry.getKey().getLastUpdateTime().before(task.getLastUpdateTime()) && !entry.getKey().getLastUpdateTime().equals(task.getLastUpdateTime()))) {
                    entry.getKey().setLastUpdateTime(task.getLastUpdateTime());
                }
                Date tempDate = task.getLastUpdateTime();
                if (entry.getKey().getStartTime() == null || entry.getKey().getStartTime().after(task.getStartTime())) {
                    entry.getKey().setStartTime(task.getStartTime());
                }
                if (entry.getKey().getEndTime() == null || entry.getKey().getEndTime().before(task.getEndTime())) {
                    entry.getKey().setEndTime(task.getEndTime());
                }
                entry.getKey().setLastUpdateTime(tempDate);
            }
            if (hasFailedStatus) {
                entry.getKey().setStatus(JobExecutionStatus.FAILED);
            } else if (finishedCount == entry.getValue().size()) {
                entry.getKey().setStatus(JobExecutionStatus.FINISHED);
            } else if (hasStartedStatus) {
                entry.getKey().setStatus(JobExecutionStatus.STARTED);
            } else if (hasAbortedStatus) {
                entry.getKey().setStatus(JobExecutionStatus.ABORTED);
            } else {
                entry.getKey().setStatus(JobExecutionStatus.UNKNOWN);
            }
        }
        ArrayList<Job> newTaskList = new ArrayList<>();
        for (Job task : taskListWithCorrelationFilter) {
            String id;
            if (task.getCorrelationId().startsWith(WEBADMIN)) {
                id = task.getCorrelationId();
            } else {
                id = task.getId().toString();
            }
            boolean hadDetails = detailedTaskMap.containsKey(id) && detailedTaskMap.get(id) != null;
            if (hadDetails && task.getLastUpdateTime().getTime() - detailedTaskMap.get(id).getLastUpdateTime().getTime() < 100) {
                task.setSteps(detailedTaskMap.get(id).getSteps());
            } else if (hadDetails) {
                detailedTaskMap.remove(id);
                updateSingleTask(id);
            }
            newTaskList.add(task);
        }
        setItems(newTaskList);
    });
    GetJobsByOffsetQueryParameters tempVar = new GetJobsByOffsetQueryParameters();
    tempVar.setRefresh(getIsQueryFirstTime());
    Frontend.getInstance().runQuery(QueryType.GetJobsByOffset, tempVar, asyncQuery);
    setIsQueryFirstTime(false);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GetJobsByOffsetQueryParameters(org.ovirt.engine.core.common.queries.GetJobsByOffsetQueryParameters) Job(org.ovirt.engine.core.common.job.Job) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Job (org.ovirt.engine.core.common.job.Job)1 GetJobsByOffsetQueryParameters (org.ovirt.engine.core.common.queries.GetJobsByOffsetQueryParameters)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1