Search in sources :

Example 1 with Value

use of org.ow2.authzforce.core.pdp.api.value.Value 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 2 with Value

use of org.ow2.authzforce.core.pdp.api.value.Value in project scheduling by ow2-proactive.

the class SchedulerStateRest method putThirdPartyCredential.

@Override
public void putThirdPartyCredential(String sessionId, String key, String value) throws NotConnectedRestException, PermissionRestException, SchedulerRestException {
    try {
        Scheduler s = checkAccess(sessionId);
        s.putThirdPartyCredential(key, value);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (KeyException e) {
        throw new SchedulerRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) KeyException(java.security.KeyException)

Example 3 with Value

use of org.ow2.authzforce.core.pdp.api.value.Value in project scheduling by ow2-proactive.

the class SchedulerStateRest method serializedValueOfTaskResult.

/**
 * Returns the value of the task result of the task <code>taskName</code> of
 * the job <code>jobId</code> This method returns the result as a byte array
 * whatever the result is.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return the value of the task result as a byte array.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/serializedvalue")
@Produces("*/*")
public byte[] serializedValueOfTaskResult(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws Throwable {
    Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result/serializedvalue");
    TaskResult tr = s.getTaskResult(jobId, taskname);
    tr = PAFuture.getFutureValue(tr);
    return tr.getSerializedValue();
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 4 with Value

use of org.ow2.authzforce.core.pdp.api.value.Value in project scheduling by ow2-proactive.

the class SchedulerStateRest method valueOfTaskResultByTag.

/**
 * Returns the value of the task result for a set of tasks of the job
 * <code>jobId</code> filtered by a given tag. <strong>the result is
 * deserialized before sending to the client, if the class is not found the
 * content is replaced by the string 'Unknown value type' </strong>. To get
 * the serialized form of a given result, one has to call the following
 * restful service jobs/{jobid}/tasks/tag/{tasktag}/result/serializedvalue
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the value of the task result
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/value")
@Produces("application/json")
public Map<String, String> valueOfTaskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws Throwable {
    Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag/" + taskTag + "/result/value");
    List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
    Map<String, String> result = new HashMap<String, String>(taskResults.size());
    for (TaskResult currentTaskResult : taskResults) {
        result.put(currentTaskResult.getTaskId().getReadableName(), getTaskResultValueAsStringOrExceptionStackTrace(currentTaskResult));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 5 with Value

use of org.ow2.authzforce.core.pdp.api.value.Value in project scheduling by ow2-proactive.

the class SchedulerStateRest method schedulerChangeJobPriorityByValue.

/**
 * changes the priority of a job
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the job id
 * @param priorityValue
 *            a string representing the value of the priority
 * @throws NumberFormatException
 * @throws NotConnectedRestException
 * @throws UnknownJobRestException
 * @throws PermissionRestException
 * @throws JobAlreadyFinishedRestException
 */
@Override
@PUT
@Path("jobs/{jobid}/priority/byvalue/{value}")
public void schedulerChangeJobPriorityByValue(@HeaderParam("sessionid") final String sessionId, @PathParam("jobid") final String jobId, @PathParam("value") String priorityValue) throws NumberFormatException, NotConnectedRestException, UnknownJobRestException, PermissionRestException, JobAlreadyFinishedRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/priority/byvalue" + priorityValue);
        s.changeJobPriority(jobId, JobPriority.findPriority(Integer.parseInt(priorityValue)));
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (JobAlreadyFinishedException e) {
        throw new JobAlreadyFinishedRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) JobAlreadyFinishedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobAlreadyFinishedRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Aggregations

Test (org.junit.Test)77 HashMap (java.util.HashMap)30 IOException (java.io.IOException)26 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)26 JobId (org.ow2.proactive.scheduler.common.job.JobId)22 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)20 ModelValidatorContext (org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext)18 File (java.io.File)16 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)15 ArrayList (java.util.ArrayList)14 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)14 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)14 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)13 Serializable (java.io.Serializable)12 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)12 Map (java.util.Map)11 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)11 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)10 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)10 FileNotFoundException (java.io.FileNotFoundException)9