You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ra...@apache.org on 2013/03/12 17:52:21 UTC

svn commit: r1455613 [1/2] - in /airavata/trunk/modules/gfac-core: ./ src/main/java/org/apache/airavata/gfac/ src/main/java/org/apache/airavata/gfac/context/ src/main/java/org/apache/airavata/gfac/context/security/ src/main/java/org/apache/airavata/gfa...

Author: raminder
Date: Tue Mar 12 16:52:19 2013
New Revision: 1455613

URL: http://svn.apache.org/r1455613
Log:
Added support for SSH provider (AIRAVATA-752) and multiple security context

Added:
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/AmazonSecurityContext.java
      - copied, changed from r1454084, airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AmazonSecurityContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java
      - copied, changed from r1454084, airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SSHSecurityContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SecurityContext.java
      - copied, changed from r1454084, airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/SecurityContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPDirectorySetupHandler.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPInputHandler.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPOutputHandler.java
    airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTest.java
Removed:
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AmazonSecurityContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/SecurityContext.java
Modified:
    airavata/trunk/modules/gfac-core/pom.xml
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/JobExecutionContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GFacHandler.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GramDirectorySetupHandler.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPInputHandler.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPOutputHandler.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/GFacProvider.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/GramProvider.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
    airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/AbstractBESTest.java
    airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
    airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/EC2ProviderTest.java
    airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTest.java
    airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java
    airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/ParamChemTest.java
    airavata/trunk/modules/gfac-core/src/test/resources/gfac-config.xml

Modified: airavata/trunk/modules/gfac-core/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/pom.xml?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/pom.xml (original)
+++ airavata/trunk/modules/gfac-core/pom.xml Tue Mar 12 16:52:19 2013
@@ -85,7 +85,7 @@
         <dependency>
             <groupId>net.schmizz</groupId>
             <artifactId>sshj</artifactId>
-            <version>0.5.0</version>
+            <version>0.8.0</version>
         </dependency>
 
         <!-- Amazon -->

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java Tue Mar 12 16:52:19 2013
@@ -17,34 +17,48 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
 package org.apache.airavata.gfac;
 
 public class Constants {
-    public static final String XPATH_EXPR_GLOBAL_INFLOW_HANDLERS = "/GFac/GlobalHandlers/InHandlers/Handler";
-    public static final String XPATH_EXPR_GLOBAL_OUTFLOW_HANDLERS = "/GFac/GlobalHandlers/OutHandlers/Handler";
+	public static final String XPATH_EXPR_GLOBAL_INFLOW_HANDLERS = "/GFac/GlobalHandlers/InHandlers/Handler";
+	public static final String XPATH_EXPR_GLOBAL_OUTFLOW_HANDLERS = "/GFac/GlobalHandlers/OutHandlers/Handler";
 
-    public static final String XPATH_EXPR_APPLICATION_HANDLERS_START = "/GFac/Application[@name='";
-    public static final String XPATH_EXPR_APPLICATION_INFLOW_HANDLERS_END = "']/InHandlers/Handler";
-    public static final String XPATH_EXPR_APPLICATION_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler";
-
-
-    public static final String XPATH_EXPR_PROVIDER_HANDLERS_START = "/GFac/Provider[@class='";
-    public static final String XPATH_EXPR_PROVIDER_INFLOW_HANDLERS_END = "']/InHandlers/Handler";
-    public static final String XPATH_EXPR_PROVIDER_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler";
-
-
-    public static final String GFAC_CONFIG_HANDLER_CLASS_ATTRIBUTE = "class";
-    public static final String GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE = "class";
-    public static final String NEWLINE = System.getProperty("line.separator");
-    public static final String INPUT_DATA_DIR_VAR_NAME = "inputData";
-    public static final String OUTPUT_DATA_DIR_VAR_NAME = "outputData";
-    public static final int DEFAULT_GSI_FTP_PORT = 2811;
-    public static final String _127_0_0_1 = "127.0.0.1";
-    public static final String LOCALHOST = "localhost";
-
-    public static final String PROP_WORKFLOW_INSTANCE_ID = "workflow.instance.id";
-    public static final String PROP_WORKFLOW_NODE_ID = "workflow.node.id";
-    public static final String PROP_BROKER_URL = "broker.url";
-    public static final String PROP_TOPIC = "topic";}
+	public static final String XPATH_EXPR_APPLICATION_HANDLERS_START = "/GFac/Application[@name='";
+	public static final String XPATH_EXPR_APPLICATION_INFLOW_HANDLERS_END = "']/InHandlers/Handler";
+	public static final String XPATH_EXPR_APPLICATION_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler";
+
+	public static final String XPATH_EXPR_PROVIDER_HANDLERS_START = "/GFac/Provider[@class='";
+	public static final String XPATH_EXPR_PROVIDER_INFLOW_HANDLERS_END = "']/InHandlers/Handler";
+	public static final String XPATH_EXPR_PROVIDER_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler";
+
+	public static final String GFAC_CONFIG_HANDLER_CLASS_ATTRIBUTE = "class";
+	public static final String GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE = "class";
+	public static final String NEWLINE = System.getProperty("line.separator");
+	public static final String INPUT_DATA_DIR_VAR_NAME = "inputData";
+	public static final String OUTPUT_DATA_DIR_VAR_NAME = "outputData";
+	public static final int DEFAULT_GSI_FTP_PORT = 2811;
+	public static final String _127_0_0_1 = "127.0.0.1";
+	public static final String LOCALHOST = "localhost";
+
+	public static final String PROP_WORKFLOW_INSTANCE_ID = "workflow.instance.id";
+	public static final String PROP_WORKFLOW_NODE_ID = "workflow.node.id";
+	public static final String PROP_BROKER_URL = "broker.url";
+	public static final String PROP_TOPIC = "topic";
+	public static final String SPACE = " ";
+	public static final int COMMAND_EXECUTION_TIMEOUT = 5;
+	public static final String EXECUTABLE_NAME = "run.sh";
+
+	public static final String TRUSTED_CERT_LOCATION = "trusted.cert.location";
+    public static final String MYPROXY_SERVER = "myproxy.server";
+    public static final String MYPROXY_USER = "myproxy.user";
+    public static final String MYPROXY_PASS = "myproxy.pass";
+    public static final String MYPROXY_LIFE = "myproxy.life";
+    /*
+     * SSH properties
+     */
+    public static final String SSH_PRIVATE_KEY = "ssh.key";
+    public static final String SSH_PRIVATE_KEY_PASS = "ssh.keypass";
+    public static final String SSH_USER_NAME = "ssh.username";
+}

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java Tue Mar 12 16:52:19 2013
@@ -1,11 +1,28 @@
 package org.apache.airavata.gfac;
 
-import com.amazonaws.services.glacier.internal.TreeHashInputStream;
-import com.sun.org.apache.bcel.internal.generic.NEW;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
 import org.apache.airavata.client.api.AiravataAPI;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.exception.UnspecifiedApplicationSettingsException;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.gfac.context.security.GSISecurityContext;
 import org.apache.airavata.gfac.utils.GridConfigurationHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -14,34 +31,12 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.*;
-import java.io.File;
-import java.io.IOException;
-import java.util.*;
-
 public class GFacConfiguration {
     public static final Logger log = LoggerFactory.getLogger(GFacConfiguration.class);
-    public static final String TRUSTED_CERT_LOCATION = "trusted.cert.location";
-    public static final String MYPROXY_SERVER = "myproxy.server";
-    public static final String MYPROXY_USER = "myproxy.user";
-    public static final String MYPROXY_PASS = "myproxy.pass";
-    public static final String MYPROXY_LIFE = "myproxy.life";
-
-    private String myProxyServer;
 
-    private String myProxyUser;
-
-    private String myProxyPassphrase;
-
-    private int myProxyLifeCycle;
 
     private AiravataAPI airavataAPI;
 
-    private String trustedCertLocation;
-
     private static Document handlerDoc;
     // Keep list of full qualified class names of GFac handlers which should invoked before
     // the provider
@@ -81,47 +76,14 @@ public class GFacConfiguration {
         return gridConfigurationHandlers.toArray(new GridConfigurationHandler[]{});
     }
 
-    public GFacConfiguration(AiravataAPI airavataAPI, Properties configurationProperties) {
-        this.airavataAPI = airavataAPI;
-        if (configurationProperties != null) {
-            myProxyUser = configurationProperties.getProperty(MYPROXY_USER);
-            myProxyServer = configurationProperties.getProperty(MYPROXY_SERVER);
-            myProxyPassphrase = configurationProperties.getProperty(MYPROXY_PASS);
-            myProxyLifeCycle = Integer.parseInt(configurationProperties.getProperty(MYPROXY_LIFE));
-            trustedCertLocation = configurationProperties.getProperty(TRUSTED_CERT_LOCATION);
-        } else {
-            throw new NullPointerException("GFac Configuration properties cannot be null.");
-        }
-
-    }
-
     public GFacConfiguration(AiravataAPI airavataAPI) {
         this.airavataAPI = airavataAPI;
     }
 
-    public String getMyProxyServer() {
-        return myProxyServer;
-    }
-
-    public String getMyProxyUser() {
-        return myProxyUser;
-    }
-
-    public String getMyProxyPassphrase() {
-        return myProxyPassphrase;
-    }
-
-    public int getMyProxyLifeCycle() {
-        return myProxyLifeCycle;
-    }
-
     public AiravataAPI getAiravataAPI() {
         return airavataAPI;
     }
 
-    public String getTrustedCertLocation() {
-        return trustedCertLocation;
-    }
 
     public List<String> getInHandlers() {
         //This will avoid the misconfiguration done by user in gfac-config.xml
@@ -132,27 +94,6 @@ public class GFacConfiguration {
         //This will avoid the misconfiguration done by user in gfac-config.xml
         return removeDuplicateWithOrder(outHandlers);
     }
-
-    public void setMyProxyServer(String myProxyServer) {
-        this.myProxyServer = myProxyServer;
-    }
-
-    public void setMyProxyUser(String myProxyUser) {
-        this.myProxyUser = myProxyUser;
-    }
-
-    public void setMyProxyPassphrase(String myProxyPassphrase) {
-        this.myProxyPassphrase = myProxyPassphrase;
-    }
-
-    public void setMyProxyLifeCycle(int myProxyLifeCycle) {
-        this.myProxyLifeCycle = myProxyLifeCycle;
-    }
-
-    public void setTrustedCertLocation(String trustedCertLocation) {
-        this.trustedCertLocation = trustedCertLocation;
-    }
-
     public void setInHandlers(List<String> inHandlers) {
         this.inHandlers = inHandlers;
     }
@@ -200,50 +141,43 @@ public class GFacConfiguration {
     /**
      * Parse GFac configuration file and populate GFacConfiguration object. XML configuration
      * file for GFac will look like below.
-     * <p>
-     * &lt;GFac&gt; <br/>
-     * &lt;GlobalHandlers&gt; <br/>
-     * &lt;InHandlers&gt; <br/>
-     * &lt;Handler class="org.apache.airavata.gfac.GlobalHandler1"&gt; <br/>
-     * &lt;/InHandler&gt; <br/>
-     * &lt;OutHandlers&gt; <br/>
-     * &lt;Handler class="org.apache.airavata.gfac.GlabalHandler2"&gt; <br/>
-     * &lt;/OutHandlers&gt; <br/>
-     * &lt;/GlobalHandlers&gt; <br/>
-     * &lt;Provider class="org.apache.airavata.gfac.providers.LocalProvider" host="LocalHost"&gt; <br/>
-     * &lt;InHandlers&gt; <br/>
-     * &lt;Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler"&gt; <br/>
-     * &lt;/InHandlers&gt; <br/>
-     * &lt;OutHandlers&gt; <br/>
-     * &lt;Handler&gt;org.apache.airavata.LocalOutHandler1&lt;/Handler&gt; <br/>
-     * &lt;/OutHandlers&gt; <br/>
-     * &lt;/Provider&gt; <br/>
-     * &lt;Application name="UltraScan"&gt; <br/>
-     * &lt;InHandlers&gt; <br/>
-     * &lt;Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler"&gt; <br/>
-     * &lt;/InHandlers&gt; <br/>
-     * &lt;OutHandlers&gt; <br/>
-     * &lt;Handler class="org.apache.airavata.gfac.LocalOutHandler1"&gt; <br/>
-     * &lt;/OutHandlers&gt; <br/>
-     * &lt;/Application&gt; <br/>
-     * &lt;/GFac&gt; <br/>
-     * </p>
+     * <p/>
+     * <GFac>
+     * <GlobalHandlers>
+     * <InHandlers>
+     * <Handler class="org.apache.airavata.gfac.GlobalHandler1">
+     * </InHandler>
+     * <OutHandlers>
+     * <Handler class="org.apache.airavata.gfac.GlabalHandler2">
+     * </OutHandlers>
+     * </GlobalHandlers>
+     * <Provider class="org.apache.airavata.gfac.providers.LocalProvider" host="LocalHost">
+     * <InHandlers>
+     * <Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler">
+     * </InHandlers>
+     * <OutHandlers>
+     * <Handler>org.apache.airavata.LocalOutHandler1</Handler>
+     * </OutHandlers>
+     * </Provider>
+     * <Application name="UltraScan">
+     * <InHandlers>
+     * <Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler">
+     * </InHandlers>
+     * <OutHandlers>
+     * <Handler class="org.apache.airavata.gfac.LocalOutHandler1">
+     * </OutHandlers>
+     * </Application>
+     * </GFac>
+     *
      * @param configFile configuration file
      * @return GFacConfiguration object.
      */
+    //FIXME
     public static GFacConfiguration create(File configFile, AiravataAPI airavataAPI, Properties configurationProperties) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
         DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         handlerDoc = docBuilder.parse(configFile);
-        GFacConfiguration configuration = new GFacConfiguration(airavataAPI);
-        if (configurationProperties != null) {
-            configuration.setMyProxyUser(configurationProperties.getProperty(MYPROXY_USER));
-            configuration.setMyProxyServer(configurationProperties.getProperty(MYPROXY_SERVER));
-            configuration.setMyProxyPassphrase(configurationProperties.getProperty(MYPROXY_PASS));
-            configuration.setMyProxyLifeCycle(Integer.parseInt(configurationProperties.getProperty(MYPROXY_LIFE)));
-            configuration.setTrustedCertLocation(configurationProperties.getProperty(TRUSTED_CERT_LOCATION));
-        }
-        return configuration;
+        return new GFacConfiguration(airavataAPI);
     }
 
     private static String xpathGetText(Document doc, String expression) throws XPathExpressionException {

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java Tue Mar 12 16:52:19 2013
@@ -22,7 +22,15 @@
 package org.apache.airavata.gfac;
 
 public class GFacException extends Exception {
-    public GFacException(String s, Throwable throwable) {
+    /**
+	 *
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public GFacException(String s) {
+        super(s);
+    }
+	public GFacException(String s, Throwable throwable) {
         super(s, throwable);
     }
 }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java Tue Mar 12 16:52:19 2013
@@ -28,9 +28,11 @@ import org.apache.airavata.gfac.provider
 import org.apache.airavata.gfac.provider.impl.EC2Provider;
 import org.apache.airavata.gfac.provider.impl.GramProvider;
 import org.apache.airavata.gfac.provider.impl.LocalProvider;
+import org.apache.airavata.gfac.provider.impl.SSHProvider;
 import org.apache.airavata.schemas.gfac.Ec2HostType;
 import org.apache.airavata.schemas.gfac.GlobusHostType;
 import org.apache.airavata.schemas.gfac.UnicoreHostType;
+import org.apache.airavata.schemas.gfac.SSHHostType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,6 +72,9 @@ public class Scheduler {
         else if (hostDescription.getType() instanceof Ec2HostType) {
             return new EC2Provider();
         }
+        else if (hostDescription.getType() instanceof SSHHostType) {
+            return new SSHProvider();
+        }
         else {
             return new LocalProvider();
         }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/JobExecutionContext.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/JobExecutionContext.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/JobExecutionContext.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/JobExecutionContext.java Tue Mar 12 16:52:19 2013
@@ -22,12 +22,16 @@
 package org.apache.airavata.gfac.context;
 
 import org.apache.airavata.gfac.GFacConfiguration;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.security.SecurityContext;
 import org.apache.airavata.gfac.notification.GFacNotifier;
 import org.apache.airavata.gfac.provider.GFacProvider;
 import org.apache.airavata.schemas.wec.ContextHeaderDocument;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public class JobExecutionContext extends AbstractContext{
 
@@ -41,8 +45,6 @@ public class JobExecutionContext extends
 
     private GFacNotifier notifier;
 
-    private SecurityContext securityContext;
-
     private ContextHeaderDocument.ContextHeader contextHeader;
 
     // Keep track of the current path of the message. Before hitting provider its in-path.
@@ -68,6 +70,13 @@ public class JobExecutionContext extends
     // by this context instance.
     private String serviceName;
 
+    /**
+     *  Security context is used to handle authentication for input handlers and providers.
+     *  There can be multiple security requirement for a single job so this allows you to add multiple security types
+     *
+     */
+    private Map<String, SecurityContext> securityContext = new HashMap<String, SecurityContext>();
+
     public JobExecutionContext(GFacConfiguration gFacConfiguration,String serviceName){
         this.gfacConfiguration = gFacConfiguration;
         notifier = new GFacNotifier();
@@ -162,14 +171,6 @@ public class JobExecutionContext extends
         this.inPath = false;
     }
 
-    public SecurityContext getSecurityContext() {
-        return securityContext;
-    }
-
-    public void setSecurityContext(SecurityContext securityContext) {
-        this.securityContext = securityContext;
-    }
-
     public ContextHeaderDocument.ContextHeader getContextHeader() {
         return contextHeader;
     }
@@ -177,4 +178,17 @@ public class JobExecutionContext extends
     public void setContextHeader(ContextHeaderDocument.ContextHeader contextHeader) {
         this.contextHeader = contextHeader;
     }
+
+	public SecurityContext getSecurityContext(String name) throws GFacException{
+		SecurityContext secContext = securityContext.get(name);
+		if(secContext == null){
+			throw new GFacException( name + " not set in security context");
+		}
+		return secContext;
+	}
+
+	public void addSecurityContext(String name, SecurityContext value){
+		securityContext.put(name, value);
+    }
+
 }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java Tue Mar 12 16:52:19 2013
@@ -21,7 +21,6 @@
 
 package org.apache.airavata.gfac.context;
 
-import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 

Copied: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/AmazonSecurityContext.java (from r1454084, airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AmazonSecurityContext.java)
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/AmazonSecurityContext.java?p2=airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/AmazonSecurityContext.java&p1=airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AmazonSecurityContext.java&r1=1454084&r2=1455613&rev=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/AmazonSecurityContext.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/AmazonSecurityContext.java Tue Mar 12 16:52:19 2013
@@ -1,6 +1,9 @@
-package org.apache.airavata.gfac.context;
+package org.apache.airavata.gfac.context.security;
+
 
 public class AmazonSecurityContext extends SecurityContext {
+
+	public static final String AMAZON_SECURITY_CONTEXT = "amazon";
     private String userName;
     private String accessKey;
     private String secretKey;

Copied: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java (from r1454084, airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java)
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java?p2=airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java&p1=airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java&r1=1454084&r2=1455613&rev=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java Tue Mar 12 16:52:19 2013
@@ -18,9 +18,12 @@
  * under the License.
  *
 */
-package org.apache.airavata.gfac.context;
+package org.apache.airavata.gfac.context.security;
 
-import org.apache.airavata.gfac.GFacConfiguration;
+import java.util.Properties;
+
+import org.apache.airavata.gfac.Constants;
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.utils.MyProxyManager;
 import org.globus.gsi.GlobusCredential;
 import org.globus.tools.MyProxy;
@@ -30,6 +33,10 @@ import org.slf4j.LoggerFactory;
 
 public class GSISecurityContext extends SecurityContext {
     protected final Logger log = LoggerFactory.getLogger(this.getClass());
+    /*
+     * context name
+     */
+    public static final String GSI_SECURITY_CONTEXT = "gsi";
 
     private MyProxyManager proxyRenewer;
 
@@ -44,17 +51,25 @@ public class GSISecurityContext extends 
     private String trustedCertLoc;
 
     private GSSCredential gssCredentails;
-    
+
     private GlobusCredential globusCredential;
 
-    public GSISecurityContext(GFacConfiguration configuration) {
-        this.setMyproxyLifetime(configuration.getMyProxyLifeCycle());
-        this.setMyproxyPasswd(configuration.getMyProxyPassphrase());
-        this.setMyproxyServer(configuration.getMyProxyServer());
-        this.setMyproxyUserName(configuration.getMyProxyUser());
-        this.setTrustedCertLoc(configuration.getTrustedCertLocation());
+    public GSISecurityContext(){
+    }
+    public GSISecurityContext(Properties configuration) throws GFacException{
+    	this.setMyproxyUserName(configuration.getProperty(Constants.MYPROXY_USER));
+        this.setMyproxyServer(configuration.getProperty(Constants.MYPROXY_SERVER));
+        this.setMyproxyPasswd(configuration.getProperty(Constants.MYPROXY_PASS));
+        this.setMyproxyLifetime(Integer.parseInt(configuration.getProperty(Constants.MYPROXY_LIFE)));
+        this.setTrustedCertLoc(configuration.getProperty(Constants.TRUSTED_CERT_LOCATION));
+    }
+    public GSISecurityContext(String myproxyServer, String myproxyUserName,String myproxyPasswd, int myproxyLifetime, String trustedCertLoc){
+    	this.myproxyServer = myproxyServer;
+    	this.myproxyUserName = myproxyUserName;
+    	this.myproxyPasswd = myproxyPasswd;
+    	this.myproxyLifetime = myproxyLifetime;
+    	this.trustedCertLoc = trustedCertLoc;
     }
-
     public GSSCredential getGssCredentails() throws SecurityException {
         try {
             if (gssCredentails == null || gssCredentails.getRemainingLifetime() < 10 * 90) {
@@ -73,10 +88,9 @@ public class GSISecurityContext extends 
         }
     }
 
-    
+
     public GlobusCredential getGlobusCredential() {
     	try{
-        System.out.println(gssCredentails);
         if (gssCredentails == null || gssCredentails.getRemainingLifetime() < 10 * 90) {
             if (proxyRenewer != null) {
 //                gssCredentails = proxyRenewer.renewProxy();
@@ -94,10 +108,10 @@ public class GSISecurityContext extends 
         throw new SecurityException(e.getMessage(), e);
     }
     }
-        
-    
 
-    
+
+
+
     public String getTrustedCertLoc() {
         return trustedCertLoc;
     }
@@ -137,7 +151,7 @@ public class GSISecurityContext extends 
     public void setMyproxyLifetime(int myproxyLifetime) {
         this.myproxyLifetime = myproxyLifetime;
     }
-    
-    
-    
+
+
+
 }

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SSHSecurityContext.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SSHSecurityContext.java?rev=1455613&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SSHSecurityContext.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SSHSecurityContext.java Tue Mar 12 16:52:19 2013
@@ -0,0 +1,109 @@
+/*
+ *
+ * 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.gfac.context.security;
+
+import java.io.IOException;
+
+import net.schmizz.sshj.SSHClient;
+import net.schmizz.sshj.connection.channel.direct.Session;
+import net.schmizz.sshj.userauth.keyprovider.KeyProvider;
+
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handle SSH security
+ */
+public class SSHSecurityContext extends SecurityContext {
+	private static final Logger log = LoggerFactory.getLogger(SSHSecurityContext.class);
+
+	public static final String SSH_SECURITY_CONTEXT = "ssh";
+
+	private String username;
+	private String privateKeyLoc;
+	private String keyPass;
+	private SSHClient sshClient;
+	private Session session;
+
+	public String getUsername() {
+		return username;
+	}
+
+	public void setUsername(String username) {
+		this.username = username;
+	}
+
+	public String getPrivateKeyLoc() {
+		return privateKeyLoc;
+	}
+
+	public void setPrivateKeyLoc(String privateKeyLoc) {
+		this.privateKeyLoc = privateKeyLoc;
+	}
+
+	public String getKeyPass() {
+		return keyPass;
+	}
+
+	public void setKeyPass(String keyPass) {
+		this.keyPass = keyPass;
+	}
+
+	public void closeSession(Session session) {
+		if (session != null) {
+			try {
+				session.close();
+			} catch (Exception e) {
+				log.warn("Cannot Close SSH Session");
+			}
+		}
+	}
+
+	public Session getSession(String hostAddress) throws IOException {
+		try {
+			if (sshClient == null) {
+				sshClient = new SSHClient();
+			}
+			if (getSSHClient().isConnected())
+				return getSSHClient().startSession();
+
+			KeyProvider pkey = getSSHClient().loadKeys(getPrivateKeyLoc(), getKeyPass());
+
+			getSSHClient().loadKnownHosts();
+
+			getSSHClient().connect(hostAddress);
+			getSSHClient().authPublickey(getUsername(), pkey);
+			session = getSSHClient().startSession();
+			return session;
+
+		} catch (NullPointerException ne) {
+			throw new SecurityException("Cannot load security context for SSH", ne);
+		}
+	}
+
+	public SSHClient getSSHClient() {
+		if (sshClient == null) {
+			sshClient = new SSHClient();
+		}
+		return sshClient;
+	}
+}

Copied: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SecurityContext.java (from r1454084, airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/SecurityContext.java)
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SecurityContext.java?p2=airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SecurityContext.java&p1=airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/SecurityContext.java&r1=1454084&r2=1455613&rev=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/SecurityContext.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/security/SecurityContext.java Tue Mar 12 16:52:19 2013
@@ -19,7 +19,9 @@
  *
 */
 
-package org.apache.airavata.gfac.context;
+package org.apache.airavata.gfac.context.security;
+
+import org.apache.airavata.gfac.context.AbstractContext;
 
 public class SecurityContext extends AbstractContext {
 }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GFacHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GFacHandler.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GFacHandler.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GFacHandler.java Tue Mar 12 16:52:19 2013
@@ -21,9 +21,10 @@
 
 package org.apache.airavata.gfac.handler;
 
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 
 public interface GFacHandler {
 
-    public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException;
+    public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException,GFacException;
 }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GramDirectorySetupHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GramDirectorySetupHandler.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GramDirectorySetupHandler.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GramDirectorySetupHandler.java Tue Mar 12 16:52:19 2013
@@ -21,9 +21,10 @@
 package org.apache.airavata.gfac.handler;
 
 import org.apache.airavata.commons.gfac.type.ApplicationDescription;
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.ToolsException;
-import org.apache.airavata.gfac.context.GSISecurityContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.security.GSISecurityContext;
 import org.apache.airavata.gfac.external.GridFtp;
 import org.apache.airavata.gfac.provider.GFacProviderException;
 import org.apache.airavata.gfac.utils.GFacUtils;
@@ -45,24 +46,24 @@ import java.util.UUID;
 public class GramDirectorySetupHandler implements GFacHandler {
     private static final Logger log = LoggerFactory.getLogger(GramJobSubmissionListener.class);
 
-    public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
+    public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException,GFacException {
         log.info("Invoking GramDirectorySetupHandler ...");
-        
-        
+
+
         String[] gridFTPEndpointArray = null;
-        
+
         String hostName = null;
-        
+
         //TODO: why it is tightly coupled with gridftp
 //        GlobusHostType host = (GlobusHostType) jobExecutionContext.getApplicationContext().getHostDescription().getType();
-        
+
         //TODO: make it more reusable
         HostDescriptionType hostType = jobExecutionContext.getApplicationContext().getHostDescription().getType();
-        
-        
-        
+
+
+
         if(hostType instanceof GlobusHostType){
-        	gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray(); 
+        	gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray();
         }
         else if (hostType instanceof UnicoreHostType){
         	gridFTPEndpointArray = ((UnicoreHostType) hostType).getGridFTPEndPointArray();
@@ -71,20 +72,14 @@ public class GramDirectorySetupHandler i
         	//TODO
         }
 
-        
+
         ApplicationDescription applicationDeploymentDescription = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription();
         ApplicationDeploymentDescriptionType app = applicationDeploymentDescription.getType();
         GridFtp ftp = new GridFtp();
 
         try {
-            if (jobExecutionContext.getSecurityContext() == null ||
-                    !(jobExecutionContext.getSecurityContext() instanceof GSISecurityContext))
-            {
-                GSISecurityContext gssContext = new GSISecurityContext(jobExecutionContext.getGFacConfiguration());
-                jobExecutionContext.setSecurityContext(gssContext);
-            }
-            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext()).getGssCredentails();
-            
+            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentails();
+
             if (gridFTPEndpointArray == null || gridFTPEndpointArray.length == 0) {
             	gridFTPEndpointArray = new String[]{hostType.getHostAddress()};
             }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPInputHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPInputHandler.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPInputHandler.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPInputHandler.java Tue Mar 12 16:52:19 2013
@@ -33,10 +33,11 @@ import java.util.Set;
 
 import org.apache.airavata.commons.gfac.type.ActualParameter;
 import org.apache.airavata.commons.gfac.type.MappingFactory;
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.ToolsException;
-import org.apache.airavata.gfac.context.GSISecurityContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 import org.apache.airavata.gfac.context.MessageContext;
+import org.apache.airavata.gfac.context.security.GSISecurityContext;
 import org.apache.airavata.gfac.external.GridFtp;
 import org.apache.airavata.gfac.utils.GFacUtils;
 import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
@@ -54,8 +55,8 @@ public class GridFTPInputHandler impleme
 
     public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
         log.info("Invoking GridFTPInputHandler ...");
-        
-        
+
+
         MessageContext inputNew = new MessageContext();
         try {
             MessageContext input = jobExecutionContext.getInMessageContext();
@@ -83,23 +84,23 @@ public class GridFTPInputHandler impleme
         jobExecutionContext.setInMessageContext(inputNew);
     }
 
-    private static String stageInputFiles(JobExecutionContext jobExecutionContext, String paramValue) throws URISyntaxException, SecurityException, ToolsException, IOException {
+    private static String stageInputFiles(JobExecutionContext jobExecutionContext, String paramValue) throws URISyntaxException, SecurityException, ToolsException, IOException,GFacException {
         URI gridftpURL = new URI(paramValue);
-        
+
         String[] gridFTPEndpointArray = null;
-        
+
         // not to download input files to the input dir if its http / gsiftp
         // but if local then yes
         boolean isInputNonLocal = true;
-        
+
         //TODO: why it is tightly coupled with gridftp
 //        GlobusHostType host = (GlobusHostType) jobExecutionContext.getApplicationContext().getHostDescription().getType();
-        
+
         //TODO: make it more reusable
         HostDescriptionType hostType = jobExecutionContext.getApplicationContext().getHostDescription().getType();
-        
+
         if(jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof GlobusHostType){
-        	gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray(); 
+        	gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray();
         }
         else if (jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof UnicoreHostType){
         	gridFTPEndpointArray = ((UnicoreHostType) hostType).getGridFTPEndPointArray();
@@ -108,19 +109,12 @@ public class GridFTPInputHandler impleme
         else {
         	//TODO
         }
-        
-        
+
+
         ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
         GridFtp ftp = new GridFtp();
         URI destURI = null;
-        if (jobExecutionContext.getSecurityContext() == null ||
-                !(jobExecutionContext.getSecurityContext() instanceof GSISecurityContext)) {
-            GSISecurityContext gssContext = new GSISecurityContext(jobExecutionContext.getGFacConfiguration());
-            jobExecutionContext.setSecurityContext(gssContext);
-        }
-        GSSCredential gssCred = ((GSISecurityContext) jobExecutionContext.getSecurityContext()).getGssCredentails();
-        
-        
+        GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentails();
 
         for (String endpoint : gridFTPEndpointArray) {
             URI inputURI = GFacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
@@ -130,7 +124,7 @@ public class GridFTPInputHandler impleme
             if (fileName != null && !"".equals(fileName)) {
                 destURI = GFacUtils.createGsiftpURI(endpoint, s);
                 if (paramValue.startsWith("gsiftp")) {
-                	// no need to do if it is unicore, as unicore will download this on user's behalf to the job space dir 
+                	// no need to do if it is unicore, as unicore will download this on user's behalf to the job space dir
                 	if(isInputNonLocal) ftp.uploadFile(gridftpURL, destURI, gssCred);
                 	else return paramValue;
                 } else if (paramValue.startsWith("file")) {
@@ -156,7 +150,7 @@ public class GridFTPInputHandler impleme
                 		// don't return destUri
                 		return paramValue;
                 	}
-                		
+
                 } else {
                     //todo throw exception telling unsupported protocol
                     return paramValue;
@@ -168,8 +162,8 @@ public class GridFTPInputHandler impleme
         }
         return destURI.toString();
     }
-    
-    
-    
+
+
+
 
 }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPOutputHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPOutputHandler.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPOutputHandler.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/GridFTPOutputHandler.java Tue Mar 12 16:52:19 2013
@@ -22,10 +22,11 @@ package org.apache.airavata.gfac.handler
 
 import org.apache.airavata.commons.gfac.type.ActualParameter;
 import org.apache.airavata.commons.gfac.type.MappingFactory;
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.ToolsException;
-import org.apache.airavata.gfac.context.GSISecurityContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 import org.apache.airavata.gfac.context.MessageContext;
+import org.apache.airavata.gfac.context.security.GSISecurityContext;
 import org.apache.airavata.gfac.external.GridFtp;
 import org.apache.airavata.gfac.provider.GFacProviderException;
 import org.apache.airavata.gfac.utils.GFacUtils;
@@ -58,19 +59,19 @@ public class GridFTPOutputHandler implem
 
     public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
         log.info("Invoking GridFTPOutputHandler ...");
-        
+
        ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
-        
+
  	   HostDescriptionType hostType = jobExecutionContext.getApplicationContext().getHostDescription().getType();
  	   String[] gridFTPEndpointArray = null;
  	   String hostName = null;
  	   String hostAddress = null;
- 	   
+
        if(jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof GlobusHostType){
         	gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray();
         	hostName = ((GlobusHostType) hostType).getHostName();
         	hostAddress = ((GlobusHostType) hostType).getHostAddress();
-        	
+
        }
        else if (jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof UnicoreHostType){
         	gridFTPEndpointArray = ((UnicoreHostType) hostType).getGridFTPEndPointArray();
@@ -85,14 +86,8 @@ public class GridFTPOutputHandler implem
        File localStdErrFile = null;
        Map<String, ActualParameter> stringMap = new HashMap<String, ActualParameter>();
        try {
-            if (jobExecutionContext.getSecurityContext() == null ||
-                    !(jobExecutionContext.getSecurityContext() instanceof GSISecurityContext))
-            {
-                GSISecurityContext gssContext = new GSISecurityContext(jobExecutionContext.getGFacConfiguration());
-                jobExecutionContext.setSecurityContext(gssContext);
-            }
-            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext()).getGssCredentails();
-            String[] hostgridFTP = gridFTPEndpointArray;
+    	    GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentails();
+    	    String[] hostgridFTP = gridFTPEndpointArray;
             if (hostgridFTP == null || hostgridFTP.length == 0) {
                 hostgridFTP = new String[]{hostName};
             }
@@ -117,28 +112,28 @@ public class GridFTPOutputHandler implem
                     File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
                     localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");
 
-                    
-                    
-                    
+
+
+
                     // Shahbaz Comment: in principle when job is failed the execution chain must be stopped
                     // there
-                    
-                    
+
+
                     String stdout = null;
                     String stderr = null;
 
-                    // TODO: what if job is failed 
+                    // TODO: what if job is failed
                     // and this handler is not able to find std* files?
                     try {
                      stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile);
                      stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile);
-                     //TODO: do we also need to set them as output parameters for another job  
+                     //TODO: do we also need to set them as output parameters for another job
                     }
                     catch(ToolsException e) {
                         log.error("Cannot download stdout/err files. One reason could be the job is not successfully finished:  "+e.getMessage());
                     }
-                    
-                    
+
+
                     Map<String, Object> output = jobExecutionContext.getOutMessageContext().getParameters();
                     Set<String> keys = output.keySet();
                     for (String paramName : keys) {
@@ -192,7 +187,7 @@ public class GridFTPOutputHandler implem
             log.error(e.getMessage());
             throw new GFacHandlerException(e.getMessage(), jobExecutionContext, e, readLastLinesofStdOut(localStdErrFile.getPath(), 20));
         }
-        
+
     }
 
     private static String readLastLinesofStdOut(String path, int count) {
@@ -234,14 +229,14 @@ public class GridFTPOutputHandler implem
         return buffer.toString();
     }
 
-    private static void stageOutputFiles(JobExecutionContext jobExecutionContext, String outputFileStagingPath) throws GFacProviderException {
-    	
-    	
+    private static void stageOutputFiles(JobExecutionContext jobExecutionContext, String outputFileStagingPath) throws GFacProviderException,GFacException {
+
+
     	   HostDescriptionType hostType = jobExecutionContext.getApplicationContext().getHostDescription().getType();
     	   String[] gridFTPEndpointArray = null;
-    	   
+
            if(jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof GlobusHostType){
-           	gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray(); 
+           	gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray();
            }
            else if (jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof UnicoreHostType){
            	gridFTPEndpointArray = ((UnicoreHostType) hostType).getGridFTPEndPointArray();
@@ -249,8 +244,8 @@ public class GridFTPOutputHandler implem
            else {
            	//TODO
            }
-       
-    	
+
+
         MessageContext outputNew = new MessageContext();
         MessageContext output = jobExecutionContext.getOutMessageContext();
         Map<String, Object> parameters = output.getParameters();
@@ -259,14 +254,7 @@ public class GridFTPOutputHandler implem
                     .get(paramName);
 
             GridFtp ftp = new GridFtp();
-
-            if (jobExecutionContext.getSecurityContext() == null ||
-                    !(jobExecutionContext.getSecurityContext() instanceof GSISecurityContext))
-            {
-                GSISecurityContext gssContext = new GSISecurityContext(jobExecutionContext.getGFacConfiguration());
-                jobExecutionContext.setSecurityContext(gssContext);
-            }
-            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext()).getGssCredentails();
+            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentails();
             try {
                 if ("URI".equals(actualParameter.getType().getType().toString())) {
                     for (String endpoint : gridFTPEndpointArray) {
@@ -304,5 +292,5 @@ public class GridFTPOutputHandler implem
                 gssCred, outputFile);
         return outputFileStagingPath + File.separator + fileName;
     }
-    
+
 }

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPDirectorySetupHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPDirectorySetupHandler.java?rev=1455613&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPDirectorySetupHandler.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPDirectorySetupHandler.java Tue Mar 12 16:52:19 2013
@@ -0,0 +1,80 @@
+/*
+ *
+ * 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.gfac.handler;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import net.schmizz.sshj.connection.ConnectionException;
+import net.schmizz.sshj.connection.channel.direct.Session;
+import net.schmizz.sshj.connection.channel.direct.Session.Command;
+import net.schmizz.sshj.transport.TransportException;
+
+import org.apache.airavata.gfac.Constants;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.security.SSHSecurityContext;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SCPDirectorySetupHandler implements GFacHandler{
+    private static final Logger log = LoggerFactory.getLogger(SCPDirectorySetupHandler.class);
+	@Override
+	public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException,GFacException {
+		log.info("Setup SSH job directorties");
+		makeDirectory(jobExecutionContext);
+
+	}
+	private void makeDirectory(JobExecutionContext context) throws GFacHandlerException,GFacException {
+		SSHSecurityContext securityContext = (SSHSecurityContext)context.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
+		ApplicationDeploymentDescriptionType app = context.getApplicationContext().getApplicationDeploymentDescription().getType();
+		Session session = null;
+		try {
+			session = securityContext.getSession(context.getApplicationContext().getHostDescription().getType().getHostAddress());
+
+			StringBuilder commandString = new StringBuilder();
+
+			commandString.append("mkdir -p ");
+			commandString.append(app.getScratchWorkingDirectory());
+			commandString.append(" ; ");
+			commandString.append("mkdir -p ");
+			commandString.append(app.getStaticWorkingDirectory());
+			commandString.append(" ; ");
+			commandString.append("mkdir -p ");
+			commandString.append(app.getInputDataDirectory());
+			commandString.append(" ; ");
+			commandString.append("mkdir -p ");
+			commandString.append(app.getOutputDataDirectory());
+
+			Command cmd = session.exec(commandString.toString());
+			cmd.join(Constants.COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
+		} catch (ConnectionException e) {
+			throw new GFacHandlerException(e.getMessage(), e, context);
+		} catch (TransportException e) {
+			throw new GFacHandlerException(e.getMessage(), e, context);
+		} catch (IOException e) {
+			throw new GFacHandlerException(e.getMessage(), e, context);
+		} finally {
+			securityContext.closeSession(session);
+		}
+	}
+}

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPInputHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPInputHandler.java?rev=1455613&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPInputHandler.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPInputHandler.java Tue Mar 12 16:52:19 2013
@@ -0,0 +1,91 @@
+/*
+ *
+ * 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.gfac.handler;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import net.schmizz.sshj.xfer.scp.SCPFileTransfer;
+
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.MappingFactory;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.MessageContext;
+import org.apache.airavata.gfac.context.security.SSHSecurityContext;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.airavata.schemas.gfac.URIArrayType;
+import org.apache.airavata.schemas.gfac.URIParameterType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SCPInputHandler implements GFacHandler{
+
+	private static final Logger log = LoggerFactory.getLogger(SCPInputHandler.class);
+
+	@Override
+	public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException,GFacException {
+
+		  log.info("Invoking SCPInputHandler");
+
+
+	        MessageContext inputNew = new MessageContext();
+	        try {
+	            MessageContext input = jobExecutionContext.getInMessageContext();
+	            Set<String> parameters = input.getParameters().keySet();
+	            for (String paramName : parameters) {
+	                ActualParameter actualParameter = (ActualParameter) input.getParameters().get(paramName);
+	                String paramValue = MappingFactory.toString(actualParameter);
+	                //TODO: Review this with type
+	                if ("URI".equals(actualParameter.getType().getType().toString())) {
+	                    ((URIParameterType) actualParameter.getType()).setValue(stageInputFiles(jobExecutionContext, paramValue));
+	                } else if ("URIArray".equals(actualParameter.getType().getType().toString())) {
+	                    List<String> split = Arrays.asList(paramValue.split(","));
+	                    List<String> newFiles = new ArrayList<String>();
+	                    for (String paramValueEach : split) {
+	                        newFiles.add(stageInputFiles(jobExecutionContext, paramValueEach));
+	                    }
+	                    ((URIArrayType) actualParameter.getType()).setValueArray(newFiles.toArray(new String[newFiles.size()]));
+	                }
+	                inputNew.getParameters().put(paramName, actualParameter);
+	            }
+	        } catch (Exception e) {
+	            log.error(e.getMessage());
+	            throw new GFacHandlerException("Error while input File Staging", jobExecutionContext, e, e.getLocalizedMessage());
+	        }
+	        jobExecutionContext.setInMessageContext(inputNew);
+	}
+	 private static String stageInputFiles(JobExecutionContext context,String paramValue) throws IOException,GFacException{
+		 ApplicationDeploymentDescriptionType app = context.getApplicationContext().getApplicationDeploymentDescription().getType();
+
+		 SSHSecurityContext securityContext = (SSHSecurityContext)context.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
+		 SCPFileTransfer fileTransfer = securityContext.getSSHClient().newSCPFileTransfer();
+		 String remoteFile = app.getInputDataDirectory() + File.separatorChar + paramValue;
+
+		 File inputFile = new File(paramValue);
+		 fileTransfer.upload(inputFile.getAbsolutePath(), remoteFile);
+		 return remoteFile;
+	 }
+}

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPOutputHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPOutputHandler.java?rev=1455613&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPOutputHandler.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/handler/SCPOutputHandler.java Tue Mar 12 16:52:19 2013
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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.gfac.handler;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import net.schmizz.sshj.connection.ConnectionException;
+import net.schmizz.sshj.transport.TransportException;
+import net.schmizz.sshj.xfer.scp.SCPFileTransfer;
+
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.security.SSHSecurityContext;
+import org.apache.airavata.gfac.utils.GFacUtils;
+import org.apache.airavata.gfac.utils.OutputUtils;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.xmlbeans.XmlException;
+
+public class SCPOutputHandler implements GFacHandler{
+
+	@Override
+	public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
+		ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
+		try {
+			 SSHSecurityContext securityContext = (SSHSecurityContext)jobExecutionContext.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
+
+			// Get the Stdouts and StdErrs
+			String timeStampedServiceName = GFacUtils.createUniqueNameForService(jobExecutionContext.getServiceName());
+			File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
+			File localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");
+
+			SCPFileTransfer fileTransfer = securityContext.getSSHClient().newSCPFileTransfer();
+			fileTransfer.download(app.getStandardOutput(), localStdOutFile.getAbsolutePath());
+			fileTransfer.download(app.getStandardError(), localStdErrFile.getAbsolutePath());
+
+			String stdOutStr = GFacUtils.readFileToString(localStdOutFile.getAbsolutePath());
+			String stdErrStr = GFacUtils.readFileToString(localStdErrFile.getAbsolutePath());
+			 Map<String, ActualParameter> stringMap = new HashMap<String, ActualParameter>();
+
+			 stringMap =  OutputUtils.fillOutputFromStdout(jobExecutionContext, stdOutStr, stdErrStr);
+			 if (stringMap == null || stringMap.isEmpty()) {
+                 throw new GFacHandlerException("Empty Output returned from the Application, Double check the application" +
+                         "and ApplicationDescriptor output Parameter Names");
+             }
+
+		} catch (XmlException e) {
+			throw new GFacHandlerException("Cannot read output:" + e.getMessage(), e);
+		} catch (ConnectionException e) {
+			throw new GFacHandlerException(e.getMessage(), e);
+		} catch (TransportException e) {
+			throw new GFacHandlerException(e.getMessage(), e);
+		} catch (IOException e) {
+			throw new GFacHandlerException(e.getMessage(), e);
+		} catch (Exception e) {
+			throw new GFacHandlerException("Error in retrieving results", e);
+		}
+
+	}
+
+}

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/GFacProvider.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/GFacProvider.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/GFacProvider.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/GFacProvider.java Tue Mar 12 16:52:19 2013
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.gfac.provider;
 
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 
 public interface GFacProvider {
@@ -31,19 +32,19 @@ public interface GFacProvider {
      * @param jobExecutionContext containing job execution related information.
      * @throws GFacProviderException in case of a error initializing the environment.
      */
-    void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException;
+    void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException,GFacException;
 
     /**
      * Invoke the providers intended functionality using information and data in job execution context.
      * @param jobExecutionContext containing job execution related information.
      * @throws GFacProviderException in case of a error executing the job.
      */
-    void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException;
+    void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException;
 
     /**
      * Cleans up the acquired resources during initialization and execution of the job.
      * @param jobExecutionContext containing job execution related information.
      * @throws GFacProviderException in case of a error cleaning resources.
      */
-    void dispose(JobExecutionContext jobExecutionContext) throws GFacProviderException;
+    void dispose(JobExecutionContext jobExecutionContext) throws GFacProviderException,GFacException;
 }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/BESProvider.java Tue Mar 12 16:52:19 2013
@@ -32,25 +32,27 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.airavata.gfac.context.GSISecurityContext;
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.security.GSISecurityContext;
 import org.apache.airavata.gfac.provider.GFacProvider;
 import org.apache.airavata.gfac.provider.GFacProviderException;
 import org.apache.airavata.gfac.provider.utils.JSDLGenerator;
 import org.apache.airavata.schemas.gfac.UnicoreHostType;
+import org.apache.xmlbeans.XmlCursor;
 import org.ggf.schemas.bes.x2006.x08.besFactory.ActivityStateEnumeration;
+import org.ggf.schemas.bes.x2006.x08.besFactory.ActivityStatusType;
 import org.ggf.schemas.bes.x2006.x08.besFactory.CreateActivityDocument;
 import org.ggf.schemas.bes.x2006.x08.besFactory.CreateActivityResponseDocument;
+import org.ggf.schemas.bes.x2006.x08.besFactory.GetActivityStatusesDocument;
+import org.ggf.schemas.bes.x2006.x08.besFactory.GetActivityStatusesResponseDocument;
 import org.globus.gsi.GlobusCredential;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3.x2005.x08.addressing.EndpointReferenceType;
 
 import de.fzj.unicore.bes.client.FactoryClient;
-import de.fzj.unicore.bes.faults.InvalidRequestMessageFault;
-import de.fzj.unicore.bes.faults.NotAcceptingNewActivitiesFault;
-import de.fzj.unicore.bes.faults.UnsupportedFeatureFault;
-
+import de.fzj.unicore.bes.faults.UnknownActivityIdentifierFault;
 import de.fzj.unicore.wsrflite.xmlbeans.WSUtilities;
 import eu.emi.security.authn.x509.impl.CertificateUtils.Encoding;
 import eu.emi.security.authn.x509.impl.DirectoryCertChainValidator;
@@ -70,7 +72,7 @@ public class BESProvider implements GFac
 
     @Override
 	public void initialize(JobExecutionContext jobExecutionContext)
-			throws GFacProviderException {
+			throws GFacProviderException,GFacException {
 
     	log.info("Initializing GFAC's <<< UNICORE Provider >>>");
     	initSecurityProperties(jobExecutionContext);
@@ -87,43 +89,39 @@ public class BESProvider implements GFac
 
         EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
         eprt.addNewAddress().setStringValue(factoryUrl);
-        log.info("========================================");
-        log.info(String.format("Job Submitted to %s.\n", factoryUrl));
 
-        FactoryClient factory = null;
-        try {
-            factory = new FactoryClient(eprt, secProperties);
-        } catch (Exception e) {
-            throw new GFacProviderException("");
-        }
         CreateActivityDocument cad = CreateActivityDocument.Factory
                 .newInstance();
 
-
         try {
 			cad.addNewCreateActivity().addNewActivityDocument()
 			        .setJobDefinition(JSDLGenerator.buildJSDLInstance(jobExecutionContext).getJobDefinition());
 		} catch (Exception e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
+			throw new GFacProviderException("Cannot generate JSDL instance from the JobExecutionContext.",e1);
 		}
 
+        FactoryClient factory = null;
+        try {
+            factory = new FactoryClient(eprt, secProperties);
+        } catch (Exception e) {
+            throw new GFacProviderException("");
+        }
         CreateActivityResponseDocument response = null;
         try {
+            log.info("========================================");
+            log.info(String.format("Activity Submitting to %s ... \n", factoryUrl));
             response = factory.createActivity(cad);
-        } catch (NotAcceptingNewActivitiesFault notAcceptingNewActivitiesFault) {
-            notAcceptingNewActivitiesFault.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-        } catch (InvalidRequestMessageFault invalidRequestMessageFault) {
-            invalidRequestMessageFault.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-        } catch (UnsupportedFeatureFault unsupportedFeatureFault) {
-            unsupportedFeatureFault.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            log.info(String.format("Activity Submitted to %s \n", factoryUrl));
+        } catch (Exception e) {
+        	e.printStackTrace();
+            throw new GFacProviderException("Cannot create activity.", e);
         }
         EndpointReferenceType activityEpr = response
                 .getCreateActivityResponse().getActivityIdentifier();
 
-        log.debug("Job EPR: "+activityEpr);
+        log.debug("Activity EPR: "+activityEpr);
 
-        log.info("Job: "+activityEpr.getAddress().getStringValue()+  " Submitted.");
+        log.info("Activity: "+activityEpr.getAddress().getStringValue()+  " Submitted.");
 
         //factory.waitWhileActivityIsDone(activityEpr, 1000);
         jobId = WSUtilities.extractResourceID(activityEpr);
@@ -132,51 +130,58 @@ public class BESProvider implements GFac
                     .toString();
         }
 
-
-        String status = String.format("Job %s is %s.\n", activityEpr.getAddress()
-                .getStringValue(), factory.getActivityStatus(activityEpr)
-                .toString()).toString();
-
-
-        log.info(status);
+        log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), factory.getActivityStatus(activityEpr)
+                .toString()));
 
 
+        //TODO publish the status messages to the message bus
         while ((factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FINISHED) &&
                 (factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FAILED)){
-            status = String.format("Job %s is %s.\n", activityEpr.getAddress()
-                    .getStringValue(), factory.getActivityStatus(activityEpr)
-                    .toString()).toString();
+
+            ActivityStatusType activityStatus = null;
+    		try {
+    			activityStatus = getStatus(factory, activityEpr);
+    			log.info (subStatusAsString(activityStatus));
+    		} catch (UnknownActivityIdentifierFault e) {
+    			throw new GFacProviderException(e.getMessage(), e.getCause());
+    		}
+
             try {
-            	log.info(status);
-                Thread.sleep(1000);
+                Thread.sleep(2000);
             } catch (InterruptedException e) {
                 e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
             }
             continue;
         }
 
-        status = String.format("Job %s is %s.\n", activityEpr.getAddress()
-                .getStringValue(), factory.getActivityStatus(activityEpr)
-                .toString()).toString();
+        ActivityStatusType activityStatus = null;
+		try {
+			activityStatus = getStatus(factory, activityEpr);
+		} catch (UnknownActivityIdentifierFault e) {
+			throw new GFacProviderException(e.getMessage(), e.getCause());
+		}
 
-        log.info(status);
+        log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), activityStatus.getState().toString()));
 
+		if ((activityStatus.getState() == ActivityStateEnumeration.FAILED)) {
+				log.info(activityStatus.getFault().getFaultcode().getLocalPart()
+						+ "\n" + activityStatus.getFault().getFaultstring());
+				log.info("EXITCODE: "+activityStatus.getExitCode());
+		}
 	}
 
 	@Override
 	public void dispose(JobExecutionContext jobExecutionContext)
 			throws GFacProviderException {
-
 		secProperties = null;
-
 	}
 
 
-	protected void initSecurityProperties(JobExecutionContext jobExecutionContext) throws GFacProviderException{
+	protected void initSecurityProperties(JobExecutionContext jobExecutionContext) throws GFacProviderException,GFacException{
 
 		if (secProperties != null) return;
 
-		GSISecurityContext gssContext = new GSISecurityContext(jobExecutionContext.getGFacConfiguration());
+		GSISecurityContext gssContext = (GSISecurityContext)jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT);
 		GlobusCredential credentials = gssContext.getGlobusCredential();
 		ByteArrayOutputStream bos = new ByteArrayOutputStream();
 
@@ -218,6 +223,7 @@ public class BESProvider implements GFac
 
 	        secProperties.setOutHandlerClassNames(outHandlerLst.toArray(new String[outHandlerLst.size()]));
 
+
 		}
 		catch (Exception e) {
 			throw new GFacProviderException(e.getMessage(), e);
@@ -234,9 +240,47 @@ public class BESProvider implements GFac
 		}
 	}
 
+	protected ActivityStatusType getStatus(FactoryClient fc, EndpointReferenceType activityEpr) throws UnknownActivityIdentifierFault{
+
+    	GetActivityStatusesDocument stats = GetActivityStatusesDocument.Factory.newInstance();
 
+    	stats.addNewGetActivityStatuses().setActivityIdentifierArray(new EndpointReferenceType[] {activityEpr});
 
+		GetActivityStatusesResponseDocument resDoc = fc.getActivityStatuses(stats);
+
+		ActivityStatusType activityStatus = resDoc
+				.getGetActivityStatusesResponse()
+				.getResponseArray()[0].getActivityStatus();
+		return activityStatus;
+	}
 
 
+	protected String formatStatusMessage(String activityUrl, String status){
+		return String.format("Activity %s is %s.\n", activityUrl, status);
+	}
+
+	protected String subStatusAsString(ActivityStatusType statusType) {
+
+
+		StringBuffer sb = new StringBuffer();
+
+		sb.append(statusType.getState().toString());
+
+		XmlCursor acursor = statusType.newCursor();
+		if (acursor.toFirstChild()) {
+			do {
+				if(acursor.getName().getNamespaceURI().equals("http://schemas.ogf.org/hpcp/2007/01/fs")) {
+					sb.append(":");
+					sb.append(acursor.getName().getLocalPart());
+				}
+			} while (acursor.toNextSibling());
+			acursor.dispose();
+			return sb.toString();
+		} else {
+			acursor.dispose();
+			return sb.toString();
+		}
+
+	}
 
 }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/EC2Provider.java Tue Mar 12 16:52:19 2013
@@ -41,7 +41,8 @@ import com.sshtools.j2ssh.transport.publ
 import com.sshtools.j2ssh.util.Base64;
 import org.apache.airavata.commons.gfac.type.ActualParameter;
 import org.apache.airavata.commons.gfac.type.ApplicationDescription;
-import org.apache.airavata.gfac.context.AmazonSecurityContext;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.security.AmazonSecurityContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 import org.apache.airavata.gfac.notification.events.EC2ProviderEvent;
 import org.apache.airavata.gfac.provider.GFacProvider;
@@ -81,10 +82,10 @@ public class EC2Provider implements GFac
 
     private AmazonSecurityContext amazonSecurityContext;
 
-    public void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException {
+    public void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException,GFacException{
         if (jobExecutionContext != null) {
-            if (jobExecutionContext.getSecurityContext() instanceof AmazonSecurityContext) {
-                this.amazonSecurityContext = (AmazonSecurityContext) jobExecutionContext.getSecurityContext();
+            if (jobExecutionContext.getSecurityContext(AmazonSecurityContext.AMAZON_SECURITY_CONTEXT) instanceof AmazonSecurityContext) {
+                this.amazonSecurityContext = (AmazonSecurityContext) jobExecutionContext.getSecurityContext(AmazonSecurityContext.AMAZON_SECURITY_CONTEXT);
             } else {
                 throw new GFacProviderException("Amazon Security Context is not set" + jobExecutionContext);
             }

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/GramProvider.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/GramProvider.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/GramProvider.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/GramProvider.java Tue Mar 12 16:52:19 2013
@@ -20,9 +20,10 @@
 */
 package org.apache.airavata.gfac.provider.impl;
 
+import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.JobSubmissionFault;
-import org.apache.airavata.gfac.context.GSISecurityContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.security.GSISecurityContext;
 import org.apache.airavata.gfac.notification.events.StartExecutionEvent;
 import org.apache.airavata.gfac.provider.GFacProvider;
 import org.apache.airavata.gfac.provider.GFacProviderException;
@@ -50,24 +51,14 @@ public class GramProvider implements GFa
         job.addListener(listener);
     }
 
-    public void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException {
+    public void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException{
         jobExecutionContext.getNotifier().publish(new StartExecutionEvent());
         GlobusHostType host = (GlobusHostType) jobExecutionContext.getApplicationContext().getHostDescription().getType();
         ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
 
         StringBuffer buf = new StringBuffer();
         try {
-
-            /*
-            * Set Security
-            */
-            if (jobExecutionContext.getSecurityContext() == null ||
-                    !(jobExecutionContext.getSecurityContext() instanceof GSISecurityContext))
-            {
-                GSISecurityContext gssContext = new GSISecurityContext(jobExecutionContext.getGFacConfiguration());
-                jobExecutionContext.setSecurityContext(gssContext);
-            }
-            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext()).getGssCredentails();
+            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentails();
             job.setCredentials(gssCred);
             // We do not support multiple gatekeepers in XBaya GUI, so we simply pick the 0th element in the array
             String gateKeeper = host.getGlobusGateKeeperEndPointArray(0);