use of org.ow2.proactive.scheduler.common.job.JobState in project scheduling by ow2-proactive.
the class RestSmartProxyTest method testJobSubmission.
private void testJobSubmission(boolean isolateTaskOutput, boolean automaticTransfer) throws Exception {
TaskFlowJob job = createTestJob(isolateTaskOutput);
printJobXmlRepresentation(job);
DataTransferNotifier notifier = new DataTransferNotifier();
if (automaticTransfer) {
restSmartProxy.addEventListener(notifier);
}
JobId id = restSmartProxy.submit(job, inputLocalFolder.getAbsolutePath(), pushUrl, outputLocalFolder.getAbsolutePath(), pullUrl, isolateTaskOutput, automaticTransfer);
JobState jobState = waitForJobFinishState(id.toString());
assertEquals(JobStatus.FINISHED, jobState.getStatus());
if (!automaticTransfer) {
for (int i = 0; i < NB_TASKS; i++) {
restSmartProxy.pullData(id.toString(), TASK_NAME + i, outputLocalFolder.getAbsolutePath());
}
} else {
List<String> taskNames = taskNameList();
while (!taskNames.isEmpty()) {
String finishedTask = notifier.finishedTask();
if (taskNames.contains(finishedTask)) {
taskNames.remove(finishedTask);
}
}
}
// check the presence of output files
for (int i = 0; i < NB_TASKS; i++) {
String outputFileName = OUTPUT_FILE_BASE_NAME + "_" + i + OUTPUT_FILE_EXT;
File outputFile = new File(outputLocalFolder, outputFileName);
Assert.assertTrue(String.format("%s does not exist.", outputFile.getAbsolutePath()), outputFile.exists());
}
}
use of org.ow2.proactive.scheduler.common.job.JobState in project scheduling by ow2-proactive.
the class RestSmartProxyTest method testInErrorEventsReception.
@Test(timeout = TEN_MINUTES)
public void testInErrorEventsReception() throws Exception {
System.out.println("Begin testInErrorEventsReception ");
TaskFlowJob job = createInErrorJob();
final Semaphore semaphore = new Semaphore(0);
printJobXmlRepresentation(job);
final MutableBoolean taskHasBeenInError = new MutableBoolean(false);
final MutableBoolean taskMarkedAsFinished = new MutableBoolean(false);
SchedulerEventListenerExtended listener = new SchedulerEventListenerExtended() {
@Override
public void schedulerStateUpdatedEvent(SchedulerEvent eventType) {
System.out.println("RestSmartProxyTest.schedulerStateUpdatedEvent " + eventType);
}
@Override
public void jobSubmittedEvent(JobState job) {
System.out.println("RestSmartProxyTest.jobSubmittedEvent");
}
@Override
public void jobStateUpdatedEvent(NotificationData<JobInfo> notification) {
JobStatus status = notification.getData().getStatus();
System.out.println("RestSmartProxyTest.jobStateUpdatedEvent, eventType=" + notification.getEventType() + ", jobStatus=" + status);
if (status == JobStatus.IN_ERROR) {
semaphore.release();
}
}
@Override
public void taskStateUpdatedEvent(NotificationData<TaskInfo> notification) {
TaskStatus status = notification.getData().getStatus();
System.out.println("RestSmartProxyTest.taskStateUpdatedEvent, taskStatus=" + status);
if (status == TaskStatus.WAITING_ON_ERROR || status == TaskStatus.IN_ERROR) {
// IN_ERROR previously
taskHasBeenInError.setTrue();
}
if (status == TaskStatus.FINISHED && taskHasBeenInError.isTrue()) {
taskMarkedAsFinished.setTrue();
}
}
@Override
public void usersUpdatedEvent(NotificationData<UserIdentification> notification) {
System.out.println("RestSmartProxyTest.usersUpdatedEvent " + notification.getData());
}
@Override
public void pullDataFinished(String jobId, String taskName, String localFolderPath) {
System.out.println("RestSmartProxyTest.pullDataFinished");
}
@Override
public void pullDataFailed(String jobId, String taskName, String remoteFolder_URL, Throwable t) {
System.out.println("RestSmartProxyTest.pullDataFailed");
}
@Override
public void jobUpdatedFullDataEvent(JobState job) {
System.out.println("RestSmartProxyTest.jobUpdatedFullDataEvent");
}
};
restSmartProxy.addEventListener(listener);
JobId jobId = restSmartProxy.submit(job, inputLocalFolder.getAbsolutePath(), pushUrl, outputLocalFolder.getAbsolutePath(), pullUrl, false, false);
// the next line blocks until jobStateUpdatedEvent is called on the
// listener
// with job status set to IN_ERROR
semaphore.acquire();
String jobIdAsString = jobId.value();
System.out.println("Finish in-error task");
restSmartProxy.finishInErrorTask(jobIdAsString, inerrorTaskName);
waitForJobFinishState(jobIdAsString);
assertThat(taskHasBeenInError.booleanValue()).isTrue();
assertThat(taskMarkedAsFinished.booleanValue()).isTrue();
System.out.println("End testInErrorEventsReception");
}
use of org.ow2.proactive.scheduler.common.job.JobState in project scheduling by ow2-proactive.
the class RestSmartProxyTest method waitForJobFinishState.
private JobState waitForJobFinishState(String jobIdAsString) throws InterruptedException, NotConnectedException, UnknownJobException, PermissionException {
JobState jobState = restSmartProxy.getJobState(jobIdAsString);
Thread.sleep(ONE_SECOND);
while (jobState.getStatus().isJobAlive()) {
jobState = restSmartProxy.getJobState(jobIdAsString);
Thread.sleep(ONE_SECOND);
}
return jobState;
}
use of org.ow2.proactive.scheduler.common.job.JobState 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());
}
use of org.ow2.proactive.scheduler.common.job.JobState in project scheduling by ow2-proactive.
the class SchedulerEventBroadcaster method jobSubmittedEvent.
@Override
public void jobSubmittedEvent(JobState jobState) {
logEvent(jobState);
broadcast(new EventNotification(EventNotification.Action.JOB_SUBMITTED, SchedulerEvent.JOB_SUBMITTED.name(), jobState));
}
Aggregations