use of org.platformlayer.jobs.model.JobState 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.JobState 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();
}
Aggregations