Search in sources :

Example 1 with JobLogLine

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();
}
Also used : JobDataProtobuf(org.platformlayer.ops.jobstore.protobuf.JobDataProtobuf) GZIPOutputStream(java.util.zip.GZIPOutputStream) JobLogLine(org.platformlayer.jobs.model.JobLogLine) CodedOutputStream(com.google.protobuf.CodedOutputStream)

Example 2 with JobLogLine

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);
}
Also used : JobLogLine(org.platformlayer.jobs.model.JobLogLine)

Example 3 with JobLogLine

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);
}
Also used : JobLogLine(org.platformlayer.jobs.model.JobLogLine)

Example 4 with JobLogLine

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);
    }
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobLogLine(org.platformlayer.jobs.model.JobLogLine) JobLog(org.platformlayer.jobs.model.JobLog) JobExecutionList(org.platformlayer.jobs.model.JobExecutionList) PrintWriter(java.io.PrintWriter)

Example 5 with JobLogLine

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);
}
Also used : JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobLogLine(org.platformlayer.jobs.model.JobLogLine)

Aggregations

JobLogLine (org.platformlayer.jobs.model.JobLogLine)9 JobExecutionData (org.platformlayer.jobs.model.JobExecutionData)2 JobLog (org.platformlayer.jobs.model.JobLog)2 JobLogExceptionInfo (org.platformlayer.jobs.model.JobLogExceptionInfo)2 CodedInputStream (com.google.protobuf.CodedInputStream)1 CodedOutputStream (com.google.protobuf.CodedOutputStream)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 PlatformLayerClient (org.platformlayer.PlatformLayerClient)1 JobExecutionList (org.platformlayer.jobs.model.JobExecutionList)1 JobDataProtobuf (org.platformlayer.ops.jobstore.protobuf.JobDataProtobuf)1