use of org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider 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.AppenderProvider 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.AppenderProvider 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.AppenderProvider 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());
}
use of org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider 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);
}
}
Aggregations