Search in sources :

Example 1 with GSISSHSubmission

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

the class GSISSHExportResource method save.

public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        GSISSHExport existingGSIExport = em.find(GSISSHExport.class, new GSISSHExportPK(submissionID, export));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        GSISSHSubmission gsisshSubmission = em.find(GSISSHSubmission.class, submissionID);
        if (existingGSIExport != null) {
            existingGSIExport.setSubmissionID(submissionID);
            existingGSIExport.setExport(export);
            existingGSIExport.setGsisshJobSubmission(gsisshSubmission);
            em.merge(existingGSIExport);
        } else {
            GSISSHExport gsisshExport = new GSISSHExport();
            gsisshExport.setSubmissionID(submissionID);
            gsisshExport.setExport(export);
            gsisshExport.setGsisshJobSubmission(gsisshSubmission);
            em.persist(gsisshExport);
        }
        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) GSISSHExportPK(org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GSISSHExport(org.apache.airavata.registry.core.app.catalog.model.GSISSHExport) GSISSHSubmission(org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 2 with GSISSHSubmission

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

the class GSISSHSubmissionResource method save.

public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        GSISSHSubmission existingGSISSHSubmission = em.find(GSISSHSubmission.class, submissionID);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingGSISSHSubmission != null) {
            existingGSISSHSubmission.setSubmissionID(submissionID);
            existingGSISSHSubmission.setSshPort(sshPort);
            existingGSISSHSubmission.setResourceJobManager(resourceJobManager);
            existingGSISSHSubmission.setInstalledPath(installedPath);
            existingGSISSHSubmission.setMonitorMode(monitorMode);
            em.merge(existingGSISSHSubmission);
        } else {
            GSISSHSubmission gsisshSubmission = new GSISSHSubmission();
            gsisshSubmission.setSubmissionID(submissionID);
            gsisshSubmission.setSshPort(sshPort);
            gsisshSubmission.setResourceJobManager(resourceJobManager);
            gsisshSubmission.setInstalledPath(installedPath);
            gsisshSubmission.setMonitorMode(monitorMode);
            em.persist(gsisshSubmission);
        }
        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) GSISSHSubmission(org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 3 with GSISSHSubmission

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

the class GSISSHSubmissionResource method getIds.

public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> gsiSSHSubmissionResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GSISSH_SUBMISSION);
        List results;
        if (fieldName.equals(GSISSHSubmissionConstants.SUBMISSION_ID)) {
            generator.setParameter(GSISSHSubmissionConstants.SUBMISSION_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHSubmission gsisshSubmission = (GSISSHSubmission) result;
                    gsiSSHSubmissionResourceIDs.add(gsisshSubmission.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GSISSHSubmissionConstants.SSH_PORT)) {
            generator.setParameter(GSISSHSubmissionConstants.SSH_PORT, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHSubmission gsisshSubmission = (GSISSHSubmission) result;
                    gsiSSHSubmissionResourceIDs.add(gsisshSubmission.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GSISSHSubmissionConstants.MONITOR_MODE)) {
            generator.setParameter(GSISSHSubmissionConstants.MONITOR_MODE, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHSubmission gsisshSubmission = (GSISSHSubmission) result;
                    gsiSSHSubmissionResourceIDs.add(gsisshSubmission.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GSISSHSubmissionConstants.RESOURCE_JOB_MANAGER)) {
            generator.setParameter(GSISSHSubmissionConstants.RESOURCE_JOB_MANAGER, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHSubmission gsisshSubmission = (GSISSHSubmission) result;
                    gsiSSHSubmissionResourceIDs.add(gsisshSubmission.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GSISSHSubmissionConstants.INSTALLED_PATH)) {
            generator.setParameter(GSISSHSubmissionConstants.INSTALLED_PATH, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHSubmission gsisshSubmission = (GSISSHSubmission) result;
                    gsiSSHSubmissionResourceIDs.add(gsisshSubmission.getSubmissionID());
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for GSISSH Submission resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for GSISSH Submission 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 gsiSSHSubmissionResourceIDs;
}
Also used : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GSISSHSubmission(org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 4 with GSISSHSubmission

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

the class GSISSHSubmissionResource method get.

public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GSISSH_SUBMISSION);
        generator.setParameter(GSISSHSubmissionConstants.SUBMISSION_ID, identifier);
        Query q = generator.selectQuery(em);
        GSISSHSubmission gsisshSubmission = (GSISSHSubmission) q.getSingleResult();
        GSISSHSubmissionResource gsisshSubmissionResource = (GSISSHSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GSISSH_SUBMISSION, gsisshSubmission);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return gsisshSubmissionResource;
    } 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) GSISSHSubmission(org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 5 with GSISSHSubmission

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

the class GSISSHSubmissionResource method isExists.

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

Aggregations

EntityManager (javax.persistence.EntityManager)6 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)6 GSISSHSubmission (org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission)6 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)6 Query (javax.persistence.Query)3 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GSISSHExport (org.apache.airavata.registry.core.app.catalog.model.GSISSHExport)1 GSISSHExportPK (org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK)1