Search in sources :

Example 1 with TaskLogger

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

the class TaskLauncher method initActivity.

@Override
public void initActivity(Body body) {
    this.taskId = initializer.getTaskId();
    this.taskLogger = new TaskLogger(taskId, getHostname());
    this.progressFileReader = new ProgressFileReader();
    this.taskKiller = new TaskKiller(Thread.currentThread(), new CleanupTimeoutGetter());
    nodeShutdownHook = new Thread(new Runnable() {

        @Override
        public void run() {
            kill();
        }
    });
}
Also used : CleanupTimeoutGetter(org.ow2.proactive.scheduler.task.utils.task.termination.CleanupTimeoutGetter) TaskKiller(org.ow2.proactive.scheduler.task.utils.task.termination.TaskKiller)

Example 2 with TaskLogger

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

the class TaskLoggerTest method getStoredLogs.

@Test
public void getStoredLogs() throws Exception {
    taskLogger = new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L), "myhost");
    final StringWriter stringAppender = new StringWriter();
    AppenderProvider stringAppenderProvider = new AppenderProvider() {

        @Override
        public Appender getAppender() throws LogForwardingException {
            return new WriterAppender(new PatternLayout("%m%n"), stringAppender);
        }
    };
    taskLogger.getStoredLogs(stringAppenderProvider);
    assertEquals("", stringAppender.toString());
    taskLogger.getOutputSink().println("hello");
    taskLogger.getStoredLogs(stringAppenderProvider);
    assertEquals(String.format("hello%n"), stringAppender.toString());
}
Also used : StringWriter(java.io.StringWriter) AppenderProvider(org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider) PatternLayout(org.apache.log4j.PatternLayout) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) WriterAppender(org.apache.log4j.WriterAppender) Test(org.junit.Test)

Example 3 with TaskLogger

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

the class TaskLoggerTest method logPattern.

@Test
public void logPattern() throws Exception {
    TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L);
    taskLogger = new TaskLogger(taskId, "myhost");
    assertEquals("", taskLogger.getLogs().getAllLogs(false));
    taskLogger.getOutputSink().println("hello");
    String quotedStringTaskId = Pattern.quote(taskId.toString());
    assertTrue(taskLogger.getLogs().getAllLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] hello \r?\n"));
    taskLogger.getErrorSink().println("error");
    assertTrue(taskLogger.getLogs().getStderrLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] error \r?\n"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 4 with TaskLogger

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

the class TaskLoggerTest method logStreaming.

@Test
public void logStreaming() throws Exception {
    taskLogger = new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L), "myhost");
    final StringWriter stringAppender = new StringWriter();
    AppenderProvider stringAppenderProvider = new AppenderProvider() {

        @Override
        public Appender getAppender() throws LogForwardingException {
            return new WriterAppender(new PatternLayout("%m%n"), stringAppender);
        }
    };
    taskLogger.activateLogs(stringAppenderProvider);
    assertEquals("", stringAppender.toString());
    taskLogger.getOutputSink().println("hello");
    // async appender, it gets buffered
    assertEquals("", stringAppender.toString());
    for (int i = 0; i < 1000; i++) {
        taskLogger.getOutputSink().println("hello");
    }
    assertNotEquals("", stringAppender.toString());
}
Also used : StringWriter(java.io.StringWriter) AppenderProvider(org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider) PatternLayout(org.apache.log4j.PatternLayout) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) WriterAppender(org.apache.log4j.WriterAppender) Test(org.junit.Test)

Example 5 with TaskLogger

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

the class RMProxyActiveObject method printCleaningScriptInformations.

private void printCleaningScriptInformations(NodeSet nodes, ScriptResult<?> sResult, TaskId taskId) {
    if (logger.isInfoEnabled()) {
        TaskLogger instance = TaskLogger.getInstance();
        String nodeUrl = nodes.get(0).getNodeInformation().getURL();
        if (sResult.errorOccured()) {
            instance.error(taskId, "Exception while running cleaning script on " + nodeUrl, sResult.getException());
        } else {
            instance.info(taskId, "Cleaning script successful.");
        }
        if (sResult.getOutput() != null && !sResult.getOutput().isEmpty()) {
            instance.info(taskId, "Cleaning script output on node " + nodeUrl + ":");
            instance.info(taskId, sResult.getOutput());
        }
    }
}
Also used : TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger)

Aggregations

Test (org.junit.Test)6 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)6 StringWriter (java.io.StringWriter)2 PatternLayout (org.apache.log4j.PatternLayout)2 WriterAppender (org.apache.log4j.WriterAppender)2 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)2 AppenderProvider (org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider)2 TaskLogger (org.ow2.proactive.scheduler.util.TaskLogger)2 File (java.io.File)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LoginException (javax.security.auth.login.LoginException)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)1 TaskLoggerRelativePathGenerator (org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator)1 DataSpaceNodeClient (org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient)1 SchedulerNodeClient (org.ow2.proactive.scheduler.task.client.SchedulerNodeClient)1 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)1