Search in sources :

Example 56 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testThatJobVariablesAreUsedIfTaskHasNoParents.

@Test
public void testThatJobVariablesAreUsedIfTaskHasNoParents() throws UnknownTaskException {
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenThrow(new DatabaseManagerException());
    InternalJob mockedInternalJob = this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTaskWithoutParent());
    Map<String, JobVariable> fakeVariableMap = new HashMap<>();
    fakeVariableMap.put("TestVar", new JobVariable("TestVar", "h234"));
    when(mockedInternalJob.getVariables()).thenReturn(fakeVariableMap);
    Map<String, String> fakeReplacementVariableMap = new HashMap<>();
    fakeReplacementVariableMap.put("TestVar", "h234");
    when(mockedInternalJob.getVariablesAsReplacementMap()).thenReturn(fakeReplacementVariableMap);
    TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, mockedInternalJob, this.getMockedInternalTask());
    verify(mockedInternalJob, atLeastOnce()).getVariablesAsReplacementMap();
    assertThat(new String(taskResult.getPropagatedVariables().get("TestVar")), is("h234"));
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) JobId(org.ow2.proactive.scheduler.common.job.JobId) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) Test(org.junit.Test)

Example 57 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testThatTaskVariablesAreUsedIfTaskisInDB.

@Test
public void testThatTaskVariablesAreUsedIfTaskisInDB() throws UnknownTaskException {
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    TaskResultImpl mockedTaskResultImpl = mock(TaskResultImpl.class);
    Map<String, byte[]> fakeVariableMap = new HashMap<>();
    fakeVariableMap.put("TestVar", new String("h234").getBytes());
    when(mockedTaskResultImpl.getPropagatedVariables()).thenReturn(fakeVariableMap);
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadLastTaskResult(any(TaskId.class))).thenReturn(mockedTaskResultImpl);
    InternalJob mockedInternalJob = this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTaskWithoutParent());
    TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, mockedInternalJob, this.getMockedInternalTask());
    verify(mockedTaskResultImpl, atLeastOnce()).getPropagatedVariables();
    assertThat(new String(taskResult.getPropagatedVariables().get("TestVar")), is("h234"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 58 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class AbstractSmartProxy method syncAwaitedJob.

/**
 * This method will synchronize this proxy with a remote Scheduler for the
 * given job
 *
 * @param id job ID
 */
private void syncAwaitedJob(String id) {
    AwaitedJob awaitedJob = jobTracker.getAwaitedJob(id);
    try {
        JobState js = getJobState(id);
        for (TaskState ts : js.getTasks()) {
            String tname = ts.getName();
            AwaitedTask at = awaitedJob.getAwaitedTask(tname);
            if ((at != null) && (!at.isTransferring())) {
                TaskResult tres = null;
                try {
                    tres = getTaskResult(id, tname);
                    if (tres != null) {
                        log.debug("Synchonizing task " + tname + " of job " + id);
                        taskStateUpdatedEvent(new NotificationData<>(SchedulerEvent.TASK_RUNNING_TO_FINISHED, ts.getTaskInfo()));
                    }
                } catch (NotConnectedException e) {
                    e.printStackTrace();
                } catch (UnknownJobException e) {
                    log.error("Could not retrieve output data for job " + id + " because this job is not known by the Scheduler. \n ", e);
                } catch (UnknownTaskException e) {
                    log.error("Could not retrieve output data for task " + tname + " of job " + id + " because this task is not known by the Scheduler. \n ", e);
                } catch (Exception e) {
                    log.error("Unexpected error while getting the output data for task " + tname + " of job " + id, e);
                }
            }
        }
        if (js.isFinished()) {
            jobStateUpdatedEvent(new NotificationData<>(SchedulerEvent.JOB_RUNNING_TO_FINISHED, js.getJobInfo()));
        }
    } catch (NotConnectedException e) {
        log.error("A connection error occured while trying to download output data of Job " + id + ". This job will remain in the list of awaited jobs. Another attempt to dowload the output data will be made next time the application is initialized. ", e);
    } catch (UnknownJobException e) {
        log.error("Could not retrieve output data for job " + id + " because this job is not known by the Scheduler. \n ", e);
        log.warn("Job  " + id + " will be removed from the known job list. The system will not attempt again to retrieve data for this job. You could try to manually copy the data from the location  " + awaitedJob.getPullURL());
        jobTracker.removeAwaitedJob(id);
    } catch (PermissionException e) {
        log.error("Could not retrieve output data for job " + id + " because you don't have permmission to access this job. You need to use the same connection credentials you used for submitting the job.  \n Another attempt to dowload the output data for this job will be made next time the application is initialized. ", e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) LoginException(javax.security.auth.login.LoginException) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException)

Example 59 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class TestPreemptRestartKillTask method TestPreemtRestartKillTask.

private void TestPreemtRestartKillTask(String jobDescriptorPath) throws Exception {
    log("Submitting job");
    log(schedulerHelper.getSchedulerInterface().getClass().toString());
    schedulerHelper.addExtraNodes(3);
    JobId id = schedulerHelper.submitJob(jobDescriptorPath);
    log("Wait for event job submitted");
    schedulerHelper.waitForEventJobSubmitted(id);
    log("Wait for event t1 running");
    schedulerHelper.waitForEventTaskRunning(id, "t1");
    log("Wait for event t2 running");
    schedulerHelper.waitForEventTaskRunning(id, "t2");
    log("Wait for event t3 running");
    schedulerHelper.waitForEventTaskRunning(id, "t3");
    log("Wait for event t4 running");
    schedulerHelper.waitForEventTaskRunning(id, "t4");
    log("Preempt t1");
    schedulerHelper.getSchedulerInterface().preemptTask(id, "t1", 1);
    log("Wait for event t1 waiting for restart");
    // running jobs list must have only one job, task t1 must have number of execution to 0
    TaskInfo ti1 = schedulerHelper.waitForEventTaskWaitingForRestart(id, "t1");
    // task result for t1 must be available with TaskPreemptedException
    TaskResult tr1 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t1");
    log("Restart t2");
    schedulerHelper.getSchedulerInterface().restartTask(id, "t2", 1);
    log("Wait for event t2 waiting for restart");
    // running jobs list must have only one job, task t2 must have number of execution to 1
    TaskInfo ti2 = schedulerHelper.waitForEventTaskWaitingForRestart(id, "t2");
    // task result for t2 must be available with TaskRestartedException
    TaskResult tr2 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t2");
    log("Wait for event t2 running");
    schedulerHelper.waitForEventTaskRunning(id, "t2");
    log("Restart t2 again");
    schedulerHelper.getSchedulerInterface().restartTask(id, "t2", 1);
    log("Wait for event t2 waiting for restart again");
    // running jobs list must have only one job, task t2 must have number of execution to 2
    TaskInfo ti3 = schedulerHelper.waitForEventTaskWaitingForRestart(id, "t2");
    // task result for t2 must be available with TaskRestartedException
    TaskResult tr3 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t2");
    // ensure every tasks are running at this point
    schedulerHelper.waitForEventTaskRunning(id, "t1");
    schedulerHelper.waitForEventTaskRunning(id, "t2");
    log("Kill t3");
    schedulerHelper.getSchedulerInterface().killTask(id, "t3");
    log("Wait for event t3 finished");
    schedulerHelper.waitForEventTaskFinished(id, "t3");
    // task result for t3 must be available with TaskRestartedException
    TaskResult tr4 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t3");
    log("Kill t4");
    schedulerHelper.getSchedulerInterface().killTask(id, "t4");
    log("Wait for event job finished");
    // finished jobs list must have only one job
    JobInfo ji4 = schedulerHelper.waitForEventJobFinished(id);
    // task result for t4 must be TaskRestartedException
    JobState j4 = schedulerHelper.getSchedulerInterface().getJobState(id);
    TaskResult tr5 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t4");
    // check result j1
    assertEquals(2, ti1.getNumberOfExecutionLeft());
    assertTrue(tr1.getException() instanceof TaskPreemptedException);
    // check result j2
    assertEquals(3, ti2.getNumberOfExecutionLeft());
    assertTrue(tr2.getException() instanceof TaskRestartedException);
    // check result j3
    assertEquals(2, ti3.getNumberOfExecutionLeft());
    assertTrue(tr3.getException() instanceof TaskRestartedException);
    // check result tr4
    assertTrue(tr4.getException() instanceof TaskAbortedException);
    // check result j4
    assertEquals(JobStatus.CANCELED, ji4.getStatus());
    TaskStatus t1Status = getTask(j4, "t1").getStatus();
    assertTrue(t1Status.equals(TaskStatus.ABORTED) || t1Status.equals(TaskStatus.NOT_RESTARTED));
    TaskStatus t2Status = getTask(j4, "t2").getStatus();
    assertTrue(t2Status.equals(TaskStatus.ABORTED) || t2Status.equals(TaskStatus.NOT_RESTARTED));
    assertEquals(TaskStatus.FAULTY, getTask(j4, "t3").getStatus());
    assertEquals(TaskStatus.FAULTY, getTask(j4, "t4").getStatus());
    // check result tr5
    // 
    assertTrue(tr5.getException() instanceof Exception);
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException) JobId(org.ow2.proactive.scheduler.common.job.JobId) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException) TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException)

Example 60 with TaskResult

use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.

the class TestPreemptRestartKillTaskSchema33 method TestPreemtRestartKillTask.

private void TestPreemtRestartKillTask(String jobDescriptorPath) throws Exception {
    log("Submitting job");
    schedulerHelper.addExtraNodes(3);
    JobId id = schedulerHelper.submitJob(jobDescriptorPath);
    log("Wait for event job submitted");
    schedulerHelper.waitForEventJobSubmitted(id);
    log("Wait for event t1 running");
    schedulerHelper.waitForEventTaskRunning(id, "t1");
    log("Wait for event t2 running");
    schedulerHelper.waitForEventTaskRunning(id, "t2");
    log("Wait for event t3 running");
    schedulerHelper.waitForEventTaskRunning(id, "t3");
    log("Wait for event t4 running");
    schedulerHelper.waitForEventTaskRunning(id, "t4");
    log("Preempt t1");
    schedulerHelper.getSchedulerInterface().preemptTask(id, "t1", 1);
    log("Wait for event t1 waiting for restart");
    // running jobs list must have only one job, task t1 must have number of execution to 0
    TaskInfo ti1 = schedulerHelper.waitForEventTaskWaitingForRestart(id, "t1");
    // task result for t1 must be available with TaskPreemptedException
    TaskResult tr1 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t1");
    log("Restart t2");
    schedulerHelper.getSchedulerInterface().restartTask(id, "t2", 1);
    log("Wait for event t2 waiting for restart");
    // running jobs list must have only one job, task t2 must have number of execution to 1
    TaskInfo ti2 = schedulerHelper.waitForEventTaskWaitingForRestart(id, "t2");
    // task result for t2 must be available with TaskRestartedException
    TaskResult tr2 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t2");
    log("Wait for event t2 running");
    schedulerHelper.waitForEventTaskRunning(id, "t2");
    log("Restart t2 again");
    schedulerHelper.getSchedulerInterface().restartTask(id, "t2", 1);
    log("Wait for event t2 waiting for restart again");
    // running jobs list must have only one job, task t2 must have number of execution to 2
    TaskInfo ti3 = schedulerHelper.waitForEventTaskWaitingForRestart(id, "t2");
    // task result for t2 must be available with TaskRestartedException
    TaskResult tr3 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t2");
    // ensure every tasks are running at this point
    schedulerHelper.waitForEventTaskRunning(id, "t1");
    schedulerHelper.waitForEventTaskRunning(id, "t2");
    log("Kill t3");
    schedulerHelper.getSchedulerInterface().killTask(id, "t3");
    log("Wait for event t3 finished");
    schedulerHelper.waitForEventTaskFinished(id, "t3");
    // task result for t3 must be available with TaskRestartedException
    TaskResult tr4 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t3");
    log("Kill t4");
    schedulerHelper.getSchedulerInterface().killTask(id, "t4");
    log("Wait for event job finished");
    // finished jobs list must have only one job
    JobInfo ji4 = schedulerHelper.waitForEventJobFinished(id);
    // task result for t4 must be TaskRestartedException
    JobState j4 = schedulerHelper.getSchedulerInterface().getJobState(id);
    TaskResult tr5 = schedulerHelper.getSchedulerInterface().getTaskResult(id, "t4");
    // check result j1
    assertEquals(2, ti1.getNumberOfExecutionLeft());
    assertTrue(tr1.getException() instanceof TaskPreemptedException);
    // check result j2
    assertEquals(3, ti2.getNumberOfExecutionLeft());
    assertTrue(tr2.getException() instanceof TaskRestartedException);
    // check result j3
    assertEquals(2, ti3.getNumberOfExecutionLeft());
    assertTrue(tr3.getException() instanceof TaskRestartedException);
    // check result tr4
    assertTrue(tr4.getException() instanceof TaskAbortedException);
    // check result j4
    assertEquals(JobStatus.CANCELED, ji4.getStatus());
    TaskStatus t1Status = getTask(j4, "t1").getStatus();
    assertTrue(t1Status.equals(TaskStatus.ABORTED) || t1Status.equals(TaskStatus.NOT_RESTARTED));
    TaskStatus t2Status = getTask(j4, "t2").getStatus();
    assertTrue(t2Status.equals(TaskStatus.ABORTED) || t2Status.equals(TaskStatus.NOT_RESTARTED));
    assertEquals(TaskStatus.FAULTY, getTask(j4, "t3").getStatus());
    assertEquals(TaskStatus.FAULTY, getTask(j4, "t4").getStatus());
    // check result tr5
    // 
    assertTrue(tr5.getException() instanceof Exception);
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException) JobId(org.ow2.proactive.scheduler.common.job.JobId) TaskAbortedException(org.ow2.proactive.scheduler.common.exception.TaskAbortedException) TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) TaskRestartedException(org.ow2.proactive.scheduler.common.exception.TaskRestartedException)

Aggregations

TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)99 Test (org.junit.Test)54 JobId (org.ow2.proactive.scheduler.common.job.JobId)38 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)28 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)25 SimpleScript (org.ow2.proactive.scripting.SimpleScript)25 File (java.io.File)24 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)23 TaskScript (org.ow2.proactive.scripting.TaskScript)23 HashMap (java.util.HashMap)22 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)22 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)18 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)17 GET (javax.ws.rs.GET)16 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 GZIP (org.jboss.resteasy.annotations.GZIP)16 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)14 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)12 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)12