Search in sources :

Example 16 with AppCatalogQueryGenerator

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

the class UnicoreDataMovementResource method get.

public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(UNICORE_DATA_MOVEMENT);
        generator.setParameter(UnicoreDataMovementConstants.DATAMOVEMENT_ID, identifier);
        Query q = generator.selectQuery(em);
        UnicoreDataMovement unicoreDataMovement = (UnicoreDataMovement) q.getSingleResult();
        UnicoreDataMovementResource dataMovementResource = (UnicoreDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_DATA_MOVEMENT, unicoreDataMovement);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return dataMovementResource;
    } 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 : UnicoreDataMovement(org.apache.airavata.registry.core.app.catalog.model.UnicoreDataMovement) 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 17 with AppCatalogQueryGenerator

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

the class UnicoreJobSubmissionResource method getIds.

public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> globusSubmissionResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GLOBUS_SUBMISSION);
        List results;
        if (fieldName.equals(GlobusJobSubmissionConstants.SUBMISSION_ID)) {
            generator.setParameter(GlobusJobSubmissionConstants.SUBMISSION_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GlobusJobSubmission globusJobSubmission = (GlobusJobSubmission) result;
                    globusSubmissionResourceIDs.add(globusJobSubmission.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GlobusJobSubmissionConstants.GLOBUS_GATEKEEPER_EP)) {
            generator.setParameter(GlobusJobSubmissionConstants.GLOBUS_GATEKEEPER_EP, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GlobusJobSubmission globusJobSubmission = (GlobusJobSubmission) result;
                    globusSubmissionResourceIDs.add(globusJobSubmission.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GlobusJobSubmissionConstants.SECURITY_PROTOCAL)) {
            generator.setParameter(GlobusJobSubmissionConstants.SECURITY_PROTOCAL, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GlobusJobSubmission globusJobSubmission = (GlobusJobSubmission) result;
                    globusSubmissionResourceIDs.add(globusJobSubmission.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GlobusJobSubmissionConstants.RESOURCE_JOB_MANAGER)) {
            generator.setParameter(GlobusJobSubmissionConstants.RESOURCE_JOB_MANAGER, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GlobusJobSubmission globusJobSubmission = (GlobusJobSubmission) result;
                    globusSubmissionResourceIDs.add(globusJobSubmission.getSubmissionID());
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Globus Submission resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Globus Submission resource.");
        }
        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 AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return globusSubmissionResourceIDs;
}
Also used : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) GlobusJobSubmission(org.apache.airavata.registry.core.app.catalog.model.GlobusJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 18 with AppCatalogQueryGenerator

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

the class UnicoreJobSubmissionResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> unicoreSubmissionResourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(UNICORE_JOB_SUBMISSION);
        List results;
        if (fieldName.equals(UnicoreJobSubmissionConstants.UNICORE_ENDPOINT_URL)) {
            generator.setParameter(UnicoreJobSubmissionConstants.UNICORE_ENDPOINT_URL, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UnicoreJobSubmission unicoreJobSubmission = (UnicoreJobSubmission) result;
                    UnicoreJobSubmissionResource unicoreJobSubmissionResource = (UnicoreJobSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_JOB_SUBMISSION, unicoreJobSubmission);
                    unicoreSubmissionResourceList.add(unicoreJobSubmissionResource);
                }
            }
        } else if (fieldName.equals(UnicoreJobSubmissionConstants.SECURITY_PROTOCAL)) {
            generator.setParameter(UnicoreJobSubmissionConstants.SECURITY_PROTOCAL, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UnicoreJobSubmission unicoreJobSubmission = (UnicoreJobSubmission) result;
                    UnicoreJobSubmissionResource unicoreJobSubmissionResource = (UnicoreJobSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_JOB_SUBMISSION, unicoreJobSubmission);
                    unicoreSubmissionResourceList.add(unicoreJobSubmissionResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Unicore submission resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Unicore Submission resource.");
        }
        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 AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return unicoreSubmissionResourceList;
}
Also used : 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) UnicoreJobSubmission(org.apache.airavata.registry.core.app.catalog.model.UnicoreJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 19 with AppCatalogQueryGenerator

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

the class UserComputeHostPreferenceResource method remove.

@Override
public void remove(Object identifier) throws AppCatalogException {
    CompositeIdentifier ids;
    if (identifier instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) identifier;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_COMPUTE_RESOURCE_PREFERENCE);
        generator.setParameter(UserComputeResourcePreferenceConstants.RESOURCE_ID, ids.getTopLevelIdentifier().toString());
        generator.setParameter(UserComputeResourcePreferenceConstants.USER_ID, ids.getSecondLevelIdentifier().toString());
        generator.setParameter(UserComputeResourcePreferenceConstants.GATEWAY_ID, ids.getThirdLevelIdentifier().toString());
        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) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EntityManager(javax.persistence.EntityManager) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 20 with AppCatalogQueryGenerator

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

the class UserResourceProfileResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> userResourceProfileResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    CompositeIdentifier ids;
    if (value instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) value;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        List results;
        if (fieldName.equals(UserResourceProfileConstants.USER_ID)) {
            generator.setParameter(UserStoragePreferenceConstants.USER_ID, ids.getTopLevelIdentifier().toString());
            generator.setParameter(UserStoragePreferenceConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UserResourceProfile userResourceProfile = (UserResourceProfile) result;
                    UserResourceProfileResource userResourceProfileResource = (UserResourceProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_RESOURCE_PROFILE, userResourceProfile);
                    userResourceProfileResources.add(userResourceProfileResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for User Resource Profile resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for User Resource Profile resource.");
        }
        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 AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return userResourceProfileResources;
}
Also used : CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) 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) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)

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