Package org.apache.airavata.xbaya.invoker

Examples of org.apache.airavata.xbaya.invoker.Invoker


    node.setState(NodeExecutionState.FINISHED);
  }

  private Invoker createInvokerForEachSingleWSNode(Node foreachWSNode, String gfacURLString, WSComponent wsComponent) throws WorkflowException {
    Invoker invoker;
    String wsdlLocation = InterpreterUtil.getEPR((WSNode) foreachWSNode);
    QName portTypeQName = wsComponent.getPortTypeQName();
    if (null == wsdlLocation) {
            // WorkflowInterpreter is no longer using gfac in service mode. we only support embedded mode.
//      if (gfacURLString.startsWith("https")) {
View Full Code Here


      List<String> inputValues = createInputValues(listOfValues, inputNumber);
      for (final Iterator<String> iterator = inputValues.iterator(); iterator.hasNext();) {
        final String gfacURLString = this.getConfig().getConfiguration().getGFacURL().toString();
        final String input = iterator.next();
        WSComponent wsComponent = (WSComponent) middleNode.getComponent();
        final Invoker invoker2 = createInvokerForEachSingleWSNode(middleNode, gfacURLString, wsComponent);
        invokerList.add(invoker2);

        new Thread() {
          @Override
          public void run() {
            try {
              getInvoker(middleNode, invoker2);
              invokeGFacService(listOfValues, middleNode, inputNumber, input, invoker2);

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

        }.start();

        try {
          Thread.sleep(3000);
        } catch (InterruptedException e) {
          WorkflowInterpreter.this.config.getGUI().getErrorWindow().error(e);
        }
      }
    } else {
      Invoker invoker = null;
      for (Iterator<String> iterator = listOfValues.iterator(); iterator.hasNext();) {
        String input = iterator.next();
        final String gfacURLString = this.getConfig().getConfiguration().getGFacURL().toString();
        WSComponent wsComponent = (WSComponent) middleNode.getComponent();
        invoker = createInvokerForEachSingleWSNode(middleNode, gfacURLString, wsComponent);
        invokerList.add(invoker);
        getInvoker(middleNode, invoker);

        // find inputs
        List<DataPort> inputPorts = middleNode.getInputPorts();
        for (DataPort port : inputPorts) {
          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) {
            throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + middleNode.getID());
          }
          invoker.setInput(port.getName(), inputVal);
        }
        invoker.invoke();
      }
    }

    // String arrayElementName = foreachWSNode.getOperationName() +
    // "ArrayResponse";
    // String outputStr = "<" + arrayElementName + ">";
    // invokerMap size and endForEachNodes size can be difference
    // because we can create endForEachNode with n number of input/output
    // ports so always have to use
    // middleNode.getOutputPorts when iterate
    String[] outputStr = new String[middleNode.getOutputPorts().size()];
    int i = 0;
    for (DataPort port : middleNode.getOutputPorts()) {
      String outputString = "";
      for (Iterator<Invoker> iterator = invokerList.iterator(); iterator.hasNext();) {
        Invoker workflowInvoker = iterator.next();

        // /
        Object output = workflowInvoker.getOutput(port.getName());
        if (output instanceof org.xmlpull.v1.builder.XmlElement) {
          org.xmlpull.v1.builder.XmlElement element = (org.xmlpull.v1.builder.XmlElement) ((org.xmlpull.v1.builder.XmlElement) output).children()
              .next();
          outputString += "\n" + XMLUtil.xmlElementToString(element);
        } else {
View Full Code Here

  }

  protected void handleWSComponent(Node node) throws WorkflowException {
    WSComponent wsComponent = ((WSComponent) node.getComponent());
    QName portTypeQName = wsComponent.getPortTypeQName();
        Invoker invoker = this.invokerMap.get(node);

        // We do this because invokers cannot be cached because the puretls expires
        if (invoker != null) {
            this.invokerMap.remove(invoker);
        }

        final WSNode wsNode = (WSNode) node;
        String wsdlLocation = InterpreterUtil.getEPR(wsNode);
        final String gfacURLString = this.getConfig().getConfiguration().getGFacURL().toString();
        if (null == wsdlLocation) {

            /* If there is a instance control component connects to this
             * component send information in soap header */
            for (Node n : wsNode.getControlInPort().getFromNodes()) {
                if (n instanceof InstanceNode) {
                    AmazonSecurityContext amazonSecurityContext;
                    final String awsAccessKeyId = config.getAwsAccessKey();
                    final String awsSecretKey = config.getAwsSecretKey();
                    final String username = ((InstanceNode) n).getUsername();

                    if (((InstanceNode) n).isStartNewInstance()) {
                        final String amiId = ((InstanceNode) n).getIdAsValue();
                        final String instanceType = ((InstanceNode) n).getInstanceType();

                        amazonSecurityContext =
                                new AmazonSecurityContext(username, awsAccessKeyId, awsSecretKey, amiId, instanceType);
                    } else {
                        final String instanceId = ((InstanceNode) n).getIdAsValue();
                        amazonSecurityContext =
                                new AmazonSecurityContext(username, awsAccessKeyId, awsSecretKey, instanceId);
                    }

                    this.config.getConfiguration().setAmazonSecurityContext(amazonSecurityContext);
                }
            }

            if ((this.config.isGfacEmbeddedMode()) || (config.getAwsAccessKey() != null)) {
                invoker = new EmbeddedGFacInvoker(portTypeQName, WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode.getComponent().getWSDL()), node.getID(),
                        this.config.getMessageBoxURL().toASCIIString(), this.config.getMessageBrokerURL().toASCIIString(), this.config.getNotifier(),
                        this.config.getTopic(), this.config.getAiravataAPI(), portTypeQName.getLocalPart(), this.config.getConfiguration());
            } else {
                invoker = new GenericInvoker(portTypeQName, WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode.getComponent().getWSDL()), node.getID(),
                        this.config.getMessageBoxURL().toASCIIString(), gfacURLString, this.config.getNotifier());
            }

        } else {
      if (wsdlLocation.endsWith("/")) {
        wsdlLocation = wsdlLocation.substring(0, wsdlLocation.length() - 1);
      }
      if (!wsdlLocation.endsWith("?wsdl")) {
        wsdlLocation += "?wsdl";
      }
      invoker = new GenericInvoker(portTypeQName, wsdlLocation, node.getID(), this.getConfig().getConfiguration().getMessageBoxURL().toString(),
          gfacURLString, this.config.getNotifier());
    }
    invoker.setup();
    this.invokerMap.put(node, invoker);
    invoker.setOperation(wsComponent.getOperationName());

    // find inputs
    List<DataPort> inputPorts = node.getInputPorts();
    ODEClient odeClient = new ODEClient();
    for (DataPort port : inputPorts) {
      Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);

      /*
       * Need to override inputValue if it is odeClient
       */
      if (port.getFromNode() instanceof InputNode) {
        inputVal = WorkflowInputUtil.parseValue((WSComponentPort) port.getComponentPort(), (String) inputVal);
      }

      if (null == inputVal) {
        throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + node.getID());
      }
      if (port.getFromNode() instanceof EndForEachNode) {
        inputVal = WorkflowInputUtil.parseValue((WSComponentPort) port.getComponentPort(), (String) inputVal);
        // org.xmlpull.v1.builder.XmlElement inputElem = XMLUtil
        // .stringToXmlElement3("<" + port.getName() + ">"
        // + inputVal.toString() + "</" + port.getName()
        // + ">");
        // inputVal = inputElem;
      }
      invoker.setInput(port.getName(), inputVal);
    }
    invoker.invoke();
  }
View Full Code Here

        type = BasicTypeMapping.STRING_QNAME;
      } 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();
      }
View Full Code Here

    node.setState(NodeExecutionState.FINISHED);
  }

  private Invoker createInvokerForEachSingleWSNode(Node foreachWSNode, String gfacURLString, WSComponent wsComponent) throws WorkflowException {
    Invoker invoker;
    String wsdlLocation = InterpreterUtil.getEPR((WSNode) foreachWSNode);
    QName portTypeQName = wsComponent.getPortTypeQName();
    if (null == wsdlLocation) {
            // WorkflowInterpreter is no longer using gfac in service mode. we only support embedded mode.
//      if (gfacURLString.startsWith("https")) {
View Full Code Here

      List<String> inputValues = createInputValues(listOfValues, inputNumber);
      for (final Iterator<String> iterator = inputValues.iterator(); iterator.hasNext();) {
        final String gfacURLString = this.getConfig().getConfiguration().getGFacURL().toString();
        final String input = iterator.next();
        WSComponent wsComponent = (WSComponent) middleNode.getComponent();
        final Invoker invoker2 = createInvokerForEachSingleWSNode(middleNode, gfacURLString, wsComponent);
        invokerList.add(invoker2);

        new Thread() {
          @Override
          public void run() {
            try {
              getInvoker(middleNode, invoker2);
              invokeGFacService(listOfValues, middleNode, inputNumber, input, invoker2);

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

        }.start();

        try {
          Thread.sleep(3000);
        } catch (InterruptedException e) {
          WorkflowInterpreter.this.config.getGUI().getErrorWindow().error(e);
        }
      }
    } else {
      Invoker invoker = null;
      for (Iterator<String> iterator = listOfValues.iterator(); iterator.hasNext();) {
        String input = iterator.next();
        final String gfacURLString = this.getConfig().getConfiguration().getGFacURL().toString();
        WSComponent wsComponent = (WSComponent) middleNode.getComponent();
        invoker = createInvokerForEachSingleWSNode(middleNode, gfacURLString, wsComponent);
        invokerList.add(invoker);
        getInvoker(middleNode, invoker);

        // find inputs
        List<DataPort> inputPorts = middleNode.getInputPorts();
        for (DataPort port : inputPorts) {
          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) {
            throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + middleNode.getID());
          }
          invoker.setInput(port.getName(), inputVal);
        }
        invoker.invoke();
      }
    }

    // String arrayElementName = foreachWSNode.getOperationName() +
    // "ArrayResponse";
    // String outputStr = "<" + arrayElementName + ">";
    // invokerMap size and endForEachNodes size can be difference
    // because we can create endForEachNode with n number of input/output
    // ports so always have to use
    // middleNode.getOutputPorts when iterate
    String[] outputStr = new String[middleNode.getOutputPorts().size()];
    int i = 0;
    for (DataPort port : middleNode.getOutputPorts()) {
      String outputString = "";
      for (Iterator<Invoker> iterator = invokerList.iterator(); iterator.hasNext();) {
        Invoker workflowInvoker = iterator.next();

        // /
        Object output = workflowInvoker.getOutput(port.getName());
        if (output instanceof org.xmlpull.v1.builder.XmlElement) {
          org.xmlpull.v1.builder.XmlElement element = (org.xmlpull.v1.builder.XmlElement) ((org.xmlpull.v1.builder.XmlElement) output).children()
              .next();
          outputString += "\n" + XMLUtil.xmlElementToString(element);
        } else {
View Full Code Here

        }
        String[] vals = returnValForProvenance.toString().split(",");
        listOfValues.addAll(Arrays.asList(vals));
      }
    } 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) {
              listOfValues.add(XmlConstants.BUILDER
                  .serializeToString(object));
              // TODO fix for simple type - Done
            }
          }
        } 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) {
                  listOfValues.add(object2.toString());
                }
              }
            }
          }
        } else if (workflowInvoker instanceof SystemComponentInvoker) {
          String outputName = forEachInputNode.getOutputPort(0)
              .getName();
          returnValForProvenance = workflowInvoker
              .getOutput(outputName);
          XmlElement msgElmt = XmlConstants.BUILDER
              .parseFragmentFromString("<temp>"
                  + returnValForProvenance + "</temp>");
          Iterator valItr = msgElmt.children().iterator();
View Full Code Here

    if (fromNode instanceof InputNode) {
      outputVal = ((InputNode) fromNode).getDefaultValue();
    } else if (fromNode instanceof ConstantNode) {
      outputVal = ((ConstantNode) fromNode).getValue();
    } else if (fromNode instanceof EndifNode) {
      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 = fromNode.getOutputPort(0).getName();
      XmlElement msgElmt = XmlConstants.BUILDER
          .parseFragmentFromString("<temp>"
              + workflowInvoker.getOutput(outputName) + "</temp>");
      Iterator valItr = msgElmt.children().iterator();
      while (valItr.hasNext()) {
        Object object2 = valItr.next();
        if (object2 instanceof XmlElement) {
          outputVal = outputVal
              + ","
              + ((XmlElement) object2).children().iterator()
                  .next().toString();
        }
      }
      outputVal = ((String) outputVal).substring(1,
          ((String) outputVal).length());
    } else {
      Invoker fromInvoker = invokerMap.get(fromNode);
      try {
        if (fromInvoker != null)
          outputVal = fromInvoker.getOutput(inputPort.getFromPort()
              .getName());

      } catch (Exception e) {
        // if the value is still null look it up from the inputport name
        // because the value is set to the input port name at some point
        // there is no harm in doing this
        if (null == outputVal) {
          outputVal = fromInvoker.getOutput(inputPort.getName());
        }
      }

    }
    return outputVal;
View Full Code Here

          }
          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);
            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) {
                    listOfValues.add(object2.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();
            while (valItr.hasNext()) {
              Object object2 = valItr.next();
              if (object2 instanceof XmlElement) {
View Full Code Here

    } 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()) {
        Object object2 = valItr.next();
        if (object2 instanceof XmlElement) {

          if (((XmlElement) object2).children().iterator().hasNext()) {
            outputVal = outputVal + "," + ((XmlElement) object2).children().iterator().next().toString();
          }
        }
      }

      if (((String) outputVal).length() == 0) {
        throw new WorkflowException("Empty Output Generated");
      }
      outputVal = ((String) outputVal).substring(1, ((String) outputVal).length());
    } else {
      Invoker fromInvoker = invokerMap.get(fromNode);
      try {
        if (fromInvoker != null)
          outputVal = fromInvoker.getOutput(inputPort.getFromPort().getName());

      } catch (Exception e) {
        // if the value is still null look it up from the inputport name
        // because the value is set to the input port name at some point
        // there is no harm in doing this
        if (null == outputVal) {
          outputVal = fromInvoker.getOutput(inputPort.getName());
        }
      }

    }
    return outputVal;
View Full Code Here

TOP

Related Classes of org.apache.airavata.xbaya.invoker.Invoker

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.