Search in sources :

Example 6 with ExperimentCatResource

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

the class QueueStatusResource method get.

/**
 * This method will list all the child resources for the given resource type
 *
 * @param type child resource type
 * @return list of child resources of the given child resource type
 */
@Override
public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
    List<ExperimentCatResource> result = new ArrayList<>();
    EntityManager em = null;
    try {
        String query = "SELECT q from QueueStatus q WHERE q.time IN (SELECT MAX(q2.time) FROM QueueStatus q2 GROUP BY q2.hostName, q2.queueName)";
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q = em.createQuery(query);
        List resultList = q.getResultList();
        for (Object o : resultList) {
            QueueStatus queueStatus = (QueueStatus) o;
            QueueStatusResource queueStatusResource = new QueueStatusResource();
            queueStatusResource.setHostName(queueStatus.getHostName());
            queueStatusResource.setQueueName(queueStatus.getQueueName());
            queueStatusResource.setTime(queueStatus.getTime());
            queueStatusResource.setQueueUp(queueStatus.getQueueUp());
            queueStatusResource.setQueuedJobs(queueStatus.getQueuedJobs());
            queueStatusResource.setRunningJobs(queueStatus.getRunningJobs());
            result.add(queueStatusResource);
        }
        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 : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) QueueStatus(org.apache.airavata.registry.core.experiment.catalog.model.QueueStatus) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 7 with ExperimentCatResource

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

the class TaskResource method getTaskStatuses.

public List<TaskStatusResource> getTaskStatuses() throws RegistryException {
    List<TaskStatusResource> taskStatusResources = new ArrayList();
    List<ExperimentCatResource> resources = get(ResourceType.TASK_STATUS);
    for (ExperimentCatResource resource : resources) {
        TaskStatusResource statusResource = (TaskStatusResource) resource;
        taskStatusResources.add(statusResource);
    }
    return taskStatusResources;
}
Also used : ArrayList(java.util.ArrayList) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 8 with ExperimentCatResource

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

the class GatewayResource method get.

/**
 * @param type child resource type
 * @return list of child resources
 */
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 PROJECT:
                generator = new QueryGenerator(PROJECT);
                Gateway gatewayModel = em.find(Gateway.class, gatewayId);
                generator.setParameter("gateway", gatewayModel);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Project project = (Project) result;
                        ProjectResource projectResource = (ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
                        resourceList.add(projectResource);
                    }
                }
                break;
            case GATEWAY_WORKER:
                generator = new QueryGenerator(GATEWAY_WORKER);
                generator.setParameter(GatewayWorkerConstants.GATEWAY_ID, gatewayId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        GatewayWorker gatewayWorker = (GatewayWorker) result;
                        WorkerResource workerResource = (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
                        resourceList.add(workerResource);
                    }
                }
                break;
            case USER:
                generator = new QueryGenerator(USERS);
                q = generator.selectQuery(em);
                for (Object o : q.getResultList()) {
                    Users user = (Users) o;
                    UserResource userResource = (UserResource) Utils.getResource(ResourceType.USER, user);
                    resourceList.add(userResource);
                }
                break;
            default:
                logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
        }
        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 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 9 with ExperimentCatResource

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

the class GatewayResource method getExperiments.

public List<ExperimentResource> getExperiments() throws RegistryException {
    List<ExperimentResource> experiments = new ArrayList<ExperimentResource>();
    List<ExperimentCatResource> resources = get(ResourceType.EXPERIMENT);
    for (ExperimentCatResource resource : resources) {
        experiments.add((ExperimentResource) resource);
    }
    return experiments;
}
Also used : ArrayList(java.util.ArrayList) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 10 with ExperimentCatResource

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

the class NotificationResource method getAllNotifications.

public List<ExperimentCatResource> getAllNotifications(String gatewayId) throws RegistryException {
    List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator = new QueryGenerator(NOTIFICATION);
        generator.setParameter(NotificationConstants.GATEWAY_ID, gatewayId);
        Query q = generator.selectQuery(em);
        List<?> results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                Notification notification = (Notification) result;
                NotificationResource notificationResource = (NotificationResource) Utils.getResource(ResourceType.NOTIFICATION, notification);
                resourceList.add(notificationResource);
            }
        }
        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 resourceList;
}
Also used : EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) Notification(org.apache.airavata.registry.core.experiment.catalog.model.Notification) RegistryException(org.apache.airavata.registry.cpi.RegistryException) 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