Search in sources :

Example 1 with JobStatus

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

the class JobResource method get.

public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator;
        Query q;
        switch(type) {
            case JOB_STATUS:
                generator = new QueryGenerator(JOB_STATUS);
                generator.setParameter(JobStatusConstants.STATUS_ID, name);
                q = generator.selectQuery(em);
                JobStatus status = (JobStatus) q.getSingleResult();
                JobStatusResource statusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, status);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return statusResource;
            default:
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                logger.error("Unsupported resource type for Job resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for Job resource.");
        }
    } 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) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 2 with JobStatus

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

the class JobResource method get.

public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
    List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        QueryGenerator generator;
        List results;
        switch(type) {
            case JOB_STATUS:
                generator = new QueryGenerator(JOB_STATUS);
                generator.setParameter(JobStatusConstants.JOB_ID, jobId);
                generator.setParameter(JobStatusConstants.TASK_ID, taskId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        JobStatus jobStatus = (JobStatus) result;
                        JobStatusResource jobStatusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, jobStatus);
                        resourceList.add(jobStatusResource);
                    }
                }
                break;
            default:
                logger.error("Unsupported resource type for job resource.", new UnsupportedOperationException());
                throw new UnsupportedOperationException();
        }
        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();
        }
    }
    return resourceList;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) JobStatus(org.apache.airavata.registry.core.experiment.catalog.model.JobStatus) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 3 with JobStatus

use of org.apache.airavata.registry.core.experiment.catalog.model.JobStatus 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)3 JobStatus (org.apache.airavata.registry.core.experiment.catalog.model.JobStatus)3 RegistryException (org.apache.airavata.registry.cpi.RegistryException)3 Query (javax.persistence.Query)2 QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)1 JobStatusPK (org.apache.airavata.registry.core.experiment.catalog.model.JobStatusPK)1