Package org.apache.airavata.workflow.model.graph

Examples of org.apache.airavata.workflow.model.graph.Node$NodeObserver


      Port inputPort = graphPanel.getSelectedInputPort();
      Port outputPort = graphPanel.getSelectedOutputPort();
      this.portViewer.setInputPort(inputPort);
      this.portViewer.setOutputPort(outputPort);
      // Reset component viewer.
      Node node = graphPanel.getSelectedNode();
      Component component;
      if (node != null) {
        component = node.getComponent();
      } else {
        component = this.componentSelector.getSelectedComponent();
      }
      this.componentViewer.setComponent(component);
      String name = graphPanel.getWorkflow().getName();
View Full Code Here


        List<DataPort> inputPorts = forEachNode.getInputPorts();

        Object returnValForProvenance = null;
        for (DataPort inputPort : inputPorts) {

            Node inputNode = inputPort.getFromNode();
            // if input node for for-each is WSNode
            if (inputNode instanceof InputNode) {
                for (DataPort dataPort : forEachNode.getInputPorts()) {
                    returnValForProvenance = InterpreterUtil.findInputFromPort(dataPort, invokerMap);
                    if (null == returnValForProvenance) {
                        throw new WorkFlowInterpreterException("Unable to find input for the node:" + forEachNode.getID());
                    }
                    String[] vals = returnValForProvenance.toString().split(",");
                    listOfValues.addAll(Arrays.asList(vals));
                }
            } else {
                Invoker workflowInvoker = invokerMap.get(inputNode);
                if (workflowInvoker != null) {
                    if (workflowInvoker instanceof GenericInvoker) {

                        String outputName = inputNode.getOutputPort(0).getName();
                        returnValForProvenance = workflowInvoker.getOutput(outputName);
            Iterator children = null;
            if (returnValForProvenance instanceof org.xmlpull.v1.builder.XmlElement) {
              org.xmlpull.v1.builder.XmlElement msgElmt = (org.xmlpull.v1.builder.XmlElement) returnValForProvenance;
              children = msgElmt.children();
            } else {
              XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString("<temp>" + returnValForProvenance + "</temp>");
              children = msgElmt.children().iterator();
            }
                        while (children.hasNext()) {
                            Object object = children.next();
                            if (object instanceof org.xmlpull.v1.builder.XmlElement) {
                                org.xmlpull.v1.builder.XmlElement child = (org.xmlpull.v1.builder.XmlElement) object;
                                Iterator valItr = child.children();
                                if (valItr.hasNext()) {
                                    Object object2 = valItr.next();
                                    if (object2 instanceof String) {
                                        listOfValues.add(object2.toString());
                                    }
                                }
                            }
                            if (object instanceof XmlElement) {
                                listOfValues.add(((XmlElement) object).children().iterator().next().toString());
                            }if (object instanceof String){
                                listOfValues.add(object.toString());
                            }
                        }
                    } else if (workflowInvoker instanceof SystemComponentInvoker) {
                        int index = inputNode.getOutputPorts().indexOf(inputPort.getEdge(0).getFromPort());
                        String outputName = "";
                        if (inputNode.getInputPort(index) instanceof SystemDataPort) {
                            outputName = ((SystemDataPort) inputNode.getInputPort(index)).getWSComponentPort().getName();
                        } else if (inputNode.getInputPort(index) instanceof WSPort) {
                            outputName = ((SystemDataPort) inputNode.getInputPort(inputNode.getOutputPorts().indexOf(
                                    inputPort.getEdge(0).getFromPort()))).getWSComponentPort().getName();
                        }
                        returnValForProvenance = workflowInvoker.getOutput(outputName);
                        XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString("<temp>" + returnValForProvenance + "</temp>");
                        Iterator valItr = msgElmt.children().iterator();
View Full Code Here

     * @return
     * @throws WorkflowException
     */
    public static Object findInputFromPort(DataPort inputPort, Map<Node, Invoker> invokerMap) throws WorkflowException {
        Object outputVal = null;
        Node fromNode = inputPort.getFromNode();
        if (fromNode instanceof InputNode) {
            outputVal = ((InputNode) fromNode).getDefaultValue();
        } else if (fromNode instanceof ConstantNode) {
            outputVal = ((ConstantNode) fromNode).getValue();
        } else if (fromNode instanceof DifferedInputNode && ((DifferedInputNode) fromNode).isConfigured()) {
            outputVal = ((DifferedInputNode) fromNode).getDefaultValue();
        } else if (fromNode instanceof EndifNode || fromNode instanceof DoWhileNode  || fromNode instanceof EndDoWhileNode) {
            Invoker fromInvoker = invokerMap.get(fromNode);
            outputVal = fromInvoker.getOutput(inputPort.getFromPort().getID());
        } else if (fromNode instanceof InstanceNode) {
            return ((InstanceNode) fromNode).getOutputInstanceId();
        } else if (fromNode instanceof EndForEachNode) {
            outputVal = "";
            Invoker workflowInvoker = invokerMap.get(fromNode);
            String outputName = "";
            if (inputPort instanceof SystemDataPort) {
                outputName = ((SystemDataPort) inputPort).getWSComponentPort().getName();

            } else if (inputPort instanceof WSPort) {
                outputName = ((SystemDataPort) fromNode.getInputPort(fromNode.getOutputPorts().indexOf(inputPort.getEdge(0).getFromPort())))
                        .getWSComponentPort().getName();
            }
            XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString("<temp>" + workflowInvoker.getOutput(outputName) + "</temp>");
            Iterator valItr = msgElmt.children().iterator();
            while (valItr.hasNext()) {
View Full Code Here

        Collection<Node> toNodes = node.getOutputPort(0).getToNodes();
        if (toNodes.size() != 1) {
            throw new WorkflowRuntimeException("ForEach output does not contain single out-edge");
        }
        Node middleNode = toNodes.iterator().next();
        List<DataPort> outputPorts = middleNode.getOutputPorts();
        for (DataPort dataPort : outputPorts) {
            if (dataPort.getToNodes().size() == 1) {
                Node possibleEndForEachNode = dataPort.getToNodes().get(0);
                if (possibleEndForEachNode instanceof EndForEachNode) {
                    return possibleEndForEachNode;
                }
            }
        }
View Full Code Here

    public static Integer[] getNumberOfInputsForForEachNode(final ForEachNode forEachNode, Map<Node, Invoker> invokerMap) throws WorkflowException {
        List<DataPort> inputPorts = forEachNode.getInputPorts();
        Integer[] inputNumbers = new Integer[inputPorts.size()];
        for (DataPort forEachInputPort : inputPorts) {
            // if input node for for-each is WSNode
            Node forEachInputNode = forEachInputPort.getFromNode();
            int index = 0;
            Object returnValForProvenance = null;
            if (forEachInputNode instanceof InputNode) {
                returnValForProvenance = InterpreterUtil.findInputFromPort(forEachInputPort, invokerMap);
                if (null == returnValForProvenance) {
                    throw new WorkFlowInterpreterException("Unable to find input for the node:" + forEachNode.getID());
                }
                String[] vals = returnValForProvenance.toString().split(",");
                inputNumbers[inputPorts.indexOf(forEachInputPort)] = vals.length;
            } else {
                Invoker workflowInvoker = invokerMap.get(forEachInputNode);
                if (workflowInvoker != null) {
                    if (workflowInvoker instanceof GenericInvoker) {

                        returnValForProvenance = ((GenericInvoker) workflowInvoker).getOutputs();
                        String message = returnValForProvenance.toString();

                        XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString(message);
                        Iterator children = msgElmt.children().iterator();
                        while (children.hasNext()) {
                            Object object = children.next();
                            // foreachWSNode.getInputPort(0).getType()
                            if (object instanceof XmlElement) {
                                index++;
                            }
                        }
                    } else if (workflowInvoker instanceof WorkflowInvokerWrapperForGFacInvoker) {
                        String outputName = forEachInputNode.getOutputPort(0).getName();
                        returnValForProvenance = workflowInvoker.getOutput(outputName);
                        org.xmlpull.v1.builder.XmlElement msgElmt = (org.xmlpull.v1.builder.XmlElement) returnValForProvenance;
                        Iterator children = msgElmt.children();
                        while (children.hasNext()) {
                            Object object = children.next();
                            if (object instanceof org.xmlpull.v1.builder.XmlElement) {
                                org.xmlpull.v1.builder.XmlElement child = (org.xmlpull.v1.builder.XmlElement) object;
                                Iterator valItr = child.children();
                                if (valItr.hasNext()) {
                                    Object object2 = valItr.next();
                                    if (object2 instanceof String) {
                                        index++;
                                    }
                                }
                            }
                        }
                        inputNumbers[inputPorts.indexOf(forEachInputPort)] = index;
                    } else if (workflowInvoker instanceof SystemComponentInvoker) {
                        int portIndex = forEachInputNode.getOutputPorts().indexOf(forEachInputPort.getEdge(0).getFromPort());
                        String outputName = "";
                        if (forEachInputNode.getInputPort(portIndex) instanceof SystemDataPort) {
                            outputName = ((SystemDataPort) forEachInputNode.getInputPort(portIndex)).getWSComponentPort().getName();
                        } else if (forEachInputNode.getInputPort(portIndex) instanceof WSPort) {
                            outputName = ((WSPort) forEachInputNode.getInputPort(portIndex)).getComponentPort().getName();
                        }
                        returnValForProvenance = workflowInvoker.getOutput(outputName);
                        XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString("<temp>" + returnValForProvenance + "</temp>");
                        Iterator valItr = msgElmt.children().iterator();
                        while (valItr.hasNext()) {
View Full Code Here

      this.getWorkflow().setExecutionState(WorkflowExecutionState.RUNNING);
      ArrayList<Node> inputNodes = this.getInputNodesDynamically();
      Object[] values = new Object[inputNodes.size()];
      String[] keywords = new String[inputNodes.size()];
      for (int i = 0; i < inputNodes.size(); ++i) {
        Node node = inputNodes.get(i);
        NodeController.getGUI(node).setBodyColor(NodeState.FINISHED.color);
        notifyViaInteractor(WorkflowExecutionMessage.NODE_STATE_CHANGED, null);
        keywords[i] = ((InputNode) node).getName();
        values[i] = ((InputNode) node).getDefaultValue();
      }
      this.config.getNotifier().workflowStarted(values, keywords);
      while (this.getWorkflow().getExecutionState() != WorkflowExecutionState.STOPPED) {
        if (getRemainNodesDynamically() == 0) {
          notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_STATE_CHANGED, WorkflowExecutionState.PAUSED);
        }
        // ok we have paused sleep
        while (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
          try {
            Thread.sleep(400);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
        // get task list and execute them
        ArrayList<Node> readyNodes = this.getReadyNodesDynamically();
//                if(readyNodes.size() == 0){
//                    this.getWorkflow().setExecutionState(WorkflowExecutionState.STOPPED);
//                }
        for (Node node : readyNodes) {
          if (node.isBreak()) {
            this.notifyPause();
            break;
          }
          if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED
              || this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
View Full Code Here

      /*
       * Set type after get input value, and override inputValue if output
       * type is array
       */
      Node fromNode = dataPort.getFromNode();
      QName type = null;
      if (fromNode instanceof InputNode) {
        type = BasicTypeMapping.STRING_QNAME;
      } else if (fromNode instanceof ConstantNode) {
        type = ((ConstantNode) fromNode).getType();
View Full Code Here

      throw new WorkFlowInterpreterException("Only one node allowed inside foreach");
    }
    Iterator<Node> iterator = repeatNodes.iterator();
    if (iterator.hasNext()) {

      Node middleNode = iterator.next();

      // forEachNode should point to a WSNode and should have only one
      // output
      if ((!(middleNode instanceof WSNode)) && (!(middleNode instanceof SubWorkflowNode))) {
        throw new WorkFlowInterpreterException("Encountered Node inside foreach that is not a WSNode" + middleNode);
      } else if (middleNode instanceof SubWorkflowNode) {
        /* Get the EndforEach Node of the Subworkflow */
        Iterator<Node> subWorkflowOut = middleNode.getOutputPort(0).getToNodes().iterator();
        while (subWorkflowOut.hasNext()) {
          Node node2 = subWorkflowOut.next();
          if (node2 instanceof EndForEachNode) {
            endForEachNode = (EndForEachNode) node2;
          }
        }

        final LinkedList<String> listOfValues = new LinkedList<String>();
        InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
        final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);
        Workflow workflow1 = ((SubWorkflowNode) middleNode).getWorkflow();
        List<NodeImpl> nodes = workflow1.getGraph().getNodes();
        List<Node> wsNodes = new ArrayList<Node>();
        /* Take the List of WSNodes in the subworkflow */
        for (NodeImpl subWorkflowNode : nodes) {
          if (subWorkflowNode instanceof WSNode) {
            wsNodes.add(subWorkflowNode);
          }
        }

        for (int i = 0; i < wsNodes.size(); i++) {
          final WSNode node1 = (WSNode) wsNodes.get(i);
          SystemComponentInvoker systemInvoker = null;
          List<DataPort> outputPorts1 = node1.getOutputPorts();
          List<Node> endForEachNodes = new ArrayList<Node>();
          for (DataPort port : outputPorts1) {
            Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
            while (endForEachNodeItr1.hasNext()) {
              Node node2 = endForEachNodeItr1.next();
              if (node2 instanceof EndForEachNode) {
                endForEachNodes.add(node2);
              } else if (node2 instanceof OutputNode) {
                // intentionally left noop
              } else {
                throw new WorkFlowInterpreterException("Found More than one node inside foreach");
              }

            }
          }
          final List<Node> finalEndForEachNodes = endForEachNodes;

          Iterator<Node> endForEachNodeItr1 = node1.getOutputPort(0).getToNodes().iterator();
          while (endForEachNodeItr1.hasNext()) {
            Node node2 = endForEachNodeItr1.next();
            // Start reading input came for foreach node
            int parallelRuns = listOfValues.size() * node1.getOutputPorts().size();
            if (listOfValues.size() > 0) {
              NodeController.getGUI(forEachNode).setBodyColor(NodeState.EXECUTING.color);
              NodeController.getGUI(node1).setBodyColor(NodeState.EXECUTING.color);
              List<DataPort> outputPorts = node1.getOutputPorts();
              final AtomicInteger counter = new AtomicInteger();
              for (Node endFor : endForEachNodes) {
                systemInvoker = new SystemComponentInvoker();
                this.invokerMap.put(endFor, systemInvoker);
              }
              final Map<Node, Invoker> finalMap = this.invokerMap;
              new Thread() {
                @Override
                public void run() {
                  try {
                    runInThread(listOfValues, forEachNode, node1, finalEndForEachNodes, finalMap, counter, inputNumbers);
                  } catch (WorkflowException e) {

                    WorkflowInterpreter.this.config.getGUI().getErrorWindow().error(e);
                  }
                }

              }.start();

              while (counter.intValue() < parallelRuns) {
                try {
                  Thread.sleep(100);
                } catch (InterruptedException e) {
                  Thread.currentThread().interrupt();
                }

              }
              if (!(node2 instanceof OutputNode)) {
                listOfValues.removeAll(listOfValues);
                String output = (String) systemInvoker.getOutput(node1.getOutputPort(0).getName());
                XmlElement xmlElement = XMLUtil.stringToXmlElement("<result>" + output + "</result>");
                Iterator iterator1 = xmlElement.children().iterator();
                while (iterator1.hasNext()) {
                  Object next1 = iterator1.next();
                  if (next1 instanceof XmlElement) {
                    listOfValues.add((String) ((XmlElement) next1).children().iterator().next());
                  }
                }
              }
            }
          }
        }
        // we have finished execution so end foreach is finished
        // todo this has to be done in a separate thread
        NodeController.getGUI(endForEachNode).setBodyColor(NodeState.FINISHED.color);
        NodeController.getGUI(middleNode).setBodyColor(NodeState.FINISHED.color);
        NodeController.getGUI(node).setBodyColor(NodeState.FINISHED.color);

      } else {

        // First node after foreach should end with EndForEachNode
        List<DataPort> outputPorts1 = middleNode.getOutputPorts();
        List<Node> endForEachNodes = new ArrayList<Node>();
        for (DataPort port : outputPorts1) {
          Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
          while (endForEachNodeItr1.hasNext()) {
            Node node2 = endForEachNodeItr1.next();
            if (node2 instanceof EndForEachNode) {
              endForEachNodes.add(node2);
            } else if (node2 instanceof OutputNode) {
              // intentionally left noop
            } else {
              throw new WorkFlowInterpreterException("Found More than one node inside foreach");
            }

          }
        }
        final List<Node> finalEndForEachNodes = endForEachNodes;
        final Node foreachWSNode = middleNode;
        final LinkedList<String> listOfValues = new LinkedList<String>();

        // Start reading input came for foreach node
        InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
        final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);
View Full Code Here

          Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);

          /*
           * Handle ForEachNode
           */
          Node fromNode = port.getFromNode();
          // if (fromNode instanceof ForEachNode) {
          inputVal = WorkflowInputUtil.parseValue((WSComponentPort) port.getComponentPort(), input);
          // }

          if (null == inputVal) {
View Full Code Here

      this.getWorkflow().setExecutionState(WorkflowExecutionState.RUNNING);
      ArrayList<Node> inputNodes = this.getInputNodesDynamically();
      Object[] values = new Object[inputNodes.size()];
      String[] keywords = new String[inputNodes.size()];
      for (int i = 0; i < inputNodes.size(); ++i) {
        Node node = inputNodes.get(i);
        node.setState(NodeExecutionState.FINISHED);
        notifyViaInteractor(WorkflowExecutionMessage.NODE_STATE_CHANGED, null);
        keywords[i] = ((InputNode) node).getName();
        values[i] = ((InputNode) node).getDefaultValue();
                //Saving workflow input Node data before running the workflow
                WorkflowNodeType workflowNodeType = new WorkflowNodeType();
                workflowNodeType.setNodeType(WorkflowNodeType.WorkflowNode.INPUTNODE);
                WorkflowInstanceNode workflowInstanceNode = new WorkflowInstanceNode(new WorkflowExecution(getConfig().getTopic(),
                        getConfig().getTopic()), node.getID());
                this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().setWorkflowInstanceNodeInput(workflowInstanceNode, keywords[i] + "=" + (String) values[i]);
                this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().setWorkflowNodeType(workflowInstanceNode, workflowNodeType);
      }
      this.config.getNotifier().workflowStarted(values, keywords);
      this.config.getConfiguration().setContextHeader(WorkflowContextHeaderBuilder.getCurrentContextHeader());

      while (this.getWorkflow().getExecutionState() != WorkflowExecutionState.STOPPED) {
                ArrayList<Node> readyNodes = this.getReadyNodesDynamically();
                ArrayList<Thread> threadList = new ArrayList<Thread>();
                if (getRemainNodesDynamically() == 0) {
                    notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_STATE_CHANGED, WorkflowExecutionState.PAUSED);
                }
                // ok we have paused sleep
                while (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                    try {
                        Thread.sleep(400);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                // get task list and execute them
        for (final Node node : readyNodes) {
          if (node.isBreak()) {
            this.notifyPause();
            break;
          }
          if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED
              || this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
            break;
          }

                    // Since this is an independent node execution we can run these nodes in separate threads.
                    Thread th = new Thread() {
                        public synchronized void run() {
                            try {
                                executeDynamically(node);
                            } catch (WorkflowException e) {
                                log.error("Error execution workflow Node : " + node.getID());
                                return;
                            }
                        }
                    };
                    threadList.add(th);
View Full Code Here

TOP

Related Classes of org.apache.airavata.workflow.model.graph.Node$NodeObserver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.