Search in sources :

Example 1 with ComputeResource

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

the class ComputeResourceFileSystemResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        ComputeResourceFileSystem existingComputeResourceFileSystem = em.find(ComputeResourceFileSystem.class, new ComputeResourceFileSystem_PK(computeResourceId, fileSystem));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        ComputeResourceFileSystem computeResourceFileSystem;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingComputeResourceFileSystem == null) {
            computeResourceFileSystem = new ComputeResourceFileSystem();
        } else {
            computeResourceFileSystem = existingComputeResourceFileSystem;
        }
        computeResourceFileSystem.setComputeResourceId(getComputeResourceId());
        ComputeResource computeResource = em.find(ComputeResource.class, getComputeResourceId());
        computeResourceFileSystem.setComputeResource(computeResource);
        computeResourceFileSystem.setPath(getPath());
        computeResourceFileSystem.setFileSystem(getFileSystem());
        if (existingComputeResourceFileSystem == null) {
            em.persist(computeResourceFileSystem);
        } else {
            em.merge(computeResourceFileSystem);
        }
        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) ComputeResource(org.apache.airavata.registry.core.app.catalog.model.ComputeResource) ComputeResourceFileSystem_PK(org.apache.airavata.registry.core.app.catalog.model.ComputeResourceFileSystem_PK) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ComputeResourceFileSystem(org.apache.airavata.registry.core.app.catalog.model.ComputeResourceFileSystem)

Example 2 with ComputeResource

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

the class ComputeResourceResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(COMPUTE_RESOURCE);
        generator.setParameter(ComputeResourceConstants.RESOURCE_ID, identifier);
        Query q = generator.selectQuery(em);
        ComputeResource computeResource = (ComputeResource) q.getSingleResult();
        ComputeResourceResource computeResourceResource = (ComputeResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE, computeResource);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return computeResourceResource;
    } 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) ComputeResource(org.apache.airavata.registry.core.app.catalog.model.ComputeResource) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 3 with ComputeResource

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

the class ComputeResourceResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> computeResourceResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(COMPUTE_RESOURCE);
        Query q;
        if ((fieldName.equals(ComputeResourceConstants.RESOURCE_DESCRIPTION)) || (fieldName.equals(ComputeResourceConstants.RESOURCE_ID)) || (fieldName.equals(ComputeResourceConstants.HOST_NAME))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                ComputeResource computeResource = (ComputeResource) result;
                ComputeResourceResource computeResourceResource = (ComputeResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE, computeResource);
                computeResourceResources.add(computeResourceResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Compute Resource Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Compute Resource 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 computeResourceResources;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ComputeResource(org.apache.airavata.registry.core.app.catalog.model.ComputeResource) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 4 with ComputeResource

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

the class ComputeResourceResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        ComputeResource existingComputeResource = em.find(ComputeResource.class, resourceId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        ComputeResource computeResource;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingComputeResource == null) {
            computeResource = new ComputeResource();
            computeResource.setCreationTime(AiravataUtils.getCurrentTimestamp());
        } else {
            computeResource = existingComputeResource;
            computeResource.setUpdateTime(AiravataUtils.getCurrentTimestamp());
        }
        computeResource.setResourceDescription(getResourceDescription());
        computeResource.setResourceId(getResourceId());
        computeResource.setHostName(getHostName());
        computeResource.setEnabled(isEnabled());
        computeResource.setMaxMemoryPerNode(getMaxMemoryPerNode());
        computeResource.setCpusPerNode(cpusPerNode);
        computeResource.setDefaultNodeCount(defaultNodeCount);
        computeResource.setDefaultCPUCount(defaultCPUCount);
        computeResource.setDefaultWalltime(defaultWalltime);
        computeResource.setGatewayUsageReporting(gatewayUsageReporting);
        computeResource.setGatewayUsageModLoadCMD(gatewayUsageModLoadCMD);
        computeResource.setGatewayUsageExec(gatewayUsageExec);
        if (existingComputeResource == null) {
            em.persist(computeResource);
        } else {
            em.merge(computeResource);
        }
        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) ComputeResource(org.apache.airavata.registry.core.app.catalog.model.ComputeResource) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 5 with ComputeResource

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

the class ComputeResourceResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> computeResourceResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(COMPUTE_RESOURCE);
        Query q = generator.selectQuery(em);
        List<?> results = q.getResultList();
        for (Object result : results) {
            ComputeResource computeResource = (ComputeResource) result;
            ComputeResourceResource computeResourceResource = (ComputeResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.COMPUTE_RESOURCE, computeResource);
            computeResourceResources.add(computeResourceResource);
        }
        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 computeResourceResources;
}
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) ComputeResource(org.apache.airavata.registry.core.app.catalog.model.ComputeResource) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Aggregations

EntityManager (javax.persistence.EntityManager)14 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)14 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)14 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)14 Query (javax.persistence.Query)5 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)5 ArrayList (java.util.ArrayList)4 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)1 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)1 BatchQueue (org.apache.airavata.registry.core.app.catalog.model.BatchQueue)1 BatchQueue_PK (org.apache.airavata.registry.core.app.catalog.model.BatchQueue_PK)1 ComputeResourceFileSystem (org.apache.airavata.registry.core.app.catalog.model.ComputeResourceFileSystem)1 ComputeResourceFileSystem_PK (org.apache.airavata.registry.core.app.catalog.model.ComputeResourceFileSystem_PK)1 DataMovementInterface (org.apache.airavata.registry.core.app.catalog.model.DataMovementInterface)1 DataMovementInterface_PK (org.apache.airavata.registry.core.app.catalog.model.DataMovementInterface_PK)1 HostAlias (org.apache.airavata.registry.core.app.catalog.model.HostAlias)1 HostAliasPK (org.apache.airavata.registry.core.app.catalog.model.HostAliasPK)1 HostIPAddress (org.apache.airavata.registry.core.app.catalog.model.HostIPAddress)1 HostIPAddressPK (org.apache.airavata.registry.core.app.catalog.model.HostIPAddressPK)1 JobSubmissionInterface (org.apache.airavata.registry.core.app.catalog.model.JobSubmissionInterface)1