Search in sources :

Example 21 with ExperimentCatResource

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

the class WorkerResource method getExperiments.

/**
 * Method to get list of experiments of user with pagination and ordering
 *
 * @param limit
 * @param offset
 * @param orderByIdentifier
 * @param resultOrderType
 * @return
 * @throws org.apache.airavata.registry.cpi.RegistryException
 */
public List<ExperimentResource> getExperiments(int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
    List<ExperimentResource> result = new ArrayList<ExperimentResource>();
    List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType);
    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 22 with ExperimentCatResource

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

the class WorkerResource method create.

/**
 * Gateway worker can create child data structures such as projects and user workflows
 *
 * @param type child resource type
 * @return child resource
 */
public ExperimentCatResource create(ResourceType type) throws RegistryException {
    ExperimentCatResource result = null;
    switch(type) {
        case PROJECT:
            org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource projectResource = new org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource();
            projectResource.setWorker(this);
            projectResource.setGatewayId(gatewayId);
            result = projectResource;
            break;
        case EXPERIMENT:
            ExperimentResource experimentResource = new ExperimentResource();
            experimentResource.setUserName(user);
            experimentResource.setGatewayExecutionId(gatewayId);
            result = experimentResource;
            break;
        default:
            logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported resource type for worker resource.");
    }
    return result;
}
Also used : ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 23 with ExperimentCatResource

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

the class WorkerResource method get.

/**
 * @param type child resource type
 * @param name child resource name
 * @return child resource
 */
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
    ExperimentCatResource result = null;
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator;
        Query q;
        switch(type) {
            case PROJECT:
                generator = new QueryGenerator(PROJECT);
                generator.setParameter(ProjectConstants.PROJECT_ID, name);
                q = generator.selectQuery(em);
                Project project = (Project) q.getSingleResult();
                result = Utils.getResource(ResourceType.PROJECT, project);
                break;
            case EXPERIMENT:
                generator = new QueryGenerator(EXPERIMENT);
                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
                q = generator.selectQuery(em);
                Experiment experiment = (Experiment) q.getSingleResult();
                result = Utils.getResource(ResourceType.EXPERIMENT, experiment);
                break;
            default:
                logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
                break;
        }
        em.getTransaction().commit();
        em.close();
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return result;
}
Also used : 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) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 24 with ExperimentCatResource

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

the class WorkerResource method get.

/**
 * Method get all results of the given child resource type with paginaltion and ordering
 *
 * @param type              child resource type
 * @param limit
 * @param offset
 * @param orderByIdentifier
 * @param resultOrderType
 * @return list of child resources
 * @throws org.apache.airavata.registry.cpi.RegistryException
 */
public List<ExperimentCatResource> get(ResourceType type, int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
    List<ExperimentCatResource> result = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator;
        Query q;
        switch(type) {
            case PROJECT:
                generator = new QueryGenerator(PROJECT);
                UserPK userPK = new UserPK();
                userPK.setGatewayId(getGatewayId());
                userPK.setUserName(user);
                Users users = em.find(Users.class, userPK);
                Gateway gatewayModel = em.find(Gateway.class, gatewayId);
                generator.setParameter("users", users);
                if (gatewayModel != null) {
                    generator.setParameter("gateway", gatewayModel);
                }
                // ordering - only supported only by CREATION_TIME
                if (orderByIdentifier != null && resultOrderType != null && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) {
                    q = generator.selectQuery(em, ProjectConstants.CREATION_TIME, resultOrderType);
                } else {
                    q = generator.selectQuery(em);
                }
                // pagination
                if (limit > 0 && offset >= 0) {
                    q.setFirstResult(offset);
                    q.setMaxResults(limit);
                }
                for (Object o : q.getResultList()) {
                    Project project = (Project) o;
                    org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource projectResource = (org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
                    result.add(projectResource);
                }
                break;
            case EXPERIMENT:
                generator = new QueryGenerator(EXPERIMENT);
                generator.setParameter(ExperimentConstants.USER_NAME, getUser());
                // ordering - only supported only by CREATION_TIME
                if (orderByIdentifier != null && resultOrderType != null && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) {
                    q = generator.selectQuery(em, ExperimentConstants.CREATION_TIME, resultOrderType);
                } else {
                    q = generator.selectQuery(em);
                }
                // pagination
                if (limit > 0 && offset >= 0) {
                    q.setFirstResult(offset);
                    q.setMaxResults(limit);
                }
                for (Object o : q.getResultList()) {
                    Experiment experiment = (Experiment) o;
                    ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
                    result.add(experimentResource);
                }
                break;
            default:
                logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
                break;
        }
        em.getTransaction().commit();
        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 result;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) 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) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 25 with ExperimentCatResource

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

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