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();
}
}
}
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();
}
}
}
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;
}
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();
}
}
}
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;
}
Aggregations