Author: lahiru
Date: Thu Sep  5 21:04:37 2013
New Revision: 1520424

URL: http://svn.apache.org/r1520424
Log:
major changes to api implementation.

Added:
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/Job.java
      - copied, changed from r1520111, 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/JobDescriptor.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultCluster.java
      - copied, changed from r1519854, 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java
    airavata/sandbox/gsissh/src/test/resources/sleep.pbs
    airavata/sandbox/gsissh/src/test/resources/test.pbs
Removed:
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/SSHApi.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/SSHApiFactory.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/JobDescriptor.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApi.java
Modified:
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/AuthenticationInfo.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultJobSubmissionListener.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/MyProxyAuthenticationInfo.java
    
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/listener/JobSubmissionListener.java
    airavata/sandbox/gsissh/src/main/resources/gsissh.properties
    
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPToTest.java
    
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTest.java

Modified: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/AuthenticationInfo.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/AuthenticationInfo.java?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/AuthenticationInfo.java
 (original)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/AuthenticationInfo.java
 Thu Sep  5 21:04:37 2013
@@ -25,13 +25,26 @@ package org.apache.airavata.gsi.ssh.api;
  * Time: 3:38 PM
  */
 
+import apple.awt.ClientPropertyApplicator;
 import org.ietf.jgss.GSSCredential;
 
+import java.util.Properties;
+
 /**
  * Authentication data. Could be MyProxy user name, password, could be 
GSSCredentials
  * or could be SSH keys.
  */
-public interface AuthenticationInfo {
+public abstract class AuthenticationInfo {
+
+    public Properties properties = new Properties();
+
+    public abstract GSSCredential getCredentials() throws SecurityException;
+
+    public Properties getProperties() {
+        return properties;
+    }
 
-    GSSCredential getCredentials() throws SecurityException;
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
 }

Added: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java?rev=1520424&view=auto
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java
 (added)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java
 Thu Sep  5 21:04:37 2013
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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.gsi.ssh.api;
+
+import com.jcraft.jsch.Session;
+import org.apache.airavata.gsi.ssh.api.job.Job;
+import org.apache.airavata.gsi.ssh.listener.JobSubmissionListener;
+
+
+public interface Cluster {
+
+    /**
+     * This will submit a job to the cluster with a given pbs file and some 
parameters
+     *
+     * @param pbsFilePath
+     * @param workingDirectory
+     * @return
+     * @throws SSHApiException
+     */
+    public String submitAsyncJobWithPBS(String pbsFilePath, String 
workingDirectory) throws SSHApiException;
+
+    /**
+     * This will submit the given job and not performing any monitoring
+     *
+     * @param jobDescriptor
+     * @return
+     * @throws SSHApiException
+     */
+    public String submitAsyncJob(Job jobDescriptor) throws SSHApiException;
+
+    /**
+     * This will get all the information about the cluster and store them as 
parameters
+     * So that api user can extract required information about the cluster
+     *
+     * @return
+     * @throws SSHApiException
+     */
+    public Cluster loadCluster() throws SSHApiException;
+
+    /**
+     * This will copy the lFile to rFile location in configured cluster
+     *
+     * @param rFile
+     * @param lFile
+     * @return
+     * @throws SSHApiException
+     */
+    public Session scpTo(String rFile, String lFile) throws SSHApiException;
+
+    /**
+     * submit a job and register the listener so that status changes will be 
triggers
+     * and appropricate action implemented in the JobSubmissionListener will 
get invoked
+     *
+     * @param jobDescriptor
+     * @param listener
+     * @return
+     * @throws SSHApiException
+     */
+    public String submitAsyncJob(Job jobDescriptor, JobSubmissionListener 
listener) throws SSHApiException;
+
+    /**
+     * @param jobID
+     * @return
+     * @throws SSHApiException
+     */
+    public Job getJobById(String jobID) throws SSHApiException;
+}

Added: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java?rev=1520424&view=auto
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java
 (added)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java
 Thu Sep  5 21:04:37 2013
@@ -0,0 +1,170 @@
+/*
+ *
+ * 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.gsi.ssh.api;
+
+import com.jcraft.jsch.*;
+import org.apache.airavata.gsi.ssh.config.ConfigReader;
+import org.apache.airavata.gsi.ssh.jsch.ExtendedJSch;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CommandExecutor {
+    static {
+        JSch.setConfig("gssapi-with-mic.x509", 
"org.apache.airavata.gsi.ssh.GSSContextX509");
+        JSch.setConfig("userauth.gssapi-with-mic", 
"com.jcraft.jsch.UserAuthGSSAPIWithMICGSSCredentials");
+
+    }
+
+    private static final Logger log = 
LoggerFactory.getLogger(CommandExecutor.class);
+    public static final String X509_CERT_DIR = "X509_CERT_DIR";
+
+    /**
+     * This will execute the given command with given session and session is 
not closed at the end.
+     *
+     * @param commandInfo
+     * @param session
+     * @param commandOutput
+     * @throws SSHApiException
+     */
+    public static Session executeCommand(CommandInfo commandInfo, Session 
session,
+                                         CommandOutput commandOutput) throws 
SSHApiException {
+
+        String command = commandInfo.getCommand();
+
+        Channel channel = null;
+        try {
+            if (!session.isConnected()) {
+                session.connect();
+            }
+            channel = session.openChannel("exec");
+            ((ChannelExec) channel).setCommand(command);
+        } catch (JSchException e) {
+            session.disconnect();
+
+            throw new SSHApiException("Unable to execute command - ", e);
+        }
+
+        channel.setInputStream(null);
+        ((ChannelExec) channel).setErrStream(commandOutput.getStandardError());
+
+        try {
+            channel.connect();
+        } catch (JSchException e) {
+
+            channel.disconnect();
+            session.disconnect();
+
+            throw new SSHApiException("Unable to retrieve command output. 
Command - " + command, e);
+        }
+
+        commandOutput.onOutput(channel);
+        //Only disconnecting the channel, session can be reused
+        channel.disconnect();
+        return session;
+    }
+
+    /**
+     * This will not reuse any session, it will create the session and close 
it at the end
+     *
+     * @param commandInfo        Encapsulated information about command. E.g 
:- executable name
+     *                           parameters etc ...
+     * @param serverInfo         The SSHing server information.
+     * @param authenticationInfo Security data needs to be communicated with 
remote server.
+     * @param commandOutput      The output of the command.
+     * @throws SSHApiException
+     */
+    public static void executeCommand(CommandInfo commandInfo, ServerInfo 
serverInfo,
+                                      AuthenticationInfo authenticationInfo,
+                                      CommandOutput commandOutput, 
ConfigReader configReader) throws SSHApiException {
+        System.setProperty(X509_CERT_DIR, (String) 
authenticationInfo.getProperties().get("X509_CERT_DIR"));
+        JSch jsch = new ExtendedJSch();
+
+        log.info("Connecting to server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() + " with user name - "
+                + serverInfo.getUserName());
+
+        Session session = null;
+
+        try {
+            session = jsch.getSession(serverInfo.getUserName(), 
serverInfo.getHost(), serverInfo.getPort());
+        } catch (JSchException e) {
+            throw new SSHApiException("An exception occurred while creating 
SSH session." +
+                    "Connecting server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() +
+                    " connecting user name - "
+                    + serverInfo.getUserName(), e);
+        }
+
+        java.util.Properties config = configReader.getProperties();
+        session.setConfig(config);
+
+        // Not a good way, but we dont have any choice
+        if (session instanceof ExtendedSession) {
+            ((ExtendedSession) 
session).setAuthenticationInfo(authenticationInfo);
+        }
+
+        try {
+            session.connect();
+        } catch (JSchException e) {
+            throw new SSHApiException("An exception occurred while connecting 
to server." +
+                    "Connecting server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() +
+                    " connecting user name - "
+                    + serverInfo.getUserName(), e);
+        }
+
+        String command = commandInfo.getCommand();
+
+        Channel channel = null;
+        try {
+            channel = session.openChannel("exec");
+            ((ChannelExec) channel).setCommand(command);
+        } catch (JSchException e) {
+            session.disconnect();
+
+            throw new SSHApiException("Unable to execute command - " + command 
+
+                    " on server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() +
+                    " connecting user name - "
+                    + serverInfo.getUserName(), e);
+        }
+
+
+        channel.setInputStream(null);
+        ((ChannelExec) channel).setErrStream(commandOutput.getStandardError());
+
+        try {
+            channel.connect();
+        } catch (JSchException e) {
+
+            channel.disconnect();
+            session.disconnect();
+
+            throw new SSHApiException("Unable to retrieve command output. 
Command - " + command +
+                    " on server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() +
+                    " connecting user name - "
+                    + serverInfo.getUserName(), e);
+        }
+
+        commandOutput.onOutput(channel);
+
+        channel.disconnect();
+        session.disconnect();
+    }
+
+
+}

Modified: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java 
(original)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java 
Thu Sep  5 21:04:37 2013
@@ -20,10 +20,10 @@
 */
 package org.apache.airavata.gsi.ssh.api;
 
-import org.apache.airavata.gsi.ssh.api.job.JobDescriptor;
+import org.apache.airavata.gsi.ssh.api.job.Job;
 
 public class Core {
-    private JobDescriptor job;
+    private Job job;
     private String id;
 
     public Core(String id) {
@@ -45,11 +45,11 @@ public class Core {
     /**
      * @return job running on the core
      */
-    public JobDescriptor getJob() {
+    public Job getJob() {
         return job;
     }
 
-    public void setJob(JobDescriptor job) {
+    public void setJob(Job job) {
         this.job = job;
     }
 

Copied: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/Job.java
 (from r1520111, 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/JobDescriptor.java)
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/Job.java?p2=airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/Job.java&p1=airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/JobDescriptor.java&r1=1520111&r2=1520424&rev=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/JobDescriptor.java
 (original)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/job/Job.java
 Thu Sep  5 21:04:37 2013
@@ -30,22 +30,22 @@ import java.util.List;
  * This class define a job with required parameters, based on this 
configuration API is generating a Pbs script and
  * submit the job to the computing resource
  */
-public class JobDescriptor {
+public class Job {
 
     private JobDescriptorDocument jobDescriptionDocument;
 
 
-    public JobDescriptor() {
+    public Job() {
         jobDescriptionDocument = JobDescriptorDocument.Factory.newInstance();
         jobDescriptionDocument.addNewJobDescriptor();
     }
 
-    public JobDescriptor(JobDescriptorDocument jobDescriptorDocument) {
+    public Job(JobDescriptorDocument jobDescriptorDocument) {
         this.jobDescriptionDocument = jobDescriptorDocument;
     }
 
 
-    public JobDescriptor(CommandOutput commandOutput) {
+    public Job(CommandOutput commandOutput) {
         jobDescriptionDocument = JobDescriptorDocument.Factory.newInstance();
         jobDescriptionDocument.addNewJobDescriptor();
     }
@@ -59,11 +59,11 @@ public class JobDescriptor {
         return this.jobDescriptionDocument;
     }
 
-    public static JobDescriptor fromXML(String xml)
+    public static Job fromXML(String xml)
             throws XmlException {
         JobDescriptorDocument parse = JobDescriptorDocument.Factory
                 .parse(xml);
-        JobDescriptor jobDescriptor = new JobDescriptor(parse);
+        Job jobDescriptor = new Job(parse);
         return jobDescriptor;
     }
 

Copied: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultCluster.java
 (from r1519854, 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java)
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultCluster.java?p2=airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultCluster.java&p1=airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java&r1=1519854&r2=1520424&rev=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java
 (original)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultCluster.java
 Thu Sep  5 21:04:37 2013
@@ -18,15 +18,472 @@
  * under the License.
  *
 */
-package org.apache.airavata.gsi.ssh.api;
+package org.apache.airavata.gsi.ssh.impl;
 
-public class Cluster {
+import com.jcraft.jsch.*;
+import org.apache.airavata.gsi.ssh.api.*;
+import org.apache.airavata.gsi.ssh.api.job.Job;
+import org.apache.airavata.gsi.ssh.config.ConfigReader;
+import org.apache.airavata.gsi.ssh.jsch.ExtendedJSch;
+import org.apache.airavata.gsi.ssh.listener.JobSubmissionListener;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.transform.*;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.*;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+
+public class DefaultCluster implements Cluster {
+    static {
+        JSch.setConfig("gssapi-with-mic.x509", 
"org.apache.airavata.gsi.ssh.GSSContextX509");
+        JSch.setConfig("userauth.gssapi-with-mic", 
"com.jcraft.jsch.UserAuthGSSAPIWithMICGSSCredentials");
+
+    }
+
+    private static final Logger log = 
LoggerFactory.getLogger(DefaultCluster.class);
+    public static final String X509_CERT_DIR = "X509_CERT_DIR";
+    public static final String POLLING_FREQUENCEY = "polling.frequency";
+    public static final String SSH_SESSION_TIMEOUT = "ssh.session.timeout";
 
     private Machine[] Nodes;
-/**
- *
- * @return cluster Nodes as array of machines
- */
+
+    private ServerInfo serverInfo;
+
+    private AuthenticationInfo authenticationInfo;
+
+    private Session session;
+
+    private static JSch jSch;
+
+    private ConfigReader configReader;
+
+    public DefaultCluster(ServerInfo serverInfo, AuthenticationInfo 
authenticationInfo) throws SSHApiException {
+
+        this.serverInfo = serverInfo;
+
+        this.authenticationInfo = authenticationInfo;
+
+        System.setProperty(X509_CERT_DIR, (String) 
authenticationInfo.getProperties().get(X509_CERT_DIR));
+
+        try {
+            this.configReader = new ConfigReader();
+        } catch (IOException e) {
+            throw new SSHApiException("Unable to load system configurations.", 
e);
+        }
+        this.jSch = new ExtendedJSch();
+
+        log.info("Connecting to server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() + " with user name - "
+                + serverInfo.getUserName());
+
+        try {
+            session = jSch.getSession(serverInfo.getUserName(), 
serverInfo.getHost(), serverInfo.getPort());
+            
session.setTimeout(Integer.parseInt(configReader.getConfiguration(SSH_SESSION_TIMEOUT)));
+        } catch (JSchException e) {
+            throw new SSHApiException("An exception occurred while creating 
SSH session." +
+                    "Connecting server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() +
+                    " connecting user name - "
+                    + serverInfo.getUserName(), e);
+        }
+
+        java.util.Properties config = this.configReader.getProperties();
+        session.setConfig(config);
+
+        // Not a good way, but we dont have any choice
+        if (session instanceof ExtendedSession) {
+            ((ExtendedSession) 
session).setAuthenticationInfo(authenticationInfo);
+        }
+
+        try {
+            session.connect();
+        } catch (JSchException e) {
+            throw new SSHApiException("An exception occurred while connecting 
to server." +
+                    "Connecting server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() +
+                    " connecting user name - "
+                    + serverInfo.getUserName(), e);
+        }
+        System.out.println(session.isConnected());
+    }
+
+
+
+    public String submitAsyncJobWithPBS(String pbsFilePath, String 
workingDirectory) throws SSHApiException {
+
+        this.scpTo(workingDirectory, pbsFilePath);
+
+        // since this is a constant we do not ask users to fill this
+        RawCommandInfo rawCommandInfo = new 
RawCommandInfo("/opt/torque/bin/qsub " +
+                workingDirectory + File.separator + 
FilenameUtils.getName(pbsFilePath));
+
+        StandardOutReader jobIDReaderCommandOutput = new StandardOutReader();
+        CommandExecutor.executeCommand(rawCommandInfo, this.session, 
jobIDReaderCommandOutput);
+
+        //Check whether pbs submission is successful or not, if it failed 
throw and exception in submitJob method
+        // with the error thrown in qsub command
+        if (jobIDReaderCommandOutput.getErrorifAvailable().equals("")) {
+            return jobIDReaderCommandOutput.getStdOutput();
+        } else {
+            throw new 
SSHApiException(jobIDReaderCommandOutput.getStandardError().toString());
+        }
+    }
+
+    public String submitAsyncJob(Job jobDescriptor) throws SSHApiException {
+        TransformerFactory factory = TransformerFactory.newInstance();
+        String xsltPath = "src" + File.separator + "main" + File.separator + 
"resources" + File.separator + "PBSTemplate.xslt";
+        Source xslt = new StreamSource(new File(xsltPath));
+        Transformer transformer = null;
+        StringWriter results = new StringWriter();
+        File tempPBSFile = null;
+        try {
+            // generate the pbs script using xslt
+            transformer = factory.newTransformer(xslt);
+            Source text = new StreamSource(new 
ByteArrayInputStream(jobDescriptor.toXML().getBytes()));
+            transformer.transform(text, new StreamResult(results));
+
+            log.info("generated PBS:" + results.toString());
+
+            // creating a temporary file using pbs script generated above
+            int number = new SecureRandom().nextInt();
+            number = (number < 0 ? -number : number);
+
+            tempPBSFile = new File(Integer.toString(number) + ".pbs");
+            FileUtils.writeStringToFile(tempPBSFile, results.toString());
+
+            //reusing submitAsyncJobWithPBS method to submit a job
+
+            String jobID = 
this.submitAsyncJobWithPBS(tempPBSFile.getAbsolutePath(),
+                    jobDescriptor.getWorkingDirectory());
+            log.info("Job has successfully submitted, JobID : " + jobID);
+            return jobID.replace("\n", "");
+        } catch (TransformerConfigurationException e) {
+            throw new SSHApiException("Error parsing PBS transformation", e);
+        } catch (TransformerException e) {
+            throw new SSHApiException("Error generating PBS script", e);
+        } catch (IOException e) {
+            throw new SSHApiException("An exception occurred while connecting 
to server." +
+                    "Connecting server - " + serverInfo.getHost() + ":" + 
serverInfo.getPort() +
+                    " connecting user name - "
+                    + serverInfo.getUserName(), e);
+        } finally {
+            tempPBSFile.delete();
+        }
+    }
+
+
+    public Cluster loadCluster() throws SSHApiException {
+        RawCommandInfo rawCommandInfo = new 
RawCommandInfo("/opt/torque/bin/qnodes");
+
+        StandardOutReader stdOutReader = new StandardOutReader();
+        CommandExecutor.executeCommand(rawCommandInfo, this.getSession(), 
stdOutReader);
+        if (!stdOutReader.getErrorifAvailable().equals("")) {
+            throw new 
SSHApiException(stdOutReader.getStandardError().toString());
+        }
+        String result = stdOutReader.getStdOutput();
+        String[] Nodes = result.split("\n");
+        String[] line;
+        String header, value;
+        Machine Node;
+        Core[] Cores = null;
+        ArrayList<Machine> Machines = new ArrayList<Machine>();
+        int i = 0;
+        while (i < Nodes.length) {
+            Node = new Machine();
+            Node.setName(Nodes[i]);
+            i++;
+
+            while (i < Nodes.length) {
+                if (!Nodes[i].startsWith(" ")) {
+                    i++;
+                    break;
+                }
+
+                line = Nodes[i].split("=");
+                header = line[0].trim();
+                value = line[1].trim();
+
+                if ("state".equals(header))
+                    Node.setState(value);
+                else if ("np".equals(header)) {
+                    Node.setNp(value);
+                    int np = Integer.parseInt(Node.getNp());
+                    Cores = new Core[np];
+                    for (int n = 0; n < np; n++) {
+                        Cores[n] = new Core("" + n);
+                    }
+                } else if ("ntype".equals(header))
+                    Node.setNtype(value);
+                else if ("jobs".equals(header)) {
+                    String[] jobs = value.split(", ");
+                    Job jo = new Job();
+                    //Job[] Jobs = new Job[jobs.length];
+                    for (int j = 0; j < jobs.length; j++) {
+                        String[] c = jobs[j].split("/");
+                        String Jid = c[1];
+                        jo = this.getJobById(Jid);
+                        int core = Integer.parseInt(c[0]);
+                        Cores[core].setJob(jo);
+
+                    }
+
+
+                }
+                i++;
+            }
+            Node.setCores(Cores);
+            Machines.add(Node);
+        }
+        this.setNodes(Machines.toArray(new Machine[Machines.size()]));
+        return this;
+    }
+
+    public Job getJobById(String jobID) throws SSHApiException {
+        RawCommandInfo rawCommandInfo = new 
RawCommandInfo("/opt/torque/bin/qstat -f " + jobID);
+
+        StandardOutReader stdOutReader = new StandardOutReader();
+        CommandExecutor.executeCommand(rawCommandInfo,this.getSession(), 
stdOutReader);
+        if (!stdOutReader.getErrorifAvailable().equals("")) {
+            throw new 
SSHApiException(stdOutReader.getStandardError().toString());
+        }
+        String result = stdOutReader.getStdOutput();
+        String[] info = result.split("\n");
+        Job jobDescriptor = new Job();
+        String header = "";
+        String value = "";
+        String[] line;
+        for (int i = 0; i < info.length; i++) {
+            if (info[i].contains("=")) {
+                line = info[i].split("=", 2);
+            } else {
+                line = info[i].split(":", 2);
+            }
+            if (line.length >= 2) {
+                header = line[0].trim();
+                log.debug("Header = " + header);
+                value = line[1].trim();
+                log.debug("value = " + value);
+
+                if (header.equals("Variable_List")) {
+                    while (info[i + 1].startsWith("\t")) {
+                        value += info[i + 1];
+                        i++;
+                    }
+                    value = value.replaceAll("\t", "");
+                    jobDescriptor.setVariableList(value);
+                } else if ("Job Id".equals(header)) {
+                    jobDescriptor.setJobID(value);
+                } else if ("Job_Name".equals(header)) {
+                    jobDescriptor.setJobName(value);
+                } else if ("Account_Name".equals(header)) {
+                    jobDescriptor.setAcountString(value);
+                } else if ("job_state".equals(header)) {
+                    jobDescriptor.setStatus(value);
+                } else if ("Job_Owner".equals(header)) {
+                    jobDescriptor.setOwner(value);
+                } else if ("resources_used.cput".equals(header)) {
+                    jobDescriptor.setUsedCPUTime(value);
+                } else if ("resources_used.mem".equals(header)) {
+                    jobDescriptor.setUsedMemory(value);
+                } else if ("resources_used.walltime".equals(header)) {
+                    jobDescriptor.setEllapsedTime(value);
+                } else if ("job_state".equals(header)) {
+                    jobDescriptor.setStatus(value);
+                } else if ("queue".equals(header))
+                    jobDescriptor.setQueueName(value);
+                else if ("ctime".equals(header)) {
+                    jobDescriptor.setCTime(value);
+                } else if ("qtime".equals(header)) {
+                    jobDescriptor.setQTime(value);
+                } else if ("mtime".equals(header)) {
+                    jobDescriptor.setMTime(value);
+                } else if ("start_time".equals(header)) {
+                    jobDescriptor.setSTime(value);
+                } else if ("comp_time".equals(header)) {
+                    jobDescriptor.setCompTime(value);
+                } else if ("exec_host".equals(header)) {
+                    jobDescriptor.setExecuteNode(value);
+                } else if ("Output_Path".equals(header)) {
+                    if (info[i + 1].contains("=") || info[i + 1].contains(":"))
+                        jobDescriptor.setStandardOutFile(value);
+                    else {
+                        jobDescriptor.setStandardOutFile(value + info[i + 
1].trim());
+                        i++;
+                    }
+                } else if ("Error_Path".equals(header)) {
+                    if (info[i + 1].contains("=") || info[i + 1].contains(":"))
+                        jobDescriptor.setStandardErrorFile(value);
+                    else {
+                        String st = info[i + 1].trim();
+                        jobDescriptor.setStandardErrorFile(value + st);
+                        i++;
+                    }
+
+                } else if ("submit_args".equals(header)) {
+                    while (i + 1 < info.length) {
+                        if (info[i + 1].startsWith("\t")) {
+                            value += info[i + 1];
+                            i++;
+                        } else
+                            break;
+                    }
+                    value = value.replaceAll("\t", "");
+                    jobDescriptor.setSubmitArgs(value);
+                }
+            }
+        }
+        return jobDescriptor;
+    }
+
+    public Session scpTo(String rFile, String lFile) throws SSHApiException {
+        FileInputStream fis = null;
+        String prefix = null;
+        if (new File(lFile).isDirectory()) {
+            prefix = lFile + File.separator;
+        }
+        boolean ptimestamp = true;
+        try {
+            // exec 'scp -t rfile' remotely
+            String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + 
rFile;
+            Channel channel = session.openChannel("exec");
+            ((ChannelExec) channel).setCommand(command);
+
+            // get I/O streams for remote scp
+            OutputStream out = channel.getOutputStream();
+            InputStream in = channel.getInputStream();
+
+            channel.connect();
+
+            if (checkAck(in) != 0) {
+                System.exit(0);
+            }
+
+            File _lfile = new File(lFile);
+
+            if (ptimestamp) {
+                command = "T " + (_lfile.lastModified() / 1000) + " 0";
+                // The access time should be sent here,
+                // but it is not accessible with JavaAPI ;-<
+                command += (" " + (_lfile.lastModified() / 1000) + " 0\n");
+                out.write(command.getBytes());
+                out.flush();
+                if (checkAck(in) != 0) {
+                    System.exit(0);
+                }
+            }
+
+            // send "C0644 filesize filename", where filename should not 
include '/'
+            long filesize = _lfile.length();
+            command = "C0644 " + filesize + " ";
+            if (lFile.lastIndexOf('/') > 0) {
+                command += lFile.substring(lFile.lastIndexOf('/') + 1);
+            } else {
+                command += lFile;
+            }
+            command += "\n";
+            out.write(command.getBytes());
+            out.flush();
+            if (checkAck(in) != 0) {
+                System.exit(0);
+            }
+
+            // send a content of lFile
+            fis = new FileInputStream(lFile);
+            byte[] buf = new byte[1024];
+            while (true) {
+                int len = fis.read(buf, 0, buf.length);
+                if (len <= 0) break;
+                out.write(buf, 0, len); //out.flush();
+            }
+            fis.close();
+            fis = null;
+            // send '\0'
+            buf[0] = 0;
+            out.write(buf, 0, 1);
+            out.flush();
+            if (checkAck(in) != 0) {
+                System.exit(0);
+            }
+            out.close();
+            // We are not disconnecting the session
+//            session.disconnect();
+            channel.disconnect();
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new SSHApiException("Error occured during file transfer 
operation: " + e);
+        }
+        return session;
+    }
+
+
+    static int checkAck(InputStream in) throws IOException {
+        int b = in.read();
+        if (b == 0) return b;
+        if (b == -1) return b;
+
+        if (b == 1 || b == 2) {
+            StringBuffer sb = new StringBuffer();
+            int c;
+            do {
+                c = in.read();
+                sb.append((char) c);
+            }
+            while (c != '\n');
+            if (b == 1) { // error
+                System.out.print(sb.toString());
+            }
+            if (b == 2) { // fatal error
+                System.out.print(sb.toString());
+            }
+        }
+        return b;
+    }
+
+    public String submitAsyncJob(Job jobDescriptor, JobSubmissionListener 
listener) throws SSHApiException {
+        String jobID = this.submitAsyncJob(jobDescriptor);
+        try {
+            
Thread.sleep(Long.parseLong(configReader.getConfiguration(POLLING_FREQUENCEY)));
+        } catch (InterruptedException e) {
+            log.error("Error during job status monitoring");
+            throw new SSHApiException("Error during job status monitoring", e);
+        }
+        // Get the job status first
+        Job jobById = this.getJobById(jobID);
+
+        while (!jobById.getStatus().equals(JobStatus.C.toString())) {
+            if 
(!jobById.getStatus().equals(listener.getJobStatus().toString())) {
+                
listener.setJobStatus(JobStatus.fromString(jobById.getStatus()));
+                listener.statusChanged(jobById);
+            }
+            try {
+                
Thread.sleep(Long.parseLong(configReader.getConfiguration(POLLING_FREQUENCEY)));
+            } catch (InterruptedException e) {
+                log.error("Error during job status monitoring");
+                throw new SSHApiException("Error during job status 
monitoring", e);
+            }
+            jobById = this.getJobById(jobID);
+        }
+        listener.statusChanged(jobById);
+        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
+    }
+
+    public void setServerInfo(ServerInfo serverInfo) {
+        this.serverInfo = serverInfo;
+    }
+
+    public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) {
+        this.authenticationInfo = authenticationInfo;
+    }
+
+    public void setSession(Session session) {
+        this.session = session;
+    }
+
+     /**
+     * @return cluster Nodes as array of machines
+     */
     public Machine[] getNodes() {
         return Nodes;
     }
@@ -35,4 +492,20 @@ public class Cluster {
         this.Nodes = Nodes;
     }
 
+    public ServerInfo getServerInfo() {
+        return serverInfo;
+    }
+
+    public AuthenticationInfo getAuthenticationInfo() {
+        return authenticationInfo;
+    }
+
+    /**
+     * This gaurantee to return a valid session
+     *
+     * @return
+     */
+    public Session getSession() {
+        return this.session;
+    }
 }

Modified: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultJobSubmissionListener.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultJobSubmissionListener.java?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultJobSubmissionListener.java
 (original)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/DefaultJobSubmissionListener.java
 Thu Sep  5 21:04:37 2013
@@ -21,12 +21,12 @@
 package org.apache.airavata.gsi.ssh.impl;
 
 import org.apache.airavata.gsi.ssh.api.SSHApiException;
-import org.apache.airavata.gsi.ssh.api.job.JobDescriptor;
+import org.apache.airavata.gsi.ssh.api.job.Job;
 import org.apache.airavata.gsi.ssh.listener.JobSubmissionListener;
 
 public class DefaultJobSubmissionListener extends JobSubmissionListener {
 
-    public void statusChanged(JobDescriptor jobDescriptor) throws 
SSHApiException {
+    public void statusChanged(Job jobDescriptor) throws SSHApiException {
         System.out.println("Job status has changed : " + 
jobDescriptor.getStatus());
     }
 }

Modified: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/MyProxyAuthenticationInfo.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/MyProxyAuthenticationInfo.java?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/MyProxyAuthenticationInfo.java
 (original)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/MyProxyAuthenticationInfo.java
 Thu Sep  5 21:04:37 2013
@@ -26,14 +26,17 @@ import org.globus.myproxy.MyProxy;
 import org.globus.myproxy.MyProxyException;
 import org.ietf.jgss.GSSCredential;
 
+import java.util.Properties;
+
 /**
  * User: AmilaJ ([email protected])
  * Date: 8/14/13
  * Time: 5:22 PM
  */
 
-public class MyProxyAuthenticationInfo implements AuthenticationInfo {
+public class MyProxyAuthenticationInfo extends AuthenticationInfo {
 
+    public static final String X509_CERT_DIR = "X509_CERT_DIR";
     private String userName;
     private String password;
     private String myProxyUrl;
@@ -41,12 +44,13 @@ public class MyProxyAuthenticationInfo i
     private int lifeTime;
 
     public MyProxyAuthenticationInfo(String userName, String password, String 
myProxyUrl, int myProxyPort,
-                                     int life) {
+                                     int life, String certificatePath) {
         this.userName = userName;
         this.password = password;
         this.myProxyUrl = myProxyUrl;
         this.myProxyPort = myProxyPort;
         this.lifeTime = life;
+        properties.setProperty(X509_CERT_DIR, certificatePath);
     }
 
     public String getUserName() {
@@ -89,7 +93,7 @@ public class MyProxyAuthenticationInfo i
         this.lifeTime = lifeTime;
     }
 
-    public GSSCredential getCredentials() throws SecurityException{
+    public GSSCredential getCredentials() throws SecurityException {
         return getMyProxyCredentials();
     }
 
@@ -101,4 +105,6 @@ public class MyProxyAuthenticationInfo i
             throw new SecurityException("Error getting proxy credentials", e);
         }
     }
+
+
 }

Modified: 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/listener/JobSubmissionListener.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/listener/JobSubmissionListener.java?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/listener/JobSubmissionListener.java
 (original)
+++ 
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/listener/JobSubmissionListener.java
 Thu Sep  5 21:04:37 2013
@@ -21,7 +21,7 @@
 package org.apache.airavata.gsi.ssh.listener;
 
 import org.apache.airavata.gsi.ssh.api.SSHApiException;
-import org.apache.airavata.gsi.ssh.api.job.JobDescriptor;
+import org.apache.airavata.gsi.ssh.api.job.Job;
 import org.apache.airavata.gsi.ssh.impl.JobStatus;
 
 /**
@@ -40,7 +40,7 @@ public abstract class JobSubmissionListe
      * @param jobDescriptor
      * @throws SSHApiException
      */
-    public abstract void statusChanged(JobDescriptor jobDescriptor) throws 
SSHApiException;
+    public abstract void statusChanged(Job jobDescriptor) throws 
SSHApiException;
 
     public JobStatus getJobStatus() {
         return jobStatus;

Modified: airavata/sandbox/gsissh/src/main/resources/gsissh.properties
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/resources/gsissh.properties?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- airavata/sandbox/gsissh/src/main/resources/gsissh.properties (original)
+++ airavata/sandbox/gsissh/src/main/resources/gsissh.properties Thu Sep  5 
21:04:37 2013
@@ -1,3 +1,5 @@
 # Specifies system level configurations as a key/value pairs.
 
-StrictHostKeyChecking=no
\ No newline at end of file
+StrictHostKeyChecking=no
+polling.frequency=60000
+ssh.session.timeout=360000
\ No newline at end of file

Modified: 
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPToTest.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPToTest.java?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPToTest.java
 (original)
+++ 
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPToTest.java
 Thu Sep  5 21:04:37 2013
@@ -64,7 +64,7 @@ public class SCPToTest {
          // Create authentication
         AuthenticationInfo authenticationInfo
                 = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
+                7512, 17280000,certificateLocation);
         ServerInfo serverInfo = new ServerInfo("ogce" ,"trestles.sdsc.edu");
         SCPTo scpTo = new 
SCPTo(serverInfo,authenticationInfo,this.certificateLocation,new 
ConfigReader());
         scpTo.scpTo(rFilePath, lFilePath);

Modified: 
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTest.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTest.java?rev=1520424&r1=1520423&r2=1520424&view=diff
==============================================================================
--- 
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTest.java
 (original)
+++ 
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTest.java
 Thu Sep  5 21:04:37 2013
@@ -22,7 +22,8 @@
 package org.apache.airavata.gsi.ssh.impl;
 
 import org.apache.airavata.gsi.ssh.api.*;
-import org.apache.airavata.gsi.ssh.api.job.JobDescriptor;
+import org.apache.airavata.gsi.ssh.api.job.Job;
+import org.apache.airavata.gsi.ssh.config.ConfigReader;
 import org.testng.AssertJUnit;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
@@ -46,11 +47,12 @@ public class DefaultSSHApiTest {
     private String certificateLocation;
     private String pbsFilePath;
     private String workingDirectory;
+    private String jobID;
 
     @BeforeTest
     public void setUp() throws Exception {
-//        System.setProperty("myproxy.user", "ogce");
-//        System.setProperty("myproxy.password", "");
+        System.setProperty("myproxy.user", "ogce");
+        System.setProperty("myproxy.password", "Jdas7wph");
         System.setProperty("basedir", 
"/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
         myProxyUserName = System.getProperty("myproxy.user");
         myProxyPassword = System.getProperty("myproxy.password");
@@ -83,7 +85,7 @@ public class DefaultSSHApiTest {
         // Create authentication
         AuthenticationInfo authenticationInfo
                 = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
+                7512, 17280000,certificateLocation);
 
         // Create command
         CommandInfo commandInfo = new RawCommandInfo("/bin/ls");
@@ -94,58 +96,32 @@ public class DefaultSSHApiTest {
         // Output
         CommandOutput commandOutput = new SystemCommandOutput();
 
-        // Get the API
-        SSHApi sshApi = SSHApiFactory.createSSHApi(this.certificateLocation);
-
         // Execute command
-        sshApi.executeCommand(commandInfo, serverInfo, authenticationInfo, 
commandOutput);
+        CommandExecutor.executeCommand(commandInfo, serverInfo, 
authenticationInfo, commandOutput, new ConfigReader());
     }
 
-    @Test
-    public void testSubmitSimpleCommand() throws Exception {
-        // Create authentication
-        AuthenticationInfo authenticationInfo
-                = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
-
-        // Create command
-        CommandInfo commandInfo = new RawCommandInfo("/opt/torque/bin/qsub 
/home/ogce/test.pbs");
-
-        // Server info
-        ServerInfo serverInfo = new ServerInfo("ogce", "trestles.sdsc.edu");
-
-        // Output
-        CommandOutput commandOutput = new SystemCommandOutput();
-
-        // Get the API
-        SSHApi sshApi = SSHApiFactory.createSSHApi(this.certificateLocation);
-
-        // Execute command
-        sshApi.executeCommand(commandInfo, serverInfo, authenticationInfo, 
commandOutput);
-    }
 
     @Test
     public void testSubmitAsyncJobWithPBS() throws Exception {
         // Create authentication
         AuthenticationInfo authenticationInfo
                 = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
+                7512, 17280000,certificateLocation);
 
         // Server info
         ServerInfo serverInfo = new ServerInfo("ogce", "trestles.sdsc.edu");
 
 
-        // Get the API
-        SSHApi sshApi = SSHApiFactory.createSSHApi(this.certificateLocation);
+        Cluster trestles = new DefaultCluster(serverInfo, authenticationInfo);
 
         // Execute command
         System.out.println("Target PBS file path: " + workingDirectory);
         System.out.println("Local PBS File path: " + pbsFilePath);
-        JobDescriptor jobDescriptor = new JobDescriptor();
+        Job jobDescriptor = new Job();
         //Here we give working directory as a file name to replace the file, 
to allow multiple test runs with the same
         //file name
         jobDescriptor.setWorkingDirectory(workingDirectory);
-        String jobID = sshApi.submitAsyncJobWithPBS(serverInfo, 
authenticationInfo, pbsFilePath, jobDescriptor);
+        String jobID = trestles.submitAsyncJobWithPBS(pbsFilePath, 
workingDirectory);
         System.out.println("JobID returned : " + jobID);
     }
 
@@ -154,20 +130,20 @@ public class DefaultSSHApiTest {
         // Create authentication
         AuthenticationInfo authenticationInfo
                 = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
+                7512, 17280000,certificateLocation);
 
         // Server info
         ServerInfo serverInfo = new ServerInfo("ogce", "trestles.sdsc.edu");
 
 
-        // Get the API
-        SSHApi sshApi = SSHApiFactory.createSSHApi(this.certificateLocation);
+        Cluster trestles = new DefaultCluster(serverInfo, authenticationInfo);
+
 
         // Execute command
         System.out.println("Target PBS file path: " + workingDirectory);
         System.out.println("Local PBS File path: " + pbsFilePath);
         String workingDirectory = File.separator + "home" + File.separator + 
"ogce" + File.separator + "gsissh";
-        JobDescriptor jobDescriptor = new JobDescriptor();
+        Job jobDescriptor = new Job();
         jobDescriptor.setWorkingDirectory(workingDirectory);
         jobDescriptor.setShellName("/bin/bash");
         jobDescriptor.setJobName("GSI_SSH_SLEEP_JOB");
@@ -184,12 +160,12 @@ public class DefaultSSHApiTest {
         inputs.add("Hello World");
         jobDescriptor.setInputValues(inputs);
         System.out.println(jobDescriptor.toXML());
-        String jobID = sshApi.submitAsyncJob(serverInfo, authenticationInfo, 
jobDescriptor);
+        jobID = trestles.submitAsyncJob(jobDescriptor);
         System.out.println("JobID returned : " + jobID);
 
 //        Cluster cluster = sshApi.getCluster(serverInfo, authenticationInfo);
         Thread.sleep(1000);
-        JobDescriptor jobById = sshApi.getJobById(serverInfo, 
authenticationInfo, jobID);
+        Job jobById = trestles.getJobById(jobID);
         AssertJUnit.assertEquals(jobById.getJobId(), jobID);
         System.out.println(jobById.getAcountString());
         System.out.println(jobById.getAllEnvExport());
@@ -211,43 +187,10 @@ public class DefaultSSHApiTest {
     }
 
 
-    @Test
-    public void testGetJob() throws Exception {
-        // Create authentication
-        AuthenticationInfo authenticationInfo
-                = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
-
-        // Server info
-        ServerInfo serverInfo = new ServerInfo("ogce", "trestles.sdsc.edu");
 
 
-        // Get the API
-        SSHApi sshApi = SSHApiFactory.createSSHApi(this.certificateLocation);
-
-        // Execute command
-        String jobID = "1584791.trestles-fe1.sdsc.edu";
-        JobDescriptor jobById = sshApi.getJobById(serverInfo, 
authenticationInfo, jobID);
-        System.out.println(jobById.getAcountString());
-        System.out.println(jobById.getAllEnvExport());
-        System.out.println(jobById.getCompTime());
-        System.out.println(jobById.getExecutablePath());
-        System.out.println(jobById.getEllapsedTime());
-        System.out.println(jobById.getQueueName());
-        System.out.println(jobById.getExecuteNode());
-        System.out.println(jobById.getJobName());
-        System.out.println(jobById.getCTime());
-        System.out.println(jobById.getSTime());
-        System.out.println(jobById.getMTime());
-        System.out.println(jobById.getCompTime());
-        System.out.println(jobById.getOwner());
-        System.out.println(jobById.getQTime());
-        System.out.println(jobById.getUsedCPUTime());
-        System.out.println(jobById.getUsedMemory());
-
-    }
     @Test
-    public void testGetCluster()throws Exception{
+    public void testGetCluster() throws Exception {
 //        AuthenticationInfo authenticationInfo
 //                = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
 //                7512, 17280000);
@@ -270,20 +213,18 @@ public class DefaultSSHApiTest {
         // Create authentication
         AuthenticationInfo authenticationInfo
                 = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
+                7512, 17280000,certificateLocation);
 
         // Server info
         ServerInfo serverInfo = new ServerInfo("ogce", "trestles.sdsc.edu");
 
-
-        // Get the API
-        SSHApi sshApi = SSHApiFactory.createSSHApi(this.certificateLocation);
+        Cluster trestles = new DefaultCluster(serverInfo, authenticationInfo);
 
         // Execute command
         System.out.println("Target PBS file path: " + workingDirectory);
         System.out.println("Local PBS File path: " + pbsFilePath);
         String workingDirectory = File.separator + "home" + File.separator + 
"ogce" + File.separator + "gsissh";
-        JobDescriptor jobDescriptor = new JobDescriptor();
+        Job jobDescriptor = new Job();
         jobDescriptor.setWorkingDirectory(workingDirectory);
         jobDescriptor.setShellName("/bin/bash");
         jobDescriptor.setJobName("GSI_SSH_SLEEP_JOB");
@@ -301,36 +242,36 @@ public class DefaultSSHApiTest {
         jobDescriptor.setInputValues(inputs);
         System.out.println(jobDescriptor.toXML());
         try {
-            String jobID = sshApi.submitAsyncJob(serverInfo, 
authenticationInfo, jobDescriptor);
+            String jobID = trestles.submitAsyncJob(jobDescriptor);
             System.out.println("JobID returned : " + jobID);
         } catch (SSHApiException e) {
             System.out.println(e.getMessage());
         }
     }
 
-@Test
+    @Test
     public void testSubmitAsyncJobWithListener() throws Exception {
         // Create authentication
         AuthenticationInfo authenticationInfo
                 = new MyProxyAuthenticationInfo(myProxyUserName, 
myProxyPassword, "myproxy.teragrid.org",
-                7512, 17280000);
+                7512, 17280000,certificateLocation);
 
         // Server info
         ServerInfo serverInfo = new ServerInfo("ogce", "trestles.sdsc.edu");
 
 
-        // Get the API
-        SSHApi sshApi = SSHApiFactory.createSSHApi(this.certificateLocation);
+        Cluster trestles = new DefaultCluster(serverInfo, authenticationInfo);
+
 
         // Execute command
         System.out.println("Target PBS file path: " + workingDirectory);
         System.out.println("Local PBS File path: " + pbsFilePath);
         String workingDirectory = File.separator + "home" + File.separator + 
"ogce" + File.separator + "gsissh";
-        JobDescriptor jobDescriptor = new JobDescriptor();
+        Job jobDescriptor = new Job();
         jobDescriptor.setWorkingDirectory(workingDirectory);
         jobDescriptor.setShellName("/bin/bash");
         jobDescriptor.setJobName("GSI_SSH_SLEEP_JOB");
-        jobDescriptor.setExecutablePath("/bin/sleep");
+        jobDescriptor.setExecutablePath("/bin/echo");
         jobDescriptor.setAllEnvExport(true);
         jobDescriptor.setMailOptions("n");
         jobDescriptor.setStandardOutFile(workingDirectory + File.separator + 
"application.out");
@@ -340,10 +281,10 @@ public class DefaultSSHApiTest {
         jobDescriptor.setMaxWallTime("1:00:00");
         jobDescriptor.setAcountString("sds128");
         List<String> inputs = new ArrayList<String>();
-        inputs.add("10000");
+        inputs.add("Hello World !!");
         jobDescriptor.setInputValues(inputs);
         System.out.println(jobDescriptor.toXML());
-        sshApi.submitAsyncJob(serverInfo, authenticationInfo, 
jobDescriptor,new DefaultJobSubmissionListener());
+        trestles.submitAsyncJob(jobDescriptor, new 
DefaultJobSubmissionListener());
     }
 
 }

Added: airavata/sandbox/gsissh/src/test/resources/sleep.pbs
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/test/resources/sleep.pbs?rev=1520424&view=auto
==============================================================================
--- airavata/sandbox/gsissh/src/test/resources/sleep.pbs (added)
+++ airavata/sandbox/gsissh/src/test/resources/sleep.pbs Thu Sep  5 21:04:37 
2013
@@ -0,0 +1,14 @@
+#!/bin/bash
+# Grid Engine batch job script built by Globus job manager
+
+#$ -S /bin/bash
+#$ -V
+#$ -pe 1way 32
+#$ -m n
+#$ -q normal
+#$ -A <ACCOUNT>
+#$ -l h_rt=0:60:00
+#$ -o application.stdout
+#$ -e application.stderr
+#PBS -N GSI_SSH_SLEEP_JOB
+/bin/sleep 60

Added: airavata/sandbox/gsissh/src/test/resources/test.pbs
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/test/resources/test.pbs?rev=1520424&view=auto
==============================================================================
--- airavata/sandbox/gsissh/src/test/resources/test.pbs (added)
+++ airavata/sandbox/gsissh/src/test/resources/test.pbs Thu Sep  5 21:04:37 2013
@@ -0,0 +1,10 @@
+#!/bin/bash
+#PBS -q normal
+#PBS -A sds128
+#PBS -l nodes=1:ppn=1
+#PBS -l walltime=00:00:01
+#PBS -o job_output
+#PBS -N GSI_SSH_JOB
+#PBS -V
+
+/bin/date


Reply via email to