Search in sources :

Example 1 with DynamicComponent

use of org.apache.airavata.workflow.model.component.dynamic.DynamicComponent in project airavata by apache.

the class WorkflowInterpreter method executeDynamically.

private void executeDynamically(final Node node) throws WorkflowException, TException, RegistryException, AiravataException {
    node.setState(NodeExecutionState.EXECUTING);
    invokedNode.add(node);
    updateWorkflowNodeStatus(nodeInstanceList.get(node), WorkflowNodeState.EXECUTING);
    publishNodeStatusChange(WorkflowNodeState.EXECUTING, node.getID(), experiment.getExperimentID());
    Component component = node.getComponent();
    if (component instanceof SubWorkflowComponent) {
        handleSubWorkComponent(node);
    } else if (component instanceof WSComponent) {
        handleWSComponent(node);
    } else if (component instanceof DynamicComponent) {
        handleDynamicComponent(node);
    } else if (component instanceof ForEachComponent) {
        handleForEach(node);
    } else if (component instanceof IfComponent) {
        handleIf(node);
    } else if (component instanceof EndifComponent) {
        handleEndIf(node);
    } else if (component instanceof DoWhileComponent) {
        handleDoWhile(node);
    } else if (component instanceof EndDoWhileComponent) {
    // Component is handled in DoWhileHandler after eval condition
    } else if (component instanceof InstanceComponent) {
        handleAmazonInstance(node);
    } else if (component instanceof TerminateInstanceComponent) {
        handleAmazonTerminateInstance(node);
    } else {
        throw new WorkFlowInterpreterException("Encountered Node that cannot be executed:" + node);
    }
}
Also used : DynamicComponent(org.apache.airavata.workflow.model.component.dynamic.DynamicComponent) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) InstanceComponent(org.apache.airavata.workflow.model.component.amazon.InstanceComponent) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) Component(org.apache.airavata.workflow.model.component.Component) DynamicComponent(org.apache.airavata.workflow.model.component.dynamic.DynamicComponent) InstanceComponent(org.apache.airavata.workflow.model.component.amazon.InstanceComponent) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent)

Example 2 with DynamicComponent

use of org.apache.airavata.workflow.model.component.dynamic.DynamicComponent in project airavata by apache.

the class WorkflowInterpreter method getReadyNodesDynamically.

private ArrayList<Node> getReadyNodesDynamically() {
    ArrayList<Node> list = new ArrayList<Node>();
    ArrayList<Node> waiting = InterpreterUtil.getWaitingNodesDynamically(this.getGraph());
    // ArrayList<Node> finishedNodes = InterpreterUtil.getFinishedNodesDynamically(this.getGraph());
    // This is to support repeat the same application in the workflow.
    List<String> finishedNodeIds = InterpreterUtil.getFinishedNodesIds(this.getGraph());
    for (Node node : waiting) {
        Component component = node.getComponent();
        if (component instanceof WSComponent || component instanceof DynamicComponent || component instanceof SubWorkflowComponent || component instanceof ForEachComponent || component instanceof EndForEachComponent || component instanceof IfComponent || component instanceof InstanceComponent) {
            /*
				 * Check for control ports from other node
				 */
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && (finishedNodeIds.contains(edge.getFromPort().getNode().getID()) || // that makes sense and if anyone found a scenario it should be otherwise pls fix
                    ((ControlPort) edge.getFromPort()).isConditionMet());
                }
            }
            /*
				 * Check for input ports
				 */
            List<DataPort> inputPorts = node.getInputPorts();
            boolean inputsDone = true;
            for (DataPort dataPort : inputPorts) {
                inputsDone = inputsDone && finishedNodeIds.contains(dataPort.getFromNode().getID());
            }
            if (inputsDone && controlDone) {
                list.add(node);
            }
        } else if (component instanceof EndifComponent) {
            /*
				 * EndIfComponent can run if number of input equals to number of
				 * output that it expects
				 */
            int expectedOutput = node.getOutputPorts().size();
            int actualInput = 0;
            List<DataPort> inputPorts = node.getInputPorts();
            for (DataPort dataPort : inputPorts) {
                if (finishedNodeIds.contains(dataPort.getFromNode().getID()))
                    actualInput++;
            }
            if (expectedOutput == actualInput) {
                list.add(node);
            }
        } else if (component instanceof TerminateInstanceComponent) {
            /*
				 * All node connected to controlIn port must be done
				 */
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && finishedNodeIds.contains(edge.getFromPort().getFromNode().getID());
                }
            }
            /*
				 * Check for input ports
				 */
            List<DataPort> inputPorts = node.getInputPorts();
            boolean inputsDone = true;
            for (DataPort dataPort : inputPorts) {
                inputsDone = inputsDone && finishedNodeIds.contains(dataPort.getFromNode().getID());
            }
            if (inputsDone && controlDone) {
                list.add(node);
            }
        } else if (InputComponent.NAME.equals(component.getName()) || DifferedInputComponent.NAME.equals(component.getName()) || S3InputComponent.NAME.equals(component.getName()) || OutputComponent.NAME.equals(component.getName()) || MemoComponent.NAME.equals(component.getName()) || component instanceof EndDoWhileComponent) {
        // no op
        } else if (component instanceof DoWhileComponent) {
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && finishedNodeIds.contains(edge.getFromPort().getFromNode().getID());
                }
            }
            if (controlDone) {
                list.add(node);
            }
        } else {
            throw new WorkFlowInterpreterException("Component Not handled :" + component.getName());
        }
    }
    notifyViaInteractor(WorkflowExecutionMessage.HANDLE_DEPENDENT_NODES_DIFFERED_INPUTS, this.getGraph());
    return list;
}
Also used : DynamicComponent(org.apache.airavata.workflow.model.component.dynamic.DynamicComponent) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent) DataPort(org.apache.airavata.workflow.model.graph.DataPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) InstanceComponent(org.apache.airavata.workflow.model.component.amazon.InstanceComponent) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) Component(org.apache.airavata.workflow.model.component.Component) DynamicComponent(org.apache.airavata.workflow.model.component.dynamic.DynamicComponent) InstanceComponent(org.apache.airavata.workflow.model.component.amazon.InstanceComponent) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent)

Example 3 with DynamicComponent

use of org.apache.airavata.workflow.model.component.dynamic.DynamicComponent in project airavata by apache.

the class WorkflowInterpreter method handleDynamicComponent.

private void handleDynamicComponent(Node node) throws WorkflowException {
    DynamicComponent dynamicComponent = (DynamicComponent) node.getComponent();
    String className = dynamicComponent.getClassName();
    String operationName = dynamicComponent.getOperationName();
    URL implJarLocation = dynamicComponent.getImplJarLocation();
    DynamicNode dynamicNode = (DynamicNode) node;
    LinkedList<Object> inputs = new LinkedList<Object>();
    List<DataPort> inputPorts = dynamicNode.getInputPorts();
    for (DataPort dataPort : inputPorts) {
        Object inputVal = InterpreterUtil.findInputFromPort(dataPort, this.invokerMap);
        /*
			 * Set type after get input value, and override inputValue if output
			 * type is array
			 */
        Node fromNode = dataPort.getFromNode();
        DataType type = null;
        if (fromNode instanceof InputNode) {
            type = DataType.STRING;
        } else if (fromNode instanceof ConstantNode) {
            type = ((ConstantNode) fromNode).getType();
        } else if ((dataPort.getFromPort() instanceof WSPort) && BasicTypeMapping.isArrayType(((WSPort) dataPort.getFromPort()).getComponentPort().getElement())) {
            Invoker fromInvoker = this.invokerMap.get(fromNode);
            // inputVal = BasicTypeMapping.getOutputArray(XmlConstants.BUILDER.parseFragmentFromString(fromInvoker.getOutputs().toString()), dataPort
            // .getFromPort().getName(), BasicTypeMapping.getSimpleTypeIndex(((DataPort) dataPort.getFromPort()).getType()));
            type = ((DataPort) dataPort.getFromPort()).getType();
        } else {
            type = ((DataPort) dataPort.getFromPort()).getType();
        }
        if (null == inputVal) {
            throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + node.getID());
        }
    // inputs.add(BasicTypeMapping.getObjectOfType(type, inputVal));
    }
    DynamicInvoker dynamicInvoker = new DynamicInvoker(className, implJarLocation, operationName, inputs.toArray());
    this.invokerMap.put(node, dynamicInvoker);
    dynamicInvoker.setup();
    dynamicInvoker.invoke();
    node.setState(NodeExecutionState.FINISHED);
}
Also used : DynamicComponent(org.apache.airavata.workflow.model.component.dynamic.DynamicComponent) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) URL(java.net.URL) DataPort(org.apache.airavata.workflow.model.graph.DataPort) WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) DynamicInvoker(org.apache.airavata.workflow.engine.invoker.DynamicInvoker) Invoker(org.apache.airavata.workflow.engine.invoker.Invoker) DynamicInvoker(org.apache.airavata.workflow.engine.invoker.DynamicInvoker) ExpCatChildDataType(org.apache.airavata.registry.cpi.ExpCatChildDataType) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)

Aggregations

DynamicComponent (org.apache.airavata.workflow.model.component.dynamic.DynamicComponent)3 Component (org.apache.airavata.workflow.model.component.Component)2 InstanceComponent (org.apache.airavata.workflow.model.component.amazon.InstanceComponent)2 TerminateInstanceComponent (org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent)2 WSComponent (org.apache.airavata.workflow.model.component.ws.WSComponent)2 DataPort (org.apache.airavata.workflow.model.graph.DataPort)2 Node (org.apache.airavata.workflow.model.graph.Node)2 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)2 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)2 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)2 URL (java.net.URL)1 ExpCatChildDataType (org.apache.airavata.registry.cpi.ExpCatChildDataType)1 DynamicInvoker (org.apache.airavata.workflow.engine.invoker.DynamicInvoker)1 Invoker (org.apache.airavata.workflow.engine.invoker.Invoker)1 ControlPort (org.apache.airavata.workflow.model.graph.ControlPort)1 EdgeImpl (org.apache.airavata.workflow.model.graph.impl.EdgeImpl)1 WSPort (org.apache.airavata.workflow.model.graph.ws.WSPort)1