Search in sources :

Example 1 with LogForwardingException

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

the class SchedulerStateRest method getLiveLogJob.

/**
 * Stream the output of job identified by the id <code>jobid</code> only
 * stream currently available logs, call this method several times to get
 * the complete output.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job to retrieve
 * @throws IOException
 * @throws LogForwardingRestException
 */
@GET
@GZIP
@Path("jobs/{jobid}/livelog")
@Produces("application/json")
@Override
public String getLiveLogJob(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException, LogForwardingRestException, IOException {
    try {
        Scheduler scheduler = checkAccess(sessionId, "/scheduler/jobs/" + jobId + "/livelog");
        Session session = sessionStore.get(sessionId);
        JobState jobState = scheduler.getJobState(jobId);
        boolean isFinished = jobState != null && jobState.isFinished();
        int availableLinesCount = session.getJobsOutputController().availableLinesCount(jobId);
        if (!isFinished || availableLinesCount > 0) {
            return session.getJobsOutputController().getNewLogs(jobId);
        } else {
            session.getJobsOutputController().removeAppender(jobId);
            return "";
        }
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (LogForwardingException e) {
        throw new LogForwardingRestException(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) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) 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) LogForwardingRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.LogForwardingRestException) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 2 with LogForwardingException

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

the class SchedulerStateRestLiveLogsTest method verifyListenAndGetAppender.

private Appender verifyListenAndGetAppender(String jobId) throws NotConnectedException, UnknownJobException, PermissionException, LogForwardingException {
    ArgumentCaptor<AppenderProvider> appenderProviderArgumentCaptor = ArgumentCaptor.forClass(AppenderProvider.class);
    verify(scheduler).listenJobLogs(eq(jobId), appenderProviderArgumentCaptor.capture());
    AppenderProvider appenderProvider = appenderProviderArgumentCaptor.getValue();
    return appenderProvider.getAppender();
}
Also used : AppenderProvider(org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider)

Example 3 with LogForwardingException

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

the class TaskLogger method activateLogs.

public void activateLogs(AppenderProvider logSink) {
    logger.info("Activating logs for task " + this.taskId + " (" + taskId.getReadableName() + ")");
    if (this.loggersActivated.get()) {
        logger.info("Logs for task " + this.taskId + " are already activated");
        return;
    }
    this.loggersActivated.set(true);
    // create appender
    Appender appender;
    try {
        appender = logSink.getAppender();
    } catch (LogForwardingException e) {
        logger.error("Cannot create log appender.", e);
        return;
    }
    // fill appender
    if (!this.loggersFinalized.get()) {
        taskLogAppender.addAppender(appender);
    } else {
        logger.info("Logs for task " + this.taskId + " are closed. Flushing buffer...");
        // Everything is closed: reopen and close...
        for (LoggingEvent e : taskLogAppender.getStorage()) {
            appender.doAppend(e);
        }
        appender.close();
        this.loggersActivated.set(false);
        return;
    }
    logger.info("Activated logs for task " + this.taskId);
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException)

Example 4 with LogForwardingException

use of org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException 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 5 with LogForwardingException

use of org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException 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)

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