Search in sources :

Example 21 with JobData

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;
}
Also used : JobData(org.platformlayer.jobs.model.JobData)

Example 22 with JobData

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();
    }
}
Also used : SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) RepositoryException(org.platformlayer.RepositoryException) ManagedItemId(org.platformlayer.ids.ManagedItemId) JobData(org.platformlayer.jobs.model.JobData) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 23 with JobData

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JobData(org.platformlayer.jobs.model.JobData) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 24 with 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);
    }
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) JobData(org.platformlayer.jobs.model.JobData)

Aggregations

JobData (org.platformlayer.jobs.model.JobData)24 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)7 PlatformLayerClient (org.platformlayer.PlatformLayerClient)4 RepositoryException (org.platformlayer.RepositoryException)4 ManagedItemId (org.platformlayer.ids.ManagedItemId)4 OpsException (org.platformlayer.ops.OpsException)4 ItemBase (org.platformlayer.core.model.ItemBase)3 ProjectId (org.platformlayer.ids.ProjectId)3 SecretProvider (org.platformlayer.auth.crypto.SecretProvider)2 JobDataList (org.platformlayer.jobs.model.JobDataList)2 JobExecutionData (org.platformlayer.jobs.model.JobExecutionData)2 OpsContext (org.platformlayer.ops.OpsContext)2 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)2 CliException (com.fathomdb.cli.CliException)1 Ansi (com.fathomdb.cli.commands.Ansi)1 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SQLException (java.sql.SQLException)1 List (java.util.List)1