Search in sources :

Example 21 with AppCatalogException

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

the class SshJobSubmissionResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> sshJobSubmissionResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(SSH_JOB_SUBMISSION);
        Query q;
        if ((fieldName.equals(SshJobSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(SshJobSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID)) || (fieldName.equals(SshJobSubmissionConstants.ALTERNATIVE_SSH_HOSTNAME)) || (fieldName.equals(SshJobSubmissionConstants.SECURITY_PROTOCOL)) || (fieldName.equals(SshJobSubmissionConstants.SSH_PORT))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                SshJobSubmission sshJobSubmission = (SshJobSubmission) result;
                SshJobSubmissionResource sshJobSubmissionResource = (SshJobSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.SSH_JOB_SUBMISSION, sshJobSubmission);
                sshJobSubmissionResources.add(sshJobSubmissionResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Ssh Job Submission Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Ssh Job Submission 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 sshJobSubmissionResources;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) SshJobSubmission(org.apache.airavata.registry.core.app.catalog.model.SshJobSubmission) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 22 with AppCatalogException

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

the class StorageInterfaceResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        StorageInterface existingStorageInterface = em.find(StorageInterface.class, new StorageInterface_PK(storageResourceId, dataMovementInterfaceId));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        StorageInterface storageInterface;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingStorageInterface == null) {
            storageInterface = new StorageInterface();
            storageInterface.setCreationTime(AiravataUtils.getCurrentTimestamp());
        } else {
            storageInterface = existingStorageInterface;
            storageInterface.setUpdateTime(AiravataUtils.getCurrentTimestamp());
        }
        storageInterface.setStorageResourceId(getStorageResourceId());
        StorageResource storageResource = em.find(StorageResource.class, getStorageResourceId());
        storageInterface.setStorageResource(storageResource);
        storageInterface.setDataMovementProtocol(getDataMovementProtocol());
        storageInterface.setDataMovementInterfaceId(getDataMovementInterfaceId());
        storageInterface.setPriorityOrder(priorityOrder);
        if (existingStorageInterface == null) {
            em.persist(storageInterface);
        } else {
            em.merge(storageInterface);
        }
        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 : 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 23 with AppCatalogException

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

the class StorageInterfaceResource method remove.

@Override
public void remove(Object identifier) throws AppCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap<String, String>) identifier;
    } else {
        logger.error("Identifier should be a map with the field name and it's value");
        throw new AppCatalogException("Identifier should be a map with the field name and it's value");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_INTERFACE);
        generator.setParameter(StorageInterfaceConstants.STORAGE_RESOURCE_ID, ids.get(StorageInterfaceConstants.STORAGE_RESOURCE_ID));
        generator.setParameter(StorageInterfaceConstants.DATA_MOVEMENT_ID, ids.get(StorageInterfaceConstants.DATA_MOVEMENT_ID));
        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) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with AppCatalogException

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

the class StorageInterfaceResource method isExists.

@Override
public boolean isExists(Object identifier) throws AppCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap<String, String>) identifier;
    } else {
        logger.error("Identifier should be a map with the field name and it's value");
        throw new AppCatalogException("Identifier should be a map with the field name and it's value");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        StorageInterface storageInterface = em.find(StorageInterface.class, new StorageInterface_PK(ids.get(StorageInterfaceConstants.STORAGE_RESOURCE_ID), ids.get(StorageInterfaceConstants.DATA_MOVEMENT_ID)));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return storageInterface != null;
    } 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with AppCatalogException

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

the class StorageResourceResource method isExists.

@Override
public boolean isExists(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        StorageResource storageResource = em.find(StorageResource.class, identifier);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return storageResource != null;
    } 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)

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