Search in sources :

Example 6 with LogForwardingException

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

the class EnabledListenJobLogsSupport method listenJobLogs.

@Override
public synchronized void listenJobLogs(JobId jobId, AppenderProvider appenderProvider) throws UnknownJobException {
    jlogger.info(jobId, "listening logs");
    // create the appender to the remote listener
    Appender clientAppender = null;
    try {
        clientAppender = appenderProvider.getAppender();
    } catch (LogForwardingException e) {
        jlogger.error(jobId, "cannot create an appender", e);
        throw new InternalException("Cannot create an appender for job " + jobId, e);
    }
    boolean logIsAlreadyInitialized = jobsToBeLogged.contains(jobId);
    initJobLogging(jobId, clientAppender);
    JobResult result = dbManager.loadJobResult(jobId);
    if (result == null) {
        throw new UnknownJobException(jobId);
    }
    // for finished tasks, add logs events "manually"
    Collection<TaskResult> allRes = result.getAllResults().values();
    for (TaskResult tr : allRes) {
        this.flushTaskLogs(tr, clientAppender, jobId);
    }
    for (RunningTaskData taskData : liveJobs.getRunningTasks(jobId)) {
        jlogger.debug(jobId, "Handling log initialization for task " + taskData.getTask().getName());
        try {
            TaskLauncher taskLauncher = taskData.getLauncher();
            if (logIsAlreadyInitialized) {
                jlogger.debug(jobId, "Call getStoredLogs");
                taskLauncher.getStoredLogs(appenderProvider);
            } else {
                jlogger.debug(jobId, "Call activateLogs");
                taskLauncher.activateLogs(lfs.getAppenderProvider());
            }
        } catch (Exception e) {
            tlogger.error(taskData.getTask().getId(), "cannot create an appender provider", e);
        }
    }
    if (!result.getJobInfo().getStatus().isJobAlive()) {
        jlogger.info(jobId, "cleaning loggers for already finished job");
        cleanLoggers(jobId);
    }
}
Also used : Appender(org.apache.log4j.Appender) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 7 with LogForwardingException

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

the class TaskLogger method getStoredLogs.

public void getStoredLogs(AppenderProvider logSink) {
    Appender appender;
    try {
        appender = logSink.getAppender();
    } catch (LogForwardingException e) {
        logger.error("Cannot create log appender.", e);
        return;
    }
    taskLogAppender.appendStoredEvents(appender);
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException)

Aggregations

LogForwardingException (org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException)4 Appender (org.apache.log4j.Appender)3 AppenderProvider (org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider)3 StringWriter (java.io.StringWriter)2 FileAppender (org.apache.log4j.FileAppender)2 PatternLayout (org.apache.log4j.PatternLayout)2 WriterAppender (org.apache.log4j.WriterAppender)2 Test (org.junit.Test)2 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)2 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)2 HttpSession (javax.servlet.http.HttpSession)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 GZIP (org.jboss.resteasy.annotations.GZIP)1 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)1 InternalException (org.ow2.proactive.scheduler.common.exception.InternalException)1 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)1 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)1