use of org.platformlayer.jobs.model.JobLogLine in project platformlayer by platformlayer.
the class JobLogStoreBase method serialize.
protected void serialize(SimpleJobLogger logger, OutputStream os) throws IOException {
GZIPOutputStream gzip = new GZIPOutputStream(os);
CodedOutputStream out = CodedOutputStream.newInstance(gzip);
Iterable<JobLogLine> lines = logger.getLogEntries();
JobDataProtobuf.JobLogLine.Builder protobuf = JobDataProtobuf.JobLogLine.newBuilder();
for (JobLogLine line : lines) {
protobuf.setLevel(line.level);
if (line.message != null) {
protobuf.setMessage(line.message);
} else {
protobuf.clearMessage();
}
protobuf.setTimestamp(line.timestamp);
if (line.type != null) {
protobuf.setType(line.type);
} else {
protobuf.clearType();
}
if (line.exception != null) {
mapToProtobuf(line.exception, protobuf.getExceptionBuilder());
} else {
protobuf.clearException();
}
JobDataProtobuf.JobLogLine message = protobuf.build();
int size = message.getSerializedSize();
out.writeRawVarint32(size);
message.writeTo(out);
}
out.flush();
gzip.finish();
}
use of org.platformlayer.jobs.model.JobLogLine in project platformlayer by platformlayer.
the class JobLogPrinter method write.
private void write(JobLog jobLog) {
startJobLog(jobLog);
for (JobLogLine line : jobLog) {
write(line);
}
endJobLog(jobLog);
}
use of org.platformlayer.jobs.model.JobLogLine in project platformlayer by platformlayer.
the class SimpleJobLogger method exitScope.
@Override
public void exitScope() {
JobLogLine line = new JobLogLine();
line.type = JobLogLine.TYPE_EXIT_SCOPE;
lines.add(line);
}
use of org.platformlayer.jobs.model.JobLogLine in project platformlayer by platformlayer.
the class TailLog method runCommand.
@Override
public Object runCommand() throws PlatformLayerClientException, InterruptedException {
PlatformLayerClient client = getPlatformLayerClient();
// TODO: System.out isn't quite right
JobLogPrinter jobLogPrinter = new JobLogPrinter(new PrintWriter(System.out));
if (Strings.isNullOrEmpty(executionId)) {
JobExecutionList jobExecutions = client.listJobExecutions(jobId);
JobExecutionData last = null;
for (JobExecutionData execution : jobExecutions.getRuns()) {
if (execution.getState() == JobState.PRESTART) {
continue;
}
if (last == null) {
last = execution;
continue;
}
if (last.getStartedAt().before(execution.getStartedAt())) {
last = execution;
continue;
}
}
if (last != null) {
executionId = last.getExecutionId();
}
}
// TODO: What if executionId == null? Also retries..
JobLog previousJobLog = null;
int jobLogOffset = 0;
while (true) {
// TODO: Only fetch tail
JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
if (previousJobLog == null) {
jobLogPrinter.startJobLog(jobLog);
}
List<JobLogLine> lines = jobLog.getLines();
if (jobLogOffset < lines.size()) {
for (JobLogLine line : lines.subList(jobLogOffset, lines.size())) {
jobLogPrinter.write(line);
}
}
jobLogPrinter.flush();
jobLogOffset = lines.size();
previousJobLog = jobLog;
Thread.sleep(1000);
}
}
use of org.platformlayer.jobs.model.JobLogLine in project platformlayer by platformlayer.
the class JobLogFormatter method visit.
@Override
public void visit(CliContext context, JobLog o, OutputSink sink) throws IOException {
LinkedHashMap<String, Object> values = Maps.newLinkedHashMap();
JobExecutionData execution = o.getExecution();
if (execution != null) {
values.put("jobId", execution.getJobKey().getItemIdString());
values.put("executionId", execution.getExecutionId());
values.put("start", o.getExecution().getStartedAt());
values.put("end", o.getExecution().getEndedAt());
values.put("state", execution.getState());
}
List<JobLogLine> lines = o.getLines();
values.put("lines", lines.size());
sink.outputRow(values);
}
Aggregations