Search in sources :

Example 31 with AppCatalogException

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

the class StorageResourceResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        StorageResource existingStorageResource = em.find(StorageResource.class, storageResourceId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        StorageResource storageResource;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingStorageResource == null) {
            storageResource = new StorageResource();
            storageResource.setCreationTime(AiravataUtils.getCurrentTimestamp());
        } else {
            storageResource = existingStorageResource;
            storageResource.setUpdateTime(AiravataUtils.getCurrentTimestamp());
        }
        storageResource.setDescription(getResourceDescription());
        storageResource.setStorageResourceId(getStorageResourceId());
        storageResource.setHostName(getHostName());
        storageResource.setEnabled(isEnabled());
        if (existingStorageResource == null) {
            em.persist(storageResource);
        } else {
            em.merge(storageResource);
        }
        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();
        }
    }
}
Also used : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 32 with AppCatalogException

use of org.apache.airavata.registry.cpi.AppCatalogException 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)

Example 33 with AppCatalogException

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

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

use of org.apache.airavata.registry.cpi.AppCatalogException 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)

Aggregations

AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)353 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)268 EntityManager (javax.persistence.EntityManager)261 Query (javax.persistence.Query)176 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)176 ArrayList (java.util.ArrayList)94 HashMap (java.util.HashMap)70 Map (java.util.Map)54 List (java.util.List)42 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)22 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)14 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)13 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)10 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)8 GatewayProfile (org.apache.airavata.registry.core.app.catalog.model.GatewayProfile)6 ResourceJobManager (org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager)6 StorageResource (org.apache.airavata.registry.core.app.catalog.model.StorageResource)6 Initialize (org.apache.airavata.app.catalog.util.Initialize)5 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)5 GSISSHSubmission (org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission)5