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