Search in sources :

Example 1 with ApplicationModule

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

the class AppModuleResource method getIds.

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

Example 2 with ApplicationModule

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

the class AppModuleResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
        generator.setParameter(ApplicationModuleConstants.MODULE_ID, identifier);
        Query q = generator.selectQuery(em);
        ApplicationModule applicationModule = (ApplicationModule) q.getSingleResult();
        AppModuleResource appModuleResource = (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, applicationModule);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return appModuleResource;
    } 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) ApplicationModule(org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)

Example 3 with ApplicationModule

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

the class AppModuleResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> moduleResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
        List results;
        if (fieldName.equals(ApplicationModuleConstants.MODULE_NAME)) {
            generator.setParameter(ApplicationModuleConstants.MODULE_NAME, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    ApplicationModule applicationModule = (ApplicationModule) result;
                    AppModuleResource moduleResource = (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, applicationModule);
                    moduleResources.add(moduleResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for app module resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for app module 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 moduleResources;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ApplicationModule(org.apache.airavata.registry.core.app.catalog.model.ApplicationModule) 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)

Example 4 with ApplicationModule

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

the class AppModuleResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> appModuleResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
        generator.setParameter(ApplicationModuleConstants.GATEWAY_ID, gatewayId);
        Query q = generator.selectQuery(em);
        List<?> results = q.getResultList();
        for (Object result : results) {
            ApplicationModule module = (ApplicationModule) result;
            AppModuleResource appModuleResource = (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, module);
            appModuleResources.add(appModuleResource);
        }
        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 appModuleResources;
}
Also used : 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) ApplicationModule(org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)

Example 5 with ApplicationModule

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

the class AppDeploymentResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        ApplicationDeployment existingDeployment = em.find(ApplicationDeployment.class, deploymentId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        ApplicationModule applicationModule = em.find(ApplicationModule.class, appModuleId);
        ComputeResource computeHost = em.find(ComputeResource.class, hostId);
        if (existingDeployment != null) {
            existingDeployment.setDeploymentID(deploymentId);
            existingDeployment.setApplicationDesc(appDes);
            existingDeployment.setAppModuleID(appModuleId);
            existingDeployment.setApplicationModule(applicationModule);
            existingDeployment.setComputeResource(computeHost);
            existingDeployment.setHostID(hostId);
            existingDeployment.setExecutablePath(executablePath);
            existingDeployment.setParallelism(parallelism);
            existingDeployment.setGatewayId(gatewayId);
            existingDeployment.setDefaultQueueName(defaultQueueName);
            existingDeployment.setDefaultCPUCount(defaultCPUCount);
            existingDeployment.setDefaultNodeCount(defaultNodeCount);
            existingDeployment.setDefaultWalltime(defaultWalltime);
            existingDeployment.setEditableByUser(editableByUser);
            existingDeployment.setUpdateTime(AiravataUtils.getCurrentTimestamp());
            em.merge(existingDeployment);
        } else {
            ApplicationDeployment deployment = new ApplicationDeployment();
            deployment.setApplicationDesc(appDes);
            deployment.setDeploymentID(deploymentId);
            deployment.setAppModuleID(appModuleId);
            deployment.setHostID(hostId);
            deployment.setApplicationModule(applicationModule);
            deployment.setComputeResource(computeHost);
            deployment.setExecutablePath(executablePath);
            deployment.setParallelism(parallelism);
            deployment.setGatewayId(gatewayId);
            deployment.setDefaultQueueName(defaultQueueName);
            deployment.setDefaultCPUCount(defaultCPUCount);
            deployment.setDefaultNodeCount(defaultNodeCount);
            deployment.setDefaultWalltime(defaultWalltime);
            deployment.setEditableByUser(editableByUser);
            deployment.setCreationTime(AiravataUtils.getCurrentTimestamp());
            em.persist(deployment);
        }
        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) ComputeResource(org.apache.airavata.registry.core.app.catalog.model.ComputeResource) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ApplicationModule(org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)

Aggregations

EntityManager (javax.persistence.EntityManager)8 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)8 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)8 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)8 Query (javax.persistence.Query)4 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 AppModuleMapping (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping)1 AppModuleMapping_PK (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping_PK)1 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)1 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)1 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)1