Search in sources :

Example 1 with ResourceJobManager

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

the class ResourceJobManagerResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
        generator.setParameter(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID, identifier);
        Query q = generator.selectQuery(em);
        ResourceJobManager resourceJobManager = (ResourceJobManager) q.getSingleResult();
        ResourceJobManagerResource resourceJobManagerResource = (ResourceJobManagerResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return resourceJobManagerResource;
    } 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) ResourceJobManager(org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 2 with ResourceJobManager

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

the class LocalSubmissionResource method save.

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

Example 3 with ResourceJobManager

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

the class JobManagerCommandResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        JobManagerCommand existingJobManagerCommand = em.find(JobManagerCommand.class, new JobManagerCommand_PK(resourceJobManagerId, commandType));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        JobManagerCommand jobManagerCommand;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingJobManagerCommand == null) {
            jobManagerCommand = new JobManagerCommand();
        } else {
            jobManagerCommand = existingJobManagerCommand;
        }
        jobManagerCommand.setResourceJobManagerId(getResourceJobManagerId());
        ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, getResourceJobManagerId());
        jobManagerCommand.setResourceJobManager(resourceJobManager);
        jobManagerCommand.setCommandType(getCommandType());
        jobManagerCommand.setCommand(getCommand());
        if (existingJobManagerCommand == null) {
            em.persist(jobManagerCommand);
        } else {
            em.merge(jobManagerCommand);
        }
        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) JobManagerCommand(org.apache.airavata.registry.core.app.catalog.model.JobManagerCommand) JobManagerCommand_PK(org.apache.airavata.registry.core.app.catalog.model.JobManagerCommand_PK) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 4 with ResourceJobManager

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

the class ResourceJobManagerResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> resourceJobManagerResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
        Query q;
        if ((fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(ResourceJobManagerConstants.PUSH_MONITORING_ENDPOINT)) || (fieldName.equals(ResourceJobManagerConstants.JOB_MANAGER_BIN_PATH)) || (fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_TYPE))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                ResourceJobManager resourceJobManager = (ResourceJobManager) result;
                ResourceJobManagerResource resourceJobManagerResource = (ResourceJobManagerResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
                resourceJobManagerResources.add(resourceJobManagerResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Resource Job Manager Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Resource Job Manager 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 resourceJobManagerResources;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ResourceJobManager(org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 5 with ResourceJobManager

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

the class ResourceJobManagerResource method getIds.

@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> resourceJobManagerResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(RESOURCE_JOB_MANAGER);
        Query q;
        if ((fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(ResourceJobManagerConstants.PUSH_MONITORING_ENDPOINT)) || (fieldName.equals(ResourceJobManagerConstants.JOB_MANAGER_BIN_PATH)) || (fieldName.equals(ResourceJobManagerConstants.RESOURCE_JOB_MANAGER_TYPE))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                ResourceJobManager resourceJobManager = (ResourceJobManager) result;
                ResourceJobManagerResource resourceJobManagerResource = (ResourceJobManagerResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.RESOURCE_JOB_MANAGER, resourceJobManager);
                resourceJobManagerResourceIDs.add(resourceJobManagerResource.getResourceJobManagerId());
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Resource Job Manager Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Resource Job Manager 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 resourceJobManagerResourceIDs;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ResourceJobManager(org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

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