Search in sources :

Example 51 with RegistryException

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();
        }
    }
}
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 52 with RegistryException

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

Example 53 with RegistryException

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

Example 54 with RegistryException

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

Example 55 with RegistryException

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