Search in sources :

Example 91 with JobId

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

the class TestJobServerLogs method test.

@Test
public void test() throws Exception {
    JobId simpleJobId = schedulerHelper.submitJob(new File(simpleJobDescriptor.toURI()).getAbsolutePath());
    String taskName = "task1";
    TaskInfo ti = schedulerHelper.waitForEventTaskRunning(simpleJobId, taskName);
    String taskLogs = schedulerHelper.getSchedulerInterface().getTaskServerLogs(simpleJobId.toString(), taskName);
    if (!taskLogs.contains("task " + ti.getTaskId() + " (" + ti.getTaskId().getReadableName() + ")" + " started")) {
        log("Incorrect task server logs:");
        log(taskLogs);
        fail("Task " + ti.getTaskId() + " was not scheduled");
    }
    schedulerHelper.waitForEventJobFinished(simpleJobId);
    String jobLogs = schedulerHelper.getSchedulerInterface().getJobServerLogs(simpleJobId.toString());
    for (int i = 0; i < TASKS_IN_SIMPLE_JOB; i++) {
        TaskId taskId = TaskIdImpl.createTaskId(simpleJobId, "task" + (i + 1), i);
        String taskIdString = taskId.toString();
        String taskIdStringQuoted = Pattern.quote(taskIdString);
        if (!matchLine(jobLogs, "task " + taskIdStringQuoted + " \\(task[12]\\) started")) {
            log("Incorrect job server logs");
            log(jobLogs);
            fail("Task " + taskIdString + " was not scheduled");
        }
        if (!matchLine(jobLogs, "task " + taskIdStringQuoted + " \\(task[12]\\) finished")) {
            log("Incorrect job server logs");
            log(jobLogs);
            fail("Task " + taskIdString + " was not finished");
        }
    }
    checkRemoval(simpleJobId);
    JobId pendingJobId = schedulerHelper.submitJob(createPendingJob());
    Thread.sleep(5000);
    jobLogs = schedulerHelper.getSchedulerInterface().getJobServerLogs(pendingJobId.toString());
    if (!jobLogs.contains("will get 0 nodes")) {
        log("Incorrect job server logs");
        log(jobLogs);
        fail("RM output is not correct");
    }
    if (!jobLogs.contains(SCRIPT_OUTPUT)) {
        log("Incorrect job server logs");
        log(jobLogs);
        fail("No script output");
    }
    checkRemoval(pendingJobId);
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) WaitAndPrint(org.ow2.proactive.scheduler.examples.WaitAndPrint) Test(org.junit.Test)

Example 92 with JobId

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

the class TestJobServerLogs method checkNoLogsFromAPI.

private void checkNoLogsFromAPI(JobId jobId, List<TaskState> tasks) throws Exception {
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    try {
        scheduler.getJobServerLogs(jobId.toString());
        fail("getJobServerLogs should throw an exception for a removed job");
    } catch (UnknownJobException expected) {
    }
    for (TaskState taskState : tasks) {
        try {
            scheduler.getTaskServerLogs(jobId.toString(), taskState.getName());
            fail("getTaskServerLogs should throw an exception for a removed job");
        } catch (UnknownJobException expected) {
        }
    }
}
Also used : UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 93 with JobId

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

the class TestJobServerLogs method checkRemoval.

public void checkRemoval(JobId jobId) throws Exception {
    JobState jobState = schedulerHelper.getSchedulerInterface().getJobState(jobId);
    List<TaskState> tasks = jobState.getTasks();
    checkJobAndTaskLogFiles(jobId, tasks, true);
    // Before it was only job removal but it was bug prone (for pendingJob only)
    // because the following sequence of the events could happen:
    // 1. SchedulerMethodImpl main loop retrieves info about this forever pending job
    // 2. we call removeJob
    // 3. SchedulerMethodImpl main loop asks for RM::getRMNodes.
    // 
    // Third action would print "[SelectionManager.doSelectNodes] "scheduler"..." to the task log
    // which would actually re-created removed log file which would cause an error
    // in the last line of this method
    // that is why kill the job and after wait 5s to make sure that
    // iteration of SchedulerMethodImpl main loop is finished,
    // and finally, we remove job with its log files.
    schedulerHelper.killJob(jobId.value());
    Thread.sleep(5000);
    schedulerHelper.removeJob(jobId);
    schedulerHelper.waitForEventJobRemoved(jobId);
    System.out.println("Suppose to remove all logs at " + simpleDateFormat.format(new Date()));
    checkNoLogsFromAPI(jobId, tasks);
    checkJobAndTaskLogFiles(jobId, tasks, false);
}
Also used : JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Date(java.util.Date)

Example 94 with JobId

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

the class TestPreciousLogs method testPreciousLogs.

private void testPreciousLogs(boolean createJavaTask, boolean forkEnv) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    Map<String, List<String>> expectedOutput = new LinkedHashMap<>();
    for (int i = 0; i < 3; i++) {
        String forkOutput = "forkOutput-" + i;
        String preOutput = "preOutput-" + i;
        String postOutput = "postOutput-" + i;
        List<String> expectedTaskOutput = new ArrayList<>();
        expectedTaskOutput.add(TASK_OUTPUT);
        expectedTaskOutput.add(preOutput);
        expectedTaskOutput.add(postOutput);
        Task task;
        if (createJavaTask) {
            JavaTask javaTask = new JavaTask();
            javaTask.setExecutableClassName(TestJavaTask.class.getName());
            if (forkEnv) {
                ForkEnvironment env = new ForkEnvironment();
                env.setEnvScript(createScript(forkOutput));
                javaTask.setForkEnvironment(env);
                expectedTaskOutput.add(forkOutput);
            }
            task = javaTask;
        } else {
            NativeTask nativeTask = new NativeTask();
            File script = new File(getClass().getResource("/functionaltests/executables/test_echo_task.sh").getFile());
            if (!script.exists()) {
                Assert.fail("Can't find script " + script.getAbsolutePath());
            }
            nativeTask.setCommandLine(script.getAbsolutePath());
            task = nativeTask;
        }
        task.setMaxNumberOfExecution(1);
        task.setOnTaskError(OnTaskError.CANCEL_JOB);
        task.setPreciousLogs(true);
        task.setName("Task-" + i);
        task.setPreScript(createScript(preOutput));
        task.setPostScript(createScript(postOutput));
        expectedOutput.put(task.getName(), expectedTaskOutput);
        job.addTask(task);
    }
    JobId jobId = schedulerHelper.testJobSubmission(job);
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    String userURI = scheduler.getUserSpaceURIs().get(0);
    String userPath = new File(new URI(userURI)).getAbsolutePath();
    JobResult jobResult = scheduler.getJobResult(jobId);
    Map<String, TaskResult> results = jobResult.getAllResults();
    for (String taskName : expectedOutput.keySet()) {
        File taskLog = new File(userPath + "/" + jobId.value(), String.format("TaskLogs-%s-%s.log", jobId.value(), results.get(taskName).getTaskId().value()));
        if (!taskLog.exists()) {
            Assert.fail("Task log file " + taskLog.getAbsolutePath() + " doesn't exist");
        }
        String output = new String(FileToBytesConverter.convertFileToByteArray(taskLog));
        System.out.println("Log file for " + taskName + ":");
        System.out.println(output);
        for (String expectedLine : expectedOutput.get(taskName)) {
            Assert.assertTrue("Output doesn't contain line " + expectedLine, output.contains(expectedLine));
        }
    }
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) ArrayList(java.util.ArrayList) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 95 with JobId

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

the class TestJobMultiNodesWalltime method testJobMultiNodesWalltime.

@Test
public void testJobMultiNodesWalltime() throws Throwable {
    // submit job
    JobId id = schedulerHelper.submitJob(new File(jobDescriptor.toURI()).getAbsolutePath());
    // connect to RM
    schedulerHelper.addExtraNodes(3);
    // wait job is running
    schedulerHelper.waitForEventJobRunning(id);
    // wait for job to be finished
    schedulerHelper.waitForEventJobFinished(id, TIMEOUT);
    // remove job
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
}
Also used : File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

JobId (org.ow2.proactive.scheduler.common.job.JobId)179 Test (org.junit.Test)121 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)73 File (java.io.File)58 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)57 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)55 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)55 JobState (org.ow2.proactive.scheduler.common.job.JobState)51 ArrayList (java.util.ArrayList)45 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)43 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)42 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)40 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)38 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)37 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)36 Path (javax.ws.rs.Path)35 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)35 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)34 Produces (javax.ws.rs.Produces)33 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)33