Search in sources :

Example 36 with RegistryException

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;
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 37 with RegistryException

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;
}
Also used : QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 38 with RegistryException

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();
        }
    }
}
Also used : QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 39 with RegistryException

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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 40 with RegistryException

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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

RegistryException (org.apache.airavata.registry.cpi.RegistryException)134 EntityManager (javax.persistence.EntityManager)54 Query (javax.persistence.Query)29 QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)29 ArrayList (java.util.ArrayList)15 List (java.util.List)12 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)12 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)11 ExperimentCatalogException (org.apache.airavata.registry.cpi.ExperimentCatalogException)8 AiravataException (org.apache.airavata.common.exception.AiravataException)6 GFacException (org.apache.airavata.gfac.core.GFacException)6 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)6 Node (org.apache.airavata.workflow.model.graph.Node)6 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)6 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)6 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)6 Timestamp (java.sql.Timestamp)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 DataPort (org.apache.airavata.workflow.model.graph.DataPort)4 HashMap (java.util.HashMap)3