Search in sources :

Example 16 with ISchedulerClient

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();
    Assert.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());
}
Also used : StringWrapper(org.objectweb.proactive.core.util.wrapper.StringWrapper) Serializable(java.io.Serializable) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) VariableTask(functionaltests.jobs.VariableTask) TaskException(org.ow2.proactive.scheduler.task.exceptions.TaskException) RawTask(functionaltests.jobs.RawTask) MetadataTask(functionaltests.jobs.MetadataTask) ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) JobState(org.ow2.proactive.scheduler.common.job.JobState) SimpleJob(functionaltests.jobs.SimpleJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) ErrorTask(functionaltests.jobs.ErrorTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleJob(functionaltests.jobs.SimpleJob) Job(org.ow2.proactive.scheduler.common.job.Job) NonTerminatingJob(functionaltests.jobs.NonTerminatingJob) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId) LogTask(functionaltests.jobs.LogTask) Test(org.junit.Test)

Example 17 with ISchedulerClient

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));
}
Also used : ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) ConnectionInfo(org.ow2.proactive.authentication.ConnectionInfo) File(java.io.File) Test(org.junit.Test)

Aggregations

ISchedulerClient (org.ow2.proactive.scheduler.rest.ISchedulerClient)16 Test (org.junit.Test)14 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)9 SimpleJob (functionaltests.jobs.SimpleJob)9 Job (org.ow2.proactive.scheduler.common.job.Job)9 JobId (org.ow2.proactive.scheduler.common.job.JobId)9 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)9 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)5 ConnectionInfo (org.ow2.proactive.authentication.ConnectionInfo)3 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)3 File (java.io.File)2 JobState (org.ow2.proactive.scheduler.common.job.JobState)2 ErrorTask (functionaltests.jobs.ErrorTask)1 LogTask (functionaltests.jobs.LogTask)1 MetadataTask (functionaltests.jobs.MetadataTask)1 RawTask (functionaltests.jobs.RawTask)1 VariableTask (functionaltests.jobs.VariableTask)1 Serializable (java.io.Serializable)1 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)1 StringWrapper (org.objectweb.proactive.core.util.wrapper.StringWrapper)1