Search in sources :

Example 1 with TaskLogs

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

the class SchedulerStateRestJobLogsTest method job_full_logs_sorted.

@Test
public void job_full_logs_sorted() throws Exception {
    InternalTaskFlowJob jobState = new InternalTaskFlowJob();
    addTask(jobState, 1, 10);
    addTask(jobState, 10, 2);
    addTask(jobState, 3, 3);
    File logFolder = tempFolder.newFolder("123");
    File logFile = new File(logFolder, "TaskLogs-123-10.log");
    FileUtils.write(logFile, "10");
    logFile = new File(logFolder, "TaskLogs-123-2.log");
    FileUtils.write(logFile, "2");
    logFile = new File(logFolder, "TaskLogs-123-3.log");
    FileUtils.write(logFile, "3");
    when(mockScheduler.getJobState("123")).thenReturn(jobState);
    when(mockScheduler.getUserSpaceURIs()).thenReturn(Collections.singletonList(logFolder.getParent()));
    when(mockScheduler.getGlobalSpaceURIs()).thenReturn(Collections.singletonList(logFolder.getParent()));
    InputStream fullLogs = restScheduler.jobFullLogs(validSessionId, "123", validSessionId);
    assertEquals("1032", IOUtils.toString(fullLogs));
}
Also used : InputStream(java.io.InputStream) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) File(java.io.File) Test(org.junit.Test)

Example 2 with TaskLogs

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

the class SchedulerStateRestJobLogsTest method job_full_logs_finished.

@Test
public void job_full_logs_finished() throws Exception {
    InternalTaskFlowJob jobState = new InternalTaskFlowJob();
    InternalScriptTask task = new InternalScriptTask(jobState);
    task.setPreciousLogs(true);
    jobState.addTask(task);
    File logFolder = tempFolder.newFolder("0");
    File logFile = new File(logFolder, "TaskLogs-0-0.log");
    FileUtils.write(logFile, "logs", Charset.defaultCharset());
    when(mockScheduler.getJobState("0")).thenReturn(jobState);
    when(mockScheduler.getUserSpaceURIs()).thenReturn(Collections.singletonList(logFolder.getParent()));
    when(mockScheduler.getGlobalSpaceURIs()).thenReturn(Collections.singletonList(logFolder.getParent()));
    InputStream fullLogs = restScheduler.jobFullLogs(validSessionId, "0", validSessionId);
    assertEquals("logs", IOUtils.toString(fullLogs, Charset.defaultCharset()));
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InputStream(java.io.InputStream) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) File(java.io.File) Test(org.junit.Test)

Example 3 with TaskLogs

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

the class TaskLoggerRelativePathGeneratorTest method testGetRelativePath.

@Test
public void testGetRelativePath() {
    TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L);
    assertThat(new TaskLoggerRelativePathGenerator(taskId).getRelativePath(), is("1000/TaskLogs-1000-42.log"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 4 with TaskLogs

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

the class TaskLoggerRelativePathGeneratorTest method testGetFileName.

@Test
public void testGetFileName() {
    TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L);
    assertThat(new TaskLoggerRelativePathGenerator(taskId).getFileName(), is("TaskLogs-1000-42.log"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 5 with TaskLogs

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

the class EnabledListenJobLogsSupport method flushTaskLogs.

private void flushTaskLogs(TaskResult tr, Appender a, JobId jobId) {
    // if taskResult is not awaited, task is terminated
    TaskLogs logs = tr.getOutput();
    if (logs instanceof Log4JTaskLogs) {
        for (LoggingEvent le : ((Log4JTaskLogs) logs).getAllEvents()) {
            // write into socket appender directly to avoid double lines on other listeners
            a.doAppend(le);
        }
    } else {
        a.doAppend(createLoggingEvent(jobId, logs.getStdoutLogs(false), Level.INFO));
        a.doAppend(createLoggingEvent(jobId, logs.getStderrLogs(false), Level.DEBUG));
    }
}
Also used : TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs)

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