Search in sources :

Example 31 with WorkflowCatalogException

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

the class WorkflowCatalogImpl method getWorkflow.

@Override
public WorkflowModel getWorkflow(String workflowTemplateId) throws WorkflowCatalogException {
    try {
        WorkflowResource resource = new WorkflowResource();
        WorkflowResource wfResource = (WorkflowResource) resource.get(workflowTemplateId);
        return WorkflowCatalogThriftConversion.getWorkflow(wfResource);
    } catch (Exception e) {
        logger.error("Error while retrieving the workflow...", e);
        throw new WorkflowCatalogException(e);
    }
}
Also used : WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException)

Example 32 with WorkflowCatalogException

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

the class WorkflowCatalogImpl method updateWorkflow.

@Override
public void updateWorkflow(String workflowTemplateId, WorkflowModel workflow) throws WorkflowCatalogException {
    try {
        WorkflowResource resource = new WorkflowResource();
        WorkflowResource existingWF = (WorkflowResource) resource.get(workflowTemplateId);
        existingWF.setWfName(workflow.getName());
        existingWF.setGraph(workflow.getGraph());
        if (workflow.getImage() != null) {
            existingWF.setImage(new String(workflow.getImage()));
        }
        existingWF.save();
        List<InputDataObjectType> existingwFInputs = workflow.getWorkflowInputs();
        if (existingwFInputs != null && existingwFInputs.size() != 0) {
            for (InputDataObjectType input : existingwFInputs) {
                WorkflowInputResource wfInputResource = new WorkflowInputResource();
                Map<String, String> ids = new HashMap<String, String>();
                ids.put(WorkflowCatAbstractResource.WorkflowInputConstants.WF_TEMPLATE_ID, existingWF.getWfTemplateId());
                ids.put(WorkflowCatAbstractResource.WorkflowInputConstants.INPUT_KEY, input.getName());
                WorkflowInputResource existingInput = (WorkflowInputResource) wfInputResource.get(ids);
                existingInput.setWorkflowResource(existingWF);
                existingInput.setInputKey(input.getName());
                existingInput.setInputVal(input.getValue());
                existingInput.setWfTemplateId(existingWF.getWfTemplateId());
                existingInput.setDataType(input.getType().toString());
                existingInput.setAppArgument(input.getApplicationArgument());
                existingInput.setStandardInput(input.isStandardInput());
                existingInput.setUserFriendlyDesc(input.getUserFriendlyDescription());
                existingInput.setMetadata(input.getMetaData());
                existingInput.save();
            }
        }
        List<OutputDataObjectType> workflowOutputs = workflow.getWorkflowOutputs();
        if (workflowOutputs != null && workflowOutputs.size() != 0) {
            for (OutputDataObjectType output : workflowOutputs) {
                WorkflowOutputResource outputResource = new WorkflowOutputResource();
                Map<String, String> ids = new HashMap<String, String>();
                ids.put(WorkflowCatAbstractResource.WorkflowOutputConstants.WF_TEMPLATE_ID, existingWF.getWfTemplateId());
                ids.put(WorkflowCatAbstractResource.WorkflowOutputConstants.OUTPUT_KEY, output.getName());
                WorkflowOutputResource existingOutput = (WorkflowOutputResource) outputResource.get(ids);
                existingOutput.setWorkflowResource(existingWF);
                existingOutput.setOutputKey(output.getName());
                existingOutput.setOutputVal(output.getValue());
                existingOutput.setWfTemplateId(existingWF.getWfTemplateId());
                existingOutput.setDataType(output.getType().toString());
                existingOutput.setDataType(output.getType().toString());
                existingOutput.setAppArgument(output.getApplicationArgument());
                existingOutput.setDataNameLocation(output.getLocation());
                existingOutput.setRequired(output.isIsRequired());
                existingOutput.setRequiredToCMD(output.isRequiredToAddedToCommandLine());
                existingOutput.setOutputStreaming(output.isOutputStreaming());
                existingOutput.setDataMovement(output.isDataMovement());
                existingOutput.save();
            }
        }
    } catch (Exception e) {
        logger.error("Error while updating the workflow...", e);
        throw new WorkflowCatalogException(e);
    }
}
Also used : WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) HashMap(java.util.HashMap) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException)

Example 33 with WorkflowCatalogException

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

the class WorkflowCatalogImpl method registerWorkflow.

@Override
public String registerWorkflow(WorkflowModel workflow, String gatewayId) throws WorkflowCatalogException {
    try {
        WorkflowResource resource = new WorkflowResource();
        resource.setWfTemplateId(WorkflowCatalogUtils.getID(workflow.getName()));
        resource.setWfName(workflow.getName());
        resource.setGraph(workflow.getGraph());
        resource.setGatewayId(gatewayId);
        if (workflow.getImage() != null) {
            resource.setImage(new String(workflow.getImage()));
        }
        resource.save();
        workflow.setTemplateId(resource.getWfTemplateId());
        List<InputDataObjectType> workflowInputs = workflow.getWorkflowInputs();
        if (workflowInputs != null && workflowInputs.size() != 0) {
            for (InputDataObjectType input : workflowInputs) {
                WorkflowInputResource wfInputResource = new WorkflowInputResource();
                wfInputResource.setWorkflowResource(resource);
                wfInputResource.setInputKey(input.getName());
                wfInputResource.setInputVal(input.getValue());
                wfInputResource.setWfTemplateId(resource.getWfTemplateId());
                wfInputResource.setDataType(input.getType().toString());
                wfInputResource.setAppArgument(input.getApplicationArgument());
                wfInputResource.setStandardInput(input.isStandardInput());
                wfInputResource.setUserFriendlyDesc(input.getUserFriendlyDescription());
                wfInputResource.setMetadata(input.getMetaData());
                wfInputResource.save();
            }
        }
        List<OutputDataObjectType> workflowOutputs = workflow.getWorkflowOutputs();
        if (workflowOutputs != null && workflowOutputs.size() != 0) {
            for (OutputDataObjectType output : workflowOutputs) {
                WorkflowOutputResource outputResource = new WorkflowOutputResource();
                outputResource.setWorkflowResource(resource);
                outputResource.setOutputKey(output.getName());
                outputResource.setOutputVal(output.getValue());
                outputResource.setWfTemplateId(resource.getWfTemplateId());
                outputResource.setDataType(output.getType().toString());
                outputResource.setAppArgument(output.getApplicationArgument());
                outputResource.setDataNameLocation(output.getLocation());
                outputResource.setRequired(output.isIsRequired());
                outputResource.setRequiredToCMD(output.isRequiredToAddedToCommandLine());
                outputResource.setOutputStreaming(output.isOutputStreaming());
                outputResource.setDataMovement(output.isDataMovement());
                outputResource.save();
            }
        }
        return resource.getWfTemplateId();
    } catch (Exception e) {
        logger.error("Error while saving the workflow...", e);
        throw new WorkflowCatalogException(e);
    }
}
Also used : WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException)

Example 34 with WorkflowCatalogException

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

the class WorkflowInputResource method isExists.

public boolean isExists(Object identifier) throws WorkflowCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap<String, String>) identifier;
    } else {
        logger.error("Identifier should be a map with the field name and it's value");
        throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
    }
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        WorkflowInput workflowInput = em.find(WorkflowInput.class, new WorkflowInput_PK(ids.get(WorkflowInputConstants.WF_TEMPLATE_ID), ids.get(WorkflowInputConstants.INPUT_KEY)));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return workflowInput != null;
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new WorkflowCatalogException(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) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) EntityManager(javax.persistence.EntityManager) WorkflowInput(org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowInput_PK(org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput_PK)

Example 35 with WorkflowCatalogException

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

the class WorkflowInputResource method remove.

public void remove(Object identifier) throws WorkflowCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap) identifier;
    } else {
        logger.error("Identifier should be a map with the field name and it's value");
        throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
    }
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_INPUT);
        generator.setParameter(WorkflowInputConstants.WF_TEMPLATE_ID, ids.get(WorkflowInputConstants.WF_TEMPLATE_ID));
        generator.setParameter(WorkflowInputConstants.INPUT_KEY, ids.get(WorkflowInputConstants.INPUT_KEY));
        Query q = generator.deleteQuery(em);
        q.executeUpdate();
        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 WorkflowCatalogException(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) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) WorkflowCatalogQueryGenerator(org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

WorkflowCatalogException (org.apache.airavata.registry.cpi.WorkflowCatalogException)57 EntityManager (javax.persistence.EntityManager)50 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)50 Query (javax.persistence.Query)34 WorkflowCatalogQueryGenerator (org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)34 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 List (java.util.List)16 Workflow (org.apache.airavata.registry.core.workflow.catalog.model.Workflow)14 ComponentStatus (org.apache.airavata.registry.core.workflow.catalog.model.ComponentStatus)5 Edge (org.apache.airavata.registry.core.workflow.catalog.model.Edge)5 Node (org.apache.airavata.registry.core.workflow.catalog.model.Node)5 Port (org.apache.airavata.registry.core.workflow.catalog.model.Port)5 WorkflowInput (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput)5 WorkflowOutput (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput)5 WorkflowStatus (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowStatus)5 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)2 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)2 Edge_PK (org.apache.airavata.registry.core.workflow.catalog.model.Edge_PK)2