Search in sources :

Example 6 with ResourceJobManager

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

the class ResourceJobManagerResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        ResourceJobManager existingResourceJobManager = em.find(ResourceJobManager.class, resourceJobManagerId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        ResourceJobManager resourceJobManager;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingResourceJobManager == null) {
            resourceJobManager = new ResourceJobManager();
            resourceJobManager.setCreationTime(AiravataUtils.getCurrentTimestamp());
        } else {
            resourceJobManager = existingResourceJobManager;
            resourceJobManager.setUpdateTime(AiravataUtils.getCurrentTimestamp());
        }
        resourceJobManager.setResourceJobManagerId(getResourceJobManagerId());
        resourceJobManager.setPushMonitoringEndpoint(getPushMonitoringEndpoint());
        resourceJobManager.setJobManagerBinPath(getJobManagerBinPath());
        resourceJobManager.setResourceJobManagerType(getResourceJobManagerType());
        if (existingResourceJobManager == null) {
            em.persist(resourceJobManager);
        } else {
            em.merge(resourceJobManager);
        }
        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) ResourceJobManager(org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 7 with ResourceJobManager

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

the class ResourceJobManagerResource method isExists.

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

Example 8 with ResourceJobManager

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

the class SshJobSubmissionResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        SshJobSubmission existingSshJobSubmission = em.find(SshJobSubmission.class, jobSubmissionInterfaceId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        SshJobSubmission sshJobSubmission;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingSshJobSubmission == null) {
            sshJobSubmission = new SshJobSubmission();
            sshJobSubmission.setCreationTime(AiravataUtils.getCurrentTimestamp());
        } else {
            sshJobSubmission = existingSshJobSubmission;
            sshJobSubmission.setUpdateTime(AiravataUtils.getCurrentTimestamp());
        }
        sshJobSubmission.setResourceJobManagerId(getResourceJobManagerId());
        ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, getResourceJobManagerId());
        sshJobSubmission.setResourceJobManager(resourceJobManager);
        sshJobSubmission.setJobSubmissionInterfaceId(getJobSubmissionInterfaceId());
        sshJobSubmission.setAlternativeSshHostname(getAlternativeSshHostname());
        sshJobSubmission.setSecurityProtocol(getSecurityProtocol());
        sshJobSubmission.setSshPort(getSshPort());
        sshJobSubmission.setMonitorMode(getMonitorMode());
        if (existingSshJobSubmission == null) {
            em.persist(sshJobSubmission);
        } else {
            em.merge(sshJobSubmission);
        }
        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 : SshJobSubmission(org.apache.airavata.registry.core.app.catalog.model.SshJobSubmission) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ResourceJobManager(org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

EntityManager (javax.persistence.EntityManager)8 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)8 ResourceJobManager (org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager)8 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)8 Query (javax.persistence.Query)3 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)3 ArrayList (java.util.ArrayList)2 JobManagerCommand (org.apache.airavata.registry.core.app.catalog.model.JobManagerCommand)1 JobManagerCommand_PK (org.apache.airavata.registry.core.app.catalog.model.JobManagerCommand_PK)1 LocalSubmission (org.apache.airavata.registry.core.app.catalog.model.LocalSubmission)1 SshJobSubmission (org.apache.airavata.registry.core.app.catalog.model.SshJobSubmission)1