Search in sources :

Example 1 with QueueStatus

use of org.apache.airavata.registry.core.experiment.catalog.model.QueueStatus 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 2 with QueueStatus

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

the class QueueStatusResource method save.

/**
 * This method will save the resource to the database.
 */
@Override
public void save() throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        QueueStatus queueStatus = new QueueStatus();
        queueStatus.setHostName(hostName);
        queueStatus.setQueueName(queueName);
        queueStatus.setTime(time);
        queueStatus.setQueueUp(queueUp);
        queueStatus.setRunningJobs(runningJobs);
        queueStatus.setQueuedJobs(queuedJobs);
        em.getTransaction().begin();
        em.persist(queueStatus);
        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) QueueStatus(org.apache.airavata.registry.core.experiment.catalog.model.QueueStatus) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

EntityManager (javax.persistence.EntityManager)2 QueueStatus (org.apache.airavata.registry.core.experiment.catalog.model.QueueStatus)2 RegistryException (org.apache.airavata.registry.cpi.RegistryException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Query (javax.persistence.Query)1 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)1