use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class ProjectRegistry method getProjectIDs.
public List<String> getProjectIDs(String fieldName, Object value) throws RegistryException {
List<String> projectIds = new ArrayList<String>();
try {
if (fieldName.equals(Constants.FieldConstants.ProjectConstants.OWNER)) {
workerResource.setUser((String) value);
List<ProjectResource> projectList = workerResource.getProjects();
if (projectList != null && !projectList.isEmpty()) {
for (ProjectResource pr : projectList) {
projectIds.add(pr.getName());
}
}
return projectIds;
}
} catch (Exception e) {
logger.error("Error while retrieving projects from registry", e);
throw new RegistryException(e);
}
return projectIds;
}
use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.
the class ExpCatResourceUtils method getAllGateways.
public static List<ExperimentCatResource> getAllGateways() throws RegistryException {
List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY);
Query q = generator.selectQuery(em);
List results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
Gateway gateway = (Gateway) result;
GatewayResource gatewayResource = (GatewayResource) Utils.getResource(ResourceType.GATEWAY, gateway);
resourceList.add(gatewayResource);
}
}
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 ExpCatResourceUtils method getAllUsersInGateway.
public static List<String> getAllUsersInGateway(String gatewayId) throws RegistryException {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.USERS);
generator.setParameter(AbstractExpCatResource.UserConstants.GATEWAY_ID, gatewayId);
Query q = generator.selectQuery(em);
List<Users> users = q.getResultList();
em.getTransaction().commit();
em.close();
ArrayList<String> usernameList = new ArrayList<>();
if (users != null) {
for (int i = 0; i < users.size(); i++) {
usernameList.add(users.get(i).getUserName());
}
}
return usernameList;
} 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 WorkerResource 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();
Query q;
QueryGenerator generator;
switch(type) {
case PROJECT:
generator = new QueryGenerator(PROJECT);
generator.setParameter(ProjectConstants.PROJECT_ID, 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 worker resource.", new IllegalArgumentException());
break;
}
em.getTransaction().commit();
em.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e.getMessage());
} 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 WorkerResource method save.
/**
* save gateway worker to database
*/
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
GatewayWorkerPK gatewayWorkerPK = new GatewayWorkerPK();
gatewayWorkerPK.setGatewayId(gatewayId);
gatewayWorkerPK.setUserName(user);
GatewayWorker existingWorker = em.find(GatewayWorker.class, gatewayWorkerPK);
em.close();
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
GatewayWorker gatewayWorker = new GatewayWorker();
gatewayWorker.setUserName(user);
gatewayWorker.setGatewayId(gatewayId);
if (existingWorker != null) {
existingWorker.setUserName(user);
existingWorker.setGatewayId(gatewayId);
gatewayWorker = em.merge(existingWorker);
} else {
em.persist(gatewayWorker);
}
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