Search in sources :

Example 6 with JobStatus

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

the class AbstractSmartProxy method updateJob.

// ********* Awaited Jobs methods ******************************* //
/**
 * @return a new HashSet with the awaited jobs. Modifying the result of this
 *         method will not affect the source HashSet (the awaited jobs)
 */
/**
 * Check if the job concerned by this notification is awaited. Retrieve
 * corresponding data if needed
 *
 * @param notification
 */
protected void updateJob(NotificationData<?> notification) {
    // am I interested in this job?
    JobId id = ((NotificationData<JobInfo>) notification).getData().getJobId();
    AwaitedJob aj = jobTracker.getAwaitedJob(id.toString());
    if (aj == null)
        return;
    JobStatus status = ((NotificationData<JobInfo>) notification).getData().getStatus();
    switch(status) {
        case KILLED:
            {
                log.debug("The job " + id + "has been killed.");
                jobTracker.removeAwaitedJob(id.toString());
                break;
            }
        case FINISHED:
            {
                log.debug("The job " + id + " is finished.");
                // removeAwaitedJob(id.toString());
                break;
            }
        case CANCELED:
            {
                log.debug("The job " + id + " is canceled.");
                jobTracker.removeAwaitedJob(id.toString());
                break;
            }
        case FAILED:
            {
                log.debug("The job " + id + " is failed.");
                // removeAwaitedJob(id.toString());
                break;
            }
    }
}
Also used : JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 7 with JobStatus

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

the class AbstractRestFuncTestCase method waitJobState.

public void waitJobState(String jobId, JobStatus expected, long timeout) throws Exception {
    long stopTime = System.currentTimeMillis() + timeout;
    while (System.currentTimeMillis() < stopTime) {
        JobStatus currentStatus = getScheduler().getJobState(jobId).getStatus();
        if (currentStatus.equals(expected)) {
            return;
        } else if (!currentStatus.isJobAlive()) {
            break;
        } else {
            Thread.sleep(300);
        }
    }
    Assert.fail("Failed to wait when " + jobId + " is " + expected + ", current status is " + getScheduler().getJobState(jobId).getStatus());
}
Also used : JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus)

Example 8 with JobStatus

use of org.ow2.proactive.scheduler.common.job.JobStatus 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");
}
Also used : JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) JobState(org.ow2.proactive.scheduler.common.job.JobState) SchedulerEventListenerExtended(org.ow2.proactive.scheduler.smartproxy.common.SchedulerEventListenerExtended) Semaphore(java.util.concurrent.Semaphore) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) JobId(org.ow2.proactive.scheduler.common.job.JobId) SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent) NotificationData(org.ow2.proactive.scheduler.common.NotificationData) Test(org.junit.Test)

Example 9 with JobStatus

use of org.ow2.proactive.scheduler.common.job.JobStatus 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 10 with JobStatus

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

the class TestRMReconnectionWhileRunning method assertJobFinished.

private void assertJobFinished(JobId jobId) throws Exception {
    final JobResult result0 = schedulerHelper.getJobResult(jobId);
    assertNotNull(result0);
    final JobInfo jobInfo0 = result0.getJobInfo();
    final JobStatus status0 = jobInfo0.getStatus();
    assertFalse(status0.isJobAlive());
}
Also used : JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo)

Aggregations

JobStatus (org.ow2.proactive.scheduler.common.job.JobStatus)6 JobId (org.ow2.proactive.scheduler.common.job.JobId)5 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)4 Test (org.junit.Test)3 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)3 SchedulerEvent (org.ow2.proactive.scheduler.common.SchedulerEvent)2 Job (org.ow2.proactive.scheduler.common.job.Job)2 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)2 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)2 JobState (org.ow2.proactive.scheduler.common.job.JobState)2 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)2 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)2 TaskStatus (org.ow2.proactive.scheduler.common.task.TaskStatus)2 ErrorTask (functionaltests.jobs.ErrorTask)1 LogTask (functionaltests.jobs.LogTask)1 MetadataTask (functionaltests.jobs.MetadataTask)1 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)1 RawTask (functionaltests.jobs.RawTask)1 SimpleJob (functionaltests.jobs.SimpleJob)1 VariableTask (functionaltests.jobs.VariableTask)1