use of org.platformlayer.jobs.model.JobExecutionList in project platformlayer by platformlayer.
the class HttpPlatformLayerClient method listJobExecutions.
@Override
public JobExecutionList listJobExecutions(String jobId) throws PlatformLayerClientException {
String relativePath = "jobs/" + jobId + "/runs";
JobExecutionList executions = doRequest(HttpMethod.GET, relativePath, JobExecutionList.class, Format.XML, null, null);
return executions;
}
use of org.platformlayer.jobs.model.JobExecutionList in project platformlayer by platformlayer.
the class PlatformLayerTestContext method waitForJobComplete.
public JobData waitForJobComplete(JobData job, TimeSpan timeout) throws OpsException, IOException {
TypedPlatformLayerClient client = getTypedClient();
PlatformLayerKey jobKey = job.key;
long startedAt = System.currentTimeMillis();
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted", e);
}
if (timeout != null && timeout.hasTimedOut(startedAt)) {
throw new OpsException("Timeout waiting for job completion");
}
// TODO: We really need a "get job status" function
JobData found = null;
for (JobData candidate : client.listJobs().getJobs()) {
if (jobKey.equals(candidate.getJobKey())) {
found = candidate;
}
}
if (found == null) {
// Assume completed?
throw new IllegalStateException("Job not found in job list");
}
JobExecutionList executions = client.listJobExecutions(job.getJobKey().getItemIdString());
JobExecutionData foundExecution = null;
for (JobExecutionData candidate : executions) {
if (jobKey.equals(candidate.getJobKey())) {
foundExecution = candidate;
}
}
if (foundExecution == null) {
throw new IllegalStateException("Execution not found in execution list");
}
JobState state = foundExecution.getState();
switch(state) {
case FAILED:
case SUCCESS:
System.out.println("Job completed; state=" + state);
return found;
case RUNNING:
System.out.println("Continuing to wait for " + job.key + "; state=" + state);
break;
default:
throw new IllegalStateException("Unexpected state: " + state + " for " + job.key);
}
}
}
use of org.platformlayer.jobs.model.JobExecutionList 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.JobExecutionList in project platformlayer by platformlayer.
the class HttpPlatformLayerClient method listJobExecutions.
@Override
public JobExecutionList listJobExecutions() throws PlatformLayerClientException {
String relativePath = "jobs/runs";
JobExecutionList jobs = doRequest(HttpMethod.GET, relativePath, JobExecutionList.class, Format.XML, null, null);
return jobs;
}
use of org.platformlayer.jobs.model.JobExecutionList 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);
}
}
Aggregations