Search in sources :

Example 1 with JobStatusPK

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

the class JobStatusResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        if (jobId == null || statusId == null || taskId == null) {
            throw new RegistryException("Does not have the job id or status id or task id");
        }
        em = ExpCatResourceUtils.getEntityManager();
        JobStatus jobStatus;
        JobStatusPK jobStatusPK = new JobStatusPK();
        jobStatusPK.setJobId(jobId);
        jobStatusPK.setStatusId(statusId);
        jobStatusPK.setTaskId(taskId);
        JobStatus existingJobStatus = em.find(JobStatus.class, jobStatusPK);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingJobStatus == null) {
            jobStatus = new JobStatus();
        } else {
            jobStatus = existingJobStatus;
        }
        jobStatus.setStatusId(statusId);
        jobStatus.setJobId(jobId);
        jobStatus.setTaskId(taskId);
        jobStatus.setState(state);
        jobStatus.setReason(reason);
        if (timeOfStateChange == null) {
            timeOfStateChange = AiravataUtils.getCurrentTimestamp();
        }
        jobStatus.setTimeOfStateChange(timeOfStateChange);
        if (existingJobStatus == null) {
            em.persist(jobStatus);
        } else {
            em.merge(jobStatus);
        }
        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 : JobStatus(org.apache.airavata.registry.core.experiment.catalog.model.JobStatus) JobStatusPK(org.apache.airavata.registry.core.experiment.catalog.model.JobStatusPK) EntityManager(javax.persistence.EntityManager) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

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