Search in sources :

Example 1 with TaskLoggerRelativePathGenerator

use of org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator 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 2 with TaskLoggerRelativePathGenerator

use of org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator 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 3 with TaskLoggerRelativePathGenerator

use of org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator in project scheduling by ow2-proactive.

the class TaskLoggerTest method createFileAppenderTest.

@Test
public void createFileAppenderTest() throws Exception {
    JobId jobid = new JobIdImpl(1000, "job");
    TaskId taskId = TaskIdImpl.createTaskId(jobid, "task", 42L);
    taskLogger = new TaskLogger(taskId, "myhost");
    File logFolder = tempFolder.newFolder("logfolder");
    File logAppender = taskLogger.createFileAppender(logFolder);
    System.out.println(logAppender.getParentFile().getName());
    assertEquals(logAppender.getParentFile().getName(), jobid.value());
    assertEquals(logAppender.getName(), new TaskLoggerRelativePathGenerator(taskId).getFileName());
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) File(java.io.File) TaskLoggerRelativePathGenerator(org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 4 with TaskLoggerRelativePathGenerator

use of org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator in project scheduling by ow2-proactive.

the class TaskLauncher method copyTaskLogsToUserSpace.

private void copyTaskLogsToUserSpace(File taskLogFile, TaskDataspaces dataspaces) {
    if (initializer.isPreciousLogs()) {
        try {
            FileSelector taskLogFileSelector = new FileSelector(taskLogFile.getName());
            taskLogFileSelector.setIncludes(new TaskLoggerRelativePathGenerator(taskId).getRelativePath());
            dataspaces.copyScratchDataToOutput(Collections.singletonList(new OutputSelector(taskLogFileSelector, OutputAccessMode.TransferToUserSpace)));
        } catch (FileSystemException e) {
            logger.warn("Cannot copy logs of task to user data spaces", e);
        }
    }
}
Also used : FileSystemException(org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) TaskLoggerRelativePathGenerator(org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator)

Example 5 with TaskLoggerRelativePathGenerator

use of org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator in project scheduling by ow2-proactive.

the class TaskLogger method createFileAppender.

public File createFileAppender(File pathToFolder) throws IOException {
    if (taskLogAppender.getAppender(FILE_APPENDER_NAME) != null) {
        throw new IllegalStateException("Only one file appender can be created");
    }
    File logFile = new File(pathToFolder, new TaskLoggerRelativePathGenerator(taskId).getRelativePath());
    logFile.getParentFile().mkdirs();
    FileUtils.touch(logFile);
    logFile.setWritable(true, false);
    FileAppender fap = new FileAppender(Log4JTaskLogs.getTaskLogLayout(), logFile.getAbsolutePath(), false);
    fap.setName(FILE_APPENDER_NAME);
    taskLogAppender.addAppender(fap);
    return logFile;
}
Also used : FileAppender(org.apache.log4j.FileAppender) File(java.io.File) TaskLoggerRelativePathGenerator(org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator)

Aggregations

Test (org.junit.Test)3 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)3 TaskLoggerRelativePathGenerator (org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator)3 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)3 File (java.io.File)2 FileAppender (org.apache.log4j.FileAppender)1 FileSystemException (org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException)1 FileSelector (org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1 OutputSelector (org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector)1