airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1311379 - in /incubator/airavata/trunk/modules/xbaya-gui: ./ src/main/java/org/apache/airavata/xbaya/interpretor/ src/main/java/org/apache/airavata/xbaya/invoker/
Date Mon, 09 Apr 2012 19:11:31 GMT
Author: lahiru
Date: Mon Apr  9 19:11:30 2012
New Revision: 1311379

URL: http://svn.apache.org/viewvc?rev=1311379&view=rev
Log:
adding embedded gfac feature to WorkflowInterpreter.

Added:
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/EmbeddedGFacInvoker.java
Modified:
    incubator/airavata/trunk/modules/xbaya-gui/pom.xml
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpreter.java
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpretorSkeleton.java
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/GenericInvoker.java

Modified: incubator/airavata/trunk/modules/xbaya-gui/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/pom.xml?rev=1311379&r1=1311378&r2=1311379&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/pom.xml (original)
+++ incubator/airavata/trunk/modules/xbaya-gui/pom.xml Mon Apr  9 19:11:30 2012
@@ -374,6 +374,11 @@
 		</dependency>
         <dependency>
 			<groupId>org.apache.airavata</groupId>
+			<artifactId>gfac-core</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+        <dependency>
+			<groupId>org.apache.airavata</groupId>
 			<artifactId>registry-migrator</artifactId>
 			<version>${project.version}</version>
 		</dependency>

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpreter.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpreter.java?rev=1311379&r1=1311378&r2=1311379&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpreter.java
(original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpreter.java
Mon Apr  9 19:11:30 2012
@@ -44,7 +44,9 @@ import org.apache.airavata.common.regist
 import org.apache.airavata.common.utils.Pair;
 import org.apache.airavata.common.utils.WSDLUtil;
 import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.registry.api.AiravataRegistry;
 import org.apache.airavata.registry.api.WorkflowExecutionStatus.ExecutionStatus;
+import org.apache.airavata.registry.api.impl.AiravataJCRRegistry;
 import org.apache.airavata.xbaya.XBayaConfiguration;
 import org.apache.airavata.xbaya.XBayaEngine;
 import org.apache.airavata.xbaya.XBayaException;
@@ -94,6 +96,7 @@ import org.apache.airavata.xbaya.graph.w
 import org.apache.airavata.xbaya.graph.ws.WSPort;
 import org.apache.airavata.xbaya.gui.Cancelable;
 import org.apache.airavata.xbaya.gui.WaitDialog;
+import org.apache.airavata.xbaya.invoker.EmbeddedGFacInvoker;
 import org.apache.airavata.xbaya.invoker.GenericInvoker;
 import org.apache.airavata.xbaya.invoker.Invoker;
 import org.apache.airavata.xbaya.invoker.WorkflowInvokerWrapperForGFacInvoker;
@@ -164,6 +167,8 @@ public class WorkflowInterpreter {
 
 	private String topic;
 
+    private Boolean gfacEmbeddedMode = false;
+
 	private LeadResourceMapping resourceMapping;
 
 	private boolean actOnProvenance = false;
@@ -909,19 +914,41 @@ public class WorkflowInterpreter {
 					// if user configure the msgBox url using the UI we have to
 					// pick the latest one which
 					// set by the UI
-					invoker = new GenericInvoker(portTypeQName,
-							WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
-									.getComponent().getWSDL()), node.getID(),
-							this.engine.getMonitor().getConfiguration()
-									.getMessageBoxURL().toASCIIString(),
-							gfacURLString, this.notifier);
+                    if (this.gfacEmbeddedMode) {
+                        invoker = new EmbeddedGFacInvoker(portTypeQName,
+                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
+                                        .getComponent().getWSDL()), node.getID(),
+                                this.engine.getMonitor().getConfiguration()
+                                        .getMessageBoxURL().toASCIIString(),
+                                gfacURLString, this.notifier, this.topic,
+                                this.engine.getConfiguration().getJcrComponentRegistry().getRegistry(),
+                                portTypeQName.getLocalPart());
+                    } else {
+                        invoker = new GenericInvoker(portTypeQName,
+                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
+                                        .getComponent().getWSDL()), node.getID(),
+                                this.engine.getMonitor().getConfiguration()
+                                        .getMessageBoxURL().toASCIIString(),
+                                gfacURLString, this.notifier);
+                    }
 				} else {
-					invoker = new GenericInvoker(portTypeQName,
-							WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
-									.getComponent().getWSDL()), node.getID(),
-							this.configuration.getMessageBoxURL()
-									.toASCIIString(), gfacURLString,
-							this.notifier);
+                    if(this.gfacEmbeddedMode){
+                        invoker = new EmbeddedGFacInvoker(portTypeQName,
+                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
+                                        .getComponent().getWSDL()), node.getID(),
+                                this.configuration.getMessageBoxURL()
+                                        .toASCIIString(),
+                                gfacURLString, this.notifier, this.topic, configuration.getJcrComponentRegistry().getRegistry(),
+                                portTypeQName.getLocalPart());
+                    }else{
+                        invoker = new GenericInvoker(portTypeQName,
+                                WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(wsNode
+                                        .getComponent().getWSDL()), node.getID(),
+                                this.configuration.getMessageBoxURL()
+                                        .toASCIIString(), gfacURLString,
+                                this.notifier);
+
+                    }
 				}
 			}
 
@@ -1818,11 +1845,6 @@ public class WorkflowInterpreter {
 		return list;
 
 	}
-
-
-
-
-
 	public boolean isRunWithCrossProduct() {
 		return runWithCrossProduct;
 	}
@@ -1842,4 +1864,12 @@ public class WorkflowInterpreter {
 	public void setProvenanceWriter(PredicatedTaskRunner provenanceWriter) {
 		this.provenanceWriter = provenanceWriter;
 	}
+
+    public void setGfacEmbeddedMode(Boolean gfacEmbeddedMode) {
+        this.gfacEmbeddedMode = gfacEmbeddedMode;
+    }
+
+    public Boolean getGfacEmbeddedMode() {
+        return gfacEmbeddedMode;
+    }
 }
\ No newline at end of file

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpretorSkeleton.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpretorSkeleton.java?rev=1311379&r1=1311378&r2=1311379&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpretorSkeleton.java
(original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/interpretor/WorkflowInterpretorSkeleton.java
Mon Apr  9 19:11:30 2012
@@ -21,14 +21,21 @@
 
 package org.apache.airavata.xbaya.interpretor;
 
+import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.airavata.common.registry.api.exception.RegistryException;
 import org.apache.airavata.common.registry.api.impl.JCRRegistry;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.commons.gfac.type.HostDescription;
+import org.apache.airavata.schemas.gfac.GlobusHostType;
+import org.apache.airavata.schemas.gfac.HostDescriptionType;
 import org.apache.airavata.xbaya.XBayaConfiguration;
 import org.apache.airavata.xbaya.XBayaConstants;
 import org.apache.airavata.xbaya.XBayaException;
@@ -44,8 +51,17 @@ import org.apache.airavata.xbaya.wf.Work
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.engine.ServiceLifeCycle;
+import org.apache.xmlbeans.XmlObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
 
 import javax.jcr.RepositoryException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 
 /**
  * WorkflowInterpretorSkeleton java skeleton for the axisService
@@ -69,11 +85,13 @@ public class WorkflowInterpretorSkeleton
     public static  String jcrURL = "";
     public static boolean runInThread = false;
     public static final String RUN_IN_THREAD = "runInThread";
+    public static  Boolean gfacEmbeddedMode = false;
     private static PredicatedTaskRunner runner = null;
     public static  JCRComponentRegistry jcrComponentRegistry = null;
     public static int provenanceWriterThreadPoolSize = 1;
     public static final String PROVENANCE_WRITER_THREAD_POOL_SIZE = "provenanceWriterThreadPoolSize";
     public static final int JCR_AVAIALABILITY_WAIT_INTERVAL = 1000 * 10;
+    public static final String GFAC_EMBEDDED = "gfac.embedded";
 
     public void startUp(final ConfigurationContext configctx, AxisService service) {
     	new Thread(){
@@ -94,19 +112,24 @@ public class WorkflowInterpretorSkeleton
 		            jcrUserName = (String)properties.get(JCR_USER);
 		            jcrPassword = (String) properties.get(JCR_PASS);
 		            jcrURL = (String) properties.get(JCR_URL);
-		            provenanceWriterThreadPoolSize = Integer.parseInt((String)properties.get(PROVENANCE_WRITER_THREAD_POOL_SIZE));
-		
+		            provenanceWriterThreadPoolSize = Integer.parseInt((String) properties.get(PROVENANCE_WRITER_THREAD_POOL_SIZE));
 		            if("true".equals(properties.get(PROVENANCE))){
 		                provenance = true;
 		                runner = new PredicatedTaskRunner(provenanceWriterThreadPoolSize);
 		                try {
 		                    jcrComponentRegistry = new JCRComponentRegistry(new URI(jcrURL),jcrUserName,jcrPassword);
+                            List<HostDescription> hostList = getDefinedHostDescriptions();
+                            for(HostDescription host:hostList){
+                                jcrComponentRegistry.getRegistry().saveHostDescription(host);
+                            }
 		                } catch (RepositoryException e) {
 		                    e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
 		                } catch (URISyntaxException e) {
 		                    e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
-		                }
-		            }else{
+		                } catch (RegistryException e) {
+                            e.printStackTrace();  //To change body of catch statement use
File | Settings | File Templates.
+                        }
+                    }else{
 		                provenance = false;
 		            }
 		            if("true".equals(properties.get(RUN_IN_THREAD))){
@@ -114,6 +137,12 @@ public class WorkflowInterpretorSkeleton
 		            }else{
 		                runInThread = false;
 		            }
+
+                     if("true".equals(properties.get(GFAC_EMBEDDED))){
+		                gfacEmbeddedMode = true;
+		            }else{
+		                gfacEmbeddedMode = false;
+		            }
 		
 		        } catch (IOException e) {
 		            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
@@ -194,6 +223,7 @@ public class WorkflowInterpretorSkeleton
         final WorkflowInterpreter finalInterpreter = interpreter;
         interpreter.setActOnProvenance(provenance);
         interpreter.setProvenanceWriter(runner);
+        interpreter.setGfacEmbeddedMode(gfacEmbeddedMode);
         final String experimentId = topic;
         System.err.println("Created the interpreter");
         if(inNewThread){
@@ -260,4 +290,43 @@ public class WorkflowInterpretorSkeleton
              runner.shutDown();
          }
     }
+
+    private List<HostDescription> getDefinedHostDescriptions() {
+        URL url = this.getClass().getClassLoader().getResource("host.xml");
+        File fXmlFile = new File(url.getPath());
+        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder dBuilder = null;
+        ArrayList<HostDescription> hostDescriptions = new ArrayList<HostDescription>();
+        try {
+            dBuilder = dbFactory.newDocumentBuilder();
+            Document doc = dBuilder.parse(fXmlFile);
+            doc.getDocumentElement().normalize();
+            System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
+            NodeList nList = doc.getElementsByTagName("server");
+            for (int temp = 0; temp < nList.getLength(); temp++) {
+                Node nNode = nList.item(temp);
+                HostDescription hostDescription ;
+                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+                    Element eElement = (Element) nNode;
+                    if(XMLUtil.getTagValue("gram.endpoint", eElement) != null){
+                        hostDescription = new HostDescription(GlobusHostType.type);
+                         ((GlobusHostType)hostDescription.getType()).addGlobusGateKeeperEndPoint(XMLUtil.getTagValue("gram.endpoint",
eElement));
+                        ((GlobusHostType)hostDescription.getType()).addGridFTPEndPoint(XMLUtil.getTagValue("gridftp.endpoint",
eElement));
+                    }else{
+                        hostDescription = new HostDescription(HostDescriptionType.type);
+                    }
+                    (hostDescription.getType()).setHostName(XMLUtil.getTagValue("name", eElement));
+                    (hostDescription.getType()).setHostAddress(XMLUtil.getTagValue("host",
eElement));
+                    hostDescriptions.add(hostDescription);
+                }
+            }
+        } catch (ParserConfigurationException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        } catch (SAXException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        } catch (IOException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+        return hostDescriptions;
+    }
 }

Added: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/EmbeddedGFacInvoker.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/EmbeddedGFacInvoker.java?rev=1311379&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/EmbeddedGFacInvoker.java
(added)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/EmbeddedGFacInvoker.java
Mon Apr  9 19:11:30 2012
@@ -0,0 +1,470 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+package org.apache.airavata.xbaya.invoker;
+
+import org.apache.airavata.common.registry.api.exception.RegistryException;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.common.workflow.execution.context.WorkflowContextHeaderBuilder;
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.ServiceDescription;
+import org.apache.airavata.commons.gfac.wsdl.WSDLConstants;
+import org.apache.airavata.core.gfac.GfacAPI;
+import org.apache.airavata.core.gfac.context.GFacConfiguration;
+import org.apache.airavata.core.gfac.context.JobContext;
+import org.apache.airavata.core.gfac.context.invocation.InvocationContext;
+import org.apache.airavata.core.gfac.context.invocation.impl.DefaultInvocationContext;
+import org.apache.airavata.core.gfac.context.message.MessageContext;
+import org.apache.airavata.core.gfac.context.message.impl.ParameterContextImpl;
+import org.apache.airavata.core.gfac.utils.GfacUtils;
+import org.apache.airavata.registry.api.AiravataRegistry;
+import org.apache.airavata.schemas.gfac.Parameter;
+import org.apache.airavata.schemas.gfac.ServiceDescriptionType;
+import org.apache.airavata.xbaya.XBayaException;
+import org.apache.airavata.xbaya.XBayaRuntimeException;
+import org.apache.airavata.xbaya.invoker.factory.InvokerFactory;
+import org.apache.airavata.xbaya.jython.lib.ServiceNotifiable;
+import org.apache.airavata.xbaya.jython.lib.WorkflowNotifiable;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.v1.builder.XmlElement;
+import xsul.wsdl.WsdlDefinitions;
+import xsul.wsdl.WsdlException;
+import xsul.wsdl.WsdlResolver;
+import xsul.wsif.WSIFMessage;
+import xsul.wsif.impl.WSIFMessageElement;
+import xsul.xhandler_soap_sticky_header.StickySoapHeaderHandler;
+import xsul.xwsif_runtime.WSIFClient;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.File;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.*;
+import java.util.concurrent.*;
+
+public class EmbeddedGFacInvoker implements Invoker{
+
+      private static final Logger logger = LoggerFactory.getLogger(EmbeddedGFacInvoker.class);
+
+    private String nodeID;
+
+    private QName portTypeQName;
+
+    private String wsdlLocation;
+
+    private String serviceInformation;
+
+    private String messageBoxURL;
+
+    private String gfacURL;
+
+    private Invoker invoker;
+
+
+    private Future<Boolean> result;
+
+    private ServiceNotifiable notifier;
+
+    private AiravataRegistry registry;
+
+    private String topic;
+
+    private String serviceName;
+    /**
+     * used for notification
+     */
+    private List<Object> inputValues = new ArrayList<Object>();
+
+    /**
+     * used for notification
+     */
+    private List<String> inputNames = new ArrayList<String>();
+
+    boolean failerSent;
+
+    private WsdlDefinitions wsdlDefinitionObject;
+
+    Map<Parameter,ActualParameter> actualParameters = new HashMap<Parameter,ActualParameter>();
+
+    /**
+     * Creates an InvokerWithNotification.
+     *
+     * @param portTypeQName
+     *
+     * @param wsdlLocation
+     *            The URL of WSDL of the service to invoke
+     * @param nodeID
+     *            The ID of the service
+     * @param notifier
+     *            The notification sender
+     */
+    public EmbeddedGFacInvoker(QName portTypeQName, String wsdlLocation, String nodeID, WorkflowNotifiable
notifier) {
+        this(portTypeQName, wsdlLocation, nodeID, null, notifier);
+    }
+
+    /**
+     * Creates an InvokerWithNotification.
+     *
+     * @param portTypeQName
+     *
+     * @param wsdlLocation
+     *            The URL of WSDL of the service to invoke
+     * @param nodeID
+     *            The ID of the service
+     * @param gfacURL
+     *            The URL of GFac service.
+     * @param notifier
+     *            The notification sender
+     */
+    public EmbeddedGFacInvoker(QName portTypeQName, String wsdlLocation, String nodeID, String
gfacURL,
+            WorkflowNotifiable notifier) {
+        this(portTypeQName, wsdlLocation, nodeID, null, gfacURL, notifier);
+    }
+
+    /**
+     * Creates an InvokerWithNotification.
+     *
+     * @param portTypeQName
+     *
+     * @param wsdlLocation
+     *            The URL of WSDL of the service to invoke
+     * @param nodeID
+     *            The ID of the service
+     * @param messageBoxURL
+     * @param gfacURL
+     *            The URL of GFac service.
+     * @param notifier
+     *            The notification sender
+     */
+    public EmbeddedGFacInvoker(QName portTypeQName, String wsdlLocation, String nodeID, String
messageBoxURL,
+            String gfacURL, WorkflowNotifiable notifier) {
+        this.nodeID = nodeID;
+        this.portTypeQName = portTypeQName;
+        this.wsdlLocation = wsdlLocation;
+        this.serviceInformation = wsdlLocation;
+        this.messageBoxURL = messageBoxURL;
+        this.gfacURL = gfacURL;
+        this.notifier = notifier.createServiceNotificationSender(nodeID);
+
+        this.failerSent = false;
+    }
+
+    /**
+     *
+     * @param portTypeQName
+     * @param wsdl
+     * @param nodeID
+     * @param messageBoxURL
+     * @param gfacURL
+     * @param notifier
+     */
+    public EmbeddedGFacInvoker(QName portTypeQName, WsdlDefinitions wsdl, String nodeID,
String messageBoxURL,
+            String gfacURL, WorkflowNotifiable notifier,String topic,AiravataRegistry registry,String
serviceName) {
+        final String wsdlStr = xsul.XmlConstants.BUILDER.serializeToString(wsdl);
+        this.nodeID = nodeID;
+        this.portTypeQName = portTypeQName;
+        this.wsdlDefinitionObject = wsdl;
+        this.messageBoxURL = messageBoxURL;
+        this.serviceInformation = wsdlStr;
+        this.gfacURL = gfacURL;
+        this.notifier = notifier.createServiceNotificationSender(nodeID);
+        this.registry = registry;
+        this.topic = topic;
+        this.serviceName = serviceName;
+        this.failerSent = false;
+    }
+
+    /**
+     *
+     * @throws XBayaException
+     */
+    public void setup() throws XBayaException {
+    }
+
+    private void setup(WsdlDefinitions definitions) throws XBayaException {
+    }
+
+    /**
+     *
+     * @param operationName
+     *            The name of the operation
+     * @throws XBayaException
+     */
+    public void setOperation(String operationName) throws XBayaException {
+    }
+
+    /**
+     *
+     * @param name
+     *            The name of the input parameter
+     * @param value
+     *            The value of the input parameter
+     * @throws XBayaException
+     */
+    public void setInput(String name, Object value) throws XBayaException {
+        try {
+            if (value instanceof XmlElement) {
+                logger.info("value: " + XMLUtil.xmlElementToString((XmlElement) value));
+            }
+            this.inputNames.add(name);
+            this.inputValues.add(value);
+            ServiceDescription serviceDescription = registry.getServiceDescription(this.serviceName);
+            ServiceDescriptionType serviceDescriptionType = serviceDescription.getType();
+            for (Parameter parameter : serviceDescriptionType.getInputParametersArray())
{
+                //todo this implementation doesn't work when there are n number of nodes
connecting .. need to fix
+                actualParameters.put(parameter, GfacUtils.getInputActualParameter(parameter,
(String) value));
+            }
+        } catch (RuntimeException e) {
+            logger.error(e.getMessage(), e);
+            String message = "Error in setting an input. name: " + name + " value: " + value;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        } catch (Error e) {
+            logger.error(e.getMessage(), e);
+            String message = "Unexpected error: " + this.serviceInformation;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        } catch (RegistryException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        } catch (Exception e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+    }
+
+    /**
+     *
+     * @return
+     * @throws XBayaException
+     */
+    public synchronized boolean invoke() throws XBayaException {
+        try {
+            ExecutorService executor = Executors.newSingleThreadExecutor();
+            this.result = executor.submit(new Callable<Boolean>() {
+                @SuppressWarnings("boxing")
+                public Boolean call() {
+                    try {
+                        JobContext jobContext = new JobContext(actualParameters,EmbeddedGFacInvoker.this.topic,EmbeddedGFacInvoker.this.serviceName);
+                        GFacConfiguration gFacConfiguration = new GFacConfiguration("myproxy.teragrid.org",
"ogce",
+                            "Jdas7wph", 3600, EmbeddedGFacInvoker.this.gfacURL, EmbeddedGFacInvoker.this.registry,
"/Users/lahirugunathilake/Downloads/certificates");
+
+                        GfacAPI gfacAPI1 = new GfacAPI();
+                        InvocationContext defaultInvocationContext = gfacAPI1.gridJobSubmit(jobContext,
gFacConfiguration);
+                        ParameterContextImpl outputParamContext = (ParameterContextImpl)
defaultInvocationContext
+                                .<ActualParameter>getMessageContext("output");
+                        if (outputParamContext.getNames().hasNext()) {
+                            /*
+                            * Process Output
+                            */
+                            OMFactory fac = OMAbstractFactory.getOMFactory();
+                            OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2/xsd",
"ns1");
+                            OMElement outputElement = fac.createOMElement("invokeResponse",
omNs);
+
+                            for (Iterator<String> iterator = outputParamContext.getNames();
iterator.hasNext(); ) {
+                                String name = iterator.next();
+                                String outputString = outputParamContext.getValue(name).toXML().replaceAll("GFacParameter",
name);
+                                XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new
StringReader(outputString));
+                                StAXOMBuilder builder = new StAXOMBuilder(reader);
+                                outputElement.addChild(builder.getDocumentElement());
+                            }
+                            // Send notification
+                            logger.info("outputMessage: " + outputElement.toString());
+                            EmbeddedGFacInvoker.this.notifier.serviceFinished(new WSIFMessageElement(XMLUtil.stringToXmlElement3(outputElement.toStringWithConsume())));
+                        } else {
+                            // An implementation of WSIFMessage,
+                            // WSIFMessageElement, implements toString(), which
+                            // serialize the message XML.
+                            EmbeddedGFacInvoker.this.notifier.receivedFault(new WSIFMessageElement(XMLUtil.stringToXmlElement3("<Message>Invocation
Failed</Message>")));
+                            EmbeddedGFacInvoker.this.failerSent = true;
+                        }
+                        return true;
+                    } catch (XBayaException e) {
+                        logger.error(e.getMessage(), e);
+                        // An appropriate message has been set in the exception.
+                        EmbeddedGFacInvoker.this.notifier.invocationFailed(e.getMessage(),
e);
+                        EmbeddedGFacInvoker.this.failerSent = true;
+                        throw new XBayaRuntimeException(e);
+                    } catch (RuntimeException e) {
+                        logger.error(e.getMessage(), e);
+                        String message = "Error in invoking a service: " + EmbeddedGFacInvoker.this.serviceInformation;
+                        EmbeddedGFacInvoker.this.notifier.invocationFailed(message, e);
+                        EmbeddedGFacInvoker.this.failerSent = true;
+                        throw e;
+                    } catch (XMLStreamException e) {
+                        e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
+                    } catch (Exception e) {
+                        e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
+                    }
+                    return false;
+                }
+            });
+            // Kill the thread inside of executor. This is necessary for Jython
+            // script to finish.
+//            executor.shutdown();
+
+            // Let other threads know that job has been submitted.
+            notifyAll();
+
+            // Check if the invocation itself fails. This happens immediately.
+            try {
+                this.result.get(100, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                logger.error(e.getMessage(), e);
+            } catch (TimeoutException e) {
+                // The job is probably running fine.
+                // The normal case.
+                return true;
+            } catch (ExecutionException e) {
+                // The service-failed notification should have been sent
+                // already.
+                logger.error(e.getMessage(), e);
+                String message = "Error in invoking a service: " + this.serviceInformation;
+                throw new XBayaException(message, e);
+            }
+        } catch (RuntimeException e) {
+            logger.error(e.getMessage(), e);
+            String message = "Error in invoking a service: " + this.serviceInformation;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        } catch (Error e) {
+            logger.error(e.getMessage(), e);
+            String message = "Unexpected error: " + this.serviceInformation;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        } catch (Exception e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+        return true;
+    }
+
+    /**
+     *
+     * @throws XBayaException
+     */
+    @SuppressWarnings("boxing")
+    public synchronized void waitToFinish() throws XBayaException {
+        try {
+            while (this.result == null) {
+                // The job is not submitted yet.
+                try {
+                    wait();
+                } catch (InterruptedException e) {
+                    logger.error(e.getMessage(), e);
+                }
+            }
+            // Wait for the job to finish.
+            Boolean success = this.result.get();
+            if (success == false) {
+                WSIFMessage faultMessage = this.invoker.getFault();
+                String message = "Error in a service: ";
+                // An implementation of WSIFMessage,
+                // WSIFMessageElement, implements toString(), which
+                // serialize the message XML.
+                message += faultMessage.toString();
+                throw new XBayaException(message);
+            }
+        } catch (InterruptedException e) {
+            logger.error(e.getMessage(), e);
+        } catch (ExecutionException e) {
+            // The service-failed notification should have been sent already.
+            logger.error(e.getMessage(), e);
+            String message = "Error in invoking a service: " + this.serviceInformation;
+            throw new XBayaException(message, e);
+        } catch (RuntimeException e) {
+            logger.error(e.getMessage(), e);
+            String message = "Error while waiting for a service to finish: " + this.serviceInformation;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        } catch (Error e) {
+            logger.error(e.getMessage(), e);
+            String message = "Unexpected error: " + this.serviceInformation;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        }
+    }
+
+    /**
+     *
+     * @param name
+     *            The name of the output parameter
+     * @return
+     * @throws XBayaException
+     */
+    public Object getOutput(String name) throws XBayaException {
+        try {
+            waitToFinish();
+            Object output = this.invoker.getOutput(name);
+            if (output instanceof XmlElement) {
+                logger.info("output: " + XMLUtil.xmlElementToString((XmlElement) output));
+            }
+            return output;
+        } catch (XBayaException e) {
+            logger.error(e.getMessage(), e);
+            // An appropriate message has been set in the exception.
+            if (!this.failerSent) {
+                this.notifier.invocationFailed(e.getMessage(), e);
+            }
+            throw e;
+        } catch (RuntimeException e) {
+            logger.error(e.getMessage(), e);
+            String message = "Error while waiting for a output: " + name;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        } catch (Error e) {
+            logger.error(e.getMessage(), e);
+            String message = "Unexpected error: " + this.serviceInformation;
+            this.notifier.invocationFailed(message, e);
+            throw new XBayaException(message, e);
+        }
+    }
+
+    /**
+     *
+     * @return
+     * @throws XBayaException
+     */
+    public WSIFMessage getOutputs() throws XBayaException {
+        return this.invoker.getOutputs();
+    }
+
+    @Override
+    public WSIFClient getClient() {
+        return null;
+    }
+
+    @Override
+    public WSIFMessage getInputs() throws XBayaException {
+        return null;
+    }
+
+    @Override
+    public WSIFMessage getFault() throws XBayaException {
+        return null;
+    }
+}

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/GenericInvoker.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/GenericInvoker.java?rev=1311379&r1=1311378&r2=1311379&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/GenericInvoker.java
(original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/invoker/GenericInvoker.java
Mon Apr  9 19:11:30 2012
@@ -149,7 +149,6 @@ public class GenericInvoker implements I
         this.messageBoxURL = messageBoxURL;
         this.gfacURL = gfacURL;
         this.notifier = notifier.createServiceNotificationSender(nodeID);
-
         this.failerSent = false;
     }
 
@@ -172,7 +171,6 @@ public class GenericInvoker implements I
         this.serviceInformation = wsdlStr;
         this.gfacURL = gfacURL;
         this.notifier = notifier.createServiceNotificationSender(nodeID);
-
         this.failerSent = false;
     }
 
@@ -233,10 +231,6 @@ public class GenericInvoker implements I
         //todo write a UI component to collect this information and pass it through Header
 //        builder.setGridMyProxyRepository("myproxy.nersc.gov","fangliu","Jdas7wph",14000);
         StickySoapHeaderHandler handler = new StickySoapHeaderHandler("use-workflowcontext-header",
builder.getXml());
-
-
-
-
         // Create Invoker
         this.invoker = InvokerFactory.createInvoker(this.portTypeQName, definitions, this.gfacURL,
this.messageBoxURL,
                 builder, true);



Mime
View raw message