Search in sources :

Example 21 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class ExpCatResourceUtils method isUserExist.

public static boolean isUserExist(String username, String gatewayId) throws RegistryException {
    EntityManager em = null;
    try {
        em = getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.USERS);
        generator.setParameter(AbstractExpCatResource.UserConstants.USERNAME, username);
        generator.setParameter(AbstractExpCatResource.UserConstants.GATEWAY_ID, gatewayId);
        Query q = generator.selectQuery(em);
        int size = q.getResultList().size();
        em.getTransaction().commit();
        em.close();
        return size > 0;
    } 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) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 22 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class ExpCatResourceUtils method removeGatewayWorker.

/**
 * @param gatewayResource
 * @param userResource
 * @return
 */
public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
    EntityManager em = null;
    try {
        em = getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY_WORKER);
        generator.setParameter(AbstractExpCatResource.GatewayWorkerConstants.GATEWAY_ID, gatewayResource.getGatewayName());
        generator.setParameter(AbstractExpCatResource.UserConstants.USERNAME, userResource.getUserName());
        Query q = generator.deleteQuery(em);
        q.executeUpdate();
        em.getTransaction().commit();
        em.close();
        return true;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return false;
    } 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) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 23 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class GatewayResource method get.

/**
 * Gateway can get information of his children
 * @param type child resource type
 * @param name child resource name
 * @return specific child resource type
 */
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 GATEWAY_WORKER:
                generator = new QueryGenerator(GATEWAY_WORKER);
                generator.setParameter(GatewayWorkerConstants.USERNAME, name);
                generator.setParameter(GatewayWorkerConstants.GATEWAY_ID, gatewayId);
                q = generator.selectQuery(em);
                GatewayWorker worker = (GatewayWorker) q.getSingleResult();
                WorkerResource workerResource = (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER, worker);
                em.getTransaction().commit();
                em.close();
                return workerResource;
            case USER:
                generator = new QueryGenerator(USERS);
                generator.setParameter(UserConstants.USERNAME, name);
                q = generator.selectQuery(em);
                Users user = (Users) q.getSingleResult();
                UserResource userResource = (UserResource) Utils.getResource(ResourceType.USER, user);
                em.getTransaction().commit();
                em.close();
                return userResource;
            case EXPERIMENT:
                generator = new QueryGenerator(EXPERIMENT);
                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
                q = generator.selectQuery(em);
                Experiment experiment = (Experiment) q.getSingleResult();
                ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
                em.getTransaction().commit();
                em.close();
                return experimentResource;
            default:
                em.getTransaction().commit();
                em.close();
                logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for gateway 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 : 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 24 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class JobResource method remove.

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 JOB_STATUS:
                generator = new QueryGenerator(JOB_STATUS);
                generator.setParameter(JobStatusConstants.STATUS_ID, name);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            default:
                logger.error("Unsupported resource type for job details resource.", new IllegalArgumentException());
                break;
        }
        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();
        }
    }
}
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 25 with QueryGenerator

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

Aggregations

QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)31 RegistryException (org.apache.airavata.registry.cpi.RegistryException)31 EntityManager (javax.persistence.EntityManager)25 Query (javax.persistence.Query)25 ArrayList (java.util.ArrayList)11 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)10 List (java.util.List)8 ExperimentCatalogException (org.apache.airavata.registry.cpi.ExperimentCatalogException)6 Job (org.apache.airavata.registry.core.experiment.catalog.model.Job)2 JobStatus (org.apache.airavata.registry.core.experiment.catalog.model.JobStatus)2 Notification (org.apache.airavata.registry.core.experiment.catalog.model.Notification)2 Process (org.apache.airavata.registry.core.experiment.catalog.model.Process)2 TaskError (org.apache.airavata.registry.core.experiment.catalog.model.TaskError)2 TaskStatus (org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus)2