Search in sources :

Example 31 with ExperimentCatResource

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

the class ProjectResource method getExperiments.

public List<ExperimentResource> getExperiments(int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
    List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType);
    List<ExperimentResource> result = new ArrayList<ExperimentResource>();
    for (ExperimentCatResource resource : list) {
        result.add((ExperimentResource) resource);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 32 with ExperimentCatResource

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

Example 33 with ExperimentCatResource

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

the class TaskResource method getTaskErrors.

public List<TaskErrorResource> getTaskErrors() throws RegistryException {
    List<TaskErrorResource> taskErrorResources = new ArrayList();
    List<ExperimentCatResource> resources = get(ResourceType.TASK_ERROR);
    for (ExperimentCatResource resource : resources) {
        TaskErrorResource errorResource = (TaskErrorResource) resource;
        taskErrorResources.add(errorResource);
    }
    return taskErrorResources;
}
Also used : ArrayList(java.util.ArrayList) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 34 with ExperimentCatResource

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

the class TaskResource method getJobList.

public List<JobResource> getJobList() throws RegistryException {
    List<JobResource> jobResources = new ArrayList();
    List<ExperimentCatResource> resources = get(ResourceType.JOB);
    for (ExperimentCatResource resource : resources) {
        JobResource jobResource = (JobResource) resource;
        jobResources.add(jobResource);
    }
    return jobResources;
}
Also used : ArrayList(java.util.ArrayList) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 35 with ExperimentCatResource

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

the class ExperimentResource 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 EXPERIMENT_INPUT:
                generator = new QueryGenerator(EXPERIMENT_INPUT);
                generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ExperimentInput experimentInput = (ExperimentInput) result;
                        ExperimentInputResource experimentInputResource = (ExperimentInputResource) Utils.getResource(ResourceType.EXPERIMENT_INPUT, experimentInput);
                        resourceList.add(experimentInputResource);
                    }
                }
                break;
            case EXPERIMENT_OUTPUT:
                generator = new QueryGenerator(EXPERIMENT_OUTPUT);
                generator.setParameter(ExperimentOutputConstants.EXPERIMENT_ID, experimentId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ExperimentOutput experimentOutput = (ExperimentOutput) result;
                        ExperimentOutputResource experimentOutputResource = (ExperimentOutputResource) Utils.getResource(ResourceType.EXPERIMENT_OUTPUT, experimentOutput);
                        resourceList.add(experimentOutputResource);
                    }
                }
                break;
            case PROCESS:
                generator = new QueryGenerator(PROCESS);
                generator.setParameter(ProcessConstants.EXPERIMENT_ID, experimentId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Process process = (Process) result;
                        ProcessResource processResource = (ProcessResource) Utils.getResource(ResourceType.PROCESS, process);
                        resourceList.add(processResource);
                    }
                }
                break;
            case EXPERIMENT_ERROR:
                generator = new QueryGenerator(EXPERIMENT_ERROR);
                generator.setParameter(ExperimentErrorConstants.EXPERIMENT_ID, experimentId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ExperimentError experimentError = (ExperimentError) result;
                        ExperimentErrorResource experimentErrorResource = (ExperimentErrorResource) Utils.getResource(ResourceType.EXPERIMENT_ERROR, experimentError);
                        resourceList.add(experimentErrorResource);
                    }
                }
                break;
            case EXPERIMENT_STATUS:
                generator = new QueryGenerator(EXPERIMENT_STATUS);
                generator.setParameter(ExperimentStatusConstants.EXPERIMENT_ID, experimentId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ExperimentStatus experimentStatus = (ExperimentStatus) result;
                        ExperimentStatusResource experimentStatusResource = (ExperimentStatusResource) Utils.getResource(ResourceType.EXPERIMENT_STATUS, experimentStatus);
                        resourceList.add(experimentStatusResource);
                    }
                }
                break;
            default:
                logger.error("Unsupported resource type for experiment 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) Process(org.apache.airavata.registry.core.experiment.catalog.model.Process) 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) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Aggregations

ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)36 ArrayList (java.util.ArrayList)31 RegistryException (org.apache.airavata.registry.cpi.RegistryException)12 EntityManager (javax.persistence.EntityManager)11 Query (javax.persistence.Query)11 QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)10 List (java.util.List)8 Notification (org.apache.airavata.model.workspace.Notification)1 Job (org.apache.airavata.registry.core.experiment.catalog.model.Job)1 JobStatus (org.apache.airavata.registry.core.experiment.catalog.model.JobStatus)1 Notification (org.apache.airavata.registry.core.experiment.catalog.model.Notification)1 Process (org.apache.airavata.registry.core.experiment.catalog.model.Process)1 QueueStatus (org.apache.airavata.registry.core.experiment.catalog.model.QueueStatus)1 TaskError (org.apache.airavata.registry.core.experiment.catalog.model.TaskError)1 TaskStatus (org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus)1 NotificationResource (org.apache.airavata.registry.core.experiment.catalog.resources.NotificationResource)1 QueueStatusResource (org.apache.airavata.registry.core.experiment.catalog.resources.QueueStatusResource)1 Test (org.junit.Test)1