use of org.platformlayer.jobs.model.JobExecutionData in project platformlayer by platformlayer.
the class ListJobExecutions method formatRaw.
@Override
public void formatRaw(Object o, PrintWriter writer) {
JobExecutionList jobs = (JobExecutionList) o;
switch(getFormat()) {
case JSON:
JsonHelper<JobExecutionList> jsonHelper = JsonHelper.build(JobExecutionList.class);
boolean formatted = true;
try {
String json = jsonHelper.marshal(jobs, formatted);
writer.println(json);
return;
} catch (IOException e) {
throw new CliException("Error formatting for output", e);
}
}
Ansi ansi = new Ansi(writer);
for (JobExecutionData job : jobs) {
JobState state = job.state;
if (state != null) {
switch(job.state) {
case FAILED:
ansi.setColorRed();
break;
case SUCCESS:
ansi.setColorGreen();
break;
case RUNNING:
ansi.setColorBlue();
break;
default:
ansi.setColorBlue();
break;
}
} else {
ansi.setColorBlue();
}
writer.println(job.getJobId() + "/" + job.executionId);
}
ansi.reset();
}
use of org.platformlayer.jobs.model.JobExecutionData in project platformlayer by platformlayer.
the class GetJobLog method runCommand.
@Override
public Object runCommand() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
if (jobId.contains("/") && executionId == null) {
String[] tokens = jobId.split("/");
if (tokens.length == 2) {
jobId = tokens[0];
executionId = tokens[1];
}
}
List<JobLog> logs = Lists.newArrayList();
if (Strings.isNullOrEmpty(executionId)) {
JobExecutionList jobExecutions = client.listJobExecutions(jobId);
List<JobExecutionData> runs = jobExecutions.getRuns();
sort(runs);
// TODO: Remove limit (or iterate)
if (runs.size() > 10) {
runs = Lists.newArrayList(runs.subList(runs.size() - 10, runs.size()));
}
// TODO: Fix 1+N slowness...
for (JobExecutionData execution : runs) {
if (execution.getState() == JobState.PRESTART) {
continue;
}
String executionId = execution.getExecutionId();
try {
JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
logs.add(jobLog);
} catch (PlatformLayerClientNotFoundException e) {
// TODO: Warn?
}
}
} else {
JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
logs.add(jobLog);
}
return logs;
}
use of org.platformlayer.jobs.model.JobExecutionData 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.JobExecutionData in project platformlayer by platformlayer.
the class JobDataFormatter method visit.
@Override
public void visit(CliContext context, JobData o, OutputSink sink) throws IOException {
LinkedHashMap<String, Object> values = Maps.newLinkedHashMap();
values.put("id", o.key.getItemIdString());
values.put("target", o.targetId);
values.put("action", o.action.getType());
// values.put("state", o.state);
JobExecutionData lastRun = o.getLastRun();
values.put("lastrun:id", lastRun != null ? lastRun.getExecutionId() : null);
values.put("lastrun:state", lastRun != null ? lastRun.getState() : null);
values.put("lastrun:end", lastRun != null ? lastRun.getEndedAt() : null);
sink.outputRow(values);
}
use of org.platformlayer.jobs.model.JobExecutionData 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