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