Search in sources :

Example 56 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ProcessInputResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        if (processId == null) {
            throw new RegistryException("Does not have the process id");
        }
        em = ExpCatResourceUtils.getEntityManager();
        ProcessInput processInput;
        ProcessInputPK processInputPk = new ProcessInputPK();
        processInputPk.setProcessId(processId);
        processInputPk.setInputName(inputName);
        ProcessInput existingProInput = em.find(ProcessInput.class, processInputPk);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingProInput == null) {
            processInput = new ProcessInput();
        } else {
            processInput = existingProInput;
        }
        processInput.setProcessId(processId);
        processInput.setInputName(inputName);
        processInput.setInputValue(inputValue);
        processInput.setDataType(dataType);
        processInput.setApplicationArgument(applicationArgument);
        processInput.setStandardInput(standardInput);
        processInput.setUserFriendlyDescription(userFriendlyDescription);
        processInput.setMetadata(metadata);
        processInput.setInputOrder(inputOrder);
        processInput.setIsRequired(isRequired);
        processInput.setRequiredToAddedToCmd(requiredToAddedToCmd);
        processInput.setDataStaged(dataStaged);
        processInput.setStorageResourceId(storageResourceId);
        processInput.setIsReadOnly(isReadOnly);
        if (existingProInput == null) {
            em.persist(processInput);
        } else {
            em.merge(processInput);
        }
        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 RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ProcessInput(org.apache.airavata.registry.core.experiment.catalog.model.ProcessInput) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ProcessInputPK(org.apache.airavata.registry.core.experiment.catalog.model.ProcessInputPK) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 57 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ProcessResource method get.

public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator;
        Query q;
        switch(type) {
            case PROCESS_STATUS:
                generator = new QueryGenerator(PROCESS_STATUS);
                generator.setParameter(ProcessStatusConstants.STATUS_ID, name);
                q = generator.selectQuery(em);
                ProcessStatus status = (ProcessStatus) q.getSingleResult();
                ProcessStatusResource statusResource = (ProcessStatusResource) Utils.getResource(ResourceType.PROCESS_STATUS, status);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return statusResource;
            case PROCESS_ERROR:
                generator = new QueryGenerator(PROCESS_ERROR);
                generator.setParameter(ProcessErrorConstants.ERROR_ID, name);
                q = generator.selectQuery(em);
                ProcessError processError = (ProcessError) q.getSingleResult();
                ProcessErrorResource processErrorResource = (ProcessErrorResource) Utils.getResource(ResourceType.PROCESS_ERROR, processError);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processErrorResource;
            case PROCESS_INPUT:
                generator = new QueryGenerator(PROCESS_INPUT);
                generator.setParameter(ProcessInputConstants.INPUT_NAME, name);
                generator.setParameter(ProcessInputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                ProcessInput processInput = (ProcessInput) q.getSingleResult();
                ProcessInputResource processInputResource = (ProcessInputResource) Utils.getResource(ResourceType.PROCESS_INPUT, processInput);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processInputResource;
            case PROCESS_OUTPUT:
                generator = new QueryGenerator(PROCESS_OUTPUT);
                generator.setParameter(ProcessOutputConstants.OUTPUT_NAME, name);
                generator.setParameter(ProcessInputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                ProcessOutput processOutput = (ProcessOutput) q.getSingleResult();
                ProcessOutputResource outputResource = (ProcessOutputResource) Utils.getResource(ResourceType.PROCESS_OUTPUT, processOutput);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return outputResource;
            case PROCESS_RESOURCE_SCHEDULE:
                generator = new QueryGenerator(PROCESS_RESOURCE_SCHEDULE);
                generator.setParameter(ProcessResourceScheduleConstants.PROCESS_ID, name);
                q = generator.selectQuery(em);
                ProcessResourceSchedule processResourceSchedule = (ProcessResourceSchedule) q.getSingleResult();
                ProcessResourceScheduleResource processResourceScheduleResource = (ProcessResourceScheduleResource) Utils.getResource(ResourceType.PROCESS_RESOURCE_SCHEDULE, processResourceSchedule);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processResourceScheduleResource;
            case TASK:
                generator = new QueryGenerator(TASK);
                generator.setParameter(TaskConstants.TASK_ID, name);
                q = generator.selectQuery(em);
                Task task = (Task) q.getSingleResult();
                TaskResource taskResource = (TaskResource) Utils.getResource(ResourceType.TASK, task);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return taskResource;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.JOB_ID, name);
                generator.setParameter(JobConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                Job job = (Job) q.getSingleResult();
                JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return jobResource;
            default:
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                logger.error("Unsupported resource type for process resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for process resource.");
        }
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : Query(javax.persistence.Query) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)

Example 58 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ProcessResource method get.

public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
    List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        QueryGenerator generator;
        List results;
        switch(type) {
            case PROCESS_INPUT:
                generator = new QueryGenerator(PROCESS_INPUT);
                generator.setParameter(ProcessInputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessInput processInput = (ProcessInput) result;
                        ProcessInputResource processInputResource = (ProcessInputResource) Utils.getResource(ResourceType.PROCESS_INPUT, processInput);
                        resourceList.add(processInputResource);
                    }
                }
                break;
            case PROCESS_OUTPUT:
                generator = new QueryGenerator(PROCESS_OUTPUT);
                generator.setParameter(ProcessOutputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessOutput processOutput = (ProcessOutput) result;
                        ProcessOutputResource processOutputResource = (ProcessOutputResource) Utils.getResource(ResourceType.PROCESS_OUTPUT, processOutput);
                        resourceList.add(processOutputResource);
                    }
                }
                break;
            case TASK:
                generator = new QueryGenerator(TASK);
                generator.setParameter(TaskConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Task task = (Task) result;
                        TaskResource taskResource = (TaskResource) Utils.getResource(ResourceType.TASK, task);
                        resourceList.add(taskResource);
                    }
                }
                break;
            case PROCESS_ERROR:
                generator = new QueryGenerator(PROCESS_ERROR);
                generator.setParameter(ProcessErrorConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessError processError = (ProcessError) result;
                        ProcessErrorResource processErrorResource = (ProcessErrorResource) Utils.getResource(ResourceType.PROCESS_ERROR, processError);
                        resourceList.add(processErrorResource);
                    }
                }
                break;
            case PROCESS_STATUS:
                generator = new QueryGenerator(PROCESS_STATUS);
                generator.setParameter(ProcessStatusConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessStatus processStatus = (ProcessStatus) result;
                        ProcessStatusResource processStatusResource = (ProcessStatusResource) Utils.getResource(ResourceType.PROCESS_STATUS, processStatus);
                        resourceList.add(processStatusResource);
                    }
                }
                break;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Job job = (Job) result;
                        JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
                        resourceList.add(jobResource);
                    }
                }
                break;
            default:
                logger.error("Unsupported resource type for task resource.", new UnsupportedOperationException());
                throw new UnsupportedOperationException();
        }
        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 RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return resourceList;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 59 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ExperimentResource method remove.

public void remove(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        QueryGenerator generator;
        switch(type) {
            case EXPERIMENT_ERROR:
                generator = new QueryGenerator(EXPERIMENT_ERROR);
                generator.setParameter(ExperimentErrorConstants.ERROR_ID, name);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            case EXPERIMENT_STATUS:
                generator = new QueryGenerator(EXPERIMENT_STATUS);
                generator.setParameter(ExperimentStatusConstants.EXPERIMENT_ID, experimentId);
                generator.setParameter(ExperimentStatusConstants.STATUS_ID, name);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            case EXPERIMENT_INPUT:
                generator = new QueryGenerator(EXPERIMENT_INPUT);
                generator.setParameter(ExperimentInputConstants.INPUT_NAME, name);
                generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            case EXPERIMENT_OUTPUT:
                generator = new QueryGenerator(EXPERIMENT_OUTPUT);
                generator.setParameter(ExperimentOutputConstants.OUTPUT_NAME, name);
                generator.setParameter(ExperimentOutputConstants.EXPERIMENT_ID, experimentId);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            case USER_CONFIGURATION_DATA:
                generator = new QueryGenerator(USER_CONFIGURATION_DATA);
                generator.setParameter(UserConfigurationDataConstants.EXPERIMENT_ID, experimentId);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            case PROCESS:
                generator = new QueryGenerator(PROCESS);
                generator.setParameter(ProcessConstants.PROCESS_ID, name);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            default:
                logger.error("Unsupported resource type for process detail resource.", new IllegalArgumentException());
                break;
        }
        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 RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 60 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class ExperimentResource method get.

public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator;
        Query q;
        switch(type) {
            case EXPERIMENT_STATUS:
                generator = new QueryGenerator(EXPERIMENT_STATUS);
                generator.setParameter(ExperimentStatusConstants.STATUS_ID, name);
                q = generator.selectQuery(em);
                ExperimentStatus status = (ExperimentStatus) q.getSingleResult();
                ExperimentStatusResource statusResource = (ExperimentStatusResource) Utils.getResource(ResourceType.EXPERIMENT_STATUS, status);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return statusResource;
            case EXPERIMENT_ERROR:
                generator = new QueryGenerator(EXPERIMENT_ERROR);
                generator.setParameter(ExperimentErrorConstants.ERROR_ID, name);
                q = generator.selectQuery(em);
                ExperimentError experimentError = (ExperimentError) q.getSingleResult();
                ExperimentErrorResource processErrorResource = (ExperimentErrorResource) Utils.getResource(ResourceType.EXPERIMENT_ERROR, experimentError);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processErrorResource;
            case EXPERIMENT_INPUT:
                generator = new QueryGenerator(EXPERIMENT_INPUT);
                generator.setParameter(ExperimentInputConstants.INPUT_NAME, name);
                generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
                q = generator.selectQuery(em);
                ExperimentInput experimentInput = (ExperimentInput) q.getSingleResult();
                ExperimentInputResource experimentInputResource = (ExperimentInputResource) Utils.getResource(ResourceType.EXPERIMENT_INPUT, experimentInput);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return experimentInputResource;
            case EXPERIMENT_OUTPUT:
                generator = new QueryGenerator(EXPERIMENT_OUTPUT);
                generator.setParameter(ExperimentOutputConstants.OUTPUT_NAME, name);
                generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
                q = generator.selectQuery(em);
                ExperimentOutput experimentOutput = (ExperimentOutput) q.getSingleResult();
                ExperimentOutputResource outputResource = (ExperimentOutputResource) Utils.getResource(ResourceType.EXPERIMENT_OUTPUT, experimentOutput);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return outputResource;
            case USER_CONFIGURATION_DATA:
                generator = new QueryGenerator(USER_CONFIGURATION_DATA);
                generator.setParameter(UserConfigurationDataConstants.EXPERIMENT_ID, name);
                q = generator.selectQuery(em);
                UserConfigurationData configurationData = (UserConfigurationData) q.getSingleResult();
                UserConfigurationDataResource configurationDataResource = (UserConfigurationDataResource) Utils.getResource(ResourceType.USER_CONFIGURATION_DATA, configurationData);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return configurationDataResource;
            case PROCESS:
                generator = new QueryGenerator(PROCESS);
                generator.setParameter(ProcessConstants.PROCESS_ID, name);
                q = generator.selectQuery(em);
                Process process = (Process) q.getSingleResult();
                ProcessResource processResource = (ProcessResource) Utils.getResource(ResourceType.PROCESS, process);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processResource;
            default:
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                logger.error("Unsupported resource type for experiment resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for experiment resource.");
        }
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : Query(javax.persistence.Query) Process(org.apache.airavata.registry.core.experiment.catalog.model.Process) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)

Aggregations

RegistryException (org.apache.airavata.registry.cpi.RegistryException)134 EntityManager (javax.persistence.EntityManager)54 Query (javax.persistence.Query)29 QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)29 ArrayList (java.util.ArrayList)15 List (java.util.List)12 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)12 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)11 ExperimentCatalogException (org.apache.airavata.registry.cpi.ExperimentCatalogException)8 AiravataException (org.apache.airavata.common.exception.AiravataException)6 GFacException (org.apache.airavata.gfac.core.GFacException)6 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)6 Node (org.apache.airavata.workflow.model.graph.Node)6 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)6 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)6 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)6 Timestamp (java.sql.Timestamp)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 DataPort (org.apache.airavata.workflow.model.graph.DataPort)4 HashMap (java.util.HashMap)3