Search in sources :

Example 96 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerDBManager method loadTaskResult.

@SuppressWarnings("unchecked")
private TaskResult loadTaskResult(Session session, TaskId taskId, int resultIndex) {
    DBTaskId dbTaskId = taskId(taskId);
    TaskData task = session.load(TaskData.class, dbTaskId);
    Query query = session.getNamedQuery("loadTasksResultByTask").setParameter("task", task);
    query.setMaxResults(1);
    query.setFirstResult(resultIndex);
    List<TaskResultData> results = (List<TaskResultData>) query.list();
    if (results.isEmpty()) {
        return null;
    } else {
        return results.get(0).toTaskResult(taskId);
    }
}
Also used : DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) Query(org.hibernate.Query) List(java.util.List) ArrayList(java.util.ArrayList)

Example 97 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerDBManager method saveTaskDependencies.

private void saveTaskDependencies(Session session, List<InternalTask> tasks, List<TaskData> taskRuntimeDataList) {
    for (int i = 0; i < tasks.size(); i++) {
        InternalTask task = tasks.get(i);
        TaskData taskRuntimeData = taskRuntimeDataList.get(i);
        saveSingleTaskDependencies(session, task, taskRuntimeData);
    }
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Example 98 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerDBManager method loadJobResult.

@SuppressWarnings("unchecked")
private JobResultImpl loadJobResult(Session session, Query query, JobData job, JobId jobId) {
    JobResultImpl jobResult = new JobResultImpl();
    jobResult.setJobInfo(job.createJobInfo(jobId));
    DBTaskId currentTaskId = null;
    List<Object[]> resultList = (List<Object[]>) query.list();
    if (resultList.isEmpty()) {
        return jobResult;
    }
    int counter = 0;
    for (Object[] result : resultList) {
        TaskResultData resultData = (TaskResultData) result[0];
        DBTaskId dbTaskId = (DBTaskId) result[1];
        String taskName = (String) result[2];
        Boolean preciousResult = (Boolean) result[3];
        boolean nextTask = !dbTaskId.equals(currentTaskId);
        if (nextTask) {
            TaskId taskId = TaskIdImpl.createTaskId(jobId, taskName, dbTaskId.getTaskId());
            jobResult.addTaskResult(taskName, resultData.toTaskResult(taskId), preciousResult);
            currentTaskId = dbTaskId;
        }
        if (++counter % 100 == 0) {
            session.clear();
        }
    }
    return jobResult;
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) List(java.util.List) ArrayList(java.util.ArrayList)

Example 99 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerDBManager method updateTaskData.

private int updateTaskData(final TaskState task, Session session) {
    Query taskUpdateQuery = session.getNamedQuery("updateTaskData");
    TaskInfo taskInfo = task.getTaskInfo();
    return taskUpdateQuery.setParameter("taskStatus", taskInfo.getStatus()).setParameter("numberOfExecutionLeft", taskInfo.getNumberOfExecutionLeft()).setParameter("numberOfExecutionOnFailureLeft", taskInfo.getNumberOfExecutionOnFailureLeft()).setParameter("inErrorTime", taskInfo.getInErrorTime()).setParameter("taskId", taskId(task.getId())).executeUpdate();
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) Query(org.hibernate.Query)

Example 100 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class TaskDBUtils method getTotalNumberOfTasks.

public static SessionWork<Integer> getTotalNumberOfTasks(final DBTaskDataParameters params) {
    return new SessionWork<Integer>() {

        @Override
        public Integer doInTransaction(Session session) {
            Set<TaskStatus> taskStatuses = params.getStatuses();
            if (taskStatuses.isEmpty()) {
                return 0;
            }
            boolean hasUser = params.hasUser();
            boolean hasTag = params.hasTag();
            boolean hasDateFrom = params.hasDateFrom();
            boolean hasDateTo = params.hasDateTo();
            String queryPrefix = "select count(*) from TaskData T where ";
            Query query = getQuery(session, params, taskStatuses, hasUser, hasTag, hasDateFrom, hasDateTo, SortSpecifierContainer.EMPTY_CONTAINER, queryPrefix);
            Long count = (Long) query.uniqueResult();
            return count.intValue();
        }
    };
}
Also used : SessionWork(org.ow2.proactive.db.SessionWork) Query(org.hibernate.Query) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) Session(org.hibernate.Session)

Aggregations

Path (javax.ws.rs.Path)49 Produces (javax.ws.rs.Produces)47 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)39 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)36 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)34 GET (javax.ws.rs.GET)32 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)29 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)25 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)24 GZIP (org.jboss.resteasy.annotations.GZIP)23 Session (org.ow2.proactive_grid_cloud_portal.common.Session)18 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)17 ArrayList (java.util.ArrayList)16 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)15 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)15 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)15 JobState (org.ow2.proactive.scheduler.common.job.JobState)12 IOException (java.io.IOException)11 POST (javax.ws.rs.POST)11