use of org.ow2.proactive.db.SortOrder in project scheduling by ow2-proactive.
the class SchedulerStateRest method createJobSortParams.
private static List<SortParameter<JobSortParameter>> createJobSortParams(String sortString) {
String[] sortParams = sortString.split(",");
List<SortParameter<JobSortParameter>> jobSortParamsList = new ArrayList<>(sortParams.length);
for (String param : sortParams) {
SortOrder order;
if (param.endsWith(ASC_SUFFIX)) {
order = SortOrder.ASC;
param = param.substring(0, param.length() - ASC_SUFFIX.length());
} else if (param.endsWith(DESC_SUFFIX)) {
order = SortOrder.DESC;
param = param.substring(0, param.length() - DESC_SUFFIX.length());
} else {
throw new IllegalArgumentException("Invalid sort order in " + sortString);
}
JobSortParameter jobSortParameter = JobSortParameter.valueOf(param);
jobSortParamsList.add(new SortParameter<>(jobSortParameter, order));
}
return jobSortParamsList;
}
use of org.ow2.proactive.db.SortOrder in project scheduling by ow2-proactive.
the class SchedulerDBManager method getJobs.
public Page<JobInfo> getJobs(final int offset, final int limit, final String user, final boolean pending, final boolean running, final boolean finished, final boolean childJobs, String jobName, String projectName, Long parentId, final List<SortParameter<JobSortParameter>> sortParameters) {
if (!pending && !running && !finished) {
return new Page<>(new ArrayList<JobInfo>(0), 0);
}
DBJobDataParameters params = new DBJobDataParameters(offset, limit, user, pending, running, finished, childJobs, jobName, projectName, parentId, sortParameters);
int totalNbJobs = getTotalNumberOfJobs(params);
final Set<JobStatus> jobStatuses = params.getStatuses();
List<JobInfo> lJobs = executeReadOnlyTransaction(session -> {
Criteria criteria = session.createCriteria(JobData.class);
if (limit > 0) {
criteria.setMaxResults(limit);
}
if (offset >= 0) {
criteria.setFirstResult(offset);
}
if (user != null && !user.isEmpty()) {
criteria.add(Restrictions.eq("owner", user));
}
if (!childJobs) {
criteria.add(Restrictions.isNull("parentId"));
}
if (jobName != null && !jobName.isEmpty()) {
criteria.add(Restrictions.like("jobName", jobName, MatchMode.START));
}
if (projectName != null && !projectName.isEmpty()) {
criteria.add(Restrictions.like("projectName", projectName, MatchMode.START));
}
if (childJobs && parentId != null && parentId > 0L) {
criteria.add(Restrictions.eq("parentId", parentId));
}
boolean allJobs = pending && running && finished;
if (!allJobs) {
criteria.add(Restrictions.in("status", jobStatuses));
}
if (sortParameters != null) {
Order sortOrder;
for (SortParameter<JobSortParameter> param : sortParameters) {
switch(param.getParameter()) {
case ID:
sortOrder = configureSortOrder(param, Property.forName("id"));
break;
case NAME:
sortOrder = configureSortOrder(param, Property.forName("jobName"));
break;
case OWNER:
sortOrder = configureSortOrder(param, Property.forName("owner"));
break;
case PRIORITY:
sortOrder = configureSortOrder(param, Property.forName("priority"));
break;
case STATE:
sortOrder = new GroupByStatusSortOrder(param.getSortOrder(), "status");
break;
case SUBMIT_TIME:
sortOrder = configureSortOrder(param, Property.forName("submittedTime"));
break;
case START_TIME:
sortOrder = configureSortOrder(param, Property.forName("startTime"));
break;
case FINISH_TIME:
sortOrder = configureSortOrder(param, Property.forName("finishedTime"));
break;
case IN_ERROR_TIME:
sortOrder = configureSortOrder(param, Property.forName("finishedTime"));
break;
case TOTAL_TASKS:
sortOrder = configureSortOrder(param, Property.forName("totalNumberOfTasks"));
break;
case PENDING_TASKS:
sortOrder = configureSortOrder(param, Property.forName("numberOfPendingTasks"));
break;
case RUNNING_TASKS:
sortOrder = configureSortOrder(param, Property.forName("numberOfRunningTasks"));
break;
case IN_ERROR_TASKS:
sortOrder = configureSortOrder(param, Property.forName("numberOfInErrorTasks"));
break;
case FINISHED_TASKS:
sortOrder = configureSortOrder(param, Property.forName("numberOfFinishedTasks"));
break;
case FAULTY_TASKS:
sortOrder = configureSortOrder(param, Property.forName("numberOfFaultyTasks"));
break;
case FAILED_TASKS:
sortOrder = configureSortOrder(param, Property.forName("numberOfFailedTasks"));
break;
default:
throw new IllegalArgumentException("Unsupported sort parameter: " + param.getParameter());
}
criteria.addOrder(sortOrder);
}
}
List<JobData> jobsList = criteria.list();
return jobsList.stream().map(JobData::toJobInfo).collect(Collectors.toList());
});
return new Page<>(lJobs, totalNbJobs);
}
Aggregations