Search in sources :

Example 11 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class StorageResourceResource method remove.

@Override
public void remove(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        generator.setParameter(StorageResourceConstants.RESOURCE_ID, identifier);
        Query q = generator.deleteQuery(em);
        q.executeUpdate();
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 12 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class StorageResourceResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        generator.setParameter(StorageResourceConstants.RESOURCE_ID, identifier);
        Query q = generator.selectQuery(em);
        StorageResource storageResource = (StorageResource) q.getSingleResult();
        StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return storageResourceResource;
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 13 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class StorageResourceResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> storageResourceResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        Query q = generator.selectQuery(em);
        List<?> results = q.getResultList();
        for (Object result : results) {
            StorageResource storageResource = (StorageResource) result;
            StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
            storageResourceResources.add(storageResourceResource);
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return storageResourceResources;
}
Also used : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 14 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class StorageResourceResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> storageResourceResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        Query q;
        if ((fieldName.equals(StorageResourceConstants.RESOURCE_DESCRIPTION)) || (fieldName.equals(StorageResourceConstants.RESOURCE_ID)) || (fieldName.equals(StorageResourceConstants.HOST_NAME))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                StorageResource storageResource = (StorageResource) result;
                StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
                storageResourceResources.add(storageResourceResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Storage Resource Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Storage Resource Resource.");
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return storageResourceResources;
}
Also used : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 15 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class UnicoreDataMovementResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> unicoreDMResourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(UNICORE_DATA_MOVEMENT);
        List results;
        if (fieldName.equals(UnicoreDataMovementConstants.UNICORE_ENDPOINT_URL)) {
            generator.setParameter(UnicoreDataMovementConstants.UNICORE_ENDPOINT_URL, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UnicoreDataMovement dataMovement = (UnicoreDataMovement) result;
                    UnicoreDataMovementResource unicoreJobSubmissionResource = (UnicoreDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_DATA_MOVEMENT, dataMovement);
                    unicoreDMResourceList.add(unicoreJobSubmissionResource);
                }
            }
        } else if (fieldName.equals(UnicoreDataMovementConstants.SECURITY_PROTOCAL)) {
            generator.setParameter(UnicoreDataMovementConstants.SECURITY_PROTOCAL, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UnicoreDataMovement dataMovement = (UnicoreDataMovement) result;
                    UnicoreDataMovementResource dataMovementResource = (UnicoreDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_DATA_MOVEMENT, dataMovement);
                    unicoreDMResourceList.add(dataMovementResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Unicore data movement resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Unicore data movement resource.");
        }
        em.getTransaction().commit();
        em.close();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return unicoreDMResourceList;
}
Also used : UnicoreDataMovement(org.apache.airavata.registry.core.app.catalog.model.UnicoreDataMovement) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) List(java.util.List) ArrayList(java.util.ArrayList) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Aggregations

EntityManager (javax.persistence.EntityManager)176 Query (javax.persistence.Query)176 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)176 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)176 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)176 ArrayList (java.util.ArrayList)80 List (java.util.List)41 HashMap (java.util.HashMap)36 Map (java.util.Map)36 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)10 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)5 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)5 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)5 StorageResource (org.apache.airavata.registry.core.app.catalog.model.StorageResource)5 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)4 GatewayProfile (org.apache.airavata.registry.core.app.catalog.model.GatewayProfile)4 GlobusJobSubmission (org.apache.airavata.registry.core.app.catalog.model.GlobusJobSubmission)4 UserResourceProfile (org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)4 ApplicationIntInput (org.apache.airavata.registry.core.app.catalog.model.ApplicationIntInput)3 ApplicationIntOutput (org.apache.airavata.registry.core.app.catalog.model.ApplicationIntOutput)3