Search in sources :

Example 1 with JobPK

use of org.apache.airavata.registry.core.experiment.catalog.model.JobPK in project airavata by apache.

the class JobResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        JobPK jobPK = new JobPK();
        jobPK.setJobId(jobId);
        jobPK.setTaskId(taskId);
        Job existingJob = em.find(Job.class, jobPK);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        Job job;
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingJob == null) {
            job = new Job();
        } else {
            job = existingJob;
        }
        job.setJobId(jobId);
        job.setTaskId(taskId);
        job.setProcessId(processId);
        if (jobDescription != null) {
            job.setJobDescription(jobDescription.toCharArray());
        }
        if (stdOut != null) {
            job.setStdOut(stdOut.toCharArray());
        }
        if (stdErr != null) {
            job.setStdErr(stdErr.toCharArray());
        }
        job.setCreationTime(creationTime);
        job.setComputeResourceConsumed(computeResourceConsumed);
        job.setJobName(jobName);
        job.setWorkingDir(workingDir);
        job.setExitCode(exitCode);
        if (existingJob == null) {
            em.persist(job);
        } else {
            em.merge(job);
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Job(org.apache.airavata.registry.core.experiment.catalog.model.Job) RegistryException(org.apache.airavata.registry.cpi.RegistryException) JobPK(org.apache.airavata.registry.core.experiment.catalog.model.JobPK) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Job (org.apache.airavata.registry.core.experiment.catalog.model.Job)1 JobPK (org.apache.airavata.registry.core.experiment.catalog.model.JobPK)1 RegistryException (org.apache.airavata.registry.cpi.RegistryException)1