use of org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource in project airavata by apache.
the class WorkerResource method getExperiments.
/**
* Method to get list of experiments of user with pagination and ordering
*
* @param limit
* @param offset
* @param orderByIdentifier
* @param resultOrderType
* @return
* @throws org.apache.airavata.registry.cpi.RegistryException
*/
public List<ExperimentResource> getExperiments(int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
List<ExperimentResource> result = new ArrayList<ExperimentResource>();
List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType);
for (ExperimentCatResource resource : list) {
result.add((ExperimentResource) resource);
}
return result;
}
use of org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource in project airavata by apache.
the class WorkerResource method create.
/**
* Gateway worker can create child data structures such as projects and user workflows
*
* @param type child resource type
* @return child resource
*/
public ExperimentCatResource create(ResourceType type) throws RegistryException {
ExperimentCatResource result = null;
switch(type) {
case PROJECT:
org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource projectResource = new org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource();
projectResource.setWorker(this);
projectResource.setGatewayId(gatewayId);
result = projectResource;
break;
case EXPERIMENT:
ExperimentResource experimentResource = new ExperimentResource();
experimentResource.setUserName(user);
experimentResource.setGatewayExecutionId(gatewayId);
result = experimentResource;
break;
default:
logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for worker resource.");
}
return result;
}
use of org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource in project airavata by apache.
the class WorkerResource method get.
/**
* @param type child resource type
* @param name child resource name
* @return child resource
*/
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
ExperimentCatResource result = null;
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case PROJECT:
generator = new QueryGenerator(PROJECT);
generator.setParameter(ProjectConstants.PROJECT_ID, name);
q = generator.selectQuery(em);
Project project = (Project) q.getSingleResult();
result = Utils.getResource(ResourceType.PROJECT, project);
break;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
q = generator.selectQuery(em);
Experiment experiment = (Experiment) q.getSingleResult();
result = Utils.getResource(ResourceType.EXPERIMENT, experiment);
break;
default:
logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
break;
}
em.getTransaction().commit();
em.close();
} catch (Exception 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 WorkerResource method get.
/**
* Method get all results of the given child resource type with paginaltion and ordering
*
* @param type child resource type
* @param limit
* @param offset
* @param orderByIdentifier
* @param resultOrderType
* @return list of child resources
* @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> result = new ArrayList<ExperimentCatResource>();
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case PROJECT:
generator = new QueryGenerator(PROJECT);
UserPK userPK = new UserPK();
userPK.setGatewayId(getGatewayId());
userPK.setUserName(user);
Users users = em.find(Users.class, userPK);
Gateway gatewayModel = em.find(Gateway.class, gatewayId);
generator.setParameter("users", users);
if (gatewayModel != null) {
generator.setParameter("gateway", gatewayModel);
}
// 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);
}
for (Object o : q.getResultList()) {
Project project = (Project) o;
org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource projectResource = (org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
result.add(projectResource);
}
break;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.USER_NAME, getUser());
// ordering - only supported only by CREATION_TIME
if (orderByIdentifier != null && resultOrderType != null && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.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);
}
for (Object o : q.getResultList()) {
Experiment experiment = (Experiment) o;
ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
result.add(experimentResource);
}
break;
default:
logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
break;
}
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 JobResource method get.
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 JOB_STATUS:
generator = new QueryGenerator(JOB_STATUS);
generator.setParameter(JobStatusConstants.JOB_ID, jobId);
generator.setParameter(JobStatusConstants.TASK_ID, taskId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
JobStatus jobStatus = (JobStatus) result;
JobStatusResource jobStatusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, jobStatus);
resourceList.add(jobStatusResource);
}
}
break;
default:
logger.error("Unsupported resource type for job resource.", new UnsupportedOperationException());
throw new UnsupportedOperationException();
}
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();
}
}
return resourceList;
}
Aggregations