Search in sources :

Example 6 with TaskLogs

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

the class TaskResultCreator method getTaskResult.

public TaskResultImpl getTaskResult(SchedulerDBManager dbManager, InternalJob job, InternalTask task, Throwable exception, TaskLogs output) throws UnknownTaskException {
    if (task == null) {
        throw new UnknownTaskException();
    }
    JobDescriptor jobDescriptor = job.getJobDescriptor();
    EligibleTaskDescriptor eligibleTaskDescriptor = null;
    if (jobDescriptor.getPausedTasks().get(task.getId()) != null) {
        eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getPausedTasks().get(task.getId());
    } else if (jobDescriptor.getRunningTasks().get(task.getId()) != null) {
        eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getRunningTasks().get(task.getId());
    }
    TaskResultImpl taskResult = getEmptyTaskResult(task, exception, output);
    taskResult.setPropagatedVariables(getPropagatedVariables(dbManager, eligibleTaskDescriptor, job, task));
    return taskResult;
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor)

Example 7 with TaskLogs

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

the class TestTaskResultData method testLog4jLogs.

@Test
public void testLog4jLogs() throws Exception {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    InternalTask task = (InternalTask) job.getTasks().get(0);
    LinkedList<LoggingEvent> events = new LinkedList<>();
    for (int i = 0; i < 3; i++) {
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.INFO, "info" + i, null));
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.ERROR, "error" + i, null));
    }
    TaskResultImpl result = new TaskResultImpl(null, "result", new Log4JTaskLogs(events, "0"), 0);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
    TaskLogs logs = restoredResult.getOutput();
    Assert.assertNotNull(logs);
    String logsString = logs.getStdoutLogs(false);
    Assert.assertTrue(logsString.contains("info0"));
    Assert.assertTrue(logsString.contains("info1"));
    Assert.assertTrue(logsString.contains("info2"));
    logsString = logs.getStderrLogs(false);
    Assert.assertTrue(logsString.contains("error0"));
    Assert.assertTrue(logsString.contains("error1"));
    Assert.assertTrue(logsString.contains("error2"));
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 8 with TaskLogs

use of org.ow2.proactive.scheduler.common.task.TaskLogs 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 9 with TaskLogs

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

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

the class SchedulerStateRest method jobFullLogs.

@Override
@GET
@GZIP
@Path("jobs/{jobid}/log/full")
@Produces("application/json")
public InputStream jobFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException {
    if (sessionId == null) {
        sessionId = session;
    }
    try {
        Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/log/full");
        JobState jobState = scheduler.getJobState(jobId);
        List<TaskState> tasks = jobState.getTasks();
        List<InputStream> streams = new ArrayList<>(tasks.size());
        Collections.sort(tasks, TaskState.COMPARE_BY_FINISHED_TIME_ASC);
        for (TaskState taskState : tasks) {
            InputStream inputStream = null;
            try {
                if (taskState.isPreciousLogs()) {
                    inputStream = retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskState.getId());
                } else {
                    String taskLogs = retrieveTaskLogsUsingDatabase(sessionId, jobId, taskState.getName());
                    if (!taskLogs.isEmpty()) {
                        inputStream = IOUtils.toInputStream(taskLogs);
                    }
                    logger.warn("Retrieving truncated logs for task '" + taskState.getId() + "'");
                }
            } catch (Exception e) {
                logger.info("Could not retrieve logs for task " + taskState.getId() + " (could be a non finished or killed task)", e);
            }
            if (inputStream != null) {
                streams.add(inputStream);
            }
        }
        if (streams.isEmpty()) {
            // will produce HTTP 204 code
            return null;
        } else {
            return new SequenceInputStream(Collections.enumeration(streams));
        }
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) LogForwardingRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.LogForwardingRestException) NodeException(org.objectweb.proactive.core.node.NodeException) 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) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) ConnectionException(org.ow2.proactive.scheduler.common.exception.ConnectionException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) URISyntaxException(java.net.URISyntaxException) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobAlreadyFinishedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobAlreadyFinishedRestException) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) SequenceInputStream(java.io.SequenceInputStream) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

Test (org.junit.Test)8 File (java.io.File)5 TaskLogs (org.ow2.proactive.scheduler.common.task.TaskLogs)4 InputStream (java.io.InputStream)3 JobId (org.ow2.proactive.scheduler.common.job.JobId)3 Log4JTaskLogs (org.ow2.proactive.scheduler.common.task.Log4JTaskLogs)3 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)3 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)3 ArrayList (java.util.ArrayList)2 LoggingEvent (org.apache.log4j.spi.LoggingEvent)2 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)2 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)2 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)2 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)2 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)2 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)2 BufferedInputStream (java.io.BufferedInputStream)1