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;
}
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();
}
}
}
Aggregations