Search in sources :

Example 1 with JobInfo

use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.

the class JobData method toJobInfo.

JobInfo toJobInfo() {
    JobId jobIdInstance = new JobIdImpl(getId(), getJobName());
    JobInfoImpl jobInfo = createJobInfo(jobIdInstance);
    return jobInfo;
}
Also used : JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 2 with JobInfo

use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.

the class TestLoadJobsPagination method testPagingAndFilteting.

@Test
public void testPagingAndFilteting() throws Exception {
    InternalJob job;
    InternalTask task;
    // pending job - 1
    defaultSubmitJob(createJob());
    // job for user1 - 2
    defaultSubmitJob(createJob(), "user1");
    // running job - 3
    job = defaultSubmitJob(createJob());
    job.start();
    task = startTask(job, job.getITasks().get(0));
    dbManager.jobTaskStarted(job, task, true);
    // killed job - 4
    job = defaultSubmitJob(createJob());
    job.failed(null, JobStatus.KILLED);
    dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
    // job for user2 - 5
    defaultSubmitJob(createJob(), "user2");
    // finished job - 6
    job = defaultSubmitJob(createJob());
    job.start();
    task = startTask(job, job.getITasks().get(0));
    dbManager.jobTaskStarted(job, task, true);
    TaskResultImpl result = new TaskResultImpl(null, new TestResult(0, "result"), null, 0);
    job.terminateTask(false, task.getId(), null, null, result);
    job.terminate();
    dbManager.updateAfterTaskFinished(job, task, new TaskResultImpl(null, new TestResult(0, "result"), null, 0));
    // canceled job - 7
    job = defaultSubmitJob(createJob());
    job.failed(job.getITasks().get(0).getId(), JobStatus.CANCELED);
    dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
    // job marked as removed, method 'getJobs' shouldn't return it
    job = defaultSubmitJob(createJob());
    dbManager.removeJob(job.getId(), System.currentTimeMillis(), false);
    List<JobInfo> jobs;
    List<SortParameter<JobSortParameter>> sortParameters = new ArrayList<>();
    sortParameters.add(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC));
    jobs = dbManager.getJobs(5, 1, null, true, true, true, sortParameters).getList();
    JobInfo jobInfo = jobs.get(0);
    Assert.assertEquals("6", jobInfo.getJobId().value());
    Assert.assertEquals(JobStatus.FINISHED, jobInfo.getStatus());
    Assert.assertEquals("TestLoadJobsPagination", jobInfo.getJobId().getReadableName());
    Assert.assertEquals(1, jobInfo.getTotalNumberOfTasks());
    Assert.assertEquals(1, jobInfo.getNumberOfFinishedTasks());
    Assert.assertEquals(0, jobInfo.getNumberOfRunningTasks());
    Assert.assertEquals(0, jobInfo.getNumberOfPendingTasks());
    Assert.assertEquals(JobPriority.NORMAL, jobInfo.getPriority());
    Assert.assertEquals(DEFAULT_USER_NAME, jobInfo.getJobOwner());
    jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(-1, -1, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(-1, 5, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5);
    jobs = dbManager.getJobs(2, -1, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(0, 0, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(0, 1, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1);
    jobs = dbManager.getJobs(0, 3, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 2, 3);
    jobs = dbManager.getJobs(1, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 2, 3, 4, 5, 6, 7);
    jobs = dbManager.getJobs(5, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 6, 7);
    jobs = dbManager.getJobs(6, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs, 7);
    jobs = dbManager.getJobs(7, 10, null, true, true, true, sortParameters).getList();
    checkJobs(jobs);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, true, sortParameters).getList();
    checkJobs(jobs, 1, 3, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, "user1", true, true, true, sortParameters).getList();
    checkJobs(jobs, 2);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, false, sortParameters).getList();
    checkJobs(jobs, 1);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, false, sortParameters).getList();
    checkJobs(jobs, 3);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, true, sortParameters).getList();
    checkJobs(jobs, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, true, sortParameters).getList();
    checkJobs(jobs, 3, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, true, sortParameters).getList();
    checkJobs(jobs, 1, 4, 6, 7);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, false, sortParameters).getList();
    checkJobs(jobs, 1, 3);
    jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, false, sortParameters).getList();
    checkJobs(jobs);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList) JobSortParameter(org.ow2.proactive.scheduler.common.JobSortParameter) SortParameter(org.ow2.proactive.db.SortParameter) Test(org.junit.Test)

Example 3 with JobInfo

use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobsInfo.

/**
 * Returns a subset of the scheduler state, including pending, running,
 * finished jobs (in this particular order). each jobs is described using -
 * its id - its owner - the JobInfo class
 *
 * @param index
 *            optional, if a sublist has to be returned the index of the
 *            sublist
 * @param limit
 *            optional, if a sublist has to be returned, the limit of the
 *            sublist
 * @param sessionId
 *            a valid session id
 * @return a list of UserJobData
 */
@Override
@GET
@Path("jobsinfo")
@Produces({ "application/json", "application/xml" })
public RestPage<UserJobData> jobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit) throws PermissionRestException, NotConnectedRestException {
    try {
        Scheduler s = checkAccess(sessionId, "/scheduler/jobsinfo");
        Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(false, true, true, true), DEFAULT_JOB_SORT_PARAMS);
        List<UserJobData> userJobInfoList = new ArrayList<UserJobData>(page.getList().size());
        for (JobInfo jobInfo : page.getList()) {
            userJobInfoList.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
        }
        return new RestPage<UserJobData>(userJobInfoList, page.getSize());
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UserJobData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with JobInfo

use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.

the class SchedulerStateRest method revisionAndJobsInfo.

/**
 * Returns a map containing one entry with the revision id as key and the
 * list of UserJobData as value. each jobs is described using - its id - its
 * owner - the JobInfo class
 *
 * @param sessionId
 *            a valid session id
 * @param index
 *            optional, if a sublist has to be returned the index of the
 *            sublist
 * @param limit
 *            optional, if a sublist has to be returned, the limit of the
 *            sublist
 * @param myJobs
 *            fetch only the jobs for the user making the request
 * @param pending
 *            fetch pending jobs
 * @param running
 *            fetch running jobs
 * @param finished
 *            fetch finished jobs
 * @return a map containing one entry with the revision id as key and the
 *         list of UserJobData as value.
 */
@Override
@GET
@GZIP
@Path("revisionjobsinfo")
@Produces({ "application/json", "application/xml" })
public RestMapPage<Long, ArrayList<UserJobData>> revisionAndJobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit, @QueryParam("myjobs") @DefaultValue("false") boolean myJobs, @QueryParam("pending") @DefaultValue("true") boolean pending, @QueryParam("running") @DefaultValue("true") boolean running, @QueryParam("finished") @DefaultValue("true") boolean finished) throws PermissionRestException, NotConnectedRestException {
    try {
        Scheduler s = checkAccess(sessionId, "revisionjobsinfo?index=" + index + "&limit=" + limit);
        String user = sessionStore.get(sessionId).getUserName();
        boolean onlyUserJobs = (myJobs && user != null && user.trim().length() > 0);
        Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(onlyUserJobs, pending, running, finished), DEFAULT_JOB_SORT_PARAMS);
        List<JobInfo> jobsInfo = page.getList();
        ArrayList<UserJobData> jobs = new ArrayList<>(jobsInfo.size());
        for (JobInfo jobInfo : jobsInfo) {
            jobs.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
        }
        HashMap<Long, ArrayList<UserJobData>> map = new HashMap<Long, ArrayList<UserJobData>>(1);
        map.put(SchedulerStateListener.getInstance().getSchedulerStateRevision(), jobs);
        RestMapPage<Long, ArrayList<UserJobData>> restMapPage = new RestMapPage<Long, ArrayList<UserJobData>>();
        restMapPage.setMap(map);
        restMapPage.setSize(page.getSize());
        return restMapPage;
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) RestMapPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestMapPage) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) HashMap(java.util.HashMap) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UserJobData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.UserJobData) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 5 with JobInfo

use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.

the class TestJobNativeSubmission method testJobNativeSubmission.

@Test
public void testJobNativeSubmission() throws Throwable {
    // test submission and event reception
    TaskFlowJob job = new TaskFlowJob();
    NativeTask successfulTask = new NativeTask();
    successfulTask.setName("successfulTask");
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.windows) {
        successfulTask.setCommandLine("cmd", "/C", "ping 127.0.0.1 -n 10", ">", "NUL");
    } else {
        successfulTask.setCommandLine("ping", "-c", "5", "127.0.0.1");
    }
    job.addTask(successfulTask);
    NativeTask invalidCommandTask = new NativeTask();
    invalidCommandTask.setName("invalidCommandTask");
    invalidCommandTask.addDependence(successfulTask);
    invalidCommandTask.setCommandLine("invalid_command");
    job.addTask(invalidCommandTask);
    // SCHEDULING-1987
    NativeTask taskReadingInput = new NativeTask();
    taskReadingInput.setName("taskReadingInput");
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.windows) {
        // wait for y/n
        taskReadingInput.setCommandLine("choice");
    } else {
        // cat hangs for user's input
        taskReadingInput.setCommandLine("cat");
    }
    job.addTask(taskReadingInput);
    JobId id = schedulerHelper.submitJob(job);
    log("Job submitted, id " + id.toString());
    log("Waiting for jobSubmitted Event");
    JobState receivedState = schedulerHelper.waitForEventJobSubmitted(id);
    assertEquals(receivedState.getId(), id);
    log("Waiting for job running");
    JobInfo jInfo = schedulerHelper.waitForEventJobRunning(id);
    assertEquals(jInfo.getJobId(), id);
    assertEquals(JobStatus.RUNNING, jInfo.getStatus());
    schedulerHelper.waitForEventTaskRunning(id, successfulTask.getName());
    TaskInfo tInfo = schedulerHelper.waitForEventTaskFinished(id, successfulTask.getName());
    assertEquals(TaskStatus.FINISHED, tInfo.getStatus());
    schedulerHelper.waitForEventTaskRunning(id, invalidCommandTask.getName());
    tInfo = schedulerHelper.waitForEventTaskFinished(id, invalidCommandTask.getName());
    assertEquals(TaskStatus.FAULTY, tInfo.getStatus());
    TaskInfo taskReadingInputInfo = schedulerHelper.waitForEventTaskFinished(id, taskReadingInput.getName());
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.windows) {
        // choice fails when input is closed
        assertEquals(TaskStatus.FAULTY, taskReadingInputInfo.getStatus());
    } else {
        assertEquals(TaskStatus.FINISHED, taskReadingInputInfo.getStatus());
    }
    schedulerHelper.waitForEventJobFinished(id);
    // remove job
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) Test(org.junit.Test)

Aggregations

JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)47 JobId (org.ow2.proactive.scheduler.common.job.JobId)29 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)12 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)12 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)11 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)10 JobState (org.ow2.proactive.scheduler.common.job.JobState)10 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)10 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)8 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)8 File (java.io.File)7 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)7 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)7 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)7 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)7 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)7