use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.
the class HttpPlatformLayerClient method deleteItem.
// public <T> void deleteItem(T item) throws PlatformLayerClientException {
// JaxbHelper jaxbHelper = toJaxbHelper(item);
//
// PlatformLayerKey key = toKey(jaxbHelper, item);
// deleteItem(key);
// }
@Override
public JobData deleteItem(PlatformLayerKey key) throws PlatformLayerClientException {
String relativePath = buildRelativePath(key);
JobData retval = doRequest(HttpMethod.DELETE, relativePath, JobData.class, Format.XML, null, null);
return retval;
}
use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.
the class JdbcJobRepository method listRecentJobs.
// @Override
// @JdbcTransaction
// public List<JobExecutionData> listRecentExecutions(JobQuery jobQuery) throws RepositoryException {
// DbHelper db = new DbHelper();
// try {
// // We use JoinedQueryResult because we have a compound PK (projectId / jobId)
// // and JPA makes this really complicated.
//
// ProjectId projectId = jobQuery.project;
// Preconditions.checkNotNull(projectId);
// int project = db.mapToValue(projectId);
//
// Long maxAge = null;
// if (jobQuery.maxAge != null) {
// maxAge = jobQuery.maxAge.getTotalSeconds();
// }
//
// Integer limit = jobQuery.limit;
// String filterTarget = jobQuery.target != null ? jobQuery.target.getUrl() : null;
//
// JoinedQueryResult results = db.queries.listRecentExecutions(project, maxAge, filterTarget, limit);
//
// List<JobExecutionData> ret = Lists.newArrayList();
// Map<String, JobData> jobs = Maps.newHashMap();
//
// for (JobEntity job : results.getAll(JobEntity.class)) {
// ManagedItemId jobId = new ManagedItemId(job.jobId);
// PlatformLayerKey jobKey = JobData.buildKey(projectId, jobId);
// jobs.put(job.jobId, mapFromEntity(job, jobKey));
// }
//
// for (JobExecutionEntity execution : results.getAll(JobExecutionEntity.class)) {
// JobData jobData = jobs.get(execution.jobId);
// if (jobData == null) {
// throw new IllegalStateException();
// }
//
// ManagedItemId jobId = new ManagedItemId(execution.jobId);
// PlatformLayerKey jobKey = JobData.buildKey(projectId, jobId);
// JobExecutionData run = mapFromEntity(execution, jobKey);
// run.job = jobData;
// ret.add(run);
// }
//
// sort(ret);
//
// return ret;
// } catch (SQLException e) {
// throw new RepositoryException("Error listing job executions", e);
// } finally {
// db.close();
// }
// }
@Override
@JdbcTransaction
public List<JobData> listRecentJobs(JobQuery jobQuery) throws RepositoryException {
DbHelper db = new DbHelper();
try {
ProjectId projectId = jobQuery.project;
Preconditions.checkNotNull(projectId);
int project = db.mapToValue(projectId);
Long maxAge = null;
if (jobQuery.maxAge != null) {
maxAge = jobQuery.maxAge.getTotalSeconds();
}
Integer limit = jobQuery.limit;
String filterTarget = jobQuery.target != null ? jobQuery.target.getUrl() : null;
// TODO: Include currently running jobs...
List<JobEntity> results = db.queries.listRecentJobs(project, maxAge, filterTarget, limit);
List<JobData> ret = Lists.newArrayList();
for (JobEntity job : results) {
ManagedItemId jobId = new ManagedItemId(job.jobId);
PlatformLayerKey jobKey = JobData.buildKey(projectId, jobId);
JobData jobData = mapFromEntity(job, jobKey);
ret.add(jobData);
}
sortJobs(ret);
return ret;
} catch (SQLException e) {
throw new RepositoryException("Error listing job executions", e);
} finally {
db.close();
}
}
use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.
the class PersistentJobRegistry method enqueueOperation.
@Override
public JobData enqueueOperation(Action action, ProjectAuthorization auth, PlatformLayerKey targetItem) throws OpsException {
ProjectId projectId;
try {
projectId = opsContextBuilder.getRunAsProjectId(auth);
} catch (OpsException e) {
throw new OpsException("Error getting projectId", e);
}
JobData jobData = new JobData();
jobData.action = action;
jobData.targetId = targetItem;
try {
String jobId = repository.insertJob(projectId, jobData);
jobData.key = JobData.buildKey(projectId, new ManagedItemId(jobId));
} catch (RepositoryException e) {
throw new OpsException("Error inserting job", e);
}
operationQueue.submit(auth, jobData);
return jobData;
}
use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.
the class PlatformLayerTestContext method cleanup.
public void cleanup() throws IOException, OpsException {
while (!ownedItems.isEmpty()) {
ItemBase item = ownedItems.remove(ownedItems.size() - 1);
JobData deleteJob = deleteItem(item);
System.out.println("Deleted " + item.getKey() + " jobId=" + deleteJob.getJobId());
waitForDeleted(item);
}
}
Aggregations