Package org.apache.airavata.xbaya.invoker

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


                                    + 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();
View Full Code Here


    /**
     * @throws XBayaException
     */
    public void testService() throws XBayaException {
        NotificationSender notifier = new NotificationSender(this.configuration.getBrokerURL(), "test-topic2");
        Invoker invoker = new GenericInvoker(QName.valueOf(TEST_SERVICE_QNAME), TEST_AWSDL, "test-node", null,
                this.configuration.getGFacURL().toString(), notifier);
        invoker.setup();
        invoker.setOperation("Run");
        invoker.setInput("inparam1", "test");
        invoker.invoke();
        Object output = invoker.getOutput("outparam1");
        logger.info("output: " + output);
    }
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

  }

  private void handleWSComponent(Node node) throws XBayaException {
    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.configuration.getGFacURL().toString();
    if (null == wsdlLocation) {
      if (gfacURLString.startsWith("https")) {
        GSSCredential proxy = null;
        if (this.mode == GUI_MODE) {
          this.myProxyChecker.loadIfNecessary();
          MyProxyClient myProxyClient = this.engine
              .getMyProxyClient();
          proxy = myProxyClient.getProxy();
        } else {
          proxy = SecurityUtil.getGSSCredential(this.username,
              this.password,
              this.configuration.getMyProxyServer());
        }

        LeadContextHeader leadCtxHeader = null;
        try {
          if (this.mode == GUI_MODE) {
            leadCtxHeader = XBayaUtil.buildLeadContextHeader(
                this.getWorkflow(),
                this.configuration,
                new MonitorConfiguration(this.configuration
                    .getBrokerURL(), this.topic, true,
                    this.configuration.getMessageBoxURL()),
                wsNode.getID(), null);
          } else {
            leadCtxHeader = XBayaUtil.buildLeadContextHeader(
                this.getWorkflow(),
                this.configuration,
                new MonitorConfiguration(this.configuration
                    .getBrokerURL(), this.topic, true,
                    this.configuration.getMessageBoxURL()),
                wsNode.getID(), null);
          }
        } catch (URISyntaxException e) {
          throw new XBayaException(e);
        }

        leadCtxHeader.setServiceId(node.getID());
        try {
          leadCtxHeader.setWorkflowId(new URI(this.getWorkflow()
              .getName()));

          // We do this so that the wsdl resolver can is setup
          // wsdlresolver.getInstance is static so once this is
          // done
          // rest of the loading should work.

          XBayaSecurity.init();

        } catch (URISyntaxException e) {
          throw new XBayaRuntimeException(e);
        }

        /*
         * Resource Mapping Header
         */
        if (this.resourceMapping != null) {
          leadCtxHeader.setResourceMapping(this.resourceMapping);
        }

        /*
         * 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) {
            // TODO make it as constant
            LeadResourceMapping x = new LeadResourceMapping(
                "AMAZON");

            x.addAttribute("ACCESS_KEY", AmazonCredential
                .getInstance().getAwsAccessKeyId());
            x.addAttribute("SECRET_KEY", AmazonCredential
                .getInstance().getAwsSecretAccessKey());

            if (((InstanceNode) n).isStartNewInstance()) {
              x.addAttribute("AMI_ID",
                  ((InstanceNode) n).getIdAsValue());
              x.addAttribute("INS_TYPE",
                  ((InstanceNode) n).getInstanceType());
            } else {
              x.addAttribute("INS_ID",
                  ((InstanceNode) n).getIdAsValue());
            }

            x.addAttribute("USERNAME",
                ((InstanceNode) n).getUsername());

            // set to leadHeader
            leadCtxHeader.setResourceMapping(x);
          }
        }

        invoker = new WorkflowInvokerWrapperForGFacInvoker(
            portTypeQName, gfacURLString, this.engine.getMonitor()
                .getConfiguration().getMessageBoxURL()
                .toString(), leadCtxHeader,
            this.notifier.createServiceNotificationSender(node
                .getID()));

      } else {
        if (this.mode == GUI_MODE) {
          // if user configure the msgBox url using the UI we have to
          // pick the latest one which
          // set by the UI
                    if (this.gfacEmbeddedMode) {
                        invoker = new EmbeddedGFacInvoker(portTypeQName,
                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
                                        .getComponent().getWSDL()), node.getID(),
                                this.engine.getMonitor().getConfiguration()
                                        .getMessageBoxURL().toASCIIString(),
                                this.engine.getMonitor().getConfiguration().getBrokerURL().toASCIIString(), this.notifier, this.topic,
                                this.engine.getConfiguration().getJcrComponentRegistry().getRegistry(),
                                portTypeQName.getLocalPart(),this.engine.getConfiguration());
                    } else {
                        invoker = new GenericInvoker(portTypeQName,
                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
                                        .getComponent().getWSDL()), node.getID(),
                                this.engine.getMonitor().getConfiguration()
                                        .getMessageBoxURL().toASCIIString(),
                                gfacURLString, this.notifier);
                    }
        } else {
                    if(this.gfacEmbeddedMode){
                        invoker = new EmbeddedGFacInvoker(portTypeQName,
                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
                                        .getComponent().getWSDL()), node.getID(),
                                this.configuration.getMessageBoxURL()
                                        .toASCIIString(),
                                this.configuration.getBrokerURL().toASCIIString(), this.notifier, this.topic, configuration.getJcrComponentRegistry().getRegistry(),
                                portTypeQName.getLocalPart(),this.configuration);
                    }else{
                        invoker = new GenericInvoker(portTypeQName,
                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
                                        .getComponent().getWSDL()), node.getID(),
                                this.configuration.getMessageBoxURL()
                                        .toASCIIString(), gfacURLString,
                                this.notifier);

                    }
        }
      }

    } 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.configuration.getMessageBoxURL()
              .toString(), gfacURLString, this.notifier);
    }
    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 = ODEClientUtil.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 = ODEClientUtil.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

      } 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();
View Full Code Here

  }

  private Invoker createInvokerForEachSingleWSNode(Node foreachWSNode,
      String gfacURLString, WSComponent wsComponent)
      throws XBayaException {
    Invoker invoker;
    String wsdlLocation = InterpreterUtil.getEPR((WSNode) foreachWSNode);
    QName portTypeQName = wsComponent.getPortTypeQName();
    if (null == wsdlLocation) {
      if (gfacURLString.startsWith("https")) {
        GSSCredential proxy = null;
View Full Code Here

        final String gfacURLString = this.configuration.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 (XBayaException e) {
              WorkflowInterpreter.this.engine.getErrorWindow()
                  .error(e);
            }
          }

        }.start();

        try {
          Thread.sleep(3000);
        } catch (InterruptedException e) {
          WorkflowInterpreter.this.engine.getErrorWindow().error(e);
        }
      }
    } else {
      Invoker invoker = null;
      for (Iterator<String> iterator = listOfValues.iterator(); iterator
          .hasNext();) {
        String input = iterator.next();
        final String gfacURLString = this.configuration.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 = ODEClientUtil.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

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.