use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class GatewayResource method remove.
/**
* Child resources can be removed from a gateway
* @param type child resource type
* @param name child resource name
*/
public void remove(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
Query q;
QueryGenerator generator;
switch(type) {
case USER:
generator = new QueryGenerator(USERS);
generator.setParameter(UserConstants.USERNAME, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
default:
logger.error("Unsupported resource type for gateway 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();
}
}
}
use of org.apache.airavata.registry.cpi.RegistryException 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.cpi.RegistryException in project airavata by apache.
the class JobResource method get.
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case JOB_STATUS:
generator = new QueryGenerator(JOB_STATUS);
generator.setParameter(JobStatusConstants.STATUS_ID, name);
q = generator.selectQuery(em);
JobStatus status = (JobStatus) q.getSingleResult();
JobStatusResource statusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, status);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return statusResource;
default:
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported resource type for Job resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for Job 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();
}
}
}
use of org.apache.airavata.registry.cpi.RegistryException 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;
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class NotificationResource method remove.
/**
* @param type child resource type
* @param name child resource name
*/
public void remove(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(NOTIFICATION);
generator.setParameter(NotificationConstants.NOTIFICATION_ID, name);
Query q = generator.deleteQuery(em);
q.executeUpdate();
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();
}
}
}
Aggregations