use of org.platformlayer.jobs.model.JobExecutionData in project platformlayer by platformlayer.
the class OperationQueueBase method createExecution.
protected JobExecutionData createExecution(JobData jobData) throws OpsException {
Date startedAt = new Date();
String executionId;
try {
executionId = jobRepository.insertExecution(jobData.key, startedAt);
} catch (RepositoryException e) {
throw new OpsException("Error inserting job execution into repository", e);
}
JobExecutionData execution = new JobExecutionData();
execution.job = jobData;
execution.jobKey = jobData.getJobKey();
execution.startedAt = startedAt;
execution.executionId = executionId;
execution.state = JobState.PRESTART;
return execution;
}
use of org.platformlayer.jobs.model.JobExecutionData 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.JobExecutionData in project platformlayer by platformlayer.
the class JdbcJobRepository method mapFromEntity.
private JobData mapFromEntity(JobEntity entity, PlatformLayerKey jobKey) throws RepositoryException {
JobData data = new JobData();
data.action = actionFromXml(entity.actionXml);
data.key = jobKey;
data.targetId = PlatformLayerKey.parse(entity.target);
if (entity.lastrunId != null) {
JobExecutionData execution = new JobExecutionData();
execution.endedAt = entity.lastrunEndedAt;
execution.executionId = entity.lastrunId;
execution.state = entity.lastrunState;
data.lastRun = execution;
}
return data;
}
use of org.platformlayer.jobs.model.JobExecutionData 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.JobExecutionData in project platformlayer by platformlayer.
the class JobResource method getRuns.
@GET
@Path("runs")
@Produces({ XML, JSON })
public JobExecutionList getRuns() throws OpsException {
List<JobExecutionData> jobList = jobRegistry.listExecutions(job.getJobKey());
JobExecutionList runs = JobExecutionList.create(jobList);
return runs;
}
Aggregations