Search in sources :

Example 1 with ApplicationDeployment

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

the class LibraryPrepandPathResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        LibraryPrepandPath existigPrepPath = em.find(LibraryPrepandPath.class, new LibraryPrepandPath_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 (existigPrepPath != null) {
            existigPrepPath.setValue(value);
            existigPrepPath.setApplicationDeployment(deployment);
            em.merge(existigPrepPath);
        } else {
            LibraryPrepandPath prepandPath = new LibraryPrepandPath();
            prepandPath.setDeploymentID(deploymentId);
            prepandPath.setName(name);
            prepandPath.setValue(value);
            prepandPath.setApplicationDeployment(deployment);
            em.persist(prepandPath);
        }
        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) LibraryPrepandPath_PK(org.apache.airavata.registry.core.app.catalog.model.LibraryPrepandPath_PK) LibraryPrepandPath(org.apache.airavata.registry.core.app.catalog.model.LibraryPrepandPath) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 2 with ApplicationDeployment

use of org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment 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)

Example 3 with ApplicationDeployment

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

the class AppDeploymentResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> appDeployments = new ArrayList<AppCatalogResource>();
    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;
                    AppDeploymentResource deploymentResource = (AppDeploymentResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_DEPLOYMENT, deployment);
                    appDeployments.add(deploymentResource);
                }
            }
        } 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;
                    AppDeploymentResource deploymentResource = (AppDeploymentResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_DEPLOYMENT, deployment);
                    appDeployments.add(deploymentResource);
                }
            }
        } 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();
        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 : 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) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) 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 ApplicationDeployment

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

the class AppDeploymentResource 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_DEPLOYMENT);
        generator.setParameter(ApplicationDeploymentConstants.DEPLOYMENT_ID, identifier);
        Query q = generator.selectQuery(em);
        ApplicationDeployment deployment = (ApplicationDeployment) q.getSingleResult();
        AppDeploymentResource deploymentResource = (AppDeploymentResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_DEPLOYMENT, deployment);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return deploymentResource;
    } 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) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 5 with ApplicationDeployment

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

the class AppDeploymentResource method isExists.

@Override
public boolean isExists(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        ApplicationDeployment deployment = em.find(ApplicationDeployment.class, identifier);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return deployment != 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) EntityManager(javax.persistence.EntityManager) ApplicationDeployment(org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

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