Modified: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/provider/impl/SSHProvider.java
 Tue Mar 12 16:52:19 2013
@@ -1,282 +1,196 @@
-///*
-// *
-// * 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.provider.impl;
-//
-//import java.io.File;
-//import java.io.IOException;
-//import java.util.ArrayList;
-//import java.util.HashMap;
-//import java.util.Iterator;
-//import java.util.List;
-//import java.util.Map;
-//import java.util.Map.Entry;
-//import java.util.concurrent.TimeUnit;
-//
-//import net.schmizz.sshj.SSHClient;
-//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 net.schmizz.sshj.userauth.keyprovider.KeyProvider;
-//import net.schmizz.sshj.xfer.scp.SCPFileTransfer;
-//
-//import org.apache.airavata.commons.gfac.type.ActualParameter;
-//import org.apache.airavata.core.gfac.context.invocation.InvocationContext;
-//import 
org.apache.airavata.core.gfac.context.security.impl.SSHSecurityContextImpl;
-//import org.apache.airavata.core.gfac.exception.GfacException;
-//import org.apache.airavata.core.gfac.exception.ProviderException;
-//import org.apache.airavata.core.gfac.utils.GFacConstants;
-//import org.apache.airavata.core.gfac.utils.GfacUtils;
-//import org.apache.airavata.core.gfac.utils.InputUtils;
-//import org.apache.airavata.core.gfac.utils.OutputUtils;
-//import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
-//import org.apache.airavata.schemas.gfac.NameValuePairType;
-//import org.apache.xmlbeans.XmlException;
-//
-///**
-// * Execute application using remote SSH
-// */
-//public class SSHProvider extends AbstractProvider {
-//
-//    private static final String SPACE = " ";
-//    private static final String SSH_SECURITY_CONTEXT = "ssh";
-//    private static final int COMMAND_EXECUTION_TIMEOUT = 5;
-//    private SSHSecurityContextImpl sshContext;
-//    private String command;
-//    private SSHClient ssh;
-//
-//    public SSHProvider() {
-//        ssh = new SSHClient();
-//    }
-//
-//    private Session getSession(InvocationContext context) throws IOException 
{
-//        try {
-//
-//            /*
-//             * if it is connected, create a session Note: one client can 
have multiple session (on one channel)
-//             */
-//            if (ssh.isConnected())
-//                return ssh.startSession();
-//
-//            if (sshContext == null) {
-//                sshContext = ((SSHSecurityContextImpl) 
context.getSecurityContext(SSH_SECURITY_CONTEXT));
-//            }
-//
-//            KeyProvider pkey = ssh.loadKeys(sshContext.getPrivateKeyLoc(), 
sshContext.getKeyPass());
-//
-//            ssh.loadKnownHosts();
-//            ssh.authPublickey(sshContext.getUsername(), pkey);
-//
-//            
ssh.connect(context.getExecutionDescription().getHost().getType().getHostAddress());
-//            return ssh.startSession();
-//
-//        } catch (NullPointerException ne) {
-//            throw new SecurityException("Cannot load security context for 
SSH", ne);
-//        }
-//    }
-//
-//    private void closeSession(Session session) {
-//        if (session != null) {
-//            try {
-//                session.close();
-//            } catch (Exception e) {
-//                log.warn("Cannot Close SSH Session");
-//            }
-//        }
-//    }
-//
-//    public void makeDirectory(InvocationContext context) throws 
ProviderException {
-//        ApplicationDeploymentDescriptionType app = 
context.getExecutionDescription().getApp().getType();
-//
-//        Session session = null;
-//        try {
-//            session = getSession(context);
-//
-//            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(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
-//        } catch (ConnectionException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } catch (TransportException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } catch (IOException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } finally {
-//            closeSession(session);
-//        }
-//    }
-//
-//    public void setupEnvironment(InvocationContext context) throws 
ProviderException {
-//        ApplicationDeploymentDescriptionType app = 
context.getExecutionDescription().getApp().getType();
-//
-//        // input parameter
-//        ArrayList<String> tmp = new ArrayList<String>();
-//        for (Iterator<String> iterator = context.getInput().getNames(); 
iterator.hasNext();) {
-//            String key = iterator.next();
-//            tmp.add(context.getInput().getStringValue(key));
-//        }
-//
-//        List<String> cmdList = new ArrayList<String>();
-//
-//        /*
-//         * Builder Command
-//         */
-//        cmdList.add(app.getExecutableLocation());
-//        cmdList.addAll(tmp);
-//
-//        // create process builder from command
-//        command = InputUtils.buildCommand(cmdList);
-//
-//        // redirect StdOut and StdErr
-//        // TODO: Make 1> and 2> into static constants.
-//        // TODO: This only works for the BASH shell. CSH and TCSH will be
-//        // different.
-//        command += SPACE + "1>" + SPACE + app.getStandardOutput();
-//        command += SPACE + "2>" + SPACE + app.getStandardError();
-//    }
-//
-//    public void executeApplication(InvocationContext context) throws 
ProviderException {
-//        ApplicationDeploymentDescriptionType app = 
context.getExecutionDescription().getApp().getType();
-//
-//        Session session = null;
-//        try {
-//            session = getSession(context);
-//
-//            /*
-//             * Going to working Directory
-//             */
-//            session.exec("cd " + app.getStaticWorkingDirectory());
-//
-//            // get the env of the host and the application
-//            NameValuePairType[] env = app.getApplicationEnvironmentArray();
-//
-//            Map<String, String> nv = new HashMap<String, String>();
-//            if (env != null) {
-//                for (int i = 0; i < env.length; i++) {
-//                    String key = env[i].getName();
-//                    String value = env[i].getValue();
-//                    nv.put(key, value);
-//                }
-//            }
-//            // extra env's
-//            nv.put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, 
app.getInputDataDirectory());
-//            nv.put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, 
app.getOutputDataDirectory());
-//
-//            /*
-//             * Set environment
-//             */
-//            log.debug("Command = " + command);
-//            for (Entry<String, String> entry : nv.entrySet()) {
-//                log.debug("Env[" + entry.getKey() + "] = " + 
entry.getValue());
-//                session.setEnvVar(entry.getKey(), entry.getValue());
-//            }
-//
-//            /*
-//             * Execute
-//             */
-//            Command cmd = session.exec(command);
-//            log.debug("stdout=" + 
GfacUtils.readFromStream(session.getInputStream()));
-//            cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
-//
-//            /*
-//             * check return value. usually not very helpful to draw 
conclusions based on return values so don't bother.
-//             * just provide warning in the log messages
-//             */
-//            if (cmd.getExitStatus() != 0) {
-//                log.error("Process finished with non zero return value. 
Process may have failed");
-//            } else {
-//                log.debug("Process finished with return value of zero.");
-//            }
-//
-//        } catch (ConnectionException e) {
-//            throw new  ProviderException(e.getMessage(), e, context);
-//        } catch (TransportException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } catch (IOException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } finally {
-//            closeSession(session);
-//        }
-//    }
-//
-//    public Map<String, ?> processOutput(InvocationContext context) throws 
ProviderException {
-//        ApplicationDeploymentDescriptionType app = 
context.getExecutionDescription().getApp().getType();
-//        try {
-//
-//            // Get the Stdouts and StdErrs
-//            String timeStampedServiceName = 
GfacUtils.createUniqueNameForService(context.getServiceName());
-//            File localStdOutFile = 
File.createTempFile(timeStampedServiceName, "stdout");
-//            File localStdErrFile = 
File.createTempFile(timeStampedServiceName, "stderr");
-//
-//            SCPFileTransfer fileTransfer = ssh.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());
-//
-//            return 
OutputUtils.fillOutputFromStdout(context.<ActualParameter> getOutput(), 
stdOutStr,stdErrStr);
-//
-//        } catch (XmlException e) {
-//            throw new ProviderException("Cannot read output:" + 
e.getMessage(), e, context);
-//        } catch (ConnectionException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } catch (TransportException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } catch (IOException e) {
-//            throw new ProviderException(e.getMessage(), e, context);
-//        } catch (Exception e){
-//             throw new ProviderException("Error in retrieving 
results",e,context);
-//        }
-//    }
-//
-//    public void dispose(InvocationContext invocationContext) throws 
GfacException {
-//        super.dispose(invocationContext);
-//        try {
-//            if (ssh != null && ssh.isConnected()) {
-//                ssh.disconnect();
-//            }
-//        } catch (Exception e) {
-//            log.warn("Cannot Close SSH Connection");
-//        }
-//    }
-//
-//     @Override
-//     protected Map<String, ?> processInput(InvocationContext 
invocationContext)
-//                     throws ProviderException {
-//             // TODO Auto-generated method stub
-//             return null;
-//     }
-//}
+/*
+ *
+ * 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.provider.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Random;
+import java.util.Set;
+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 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.Constants;
+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.gfac.provider.GFacProvider;
+import org.apache.airavata.gfac.provider.GFacProviderException;
+import org.apache.airavata.gfac.utils.GFacUtils;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.airavata.schemas.gfac.NameValuePairType;
+import org.apache.airavata.schemas.gfac.URIArrayType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Execute application using remote SSH
+ */
+public class SSHProvider implements GFacProvider {
+       private static final Logger log = 
LoggerFactory.getLogger(SSHProvider.class);
+       private SSHSecurityContext securityContext;
+
+       @Override
+       public void initialize(JobExecutionContext jobExecutionContext) throws 
GFacProviderException,GFacException {
+               securityContext = (SSHSecurityContext) 
jobExecutionContext.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
+               ApplicationDeploymentDescriptionType app = 
jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
+               String remoteFile = app.getStaticWorkingDirectory() + 
File.separatorChar + Constants.EXECUTABLE_NAME;
+               log.info(remoteFile);
+               try {
+                       File runscript = createShellScript(jobExecutionContext);
+                       SCPFileTransfer fileTransfer = 
securityContext.getSSHClient().newSCPFileTransfer();
+                       fileTransfer.upload(runscript.getAbsolutePath(), 
remoteFile);
+               } catch (IOException e) {
+                       throw new 
GFacProviderException(e.getLocalizedMessage(), e);
+               }
+       }
+
+       @Override
+       public void execute(JobExecutionContext jobExecutionContext) throws 
GFacProviderException {
+               ApplicationDeploymentDescriptionType app = 
jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
+               Session session = null;
+               try {
+                       session = 
securityContext.getSession(jobExecutionContext.getApplicationContext().getHostDescription().getType().getHostAddress());
+                       /*
+                        * Execute
+                        */
+                       String execuable = app.getStaticWorkingDirectory() + 
File.separatorChar + Constants.EXECUTABLE_NAME;
+                       Command cmd = session.exec("/bin/chmod 755 " + 
execuable + "; " + execuable);
+                       log.info("stdout=" + 
GFacUtils.readFromStream(session.getInputStream()));
+                       cmd.join(Constants.COMMAND_EXECUTION_TIMEOUT, 
TimeUnit.SECONDS);
+
+                       /*
+                        * check return value. usually not very helpful to draw 
conclusions
+                        * based on return values so don't bother. just provide 
warning in
+                        * the log messages
+                        */
+                       if (cmd.getExitStatus() != 0) {
+                               log.error("Process finished with non zero 
return value. Process may have failed");
+                       } else {
+                               log.info("Process finished with return value of 
zero.");
+                       }
+
+               } catch (ConnectionException e) {
+                       throw new GFacProviderException(e.getMessage(), e);
+               } catch (TransportException e) {
+                       throw new GFacProviderException(e.getMessage(), e);
+               } catch (IOException e) {
+                       throw new GFacProviderException(e.getMessage(), e);
+               }finally{
+                       securityContext.closeSession(session);
+               }
+
+       }
+
+       @Override
+       public void dispose(JobExecutionContext jobExecutionContext) throws 
GFacProviderException {
+       }
+
+       private File createShellScript(JobExecutionContext context) throws 
IOException {
+               ApplicationDeploymentDescriptionType app = 
context.getApplicationContext()
+                               
.getApplicationDeploymentDescription().getType();
+               String uniqueDir = app.getApplicationName().getStringValue() + 
System.currentTimeMillis()
+                               + new Random().nextLong();
+
+               File shellScript = File.createTempFile(uniqueDir, "sh");
+               OutputStream out = new FileOutputStream(shellScript);
+
+               out.write("#!/bin/bash\n".getBytes());
+               out.write(("cd " + app.getStaticWorkingDirectory() + 
"\n").getBytes());
+               out.write(("export " + Constants.INPUT_DATA_DIR_VAR_NAME + "=" 
+ app.getInputDataDirectory() + "\n").getBytes());
+               out.write(("export " + Constants.OUTPUT_DATA_DIR_VAR_NAME + "=" 
+ app.getOutputDataDirectory() + "\n")
+                               .getBytes());
+               // get the env of the host and the application
+               NameValuePairType[] env = app.getApplicationEnvironmentArray();
+
+               Map<String, String> nv = new HashMap<String, String>();
+               if (env != null) {
+                       for (int i = 0; i < env.length; i++) {
+                               String key = env[i].getName();
+                               String value = env[i].getValue();
+                               nv.put(key, value);
+                       }
+               }
+               for (Entry<String, String> entry : nv.entrySet()) {
+                       log.debug("Env[" + entry.getKey() + "] = " + 
entry.getValue());
+                       out.write(("export " + entry.getKey() + "=" + 
entry.getValue() + "\n").getBytes());
+
+               }
+
+               // prepare the command
+               final String SPACE = " ";
+               StringBuffer cmd = new StringBuffer();
+               cmd.append(app.getExecutableLocation());
+               cmd.append(SPACE);
+
+               MessageContext input = context.getInMessageContext();
+               ;
+               Map<String, Object> inputs = input.getParameters();
+               Set<String> keys = inputs.keySet();
+               for (String paramName : keys) {
+                       ActualParameter actualParameter = (ActualParameter) 
inputs.get(paramName);
+                       if 
("URIArray".equals(actualParameter.getType().getType().toString())) {
+                               String[] values = ((URIArrayType) 
actualParameter.getType()).getValueArray();
+                               for (String value : values) {
+                                       cmd.append(value);
+                                       cmd.append(SPACE);
+                               }
+                       } else {
+                               String paramValue = 
MappingFactory.toString(actualParameter);
+                               cmd.append(paramValue);
+                               cmd.append(SPACE);
+                       }
+               }
+               // We redirect the error and stdout to remote files, they will 
be read
+               // in later
+               cmd.append(SPACE);
+               cmd.append("1>");
+               cmd.append(SPACE);
+               cmd.append(app.getStandardOutput());
+               cmd.append(SPACE);
+               cmd.append("2>");
+               cmd.append(SPACE);
+               cmd.append(app.getStandardError());
+
+               String cmdStr = cmd.toString();
+               log.info("Command = " + cmdStr);
+               out.write((cmdStr + "\n").getBytes());
+               String message = "\"execuationSuceeded\"";
+               out.write(("echo " + message + "\n").getBytes());
+               out.close();
+
+               return shellScript;
+       }
+
+}

Modified: 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
 Tue Mar 12 16:52:19 2013
@@ -20,8 +20,9 @@
 */
 package org.apache.airavata.gfac.utils;
 
-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.notification.events.StatusChangeEvent;
 import org.globus.gram.GramException;
 import org.globus.gram.GramJob;
@@ -56,13 +57,13 @@ public class GramJobSubmissionListener i
      * @throws GramException
      * @throws SecurityException
      */
-    public void waitFor() throws InterruptedException, GSSException, 
GramException, SecurityException {
+    public void waitFor() throws InterruptedException, GSSException, 
GramException, SecurityException,GFacException {
         while (!isFinished()) {
             int proxyExpTime = job.getCredentials().getRemainingLifetime();
             if (proxyExpTime < JOB_PROXY_REMAINING_TIME_LIMIT) {
                 log.info("Job proxy expired. Trying to renew proxy");
-                GSSCredential gssCred = (new 
GSISecurityContext(context.getGFacConfiguration())).getGssCredentails();
-//                job.renew(gssCred);
+                GSSCredential gssCred = 
((GSISecurityContext)context.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentails();
+                job.renew(gssCred);
                 log.info("Myproxy renewed");
             }
 

Modified: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/AbstractBESTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/AbstractBESTest.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/AbstractBESTest.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/AbstractBESTest.java
 Tue Mar 12 16:52:19 2013
@@ -12,93 +12,111 @@ import org.apache.airavata.gfac.GFacConf
 import org.apache.airavata.gfac.context.ApplicationContext;
 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.schemas.gfac.JobTypeType;
 import org.apache.airavata.schemas.gfac.UnicoreHostType;
 import org.apache.log4j.PropertyConfigurator;
 
 public abstract class AbstractBESTest {
-       
-       protected JobExecutionContext jobExecutionContext;
 
-       public static final String[] hostArray = new String[] { 
"https://zam1161v01.zam.kfa-juelich.de:8002/INTEROP1/services/BESFactory?res=default_bes_factory";
 };
-       
-       
-       //directory where data will be copy into and copied out to unicore 
resources
-       
-       // private static final String scratchDir = 
"/brashear/msmemon/airavata";
-       
-       public static final String gridftpAddress = 
"gsiftp://gridftp1.ls4.tacc.utexas.edu:2811";;
-       public static final String scratchDir = 
"/scratch/02055/msmemon/airavata";
-       
-       protected String remoteTempDir = null;
-
-       
-
-       protected void initTest() throws Exception {
-               
PropertyConfigurator.configure("src/test/resources/logging.properties");
-
-               /*
-                * Default tmp location
-                */
-               String date = (new Date()).toString();
-               date = date.replaceAll(" ", "_");
-               date = date.replaceAll(":", "_");
-
-               
-               remoteTempDir = scratchDir + File.separator + "BESJOB" + "_" + 
date + "_"
-                               + UUID.randomUUID();
-               jobExecutionContext = new JobExecutionContext(getGFACConfig(), 
getServiceDesc("BES-APP-Service").getType().getName());
-               
jobExecutionContext.setApplicationContext(getApplicationContext());
-               jobExecutionContext.setInMessageContext(getInMessageContext());
-               
jobExecutionContext.setOutMessageContext(getOutMessageContext());
-
-       }
-       
-       protected abstract void submitJob() throws Exception;
-       
-       protected GFacConfiguration getGFACConfig() throws Exception{
+        protected JobExecutionContext jobExecutionContext;
+
+//       public static final String[] hostArray = new String[] { 
"https://zam1161v01.zam.kfa-juelich.de:8002/INTEROP1/services/BESFactory?res=default_bes_factory";
 };
+
+
+        public static final String[] hostArray = new String[] { 
"https://deisa-unic.fz-juelich.de:9111/FZJ_JUROPA/services/BESFactory?res=default_bes_factory";
 };
+
+
+
+        //directory where data will be copy into and copied out to unicore 
resources
+
+
+
+//      public static final String gridftpAddress = 
"gsiftp://gridftp1.ls4.tacc.utexas.edu:2811";;
+//      public static final String scratchDir = 
"/scratch/02055/msmemon/airavata";
+
+
+//      public static final String gridftpAddress = 
"gsiftp://gridftp.psc.xsede.org:2811";;
+//      public static final String scratchDir = "/brashear/msmemon/airavata/";
+
+
+        public static final String gridftpAddress = 
"gsiftp://osg-xsede.grid.iu.edu:2811/";;
+        public static final String scratchDir = "/home/msmemon/airavata/";
+
+
+
+
+        protected String remoteTempDir = null;
+
+
+
+        protected void initTest() throws Exception {
+                
PropertyConfigurator.configure("src/test/resources/logging.properties");
+
+                /*
+                 * Default tmp location
+                 */
+                String date = (new Date()).toString();
+                date = date.replaceAll(" ", "_");
+                date = date.replaceAll(":", "_");
+
+
+                remoteTempDir = scratchDir + File.separator + "BESJOB" + "_" + 
date + "_"
+                                + UUID.randomUUID();
+                jobExecutionContext = new JobExecutionContext(getGFACConfig(), 
getServiceDesc("BES-APP-Service").getType().getName());
+                GSISecurityContext context = new GSISecurityContext();
+                       context.setMyproxyLifetime(3600);
+                       context.setMyproxyServer("myproxy.teragrid.org");
+                       context.setMyproxyUserName("*****");
+                       context.setMyproxyPasswd("*****");
+                       context.setTrustedCertLoc("./certificates");
+                       
jobExecutionContext.addSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT, 
context);
+                
jobExecutionContext.setApplicationContext(getApplicationContext());
+                jobExecutionContext.setInMessageContext(getInMessageContext());
+                
jobExecutionContext.setOutMessageContext(getOutMessageContext());
+
+        }
+
+        protected abstract void submitJob() throws Exception;
+
+        protected GFacConfiguration getGFACConfig() throws Exception{
         URL resource = 
this.getClass().getClassLoader().getResource("gfac-config.xml");
         System.out.println(resource.getFile());
         GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()),null,null);
-               gFacConfiguration.setMyProxyLifeCycle(3600);
-               gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
-               gFacConfiguration.setMyProxyUser("msmemon");
-               gFacConfiguration.setMyProxyPassphrase("*******");
-               
gFacConfiguration.setTrustedCertLocation("/home/m.memon/.globus/certificates");
-               return gFacConfiguration;
-       }
-       
-       protected ApplicationContext getApplicationContext() {
-               ApplicationContext applicationContext = new 
ApplicationContext();
-               applicationContext.setHostDescription(getHostDesc());
-               return applicationContext;
-       }
-
-       protected HostDescription getHostDesc() {
-               HostDescription host = new 
HostDescription(UnicoreHostType.type);
-               host.getType().setHostAddress("zam1161v01.zam.kfa-juelich.de");
-               host.getType().setHostName("DEMO-INTEROP-SITE");
-               ((UnicoreHostType) 
host.getType()).setUnicoreHostAddressArray(hostArray);
-               ((UnicoreHostType) host.getType()).setGridFTPEndPointArray(new 
String[]{gridftpAddress});
-               return host;
-       }
-
-       
-       protected abstract ApplicationDescription 
getApplicationDesc(JobTypeType jobType); 
-       
-
-       protected ServiceDescription getServiceDesc(String serviceName) {
-               ServiceDescription serv = new ServiceDescription();
-               serv.getType().setName(serviceName);
-               return serv;
-       }
-       
-       
-       protected abstract MessageContext getInMessageContext();
-
-       
-       
-       protected abstract MessageContext getOutMessageContext();
+        return gFacConfiguration;
+        }
+
+        protected ApplicationContext getApplicationContext() {
+                ApplicationContext applicationContext = new 
ApplicationContext();
+                applicationContext.setHostDescription(getHostDesc());
+                return applicationContext;
+        }
+
+        protected HostDescription getHostDesc() {
+                HostDescription host = new 
HostDescription(UnicoreHostType.type);
+                host.getType().setHostAddress("zam1161v01.zam.kfa-juelich.de");
+                host.getType().setHostName("DEMO-INTEROP-SITE");
+                ((UnicoreHostType) 
host.getType()).setUnicoreHostAddressArray(hostArray);
+                ((UnicoreHostType) host.getType()).setGridFTPEndPointArray(new 
String[]{gridftpAddress});
+                return host;
+        }
+
+
+        protected abstract ApplicationDescription 
getApplicationDesc(JobTypeType jobType);
+
+
+        protected ServiceDescription getServiceDesc(String serviceName) {
+                ServiceDescription serv = new ServiceDescription();
+                serv.getType().setName(serviceName);
+                return serv;
+        }
+
+
+        protected abstract MessageContext getInMessageContext();
+
+
+
+        protected abstract MessageContext getOutMessageContext();
 
 
 }

Modified: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/BESProviderTest.java
 Tue Mar 12 16:52:19 2013
@@ -17,6 +17,7 @@ import org.apache.airavata.gfac.GFacExce
 import org.apache.airavata.gfac.context.ApplicationContext;
 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.schemas.gfac.ApplicationDeploymentDescriptionType;
 import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
 import org.apache.airavata.schemas.gfac.InputParameterType;
@@ -61,6 +62,9 @@ public class BESProviderTest {
                                + UUID.randomUUID();
 
                jobExecutionContext = new JobExecutionContext(getGFACConfig(), 
getServiceDesc().getType().getName());
+
+               // set security context
+               
jobExecutionContext.addSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT, 
getSecurityContext());
                
jobExecutionContext.setApplicationContext(getApplicationContext());
                jobExecutionContext.setInMessageContext(getInMessageContext());
                
jobExecutionContext.setOutMessageContext(getOutMessageContext());
@@ -74,14 +78,8 @@ public class BESProviderTest {
 
        private GFacConfiguration getGFACConfig() throws Exception{
         URL resource = 
BESProviderTest.class.getClassLoader().getResource("gfac-config.xml");
-        System.out.println(resource.getFile());
         GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()),null,null);
-               gFacConfiguration.setMyProxyLifeCycle(3600);
-               gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
-               gFacConfiguration.setMyProxyUser("*****");
-               gFacConfiguration.setMyProxyPassphrase("*****");
-               gFacConfiguration.setTrustedCertLocation("./certificates");
-               return gFacConfiguration;
+       return gFacConfiguration;
        }
 
        private ApplicationContext getApplicationContext() {
@@ -196,6 +194,15 @@ public class BESProviderTest {
 
         return inMessage;
        }
+       private GSISecurityContext getSecurityContext(){
+           GSISecurityContext context = new GSISecurityContext();
+        context.setMyproxyLifetime(3600);
+        context.setMyproxyServer("myproxy.teragrid.org");
+        context.setMyproxyUserName("*****");
+        context.setMyproxyPasswd("*****");
+        context.setTrustedCertLoc("./certificates");
+        return context;
+       }
 
        private MessageContext getOutMessageContext() {
 

Modified: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/EC2ProviderTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/EC2ProviderTest.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/EC2ProviderTest.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/EC2ProviderTest.java
 Tue Mar 12 16:52:19 2013
@@ -4,7 +4,7 @@ import org.apache.airavata.commons.gfac.
 import org.apache.airavata.gfac.GFacAPI;
 import org.apache.airavata.gfac.GFacConfiguration;
 import org.apache.airavata.gfac.GFacException;
-import org.apache.airavata.gfac.context.AmazonSecurityContext;
+import org.apache.airavata.gfac.context.security.AmazonSecurityContext;
 import org.apache.airavata.gfac.context.ApplicationContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 import org.apache.airavata.gfac.context.MessageContext;
@@ -64,11 +64,6 @@ public class EC2ProviderTest {
         assert resource != null;
         System.out.println(resource.getFile());
         GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()), null, null);
-        gFacConfiguration.setMyProxyLifeCycle(3600);
-        gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
-        gFacConfiguration.setMyProxyUser("*****");
-        gFacConfiguration.setMyProxyPassphrase("*****");
-        gFacConfiguration.setTrustedCertLocation("./certificates");
 
         /* EC2 Host */
         HostDescription host = new HostDescription(Ec2HostType.type);
@@ -124,7 +119,7 @@ public class EC2ProviderTest {
 
         AmazonSecurityContext amazonSecurityContext =
                 new AmazonSecurityContext(userName, accessKey, secretKey, 
instanceId);
-        jobExecutionContext.setSecurityContext(amazonSecurityContext);
+        
jobExecutionContext.addSecurityContext(AmazonSecurityContext.AMAZON_SECURITY_CONTEXT,
 amazonSecurityContext);
 
         MessageContext inMessage = new MessageContext();
         ActualParameter genomeInput1 = new ActualParameter();

Modified: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTest.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTest.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTest.java
 Tue Mar 12 16:52:19 2013
@@ -32,12 +32,14 @@ import org.apache.airavata.commons.gfac.
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.commons.gfac.type.MappingFactory;
 import org.apache.airavata.commons.gfac.type.ServiceDescription;
+import org.apache.airavata.gfac.Constants;
 import org.apache.airavata.gfac.GFacAPI;
 import org.apache.airavata.gfac.GFacConfiguration;
 import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.context.ApplicationContext;
 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.schemas.gfac.ApplicationDeploymentDescriptionType;
 import org.apache.airavata.schemas.gfac.GlobusHostType;
 import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
@@ -72,12 +74,12 @@ public class GramProviderTest {
         URL resource = 
GramProviderTest.class.getClassLoader().getResource("gfac-config.xml");
         System.out.println(resource.getFile());
         GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()),null,null);
-        gFacConfiguration.setMyProxyLifeCycle(3600);
-        gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
-        gFacConfiguration.setMyProxyUser("*****");
-        gFacConfiguration.setMyProxyPassphrase("*****");
-        gFacConfiguration.setTrustedCertLocation("./certificates");
-        //have to set InFlwo Handlers and outFlowHandlers
+//        gFacConfiguration.setMyProxyLifeCycle(3600);
+//        gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
+//        gFacConfiguration.setMyProxyUser("*****");
+//        gFacConfiguration.setMyProxyPassphrase("*****");
+//        gFacConfiguration.setTrustedCertLocation("./certificates");
+//        //have to set InFlwo Handlers and outFlowHandlers
 //        gFacConfiguration.setInHandlers(Arrays.asList(new String[] 
{"org.apache.airavata.gfac.handler.GramDirectorySetupHandler","org.apache.airavata.gfac.handler.GridFTPInputHandler"}));
 //        gFacConfiguration.setOutHandlers(Arrays.asList(new String[] 
{"org.apache.airavata.gfac.handler.GridFTPOutputHandler"}));
 
@@ -170,6 +172,8 @@ public class GramProviderTest {
         serv.getType().setOutputParametersArray(outputParamList);
 
         jobExecutionContext = new 
JobExecutionContext(gFacConfiguration,serv.getType().getName());
+        // Adding security context
+        
jobExecutionContext.addSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT, 
getSecurityContext());
         ApplicationContext applicationContext = new ApplicationContext();
         jobExecutionContext.setApplicationContext(applicationContext);
         applicationContext.setServiceDescription(serv);
@@ -206,6 +210,16 @@ public class GramProviderTest {
 
     }
 
+       private GSISecurityContext getSecurityContext() {
+               GSISecurityContext context = new GSISecurityContext();
+        context.setMyproxyLifetime(3600);
+        context.setMyproxyServer("myproxy.teragrid.org");
+        context.setMyproxyUserName("*****");
+        context.setMyproxyPasswd("*****");
+        context.setTrustedCertLoc("./certificates");
+               return context;
+       }
+
     @Test
     public void testGramProvider() throws GFacException {
         GFacAPI gFacAPI = new GFacAPI();

Modified: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTest.java
 Tue Mar 12 16:52:19 2013
@@ -18,6 +18,7 @@ import org.apache.airavata.gfac.GFacConf
 import org.apache.airavata.gfac.context.ApplicationContext;
 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.provider.utils.JSDLGenerator;
 import org.apache.airavata.gfac.provider.utils.JSDLUtils;
 import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
@@ -65,6 +66,8 @@ public class JSDLGeneratorTest {
        public void initJobContext() throws Exception {
                
PropertyConfigurator.configure("src/test/resources/logging.properties");
                jobExecutionContext = new JobExecutionContext(getGFACConfig(), 
getServiceDesc().getType().getName());
+               //Add security context
+               
jobExecutionContext.addSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT, 
getSecurityContext());
                
jobExecutionContext.setApplicationContext(getApplicationContext());
                jobExecutionContext.setInMessageContext(getInMessageContext());
                
jobExecutionContext.setOutMessageContext(getOutMessageContext());
@@ -74,11 +77,6 @@ public class JSDLGeneratorTest {
         URL resource = 
BESProviderTest.class.getClassLoader().getResource("gfac-config.xml");
         System.out.println(resource.getFile());
         GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()),null,null);
-               gFacConfiguration.setMyProxyLifeCycle(3600);
-               gFacConfiguration.setMyProxyServer("");
-               gFacConfiguration.setMyProxyUser("");
-               gFacConfiguration.setMyProxyPassphrase("");
-               gFacConfiguration.setTrustedCertLocation("");
                return gFacConfiguration;
        }
 
@@ -236,6 +234,14 @@ public class JSDLGeneratorTest {
                return om1;
        }
 
-
+       private GSISecurityContext getSecurityContext(){
+           GSISecurityContext context = new GSISecurityContext();
+        context.setMyproxyLifetime(3600);
+        context.setMyproxyServer("myproxy.teragrid.org");
+        context.setMyproxyUserName("*****");
+        context.setMyproxyPasswd("*****");
+        context.setTrustedCertLoc("./certificates");
+        return context;
+       }
 
 }

Modified: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/ParamChemTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/ParamChemTest.java?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/ParamChemTest.java
 (original)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/ParamChemTest.java
 Tue Mar 12 16:52:19 2013
@@ -20,21 +20,38 @@
 */
 package org.apache.airavata.core.gfac.services.impl;
 
-import org.apache.airavata.commons.gfac.type.*;
-import org.apache.airavata.gfac.GFacAPI;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.ApplicationDescription;
+import org.apache.airavata.commons.gfac.type.HostDescription;
+import org.apache.airavata.commons.gfac.type.ServiceDescription;
 import org.apache.airavata.gfac.GFacConfiguration;
 import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.context.ApplicationContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 import org.apache.airavata.gfac.context.MessageContext;
-import org.apache.airavata.schemas.gfac.*;
-import org.junit.Assert;
+import org.apache.airavata.gfac.context.security.GSISecurityContext;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.airavata.schemas.gfac.DataType;
+import org.apache.airavata.schemas.gfac.GlobusHostType;
+import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
+import org.apache.airavata.schemas.gfac.InputParameterType;
+import org.apache.airavata.schemas.gfac.JobTypeType;
+import org.apache.airavata.schemas.gfac.OutputParameterType;
+import org.apache.airavata.schemas.gfac.ParameterType;
+import org.apache.airavata.schemas.gfac.ProjectAccountType;
+import org.apache.airavata.schemas.gfac.QueueType;
+import org.apache.airavata.schemas.gfac.StringParameterType;
+import org.apache.airavata.schemas.gfac.URIParameterType;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.File;
-import java.util.*;
-
 public class ParamChemTest {
     private JobExecutionContext jobExecutionContext;
 
@@ -42,11 +59,13 @@ public class ParamChemTest {
     public void setUp() throws Exception {
 
         GFacConfiguration gFacConfiguration = new GFacConfiguration(null);
-        gFacConfiguration.setMyProxyLifeCycle(3600);
-        gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
-        gFacConfiguration.setMyProxyUser("ccguser");
-        gFacConfiguration.setMyProxyPassphrase("");
-        gFacConfiguration.setTrustedCertLocation("");
+        GSISecurityContext context = new GSISecurityContext();
+               context.setMyproxyLifetime(3600);
+               context.setMyproxyServer("myproxy.teragrid.org");
+               context.setMyproxyUserName("*****");
+               context.setMyproxyPasswd("*****");
+               context.setTrustedCertLoc("./certificates");
+
         //have to set InFlwo Handlers and outFlowHandlers
         gFacConfiguration.setInHandlers(Arrays.asList(new 
String[]{"org.apache.airavata.gfac.handler.GramDirectorySetupHandler", 
"org.apache.airavata.gfac.handler.GridFTPInputHandler"}));
         gFacConfiguration.setOutHandlers(Arrays.asList(new String[] 
{"org.apache.airavata.gfac.handler.GridFTPOutputHandler"}));
@@ -212,6 +231,7 @@ public class ParamChemTest {
         serv.getType().setOutputParametersArray(outputParameters.toArray(new 
OutputParameterType[]{}));
 
         jobExecutionContext = new 
JobExecutionContext(gFacConfiguration,serv.getType().getName());
+        
jobExecutionContext.addSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT, 
context);
         ApplicationContext applicationContext = new ApplicationContext();
         applicationContext.setHostDescription(host);
         applicationContext.setApplicationDeploymentDescription(appDesc);

Added: 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTest.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTest.java?rev=1455613&view=auto
==============================================================================
--- 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTest.java
 (added)
+++ 
airavata/trunk/modules/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTest.java
 Tue Mar 12 16:52:19 2013
@@ -0,0 +1,172 @@
+/*
+ *
+ * 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.core.gfac.services.impl;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.ApplicationDescription;
+import org.apache.airavata.commons.gfac.type.HostDescription;
+import org.apache.airavata.commons.gfac.type.MappingFactory;
+import org.apache.airavata.commons.gfac.type.ServiceDescription;
+import org.apache.airavata.gfac.GFacAPI;
+import org.apache.airavata.gfac.GFacConfiguration;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.ApplicationContext;
+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.InputParameterType;
+import org.apache.airavata.schemas.gfac.OutputParameterType;
+import org.apache.airavata.schemas.gfac.SSHHostType;
+import org.apache.airavata.schemas.gfac.StringParameterType;
+import org.apache.commons.lang.SystemUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SSHProviderTest {
+       private JobExecutionContext jobExecutionContext;
+    @Before
+    public void setUp() throws Exception {
+
+       URL resource = 
GramProviderTest.class.getClassLoader().getResource("gfac-config.xml");
+        GFacConfiguration gFacConfiguration = GFacConfiguration.create(new 
File(resource.getPath()),null,null);
+//        gFacConfiguration.s
+        //have to set InFlwo Handlers and outFlowHandlers
+        ApplicationContext applicationContext = new ApplicationContext();
+        HostDescription host = new HostDescription(SSHHostType.type);
+        host.getType().setHostName("gw85.iu.xsede.org");
+        host.getType().setHostAddress("gw85.iu.xsede.org");
+        applicationContext.setHostDescription(host);
+        /*
+           * App
+           */
+        ApplicationDescription appDesc = new ApplicationDescription();
+        ApplicationDeploymentDescriptionType app = appDesc.getType();
+        ApplicationDeploymentDescriptionType.ApplicationName name = 
ApplicationDeploymentDescriptionType.ApplicationName.Factory.newInstance();
+        name.setStringValue("EchoSSH");
+        app.setApplicationName(name);
+
+        /*
+           * Use bat file if it is compiled on Windows
+           */
+        if (SystemUtils.IS_OS_WINDOWS) {
+            URL url = this.getClass().getClassLoader().getResource("echo.bat");
+            app.setExecutableLocation(url.getFile());
+        } else {
+            //for unix and Mac
+            app.setExecutableLocation("/bin/echo");
+        }
+
+        /*
+         * Job location
+        */
+        String tempDir = "/tmp";
+        String date = (new Date()).toString();
+        date = date.replaceAll(" ", "_");
+        date = date.replaceAll(":", "_");
+
+        tempDir = tempDir + File.separator
+                + "EchoSSH" + "_" + date + "_" + UUID.randomUUID();
+
+        app.setScratchWorkingDirectory(tempDir);
+        app.setStaticWorkingDirectory(tempDir);
+        app.setInputDataDirectory(tempDir + File.separator + "input");
+        app.setOutputDataDirectory(tempDir + File.separator + "output");
+        app.setStandardOutput(tempDir + File.separator + "echo.stdout");
+        app.setStandardError(tempDir + File.separator + "echo.stderr");
+
+        applicationContext.setApplicationDeploymentDescription(appDesc);
+
+        /*
+           * Service
+           */
+        ServiceDescription serv = new ServiceDescription();
+        serv.getType().setName("EchoSSH");
+
+        List<InputParameterType> inputList = new 
ArrayList<InputParameterType>();
+        InputParameterType input = InputParameterType.Factory.newInstance();
+        input.setParameterName("echo_input");
+        input.setParameterType(StringParameterType.Factory.newInstance());
+        inputList.add(input);
+        InputParameterType[] inputParamList = inputList.toArray(new 
InputParameterType[inputList
+                .size()]);
+
+        List<OutputParameterType> outputList = new 
ArrayList<OutputParameterType>();
+        OutputParameterType output = OutputParameterType.Factory.newInstance();
+        output.setParameterName("echo_output");
+        output.setParameterType(StringParameterType.Factory.newInstance());
+        outputList.add(output);
+        OutputParameterType[] outputParamList = outputList
+                .toArray(new OutputParameterType[outputList.size()]);
+
+        serv.getType().setInputParametersArray(inputParamList);
+        serv.getType().setOutputParametersArray(outputParamList);
+
+        jobExecutionContext = new 
JobExecutionContext(gFacConfiguration,serv.getType().getName());
+        jobExecutionContext.setApplicationContext(applicationContext);
+
+        // Add security context
+        
jobExecutionContext.addSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT, 
getSecurityContext());
+        /*
+        * Host
+        */
+        applicationContext.setServiceDescription(serv);
+
+        MessageContext inMessage = new MessageContext();
+        ActualParameter echo_input = new ActualParameter();
+               
((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
+        inMessage.addParameter("echo_input", echo_input);
+
+        jobExecutionContext.setInMessageContext(inMessage);
+
+        MessageContext outMessage = new MessageContext();
+        ActualParameter echo_out = new ActualParameter();
+//             
((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
+        outMessage.addParameter("echo_output", echo_out);
+
+        jobExecutionContext.setOutMessageContext(outMessage);
+
+    }
+
+       private SSHSecurityContext getSecurityContext() {
+               SSHSecurityContext context = new SSHSecurityContext();
+        context.setUsername("*****");
+        context.setPrivateKeyLoc("~/.ssh/id_dsa");
+        context.setKeyPass("*****");
+               return context;
+       }
+
+    @Test
+    public void testLocalProvider() throws GFacException {
+        GFacAPI gFacAPI = new GFacAPI();
+        gFacAPI.submitJob(jobExecutionContext);
+        MessageContext outMessageContext = 
jobExecutionContext.getOutMessageContext();
+        
Assert.assertEquals(MappingFactory.toString((ActualParameter)outMessageContext.getParameter("echo_output")),
 "hello");
+    }
+}

Modified: airavata/trunk/modules/gfac-core/src/test/resources/gfac-config.xml
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/test/resources/gfac-config.xml?rev=1455613&r1=1455612&r2=1455613&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/test/resources/gfac-config.xml 
(original)
+++ airavata/trunk/modules/gfac-core/src/test/resources/gfac-config.xml Tue Mar 
12 16:52:19 2013
@@ -44,11 +44,21 @@
 
     <Application name="UltraScan">
         <InHandlers>
-            <Handler 
class="org.apache.airavata.handlers.GramDirectorySetupHandler"/>
-            <Handler class="org.apache.airavata.handlers.GridFTPInputHandler"/>
+            <Handler 
class="org.apache.airavata.gfac.handler.GramDirectorySetupHandler"/>
+            <Handler 
class="org.apache.airavata.gfac.handler.GridFTPInputHandler"/>
         </InHandlers>
         <OutHandlers>
-            <Handler 
class="org.apache.airavata.handlers.GridFTPOutputHandler"/>
+            <Handler 
class="org.apache.airavata.gfac.handler.GridFTPOutputHandler"/>
         </OutHandlers>
     </Application>
+
+     <Provider class="org.apache.airavata.gfac.provider.impl.SSHProvider">
+         <InHandlers>
+            <Handler 
class="org.apache.airavata.gfac.handler.SCPDirectorySetupHandler"/>
+            <Handler class="org.apache.airavata.gfac.handler.SCPInputHandler"/>
+        </InHandlers>
+        <OutHandlers>
+            <Handler 
class="org.apache.airavata.gfac.handler.SCPOutputHandler"/>
+        </OutHandlers>
+    </Provider>
 </GFac>
\ No newline at end of file


Reply via email to