use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.
the class UnicoreJobSubmissionResource method isExists.
public boolean isExists(Object identifier) throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
UnicoreJobSubmission unicoreJobSubmission = em.find(UnicoreJobSubmission.class, identifier);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return unicoreJobSubmission != 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.registry.cpi.AppCatalogException in project airavata by apache.
the class UnicoreJobSubmissionResource method save.
public void save() throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
UnicoreJobSubmission existingUnicoreSubmission = em.find(UnicoreJobSubmission.class, jobSubmissionInterfaceId);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
if (existingUnicoreSubmission != null) {
existingUnicoreSubmission.setSubmissionID(jobSubmissionInterfaceId);
;
existingUnicoreSubmission.setUnicoreEndpointUrl(unicoreEndpointUrl);
existingUnicoreSubmission.setSecurityProtocol(securityProtocol);
em.merge(existingUnicoreSubmission);
} else {
UnicoreJobSubmission unicoreJobSubmission = new UnicoreJobSubmission();
unicoreJobSubmission.setSubmissionID(jobSubmissionInterfaceId);
unicoreJobSubmission.setUnicoreEndpointUrl(unicoreEndpointUrl);
unicoreJobSubmission.setSecurityProtocol(securityProtocol);
em.persist(unicoreJobSubmission);
}
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.cpi.AppCatalogException in project airavata by apache.
the class UserComputeHostPreferenceResource method remove.
@Override
public void remove(Object identifier) throws AppCatalogException {
CompositeIdentifier ids;
if (identifier instanceof CompositeIdentifier) {
ids = (CompositeIdentifier) identifier;
} else {
logger.error("Identifier should be a instance of CompositeIdentifier class");
throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
}
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_COMPUTE_RESOURCE_PREFERENCE);
generator.setParameter(UserComputeResourcePreferenceConstants.RESOURCE_ID, ids.getTopLevelIdentifier().toString());
generator.setParameter(UserComputeResourcePreferenceConstants.USER_ID, ids.getSecondLevelIdentifier().toString());
generator.setParameter(UserComputeResourcePreferenceConstants.GATEWAY_ID, ids.getThirdLevelIdentifier().toString());
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.registry.cpi.AppCatalogException in project airavata by apache.
the class UserResourceProfileResource method get.
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
List<AppCatalogResource> userResourceProfileResources = new ArrayList<AppCatalogResource>();
EntityManager em = null;
CompositeIdentifier ids;
if (value instanceof CompositeIdentifier) {
ids = (CompositeIdentifier) value;
} else {
logger.error("Identifier should be a instance of CompositeIdentifier class");
throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
}
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
Query q;
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
List results;
if (fieldName.equals(UserResourceProfileConstants.USER_ID)) {
generator.setParameter(UserStoragePreferenceConstants.USER_ID, ids.getTopLevelIdentifier().toString());
generator.setParameter(UserStoragePreferenceConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
UserResourceProfile userResourceProfile = (UserResourceProfile) result;
UserResourceProfileResource userResourceProfileResource = (UserResourceProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_RESOURCE_PROFILE, userResourceProfile);
userResourceProfileResources.add(userResourceProfileResource);
}
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for User Resource Profile resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for User Resource Profile 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 userResourceProfileResources;
}
use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.
the class UserResourceProfileResource method get.
public AppCatalogResource get(Object identifier) throws AppCatalogException {
EntityManager em = null;
CompositeIdentifier ids;
if (identifier instanceof CompositeIdentifier) {
ids = (CompositeIdentifier) identifier;
} else {
logger.error("Identifier should be a instance of CompositeIdentifier class");
throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
}
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
generator.setParameter(UserResourceProfileConstants.USER_ID, ids.getTopLevelIdentifier().toString());
generator.setParameter(UserResourceProfileConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
Query q = generator.selectQuery(em);
if (q.getResultList().size() != 0) {
UserResourceProfile userResourceProfile = (UserResourceProfile) q.getSingleResult();
UserResourceProfileResource userResourceProfileResource = (UserResourceProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_RESOURCE_PROFILE, userResourceProfile);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
userResourceProfileResource.setUserId(ids.getTopLevelIdentifier().toString());
return userResourceProfileResource;
} else {
return 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();
}
}
}
Aggregations