use of org.ow2.proactive.scheduler.rest.ISchedulerClient in project scheduling by ow2-proactive.
the class SchedulerClientTest method testPushFileWithNonAdminUserPwdShouldSucceed.
@Test(timeout = MAX_WAIT_TIME)
public void testPushFileWithNonAdminUserPwdShouldSucceed() throws Exception {
File tmpFile = testFolder.newFile();
Files.write("non_admin_user_push_file_contents".getBytes(), tmpFile);
ISchedulerClient client = SchedulerClient.createInstance();
client.init(new ConnectionInfo(getRestServerUrl(), getNonAdminLogin(), getNonAdminLoginPassword(), null, true));
client.pushFile("USERSPACE", "/test_non_admin_user_push_file", "tmpfile.tmp", tmpFile.getAbsolutePath());
String destDirPath = URI.create(client.getUserSpaceURIs().get(0)).getPath();
File destFile = new File(destDirPath, "test_non_admin_user_push_file/tmpfile.tmp");
assertTrue(Files.equal(tmpFile, destFile));
}
use of org.ow2.proactive.scheduler.rest.ISchedulerClient in project scheduling by ow2-proactive.
the class SchedulerClientTest method clientInstance.
protected ISchedulerClient clientInstance() throws Exception {
ISchedulerClient client = SchedulerClient.createInstance();
client.init(new ConnectionInfo(getRestServerUrl(), getLogin(), getPassword(), null, true));
return client;
}
use of org.ow2.proactive.scheduler.rest.ISchedulerClient in project scheduling by ow2-proactive.
the class SchedulerClientTest method testRenewSession.
@Test(timeout = MAX_WAIT_TIME)
public void testRenewSession() throws Exception {
ISchedulerClient client = clientInstance();
SchedulerStatus status = client.getStatus();
assertNotNull(status);
// use an invalid session
client.setSession("invalid-session-identifier");
// client should automatically renew the session identifier
status = client.getStatus();
assertNotNull(status);
}
use of org.ow2.proactive.scheduler.rest.ISchedulerClient in project scheduling by ow2-proactive.
the class SchedulerClientTest method testGetJobs.
@Test(timeout = MAX_WAIT_TIME)
public void testGetJobs() throws Throwable {
ISchedulerClient client = clientInstance();
// Define jobs
Job job1 = defaultJob();
Job job2 = defaultJob();
Job job3 = defaultJob();
Job job4 = pendingJob();
// Set job names
job1.setName("myJobA");
job2.setName("myJobB");
job3.setName("myJobB");
job4.setName("myJobC");
// Set project names
job1.setProjectName("myProjectA");
job2.setProjectName("myProjectA");
job3.setProjectName("myProjectB");
job4.setProjectName("myProjectB");
// Remove all existing jobs
Assert.assertTrue(removeAllJobs(client));
// Submit job2 job3 job4
JobId job1Id = submitJob(job1, client);
JobId job2Id = submitJob(job2, client);
JobId job3Id = submitJob(job3, client);
JobId job4Id = submitJob(job4, client);
// Wait for job1, job2 and job3 to finish
JobResult job1Result = client.waitForJob(job1Id, TimeUnit.MINUTES.toMillis(3));
JobResult job2Result = client.waitForJob(job2Id, TimeUnit.MINUTES.toMillis(3));
JobResult job3Result = client.waitForJob(job3Id, TimeUnit.MINUTES.toMillis(3));
Assert.assertEquals(JobStatus.FINISHED, job1Result.getJobInfo().getStatus());
Assert.assertEquals(JobStatus.FINISHED, job2Result.getJobInfo().getStatus());
Assert.assertEquals(JobStatus.FINISHED, job3Result.getJobInfo().getStatus());
// Test sorts
JobFilterCriteria allJobsCriteria = new JobFilterCriteria(false, true, true, true, true, "", "", "", new Long(-1));
SortParameter jobNameDescOrder = new SortParameter<>(JobSortParameter.NAME, SortOrder.DESC);
SortParameter jobIdAscOrder = new SortParameter<>(JobSortParameter.ID, SortOrder.ASC);
List<SortParameter<JobSortParameter>> sortParameterList1 = new ArrayList<>();
sortParameterList1.add(jobNameDescOrder);
sortParameterList1.add(jobIdAscOrder);
List<JobInfo> jobsList1 = client.getJobs(0, 4, allJobsCriteria, sortParameterList1).getList();
Assert.assertEquals(jobsList1.get(0).getJobId().value(), job4Id.value());
Assert.assertEquals(jobsList1.get(1).getJobId().value(), job2Id.value());
Assert.assertEquals(jobsList1.get(2).getJobId().value(), job3Id.value());
Assert.assertEquals(jobsList1.get(3).getJobId().value(), job1Id.value());
// Test range and limit
List<JobInfo> jobsList2 = client.getJobs(2, 2, allJobsCriteria, Collections.singletonList(jobIdAscOrder)).getList();
Assert.assertEquals(jobsList2.get(0).getJobId().value(), job3Id.value());
Assert.assertEquals(jobsList2.get(1).getJobId().value(), job4Id.value());
// Test filters
JobFilterCriteria allJobsFinishedInMyProjectBCriteria = new JobFilterCriteria(false, false, false, true, false, "", "myProjectB", "", new Long(-1));
List<JobInfo> jobsList3 = client.getJobs(0, 4, allJobsFinishedInMyProjectBCriteria, Collections.singletonList(jobIdAscOrder)).getList();
Assert.assertEquals(jobsList3.size(), 1);
Assert.assertEquals(jobsList3.get(0).getJobId().value(), job3Id.value());
client.killJob(job4Id);
// Remove all existing jobs
Assert.assertTrue(removeAllJobs(client));
}
use of org.ow2.proactive.scheduler.rest.ISchedulerClient in project scheduling by ow2-proactive.
the class SchedulerClientTest method testJobResult.
@Test(timeout = MAX_WAIT_TIME)
public void testJobResult() throws Throwable {
ISchedulerClient client = clientInstance();
Job job = createJobManyTasks("JobResult", SimpleJob.class, ErrorTask.class, LogTask.class, VariableTask.class, MetadataTask.class, RawTask.class);
JobId jobId = submitJob(job, client);
JobResult result = client.waitForJob(jobId, TimeUnit.MINUTES.toMillis(3));
// job result
Assert.assertNotNull(result.getJobId());
Assert.assertNotNull(result.getJobInfo());
Assert.assertEquals(JobStatus.FINISHED, result.getJobInfo().getStatus());
// the following check cannot work because of the way the job id is created on the client side.
// Assert.assertEquals(job.getName(), result.getName());
Assert.assertTrue(result.hadException());
Assert.assertEquals(1, result.getExceptionResults().size());
// job info
checkJobInfo(result.getJobInfo());
checkJobInfo(client.getJobInfo(jobId.value()));
JobState jobState = client.getJobState(jobId.value());
JobStatus status = jobState.getStatus();
assertFalse(status.isJobAlive());
Assert.assertEquals(JobStatus.FINISHED, status);
checkJobInfo(jobState.getJobInfo());
TaskState errorTaskState = findTask(getTaskNameForClass(ErrorTask.class), jobState.getHMTasks());
Assert.assertNotNull(errorTaskState);
TaskState simpleTaskState = findTask(getTaskNameForClass(SimpleJob.class), jobState.getHMTasks());
Assert.assertNotNull(simpleTaskState);
Assert.assertEquals(TaskStatus.FAULTY, errorTaskState.getStatus());
Assert.assertEquals(TaskStatus.FINISHED, simpleTaskState.getStatus());
// task result simple
TaskResult tResSimple = result.getResult(getTaskNameForClass(SimpleJob.class));
Assert.assertNotNull(tResSimple.value());
Assert.assertNotNull(tResSimple.getSerializedValue());
Assert.assertEquals(new StringWrapper(TEST_JOB), tResSimple.value());
Assert.assertEquals(new StringWrapper(TEST_JOB), ObjectByteConverter.byteArrayToObject(tResSimple.getSerializedValue()));
// task result with error
TaskResult tResError = result.getResult(getTaskNameForClass(ErrorTask.class));
Assert.assertNotNull(tResError);
Assert.assertTrue(tResError.hadException());
Assert.assertNotNull(tResError.getException());
Assert.assertTrue(tResError.getException() instanceof TaskException);
// task result with logs
TaskResult tResLog = result.getResult(getTaskNameForClass(LogTask.class));
Assert.assertNotNull(tResLog);
Assert.assertNotNull(tResLog.getOutput());
System.err.println(tResLog.getOutput().getStdoutLogs(false));
Assert.assertTrue(tResLog.getOutput().getStdoutLogs(false).contains(LogTask.HELLO_WORLD));
// task result with variables
TaskResult tResVar = result.getResult(getTaskNameForClass(VariableTask.class));
Assert.assertNotNull(tResVar.getPropagatedVariables());
Map<String, Serializable> vars = tResVar.getVariables();
System.out.println(vars);
Assert.assertTrue(tResVar.getPropagatedVariables().containsKey(VariableTask.MYVAR));
Assert.assertEquals("myvalue", vars.get(VariableTask.MYVAR));
// task result with metadata
TaskResult tMetaVar = result.getResult(getTaskNameForClass(MetadataTask.class));
Assert.assertNotNull(tMetaVar.getMetadata());
Assert.assertTrue(tMetaVar.getMetadata().containsKey(MetadataTask.MYVAR));
// task result with raw result
TaskResult tResRaw = result.getResult(getTaskNameForClass(RawTask.class));
Assert.assertNotNull(tResRaw.value());
Assert.assertNotNull(tResRaw.getSerializedValue());
Assert.assertArrayEquals(TEST_JOB.getBytes(), (byte[]) tResRaw.value());
Assert.assertArrayEquals(TEST_JOB.getBytes(), tResRaw.getSerializedValue());
}
Aggregations