Search in sources :

Example 96 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ExpCatResourceUtils method isGatewayExist.

/**
 * @param gatewayId
 * @return
 */
public static boolean isGatewayExist(String gatewayId) throws RegistryException {
    EntityManager em = null;
    try {
        em = getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY);
        generator.setParameter(AbstractExpCatResource.GatewayConstants.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 97 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException 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 98 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ExpCatResourceUtils method addGatewayWorker.

/**
 * @param gatewayResource
 * @param userResource
 */
public static WorkerResource addGatewayWorker(GatewayResource gatewayResource, UserResource userResource) throws RegistryException {
    EntityManager em = null;
    try {
        em = getEntityManager();
        em.getTransaction().begin();
        if (!isGatewayExist(gatewayResource.getGatewayName())) {
            gatewayResource.save();
        }
        if (!isUserExist(userResource.getUserName(), gatewayResource.getGatewayId())) {
            userResource.save();
        }
        Gateway gateway = em.find(Gateway.class, gatewayResource.getGatewayId());
        GatewayWorker gatewayWorker = new GatewayWorker();
        gatewayWorker.setGateway(gateway);
        gatewayWorker.setUserName(userResource.getUserName());
        em.persist(gatewayWorker);
        em.getTransaction().commit();
        em.close();
        return (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
    } 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 : RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 99 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ExpCatResourceUtils method getUser.

public static ExperimentCatResource getUser(String userName, String gatewayId) throws RegistryException {
    EntityManager em = null;
    try {
        if (isUserExist(userName, gatewayId)) {
            em = getEntityManager();
            UserPK userPK = new UserPK();
            userPK.setUserName(userName);
            userPK.setGatewayId(gatewayId);
            Users user = em.find(Users.class, userPK);
            UserResource userResource = (UserResource) Utils.getResource(ResourceType.USER, user);
            em.close();
            return userResource;
        }
    } 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 null;
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 100 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class GatewayResource method isExists.

/**
 * check whether child resource already exist in the database
 * @param type child resource type
 * @param name name of the child resource
 * @return true or false
 */
public boolean isExists(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        switch(type) {
            case GATEWAY_WORKER:
                em = ExpCatResourceUtils.getEntityManager();
                GatewayWorkerPK gatewayWorkerPK = new GatewayWorkerPK();
                gatewayWorkerPK.setGatewayId(gatewayId);
                gatewayWorkerPK.setUserName(name.toString());
                GatewayWorker existingWorker = em.find(GatewayWorker.class, gatewayWorkerPK);
                em.close();
                return existingWorker != null;
            case USER:
                em = ExpCatResourceUtils.getEntityManager();
                UserPK userPK = new UserPK();
                userPK.setGatewayId(getGatewayId());
                userPK.setUserName(name.toString());
                Users existingUser = em.find(Users.class, userPK);
                em.close();
                return existingUser != null;
            case EXPERIMENT:
                em = ExpCatResourceUtils.getEntityManager();
                Experiment existingExp = em.find(Experiment.class, name.toString());
                em.close();
                return existingExp != null;
            default:
                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) 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