Search in sources :

Example 21 with TaskState

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

the class RunningTaskRecoveryWithRecoveredNodeTestBase method action.

@Test
public void action() throws Throwable {
    nodes = schedulerHelper.createRMNodeStarterNodes(RunningTaskRecoveryWithForkedTaskExecutorTest.class.getSimpleName(), NB_NODES);
    JobId jobid = schedulerHelper.submitJob(new File(JOB_DESCRIPTOR.toURI()).getAbsolutePath());
    schedulerHelper.waitForEventJobRunning(jobid);
    TaskState taskState = schedulerHelper.getSchedulerInterface().getJobState(jobid).getTasks().get(0);
    schedulerHelper.waitForEventTaskRunning(taskState.getJobId(), taskState.getName());
    taskState = schedulerHelper.getSchedulerInterface().getJobState(jobid).getTasks().get(0);
    String firstExecutionHostInfo = taskState.getTaskInfo().getExecutionHostName();
    // wait and restart scheduler
    Thread.sleep(RESTART_SCHEDULER_INTER_TIME_IN_MILLISECONDS);
    TestScheduler.kill();
    Thread.sleep(RESTART_SCHEDULER_INTER_TIME_IN_MILLISECONDS);
    schedulerHelper = new SchedulerTHelper(false, new File(getSchedulerReStartConfigurationURL().toURI()).getAbsolutePath(), new File(RM_CONFIGURATION_RESTART.toURI()).getAbsolutePath(), null, false);
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    TestListenJobLogs.TestAppender appender = new TestListenJobLogs.TestAppender(LOGGER_NAME);
    String loggerName = Log4JTaskLogs.JOB_LOGGER_PREFIX + jobid;
    logForwardingService.removeAllAppenders(LOGGER_NAME);
    logForwardingService.addAppender(loggerName, appender);
    scheduler.listenJobLogs(jobid, logForwardingService.getAppenderProvider());
    System.out.println("Number of nodes: " + schedulerHelper.getResourceManager().getState().getAllNodes().size());
    for (String freeNodeUrl : schedulerHelper.getResourceManager().getState().getFreeNodes()) {
        // previous executing node should not be free when the nodes are added back to the rm
        Assert.assertFalse(firstExecutionHostInfo.contains(freeNodeUrl));
    }
    // we should have just one running task
    JobState jobState = scheduler.getJobState(jobid);
    Assert.assertEquals(0, jobState.getNumberOfPendingTasks());
    Assert.assertEquals(1, jobState.getNumberOfRunningTasks());
    taskState = jobState.getTasks().get(0);
    Assert.assertEquals(firstExecutionHostInfo, taskState.getTaskInfo().getExecutionHostName());
    appender.waitForLoggingEvent(LOG_EVENT_TIMEOUT, TASK_LOG_OUTPUT_STARTING_STRING + MAXIMUM_STEP_IN_TASK_LOOP);
    schedulerHelper.waitForEventJobFinished(jobid);
    TaskResult taskResult = scheduler.getJobResult(jobid).getResult(TASK_NAME);
    Assert.assertFalse(taskResult.hadException());
    Assert.assertEquals(OK_TASK_RESULT_VALUE, taskResult.value());
    String logs = taskResult.getOutput().getStdoutLogs();
    for (int i = 0; i < MAXIMUM_STEP_IN_TASK_LOOP; i++) {
        Assert.assertTrue(logs.contains(TASK_LOG_OUTPUT_STARTING_STRING + i));
    }
}
Also used : SchedulerTHelper(functionaltests.utils.SchedulerTHelper) TestListenJobLogs(functionaltests.job.log.TestListenJobLogs) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TestScheduler(functionaltests.utils.TestScheduler) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) File(java.io.File) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 22 with TaskState

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

the class TestScriptTask method forkedTasks.

private void forkedTasks() throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
    JobId id = schedulerHelper.submitJob(job);
    schedulerHelper.waitForEventJobFinished(id);
    JobResult jobResult = schedulerHelper.getJobResult(id);
    // Hello Work script task
    TaskResult simpleTaskResult = jobResult.getResult("simple");
    assertEquals(true, simpleTaskResult.value());
    assertTrue(simpleTaskResult.getOutput().getAllLogs(false).contains("hello"));
    // return binding should be used as task result
    TaskResult returnTaskResult = jobResult.getResult("return");
    assertEquals("42", returnTaskResult.value().toString());
    // results binding should be avaible in dependent tasks
    TaskResult resultFromDependentTaskTaskResult = jobResult.getResult("results_from_dependent_task");
    assertEquals("42", resultFromDependentTaskTaskResult.value().toString());
    // pas properties are exposed in the script task
    TaskResult propertiesTaskResult = jobResult.getResult("properties");
    String logs = propertiesTaskResult.getOutput().getAllLogs(false);
    assertThat(logs, containsString("PA_JOB_ID=" + jobResult.getJobId().value()));
    assertThat(logs, containsString("PA_JOB_NAME=" + jobResult.getName()));
    assertThat(logs, containsString("PA_TASK_ID=" + propertiesTaskResult.getTaskId().value()));
    assertThat(logs, containsString("PA_TASK_NAME=" + propertiesTaskResult.getTaskId().getReadableName()));
    assertThat(logs, containsString("PA_TASK_ITERATION=0"));
    assertThat(logs, containsString("PA_TASK_REPLICATION=0"));
    // the script can be a file
    TaskResult fileTaskResult = jobResult.getResult("file");
    assertTrue(fileTaskResult.getOutput().getAllLogs(false).contains("Beginning of clean script"));
    TaskResult fileAndArgsTaskResult = jobResult.getResult("file_and_args");
    assertTrue(fileAndArgsTaskResult.getOutput().getAllLogs(false).contains("My_Magic_Arg"));
    // dataspaces binding should be available
    TaskResult dataspacesTaskResult = jobResult.getResult("dataspaces");
    String dataspacesLogs = dataspacesTaskResult.getOutput().getAllLogs(false);
    System.out.println(dataspacesLogs);
    String schedulerHome = System.getProperty("pa.scheduler.home");
    assertTrue(dataspacesLogs.contains("global=" + schedulerHome));
    assertTrue(dataspacesLogs.contains("user=" + schedulerHome));
    assertTrue(dataspacesLogs.contains("input=" + schedulerHome));
    assertTrue(dataspacesLogs.contains("output=" + schedulerHome));
    TaskResult multiNodeTaskResult = jobResult.getResult("multi-node");
    String mnLogs = multiNodeTaskResult.getOutput().getAllLogs(false);
    assertTrue("Invalid binding for nodesurl", mnLogs.contains("nodesurl=" + (SchedulerStartForFunctionalTest.RM_NODE_NUMBER - 1)));
    // script task should be forked by default, ie it will not kill the scheduler on system.exit
    JobState jobState = schedulerHelper.getSchedulerInterface().getJobState(id);
    TaskResult killJVMTaskResult = jobResult.getResult("killJVM");
    assertTrue(killJVMTaskResult.getException() instanceof ForkedJvmProcessException);
    TaskState killJVMTaskState = jobState.getHMTasks().get(killJVMTaskResult.getTaskId());
    assertEquals(TaskStatus.FAULTY, killJVMTaskState.getStatus());
}
Also used : ForkedJvmProcessException(org.ow2.proactive.scheduler.task.exceptions.ForkedJvmProcessException) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 23 with TaskState

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

the class SchedulerDBManagerTest method testUpdateTaskState.

@Test
public void testUpdateTaskState() throws Exception {
    InternalJob job = createTestJob("test", "tag", 1);
    service.submitJob(job);
    InternalTask internalTask = job.getITasks().get(0);
    internalTask.setStatus(TaskStatus.ABORTED);
    dbManager.updateTaskState(internalTask);
    Page<TaskState> tasks = dbManager.getTaskStates(0, 10, null, 0, 10, null, true, true, true, new SortSpecifierContainer());
    assertThat(tasks.getSize()).isEqualTo(1);
    TaskState taskState = tasks.getList().get(0);
    assertThat(taskState.getStatus()).isEqualTo(TaskStatus.ABORTED);
}
Also used : SortSpecifierContainer(org.ow2.proactive.scheduler.common.SortSpecifierContainer) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Test(org.junit.Test)

Example 24 with TaskState

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

the class SchedulerEfficiencyMetricsTest method test.

@Test(timeout = 3600000)
public void test() throws Exception {
    ProActiveConfiguration.load();
    RMFactory.setOsJavaProperty();
    schedulerHelper = new SchedulerTHelper(false, SCHEDULER_CONFIGURATION_START.getPath(), RM_CONFIGURATION_START.getPath(), null);
    schedulerHelper.createNodeSourceWithInfiniteTimeout("local", taskNumber);
    final TaskFlowJob job = createJob(taskNumber, TASK_DURATION);
    long start = System.currentTimeMillis();
    jobId = schedulerHelper.submitJob(job);
    long submited = System.currentTimeMillis();
    schedulerHelper.waitForEventJobFinished(jobId);
    final JobState jobState = schedulerHelper.getSchedulerInterface().getJobState(jobId);
    final long finished = jobState.getFinishedTime();
    long latestTaskStart = Long.MIN_VALUE;
    for (TaskState taskState : jobState.getTasks()) {
        if (taskState.getStartTime() > latestTaskStart) {
            latestTaskStart = taskState.getStartTime();
        }
    }
    long TCT = submited - start;
    long TST = latestTaskStart - submited;
    long TTT = finished - latestTaskStart - TASK_DURATION;
    logAndAssert("TaskCreationTimeTest", TCT);
    logAndAssert("TaskSchedulingTimeTest", TST);
    logAndAssert("TaskTerminationTimeTest", TTT);
}
Also used : SchedulerTHelper(functionaltests.utils.SchedulerTHelper) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Test(org.junit.Test)

Example 25 with TaskState

use of org.ow2.proactive.scheduler.common.task.TaskState 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)

Aggregations

TaskState (org.ow2.proactive.scheduler.common.task.TaskState)54 JobState (org.ow2.proactive.scheduler.common.job.JobState)23 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)13 TaskStateData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData)13 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)12 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)11 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)11 JobId (org.ow2.proactive.scheduler.common.job.JobId)10 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)10 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)10 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)9 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)9 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)8 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)8 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7