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);
}
}
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();
}
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);
}
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());
}
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());
}
Aggregations