Search in sources :

Example 1 with Job

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

the class TaskResource 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 TASK_STATUS:
                generator = new QueryGenerator(TASK_STATUS);
                generator.setParameter(TaskStatusConstants.STATUS_ID, name);
                q = generator.selectQuery(em);
                TaskStatus status = (TaskStatus) q.getSingleResult();
                TaskStatusResource statusResource = (TaskStatusResource) Utils.getResource(ResourceType.TASK_STATUS, status);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return statusResource;
            case TASK_ERROR:
                generator = new QueryGenerator(TASK_ERROR);
                generator.setParameter(TaskErrorConstants.ERROR_ID, name);
                q = generator.selectQuery(em);
                TaskError error = (TaskError) q.getSingleResult();
                TaskErrorResource errorResource = (TaskErrorResource) Utils.getResource(ResourceType.TASK_ERROR, error);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return errorResource;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.JOB_ID, name);
                generator.setParameter(JobConstants.TASK_ID, taskId);
                q = generator.selectQuery(em);
                Job job = (Job) q.getSingleResult();
                JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return jobResource;
            default:
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                logger.error("Unsupported resource type for Task resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for Task 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 : EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) TaskError(org.apache.airavata.registry.core.experiment.catalog.model.TaskError) TaskStatus(org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus) Job(org.apache.airavata.registry.core.experiment.catalog.model.Job) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 2 with Job

use of org.apache.airavata.registry.core.experiment.catalog.model.Job 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)

Example 3 with Job

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

the class TaskResource 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 TASK_ERROR:
                generator = new QueryGenerator(TASK_ERROR);
                generator.setParameter(TaskErrorConstants.TASK_ID, taskId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        TaskError taskError = (TaskError) result;
                        TaskErrorResource taskErrorResource = (TaskErrorResource) Utils.getResource(ResourceType.TASK_ERROR, taskError);
                        resourceList.add(taskErrorResource);
                    }
                }
                break;
            case TASK_STATUS:
                generator = new QueryGenerator(TASK_STATUS);
                generator.setParameter(TaskStatusConstants.TASK_ID, taskId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        TaskStatus taskStatus = (TaskStatus) result;
                        TaskStatusResource taskStatusResource = (TaskStatusResource) Utils.getResource(ResourceType.TASK_STATUS, taskStatus);
                        resourceList.add(taskStatusResource);
                    }
                }
                break;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.TASK_ID, taskId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Job job = (Job) result;
                        JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
                        resourceList.add(jobResource);
                    }
                }
                break;
            default:
                logger.error("Unsupported resource type for task 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) TaskError(org.apache.airavata.registry.core.experiment.catalog.model.TaskError) TaskStatus(org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) List(java.util.List) Job(org.apache.airavata.registry.core.experiment.catalog.model.Job) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Aggregations

EntityManager (javax.persistence.EntityManager)3 Job (org.apache.airavata.registry.core.experiment.catalog.model.Job)3 RegistryException (org.apache.airavata.registry.cpi.RegistryException)3 Query (javax.persistence.Query)2 TaskError (org.apache.airavata.registry.core.experiment.catalog.model.TaskError)2 TaskStatus (org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus)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 JobPK (org.apache.airavata.registry.core.experiment.catalog.model.JobPK)1