Search in sources :

Example 1 with ExperimentCatResource

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

the class QueueStatusResourceTest method test.

@Test
public void test() {
    QueueStatusResource queueStatusResource1 = new QueueStatusResource();
    queueStatusResource1.setHostName("bigred2.uits.iu.edu");
    queueStatusResource1.setQueueName("cpu");
    queueStatusResource1.setTime((long) 1 + System.currentTimeMillis());
    queueStatusResource1.setQueueUp(true);
    queueStatusResource1.setRunningJobs(3);
    queueStatusResource1.setQueuedJobs(4);
    try {
        queueStatusResource1.save();
    } catch (RegistryException e) {
        e.printStackTrace();
        Assert.fail();
    }
    QueueStatusResource queueStatusResource2 = new QueueStatusResource();
    queueStatusResource2.setHostName("bigred2.uits.iu.edu");
    queueStatusResource2.setQueueName("cpu");
    queueStatusResource2.setTime((long) 2 + System.currentTimeMillis());
    queueStatusResource2.setQueueUp(true);
    queueStatusResource2.setRunningJobs(33);
    queueStatusResource2.setQueuedJobs(44);
    try {
        queueStatusResource2.save();
    } catch (RegistryException e) {
        e.printStackTrace();
        Assert.fail();
    }
    try {
        List<ExperimentCatResource> experimentCatResources = queueStatusResource1.get(ResourceType.QUEUE_STATUS);
        Assert.assertTrue(experimentCatResources.size() == 1);
        QueueStatusResource queueStatusResource = (QueueStatusResource) experimentCatResources.get(0);
        Assert.assertEquals(queueStatusResource2.getTime(), queueStatusResource.getTime());
    } catch (RegistryException e) {
        e.printStackTrace();
        Assert.fail();
    }
}
Also used : QueueStatusResource(org.apache.airavata.registry.core.experiment.catalog.resources.QueueStatusResource) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource) Test(org.junit.Test)

Example 2 with ExperimentCatResource

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

the class WorkerResource method getProjects.

/**
 * Get projects list of user with pagination and ordering
 *
 * @return list of projects for the user
 */
public List<org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource> getProjects(int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
    List<org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource> result = new ArrayList<org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource>();
    List<ExperimentCatResource> list = get(ResourceType.PROJECT, limit, offset, orderByIdentifier, resultOrderType);
    for (ExperimentCatResource resource : list) {
        result.add((org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource) resource);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 3 with ExperimentCatResource

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

the class ProjectResource method get.

/**
 * @param type child resource type
 * @return list of child resources
 */
@Override
public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
    List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        if (type == ResourceType.EXPERIMENT) {
            em = ExpCatResourceUtils.getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator = new QueryGenerator(EXPERIMENT);
            generator.setParameter(ExperimentConstants.PROJECT_ID, id);
            Query q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    Experiment experiment = (Experiment) result;
                    ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
                    resourceList.add(experimentResource);
                }
            }
            em.getTransaction().commit();
            em.close();
        } else if (type == ResourceType.PROJECT_USER) {
            em = ExpCatResourceUtils.getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator = new QueryGenerator(PROJECT_USER);
            generator.setParameter(ProjectUserConstants.PROJECT_ID, id);
            Query q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    ProjectUser projectUser = (ProjectUser) result;
                    ProjectUserResource pr = (ProjectUserResource) Utils.getResource(ResourceType.PROJECT_USER, projectUser);
                    resourceList.add(pr);
                }
            }
            em.getTransaction().commit();
            em.close();
        } else {
            logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported resource type for project 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();
        }
    }
    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) 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 4 with ExperimentCatResource

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

the class ProjectResource method get.

/**
 * Get results with pagination and ordering
 *
 * @param type
 * @param limit
 * @param offset
 * @param orderByIdentifier
 * @return
 * @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> resourceList = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        if (type == ResourceType.EXPERIMENT) {
            em = ExpCatResourceUtils.getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator = new QueryGenerator(EXPERIMENT);
            generator.setParameter(ExperimentConstants.PROJECT_ID, id);
            Query q;
            // ordering - supported only by CREATION_TIME
            if (orderByIdentifier != null && resultOrderType != null && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.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);
            }
            List<?> results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    Experiment experiment = (Experiment) result;
                    ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
                    resourceList.add(experimentResource);
                }
            }
            em.getTransaction().commit();
            em.close();
        } else if (type == ResourceType.PROJECT_USER) {
            em = ExpCatResourceUtils.getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator = new QueryGenerator(PROJECT_USER);
            generator.setParameter(ProjectUserConstants.PROJECT_ID, id);
            Query q;
            // 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);
            }
            List<?> results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    ProjectUser projectUser = (ProjectUser) result;
                    ProjectUserResource pr = (ProjectUserResource) Utils.getResource(ResourceType.PROJECT_USER, projectUser);
                    resourceList.add(pr);
                }
            }
            em.getTransaction().commit();
            em.close();
        } else {
            logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported resource type for project 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();
        }
    }
    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) 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 5 with ExperimentCatResource

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

the class ProjectResource method getProjectUserList.

public List<ProjectUserResource> getProjectUserList() throws RegistryException {
    List<ExperimentCatResource> resources = get(ResourceType.PROJECT_USER);
    List<ProjectUserResource> projectUserResources = new ArrayList<ProjectUserResource>();
    if (resources != null && !resources.isEmpty()) {
        for (ExperimentCatResource r : resources) {
            projectUserResources.add((ProjectUserResource) r);
        }
    }
    return projectUserResources;
}
Also used : ArrayList(java.util.ArrayList) 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