Search in sources :

Example 1 with CloudJobSubmission

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

the class CloudSubmissionResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(CLOUD_JOB_SUBMISSION);
        generator.setParameter(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID, identifier);
        Query q = generator.selectQuery(em);
        CloudJobSubmission cloudJobSubmission = (CloudJobSubmission) q.getSingleResult();
        CloudSubmissionResource localSubmissionResource = (CloudSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.ClOUD_SUBMISSION, cloudJobSubmission);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return localSubmissionResource;
    } 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) CloudJobSubmission(org.apache.airavata.registry.core.app.catalog.model.CloudJobSubmission) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 2 with CloudJobSubmission

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

the class CloudSubmissionResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> localSubmissionResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(CLOUD_JOB_SUBMISSION);
        Query q;
        if ((fieldName.equals(LocalSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                CloudJobSubmission localSubmission = (CloudJobSubmission) result;
                CloudSubmissionResource localSubmissionResource = (CloudSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.ClOUD_SUBMISSION, localSubmission);
                localSubmissionResources.add(localSubmissionResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Local Submission Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Local 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 localSubmissionResources;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) CloudJobSubmission(org.apache.airavata.registry.core.app.catalog.model.CloudJobSubmission) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 3 with CloudJobSubmission

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

the class CloudSubmissionResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        CloudJobSubmission existingLocalSubmission = em.find(CloudJobSubmission.class, jobSubmissionInterfaceId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        CloudJobSubmission cloudJobSubmission;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingLocalSubmission == null) {
            cloudJobSubmission = new CloudJobSubmission();
        } else {
            cloudJobSubmission = existingLocalSubmission;
        }
        cloudJobSubmission.setExecutableType(getExecutableType());
        cloudJobSubmission.setNodeId(getNodeId());
        cloudJobSubmission.setJobSubmissionInterfaceId(getJobSubmissionInterfaceId());
        cloudJobSubmission.setSecurityProtocol(getSecurityProtocol());
        cloudJobSubmission.setJobSubmissionInterfaceId(getJobSubmissionInterfaceId());
        cloudJobSubmission.setUserAccountName(getUserAccountName());
        cloudJobSubmission.setProviderName(getProviderName());
        if (existingLocalSubmission == null) {
            em.persist(cloudJobSubmission);
        } else {
            em.merge(cloudJobSubmission);
        }
        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) CloudJobSubmission(org.apache.airavata.registry.core.app.catalog.model.CloudJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 4 with CloudJobSubmission

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

the class CloudSubmissionResource method getIds.

@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> localSubmissionResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(CLOUD_JOB_SUBMISSION);
        Query q;
        if ((fieldName.equals(LocalSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                CloudJobSubmission localSubmission = (CloudJobSubmission) result;
                LocalSubmissionResource localSubmissionResource = (LocalSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.ClOUD_SUBMISSION, localSubmission);
                localSubmissionResourceIDs.add(localSubmissionResource.getJobSubmissionInterfaceId());
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Local Submission Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Local 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 localSubmissionResourceIDs;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) CloudJobSubmission(org.apache.airavata.registry.core.app.catalog.model.CloudJobSubmission) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 5 with CloudJobSubmission

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

the class CloudSubmissionResource method isExists.

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

Aggregations

EntityManager (javax.persistence.EntityManager)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)5 CloudJobSubmission (org.apache.airavata.registry.core.app.catalog.model.CloudJobSubmission)5 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)5 Query (javax.persistence.Query)3 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)3 ArrayList (java.util.ArrayList)2