Search in sources :

Example 6 with ApplicationDeployment

use of org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment in project airavata by apache.

the class AppEnvironmentResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        AppEnvironment existigAppEnv = em.find(AppEnvironment.class, new AppEnvironment_PK(deploymentId, name));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        ApplicationDeployment deployment = em.find(ApplicationDeployment.class, deploymentId);
        if (existigAppEnv != null) {
            existigAppEnv.setValue(value);
            existigAppEnv.setApplicationDeployment(deployment);
            existigAppEnv.setOrder(order);
            em.merge(existigAppEnv);
        } else {
            AppEnvironment appEnvironment = new AppEnvironment();
            appEnvironment.setDeploymentID(deploymentId);
            appEnvironment.setName(name);
            appEnvironment.setValue(value);
            appEnvironment.setOrder(order);
            appEnvironment.setApplicationDeployment(deployment);
            em.persist(appEnvironment);
        }
        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) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppEnvironment_PK(org.apache.airavata.registry.core.app.catalog.model.AppEnvironment_PK) AppEnvironment(org.apache.airavata.registry.core.app.catalog.model.AppEnvironment) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 7 with ApplicationDeployment

use of org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment in project airavata by apache.

the class AppDeploymentResource method getIds.

@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> appDeployments = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_DEPLOYMENT);
        List results;
        if (fieldName.equals(ApplicationDeploymentConstants.APP_MODULE_ID)) {
            generator.setParameter(ApplicationDeploymentConstants.APP_MODULE_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    ApplicationDeployment deployment = (ApplicationDeployment) result;
                    appDeployments.add(deployment.getDeploymentID());
                }
            }
        } else if (fieldName.equals(ApplicationDeploymentConstants.COMPUTE_HOST_ID)) {
            generator.setParameter(ApplicationDeploymentConstants.COMPUTE_HOST_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    ApplicationDeployment deployment = (ApplicationDeployment) result;
                    appDeployments.add(deployment.getDeploymentID());
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for app deployment resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for app deployment 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 appDeployments;
}
Also used : EntityManager(javax.persistence.EntityManager) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) 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) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 8 with ApplicationDeployment

use of org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment in project airavata by apache.

the class AppDeploymentResource method getAllIds.

@Override
public List<String> getAllIds() throws AppCatalogException {
    List<String> appDeployments = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_DEPLOYMENT);
        Query q = generator.selectQuery(em);
        List results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                ApplicationDeployment deployment = (ApplicationDeployment) result;
                appDeployments.add(deployment.getDeploymentID());
            }
        }
        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 appDeployments;
}
Also used : EntityManager(javax.persistence.EntityManager) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) 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) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 9 with ApplicationDeployment

use of org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment in project airavata by apache.

the class AppDeploymentResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> appDeployments = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_DEPLOYMENT);
        generator.setParameter(ApplicationDeploymentConstants.GATEWAY_ID, gatewayId);
        Query q = generator.selectQuery(em);
        List results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                ApplicationDeployment deployment = (ApplicationDeployment) result;
                AppDeploymentResource deploymentResource = (AppDeploymentResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_DEPLOYMENT, deployment);
                appDeployments.add(deploymentResource);
            }
        }
        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 appDeployments;
}
Also used : EntityManager(javax.persistence.EntityManager) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) 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) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 10 with ApplicationDeployment

use of org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment in project airavata by apache.

the class LibraryApendPathResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        LibraryApendPath existigApendPath = em.find(LibraryApendPath.class, new LibraryApendPath_PK(deploymentId, name));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        ApplicationDeployment deployment = em.find(ApplicationDeployment.class, deploymentId);
        if (existigApendPath != null) {
            existigApendPath.setValue(value);
            existigApendPath.setApplicationDeployment(deployment);
            em.merge(existigApendPath);
        } else {
            LibraryApendPath apendPath = new LibraryApendPath();
            apendPath.setDeploymentID(deploymentId);
            apendPath.setName(name);
            apendPath.setValue(value);
            apendPath.setApplicationDeployment(deployment);
            em.persist(apendPath);
        }
        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) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) LibraryApendPath_PK(org.apache.airavata.registry.core.app.catalog.model.LibraryApendPath_PK) LibraryApendPath(org.apache.airavata.registry.core.app.catalog.model.LibraryApendPath) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

EntityManager (javax.persistence.EntityManager)13 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)13 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)13 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)13 Query (javax.persistence.Query)5 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AppEnvironment (org.apache.airavata.registry.core.app.catalog.model.AppEnvironment)1 AppEnvironment_PK (org.apache.airavata.registry.core.app.catalog.model.AppEnvironment_PK)1 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)1 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)1 LibraryApendPath (org.apache.airavata.registry.core.app.catalog.model.LibraryApendPath)1 LibraryApendPath_PK (org.apache.airavata.registry.core.app.catalog.model.LibraryApendPath_PK)1 LibraryPrepandPath (org.apache.airavata.registry.core.app.catalog.model.LibraryPrepandPath)1 LibraryPrepandPath_PK (org.apache.airavata.registry.core.app.catalog.model.LibraryPrepandPath_PK)1 ModuleLoadCmd (org.apache.airavata.registry.core.app.catalog.model.ModuleLoadCmd)1 ModuleLoadCmd_PK (org.apache.airavata.registry.core.app.catalog.model.ModuleLoadCmd_PK)1 PostJobCommand (org.apache.airavata.registry.core.app.catalog.model.PostJobCommand)1 PostJobCommandPK (org.apache.airavata.registry.core.app.catalog.model.PostJobCommandPK)1