use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class SshJobSubmissionResource method get.
@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
List<AppCatalogResource> sshJobSubmissionResources = new ArrayList<AppCatalogResource>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(SSH_JOB_SUBMISSION);
Query q;
if ((fieldName.equals(SshJobSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(SshJobSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID)) || (fieldName.equals(SshJobSubmissionConstants.ALTERNATIVE_SSH_HOSTNAME)) || (fieldName.equals(SshJobSubmissionConstants.SECURITY_PROTOCOL)) || (fieldName.equals(SshJobSubmissionConstants.SSH_PORT))) {
generator.setParameter(fieldName, value);
q = generator.selectQuery(em);
List<?> results = q.getResultList();
for (Object result : results) {
SshJobSubmission sshJobSubmission = (SshJobSubmission) result;
SshJobSubmissionResource sshJobSubmissionResource = (SshJobSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.SSH_JOB_SUBMISSION, sshJobSubmission);
sshJobSubmissionResources.add(sshJobSubmissionResource);
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for Ssh Job Submission Resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for Ssh Job Submission 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 sshJobSubmissionResources;
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class StorageInterfaceResource method remove.
@Override
public void remove(Object identifier) throws AppCatalogException {
HashMap<String, String> ids;
if (identifier instanceof Map) {
ids = (HashMap<String, String>) identifier;
} else {
logger.error("Identifier should be a map with the field name and it's value");
throw new AppCatalogException("Identifier should be a map with the field name and it's value");
}
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_INTERFACE);
generator.setParameter(StorageInterfaceConstants.STORAGE_RESOURCE_ID, ids.get(StorageInterfaceConstants.STORAGE_RESOURCE_ID));
generator.setParameter(StorageInterfaceConstants.DATA_MOVEMENT_ID, ids.get(StorageInterfaceConstants.DATA_MOVEMENT_ID));
Query q = generator.deleteQuery(em);
q.executeUpdate();
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();
}
}
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class StorageInterfaceResource method isExists.
@Override
public boolean isExists(Object identifier) throws AppCatalogException {
HashMap<String, String> ids;
if (identifier instanceof Map) {
ids = (HashMap<String, String>) identifier;
} else {
logger.error("Identifier should be a map with the field name and it's value");
throw new AppCatalogException("Identifier should be a map with the field name and it's value");
}
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
StorageInterface storageInterface = em.find(StorageInterface.class, new StorageInterface_PK(ids.get(StorageInterfaceConstants.STORAGE_RESOURCE_ID), ids.get(StorageInterfaceConstants.DATA_MOVEMENT_ID)));
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return storageInterface != 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();
}
}
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class StorageResourceResource method isExists.
@Override
public boolean isExists(Object identifier) throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
StorageResource storageResource = em.find(StorageResource.class, identifier);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return storageResource != 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();
}
}
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class StorageResourceResource method getAllIds.
@Override
public List<String> getAllIds() throws AppCatalogException {
List<String> storageResourceResources = new ArrayList<String>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
Query q = generator.selectQuery(em);
List<?> results = q.getResultList();
for (Object result : results) {
StorageResource storageResource = (StorageResource) result;
storageResourceResources.add(storageResource.getStorageResourceId());
}
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 storageResourceResources;
}
Aggregations