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

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


      /*
       * 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) {
              forEachNode.setState(NodeExecutionState.EXECUTING);
              node1.setState(NodeExecutionState.EXECUTING);
              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
        endForEachNode.setState(NodeExecutionState.FINISHED);
        middleNode.setState(NodeExecutionState.FINISHED);
        node.setState(NodeExecutionState.FINISHED);

      } 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);

        int parallelRuns = createInputValues(listOfValues, inputNumbers).size() * outputPorts1.size();
        if (listOfValues.size() > 0) {

          forEachNode.setState(NodeExecutionState.EXECUTING);
          foreachWSNode.setState(NodeExecutionState.EXECUTING);
          List<DataPort> outputPorts = middleNode.getOutputPorts();
          final AtomicInteger counter = new AtomicInteger();
          for (Node endFor : endForEachNodes) {
            final SystemComponentInvoker systemInvoker = new SystemComponentInvoker();
            this.invokerMap.put(endFor, systemInvoker);
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

    for (DataPort port : inputPorts) {
      Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);
      /*
       * Handle ForEachNode
       */
      Node fromNode = port.getFromNode();
      if (fromNode instanceof ForEachNode) {
        inputVal = inputArray[index++];
      }

      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.STOPPED);
                }
                // ok we have paused sleep
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                  log.info("Workflow execution "+config.getTopic()+" is paused.");
                  while (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                      try {
                          Thread.sleep(400);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
                  if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
                    continue;
                  }
                  log.info("Workflow execution "+config.getTopic()+" is resumed.");
                }
                // 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

      /*
       * 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) {
              forEachNode.setState(NodeExecutionState.EXECUTING);
              node1.setState(NodeExecutionState.EXECUTING);
              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
        endForEachNode.setState(NodeExecutionState.FINISHED);
        middleNode.setState(NodeExecutionState.FINISHED);
        node.setState(NodeExecutionState.FINISHED);

      } 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);

        int parallelRuns = createInputValues(listOfValues, inputNumbers).size() * outputPorts1.size();
        if (listOfValues.size() > 0) {

          forEachNode.setState(NodeExecutionState.EXECUTING);
          foreachWSNode.setState(NodeExecutionState.EXECUTING);
          List<DataPort> outputPorts = middleNode.getOutputPorts();
          final AtomicInteger counter = new AtomicInteger();
          for (Node endFor : endForEachNodes) {
            final SystemComponentInvoker systemInvoker = new SystemComponentInvoker();
            this.invokerMap.put(endFor, systemInvoker);
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

    for (DataPort port : inputPorts) {
      Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);
      /*
       * Handle ForEachNode
       */
      Node fromNode = port.getFromNode();
      if (fromNode instanceof ForEachNode) {
        inputVal = inputArray[index++];
      }

      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.STOPPED);
                }
                // ok we have paused sleep
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                  log.info("Workflow execution "+config.getTopic()+" is paused.");
                  while (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                      try {
                          Thread.sleep(400);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
                  if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
                    continue;
                  }
                  log.info("Workflow execution "+config.getTopic()+" is resumed.");
                }
                // 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

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.