use of org.platformlayer.jobs.model.JobLog in project platformlayer by platformlayer.
the class PersistentJobRegistry method getJobLog.
// @Override
// JobRecord startJob(JobRecord jobRecord) {
// PlatformLayerKey jobKey = jobRecord.getJobKey();
//
// if (jobKey != null) {
// synchronized (activeJobs) {
// activeJobs.put(jobKey, jobRecord);
// }
// }
//
// return jobRecord;
// }
// public JobData getJob(PlatformLayerKey jobKey, boolean fetchLog) {
// JobData jobData = null;
// synchronized (activeJobs) {
// jobRecord = activeJobs.get(jobKey);
// }
//
// if (jobData == null) {
// synchronized (recentJobs) {
// for (JobData recentJob : recentJobs) {
// if (recentJob.getJobKey().equals(jobKey)) {
// jobData = recentJob;
// break;
// }
// }
// }
// }
//
// if (jobData == null) {
// throw new UnsupportedOperationException();
//
// // jobRecord = repository.getJob(jobId, fetchLog);
// }
//
// return jobData;
// }
@Override
public JobLog getJobLog(PlatformLayerKey jobKey, String executionId, int logSkip) throws OpsException {
JobExecutionData execution = findExecution(jobKey, executionId);
Date startedAt = execution.getStartedAt();
if (execution.getEndedAt() == null) {
JobLog log = operationQueue.getActiveJobLog(jobKey, executionId);
if (log != null) {
JobLog ret = new JobLog();
ret.lines = Lists.newArrayList(Iterables.skip(log.lines, logSkip));
ret.execution = log.execution;
return ret;
}
}
try {
String cookie = execution.logCookie;
JobLog log = jobLogStore.getJobLog(startedAt, jobKey, executionId, cookie, logSkip);
if (log != null) {
log.execution = execution;
}
return log;
} catch (IOException e) {
throw new OpsException("Error reading job log", e);
}
}
use of org.platformlayer.jobs.model.JobLog in project platformlayer by platformlayer.
the class SimpleOperationQueue method getActiveJobLog.
@Override
public JobLog getActiveJobLog(PlatformLayerKey jobKey, String executionId) {
ActiveJobExecution activeJobExecution = activeJobs.get(jobKey);
if (activeJobExecution != null) {
SimpleJobLogger logger = (SimpleJobLogger) activeJobExecution.getLogger();
JobLog log = new JobLog();
log.lines = Lists.newArrayList(logger.getLogEntries());
log.execution = activeJobExecution.getJobExecution();
return log;
}
return null;
}
use of org.platformlayer.jobs.model.JobLog 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.JobLog 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.JobLog in project platformlayer by platformlayer.
the class HttpPlatformLayerClient method getJobExecutionLog.
@Override
public JobLog getJobExecutionLog(String jobId, String executionId) throws PlatformLayerClientException {
String relativePath = "jobs/" + jobId + "/runs/" + executionId + "/log";
JobLog jobLog = doRequest(HttpMethod.GET, relativePath, JobLog.class, Format.XML, null, null);
return jobLog;
}
Aggregations