Author: lahiru
Date: Fri Oct 11 21:13:06 2013
New Revision: 1531421
URL: http://svn.apache.org/r1531421
Log:
Adding more error handling to the api
Modified:
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/impl/PBSCluster.java
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/StandardOutReader.java
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java
airavata/sandbox/gsissh/src/main/resources/PBSTemplate.xslt
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPFromTest.java
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/DefaultSSHApiTest.java
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaSSHTest.java
airavata/sandbox/gsissh/src/test/resources/sleep.pbs
Modified:
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=1531421&r1=1531420&r2=1531421&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/api/Cluster.java
Fri Oct 11 21:13:06 2013
@@ -61,21 +61,19 @@ public interface Cluster {
/**
* This will copy the localFile to remoteFile location in configured
cluster
*
- * @param remoteFile remote file location
+ * @param remoteFile remote file location, this can be a directory too
* @param localFile local file path of the file which needs to copy to
remote location
- * @return the successful remote file path of the transfer
* @throws SSHApiException throws exception during error
*/
- public String scpTo(String remoteFile, String localFile) throws
SSHApiException;
+ public void scpTo(String remoteFile, String localFile) throws
SSHApiException;
/**
* This will copy a remote file in path rFile to local file lFile
* @param remoteFile remote file path, this has to be a full qualified path
* @param localFile This is the local file to copy, this can be a
directory too
- * @return
* @throws SSHApiException
*/
- public String scpFrom(String remoteFile, String localFile) throws
SSHApiException;
+ public void scpFrom(String remoteFile, String localFile) throws
SSHApiException;
/**
* This will create directories in computing resources
Modified:
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/PBSCluster.java
URL:
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/PBSCluster.java?rev=1531421&r1=1531420&r2=1531421&view=diff
==============================================================================
---
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/PBSCluster.java
(original)
+++
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/PBSCluster.java
Fri Oct 11 21:13:06 2013
@@ -232,11 +232,12 @@ public class PBSCluster implements Clust
//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 {
- //todo during failure do try
+ //
+
+ if (!jobIDReaderCommandOutput.getStdErrorString().equals("")) {
throw new
SSHApiException(jobIDReaderCommandOutput.getStandardError().toString());
+ } else {
+ return jobIDReaderCommandOutput.getStdOutputString();
}
}
@@ -298,10 +299,10 @@ public class PBSCluster implements Clust
StandardOutReader stdOutReader = new StandardOutReader();
CommandExecutor.executeCommand(rawCommandInfo, this.getSession(),
stdOutReader);
- if (!stdOutReader.getErrorifAvailable().equals("")) {
+ if (stdOutReader.getStdErrorString() != null) {
throw new
SSHApiException(stdOutReader.getStandardError().toString());
}
- String result = stdOutReader.getStdOutput();
+ String result = stdOutReader.getStdOutputString();
String[] Nodes = result.split("\n");
String[] line;
String header, value;
@@ -366,10 +367,10 @@ public class PBSCluster implements Clust
StandardOutReader stdOutReader = new StandardOutReader();
CommandExecutor.executeCommand(rawCommandInfo, this.getSession(),
stdOutReader);
- if (!stdOutReader.getErrorifAvailable().equals("")) {
+ if (!stdOutReader.getStdErrorString().equals("")) {
throw new
SSHApiException(stdOutReader.getStandardError().toString());
}
- String result = stdOutReader.getStdOutput();
+ String result = stdOutReader.getStdOutputString();
String[] info = result.split("\n");
JobDescriptor jobDescriptor = new JobDescriptor();
String[] line;
@@ -456,9 +457,9 @@ public class PBSCluster implements Clust
return jobDescriptor;
}
- public String scpTo(String remoteFile, String localFile) throws
SSHApiException {
+ public void scpTo(String remoteFile, String localFile) throws
SSHApiException {
try {
- return SSHUtils.scpTo(remoteFile, localFile, session);
+ SSHUtils.scpTo(remoteFile, localFile, session);
} catch (IOException e) {
throw new SSHApiException("Failed during scping local file:" +
localFile + " to remote file "
+ serverInfo.getHost() + ":rFile", e);
@@ -468,9 +469,9 @@ public class PBSCluster implements Clust
}
}
- public String scpFrom(String remoteFile, String localFile) throws
SSHApiException {
+ public void scpFrom(String remoteFile, String localFile) throws
SSHApiException {
try {
- return SSHUtils.scpFrom(remoteFile, localFile, session);
+ SSHUtils.scpFrom(remoteFile, localFile, session);
} catch (IOException e) {
throw new SSHApiException("Failed during scping local file:" +
localFile + " to remote file "
+ serverInfo.getHost() + ":rFile", e);
@@ -552,25 +553,20 @@ public class PBSCluster implements Clust
StandardOutReader stdOutReader = new StandardOutReader();
CommandExecutor.executeCommand(rawCommandInfo, this.getSession(),
stdOutReader);
// check the standard error, incase user gave wrong jobID
- if (!stdOutReader.getErrorifAvailable().equals("")) {
+ if (!stdOutReader.getStdErrorString().equals("")) {
throw new
SSHApiException(stdOutReader.getStandardError().toString());
}
- String result = stdOutReader.getStdOutput();
+ String result = stdOutReader.getStdOutputString();
String[] info = result.split("\n");
- String header = "";
- String value = "";
- String[] line;
+ String[] line = null;
for (String anInfo : info) {
if (anInfo.contains("=")) {
line = anInfo.split("=", 2);
- } else {
- line = anInfo.split(":", 2);
- }
- if (line.length >= 2) {
- } else if ("job_state".equals(header)) {
- return JobStatus.valueOf(value);
- } else {
- throw new
SSHApiException(stdOutReader.getStandardError().toString());
+ if (line.length != 0) {
+ if (line[0].contains("job_state")) {
+ return JobStatus.valueOf(line[1].replaceAll(" ", ""));
+ }
+ }
}
}
return null;
@@ -581,7 +577,7 @@ public class PBSCluster implements Clust
StandardOutReader stdOutReader = new StandardOutReader();
CommandExecutor.executeCommand(rawCommandInfo, this.getSession(),
stdOutReader);
- if (!stdOutReader.getErrorifAvailable().equals("")) {
+ if (!stdOutReader.getStdErrorString().equals("")) {
throw new
SSHApiException(stdOutReader.getStandardError().toString());
}
Modified:
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/StandardOutReader.java
URL:
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/StandardOutReader.java?rev=1531421&r1=1531420&r2=1531421&view=diff
==============================================================================
---
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/StandardOutReader.java
(original)
+++
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/impl/StandardOutReader.java
Fri Oct 11 21:13:06 2013
@@ -21,6 +21,7 @@
package org.apache.airavata.gsi.ssh.impl;
import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelExec;
import org.apache.airavata.gsi.ssh.api.CommandOutput;
import java.io.ByteArrayOutputStream;
@@ -30,12 +31,12 @@ import java.io.OutputStream;
public class StandardOutReader implements CommandOutput {
- String stdOutput = null;
- ByteArrayOutputStream os = new ByteArrayOutputStream();
+ String stdOutputString = null;
+ ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
public void onOutput(Channel channel) {
try {
StringBuffer pbsOutput = new StringBuffer("");
- InputStream inputStream = channel.getInputStream();
+ InputStream inputStream = channel.getInputStream();
byte[] tmp = new byte[1024];
while (true) {
while (inputStream.available() > 0) {
@@ -45,37 +46,37 @@ public class StandardOutReader implement
}
if (channel.isClosed()) {
String output = pbsOutput.toString();
- this.setStdOutput(output);
+ this.setStdOutputString(output);
break;
}
try {
} catch (Exception ignored) {
}
}
-
} catch (IOException e) {
e.printStackTrace();
}
}
- public OutputStream getStandardError() {
- return os;
+
+ public void exitCode(int code) {
+ System.out.println("Program exit code - " + code);
}
- public String getErrorifAvailable(){
- return os.toString();
+ public String getStdOutputString() {
+ return stdOutputString;
}
- public void exitCode(int code) {
- System.out.println("Program exit code - " + code);
+ public void setStdOutputString(String stdOutputString) {
+ this.stdOutputString = stdOutputString;
}
- public String getStdOutput() {
- return stdOutput;
+ public String getStdErrorString() {
+ return errorStream.toString();
}
- public void setStdOutput(String stdOutput) {
- this.stdOutput = stdOutput;
+ public OutputStream getStandardError() {
+ return errorStream;
}
}
Modified:
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java
URL:
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java?rev=1531421&r1=1531420&r2=1531421&view=diff
==============================================================================
---
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java
(original)
+++
airavata/sandbox/gsissh/src/main/java/org/apache/airavata/gsi/ssh/util/SSHUtils.java
Fri Oct 11 21:13:06 2013
@@ -144,9 +144,15 @@ public class SSHUtils {
channel.connect();
if (checkAck(in) != 0) {
+<<<<<<< .mine
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
+=======
String error = "Error transfering the file content";
log.error(error);
throw new SSHApiException(error);
+>>>>>>> .r1531420
}
File _lfile = new File(lFile);
@@ -159,7 +165,9 @@ public class SSHUtils {
out.write(command.getBytes());
out.flush();
if (checkAck(in) != 0) {
- System.exit(0);
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
}
}
@@ -175,7 +183,9 @@ public class SSHUtils {
out.write(command.getBytes());
out.flush();
if (checkAck(in) != 0) {
- System.exit(0);
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
}
// send a content of lFile
@@ -193,7 +203,9 @@ public class SSHUtils {
out.write(buf, 0, 1);
out.flush();
if (checkAck(in) != 0) {
- System.exit(0);
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
}
out.close();
@@ -243,7 +255,9 @@ public class SSHUtils {
channel.connect();
if (checkAck(in) != 0) {
- System.exit(0);
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
}
File _lfile = new File(localFile);
@@ -256,7 +270,9 @@ public class SSHUtils {
out.write(command.getBytes());
out.flush();
if (checkAck(in) != 0) {
- System.exit(0);
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
}
}
@@ -272,7 +288,9 @@ public class SSHUtils {
out.write(command.getBytes());
out.flush();
if (checkAck(in) != 0) {
- System.exit(0);
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
}
// send a content of lFile
@@ -290,7 +308,9 @@ public class SSHUtils {
out.write(buf, 0, 1);
out.flush();
if (checkAck(in) != 0) {
- System.exit(0);
+ String error = "Error Reading input Stream";
+ log.error(error);
+ throw new SSHApiException(error);
}
out.close();
stdOutReader.onOutput(channel);
Modified: airavata/sandbox/gsissh/src/main/resources/PBSTemplate.xslt
URL:
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/main/resources/PBSTemplate.xslt?rev=1531421&r1=1531420&r2=1531421&view=diff
==============================================================================
--- airavata/sandbox/gsissh/src/main/resources/PBSTemplate.xslt (original)
+++ airavata/sandbox/gsissh/src/main/resources/PBSTemplate.xslt Fri Oct 11
21:13:06 2013
@@ -35,6 +35,11 @@
</xsl:when>
</xsl:choose>
<xsl:choose>
+ <xsl:when test="ns:jobName">
+#PBS -N <xsl:value-of select="ns:jobName"/>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:choose>
<xsl:when test="ns:standardOutFile">
#PBS -o <xsl:value-of select="ns:standardOutFile"/>
</xsl:when>
Modified:
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPFromTest.java
URL:
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPFromTest.java?rev=1531421&r1=1531420&r2=1531421&view=diff
==============================================================================
---
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPFromTest.java
(original)
+++
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/config/SCPFromTest.java
Fri Oct 11 21:13:06 2013
@@ -20,7 +20,9 @@
*/
package org.apache.airavata.gsi.ssh.config;
+import org.apache.airavata.gsi.ssh.api.authentication.AuthenticationInfo;
import org.apache.airavata.gsi.ssh.api.authentication.GSIAuthenticationInfo;
+import
org.apache.airavata.gsi.ssh.impl.authentication.DefaultPasswordAuthenticationInfo;
import org.apache.airavata.gsi.ssh.util.SSHUtils;
import org.apache.airavata.gsi.ssh.api.ServerInfo;
import
org.apache.airavata.gsi.ssh.impl.authentication.MyProxyAuthenticationInfo;
@@ -38,12 +40,11 @@ public class SCPFromTest {
@BeforeTest
public void setUp() throws Exception {
- System.setProperty("myproxy.user", "ogce");
- System.setProperty("myproxy.password", "");
- System.setProperty("basedir",
"/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
+// System.setProperty("myproxy.user", "ogce");
+// System.setProperty("myproxy.password", "");
+// System.setProperty("basedir",
"/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
myProxyUserName = System.getProperty("myproxy.user");
myProxyPassword = System.getProperty("myproxy.password");
-
String pomDirectory = System.getProperty("basedir");
File pomFileDirectory = new File(pomDirectory);
@@ -52,11 +53,7 @@ public class SCPFromTest {
certificateLocation = pomFileDirectory.getAbsolutePath() +
"/certificates";
- if (myProxyUserName == null || myProxyPassword == null) {
- System.out.println(">>>>>> Please run tests with my proxy user
name and password. " +
- "E.g :- mvn clean install -Dmyproxy.user=xxx
-Dmyproxy.password=xxx <<<<<<<");
- throw new Exception("Need my proxy user name password to run
tests.");
- }
+
lFilePath = pomDirectory + File.separator + "pom.xml";
rFilePath = "/tmp/";
}
@@ -74,4 +71,6 @@ public class SCPFromTest {
Thread.sleep(1000);
SSHUtils.scpFrom(File.separator + "tmp" + File.separator + "pom.xml",
System.getProperty("basedir"));
}
+
+
}
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=1531421&r1=1531420&r2=1531421&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
Fri Oct 11 21:13:06 2013
@@ -57,12 +57,13 @@ public class DefaultSSHApiTest {
@BeforeTest
public void setUp() throws Exception {
- System.setProperty("myproxy.user", "ogce");
- System.setProperty("myproxy.password", "Jdas7wph");
- System.setProperty("basedir",
"/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
+// System.setProperty("myproxy.user", "ogce");
+// System.setProperty("myproxy.password", "");
+// System.setProperty("basedir",
"/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
+// System.setProperty("gsi.working.directory","/home/ogce");
myProxyUserName = System.getProperty("myproxy.user");
myProxyPassword = System.getProperty("myproxy.password");
-
+ workingDirectory = System.getProperty("gsi.working.directory");
String pomDirectory = System.getProperty("basedir");
File pomFileDirectory = new File(pomDirectory);
@@ -71,14 +72,10 @@ public class DefaultSSHApiTest {
certificateLocation = pomFileDirectory.getAbsolutePath() +
"/certificates";
- pbsFilePath = pomFileDirectory.getAbsolutePath() + File.separator +
"src" + File.separator + "test" + File.separator + "resources" + File.separator
+ "sleep.pbs";
-
- String randomPBSFile = Integer.toString((new Random()).nextInt());
- workingDirectory = File.separator + "home" + File.separator + "ogce";
- if (myProxyUserName == null || myProxyPassword == null) {
+ if (myProxyUserName == null || myProxyPassword == null ||
workingDirectory == null) {
System.out.println(">>>>>> Please run tests with my proxy user
name and password. " +
- "E.g :- mvn clean install -Dmyproxy.user=xxx
-Dmyproxy.password=xxx <<<<<<<");
+ "E.g :- mvn clean install -Dmyproxy.user=xxx
-Dmyproxy.password=xxx -Dgsi.working.directory=/path<<<<<<<");
throw new Exception("Need my proxy user name password to run
tests.");
}
}
@@ -107,29 +104,7 @@ public class DefaultSSHApiTest {
}
- @Test
- public void testSubmitAsyncJobWithPBS() throws Exception {
- // Create authentication
- GSIAuthenticationInfo authenticationInfo
- = new MyProxyAuthenticationInfo(myProxyUserName,
myProxyPassword, "myproxy.teragrid.org",
- 7512, 17280000, certificateLocation);
-
- // Server info
- ServerInfo serverInfo = new ServerInfo("ogce", "trestles.sdsc.edu");
-
-
- Cluster pbsCluster = new PBSCluster(serverInfo, authenticationInfo,
"/opt/torque/bin/");
- // Execute command
- System.out.println("Target PBS file path: " + workingDirectory);
- System.out.println("Local PBS File path: " + pbsFilePath);
- JobDescriptor jobDescriptor = new JobDescriptor();
- //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 = pbsCluster.submitBatchJobWithPBS(pbsFilePath,
workingDirectory);
- System.out.println("JobID returned : " + jobID);
- }
@Test
public void testSubmitAsyncJob() throws Exception {
@@ -147,8 +122,6 @@ public class DefaultSSHApiTest {
// 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";
// constructing the job object
JobDescriptor jobDescriptor = new JobDescriptor();
jobDescriptor.setWorkingDirectory(workingDirectory);
Modified:
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaSSHTest.java
URL:
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaSSHTest.java?rev=1531421&r1=1531420&r2=1531421&view=diff
==============================================================================
---
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaSSHTest.java
(original)
+++
airavata/sandbox/gsissh/src/test/java/org/apache/airavata/gsi/ssh/impl/VanilaSSHTest.java
Fri Oct 11 21:13:06 2013
@@ -49,25 +49,34 @@ public class VanilaSSHTest {
private String password;
private String passPhrase;
private String hostName;
+ private String workingDirectory;
+ private String privateKeyPath;
+ private String publicKeyPath;
@BeforeTest
public void setUp() throws Exception {
-
-
this.hostName = "bigred2.uits.iu.edu";
- System.setProperty("my.ssh.user", "lginnali");
- System.setProperty("my.ssh.user.password", "");
+
+// this.userName = System.setProperty("my.ssh.user", "lginnali");
+// this.password = System.setProperty("my.ssh.password", "");
+// this.workingDirectory = System.setProperty("working.directory",
"/N/u/lginnali/BigRed2/myjob");
+//
System.setProperty("basedir","/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
this.userName = System.getProperty("my.ssh.user");
- this.password = System.getProperty("my.ssh.user.password");
- System.setProperty("basedir",
"/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
-// this.passPhrase = System.getProperty("my.ssh.user.pass.phrase");
-
- if (this.userName == null || this.password == null) {
- System.out.println("########### In order to run tests you need to
set password and " +
- "passphrase ###############");
- System.out.println("Use -Dmy.ssh.user=xxx
-Dmy.ssh.user.password=yyy -Dmy.ssh.user.pass.phrase=zzz");
- }
+ this.password = System.getProperty("my.ssh.password");
+ this.privateKeyPath = System.getProperty("my.private.key.path");
+ this.publicKeyPath = System.getProperty("my.public.key.path");
+ this.passPhrase = System.getProperty("my.ssh.user.pass.phrase");
+ this.workingDirectory = System.getProperty("ssh.working.directory");
+
+ System.out.println();
+
+ if (this.userName == null || (this.userName != null && this.password
== null)
+ || (this.password==null && (this.publicKeyPath == null ||
this.privateKeyPath == null)) || this.workingDirectory == null) {
+ System.out.println("########### In order to test you have to
either username password or private,public keys");
+ System.out.println("Use -Dmy.ssh.user=xxx
-Dmy.ssh.user.password=yyy -Dmy.ssh.user.pass.phrase=zzz " +
+ "-Dmy.private.key.path -Dmy.public.key.path
-Dssh.working.directory ");
+ }
}
@@ -75,8 +84,13 @@ public class VanilaSSHTest {
public void testSimpleCommand1() throws Exception {
System.out.println("Starting vanila SSH test ....");
-
- AuthenticationInfo authenticationInfo = new
DefaultPasswordAuthenticationInfo(this.password);
+ AuthenticationInfo authenticationInfo = null;
+ if (password != null) {
+ authenticationInfo = new
DefaultPasswordAuthenticationInfo(this.password);
+ } else {
+ new DefaultPublicKeyFileAuthentication(this.publicKeyPath,
this.privateKeyPath,
+ this.passPhrase);
+ }
// Create command
CommandInfo commandInfo = new
RawCommandInfo("/opt/torque/torque-4.2.3.1/bin/qstat");
@@ -93,36 +107,17 @@ public class VanilaSSHTest {
}
- @Test
- public void testSimpleCommand2() throws Exception {
-
- System.out.println("Starting vanila SSH test ....");
-
- String privateKeyFile = "/Users/lahirugunathilake/.ssh/id_dsa";
- String publicKeyFile = "/Users/lahirugunathilake/.ssh/id_dsa.pub";
-
- AuthenticationInfo authenticationInfo = new
DefaultPublicKeyFileAuthentication(publicKeyFile, privateKeyFile,
- this.passPhrase);
-
- // Create command
- CommandInfo commandInfo = new
RawCommandInfo("/opt/torque/torque-4.2.3.1/bin/qstat");
-
- // Server info
- ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName);
-
- // Output
- CommandOutput commandOutput = new SystemCommandOutput();
-
- // Execute command
- CommandExecutor.executeCommand(commandInfo, serverInfo,
authenticationInfo, commandOutput, new ConfigReader());
-
-
- }
@Test
public void testSimplePBSJob() throws Exception {
- AuthenticationInfo authenticationInfo = new
DefaultPasswordAuthenticationInfo(this.password);
+ AuthenticationInfo authenticationInfo = null;
+ if (password != null) {
+ authenticationInfo = new
DefaultPasswordAuthenticationInfo(this.password);
+ } else {
+ new DefaultPublicKeyFileAuthentication(this.publicKeyPath,
this.privateKeyPath,
+ this.passPhrase);
+ }
// Server info
ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName);
Cluster pbsCluster = new PBSCluster(serverInfo, authenticationInfo,
"/opt/torque/torque-4.2.3.1/bin/");
@@ -133,21 +128,21 @@ public class VanilaSSHTest {
String pomFile = System.getProperty("basedir") + File.separator +
"pom.xml";
- // Constructing theworking directory for demonstration and creating
directories in the remote
- // resource
- String workingDirectory = File.separator + "N" + File.separator + "u"
+ File.separator +
- "lginnali" + File.separator + "BigRed2";
workingDirectory = workingDirectory + File.separator
+ date + "_" + UUID.randomUUID();
pbsCluster.makeDirectory(workingDirectory);
Thread.sleep(1000);
pbsCluster.makeDirectory(workingDirectory + File.separator + "inputs");
Thread.sleep(1000);
- pbsCluster.makeDirectory(workingDirectory + File.separator +
"outputs");
+ pbsCluster.makeDirectory(workingDirectory + File.separator +
"outputs");
// doing file transfer to the remote resource
- String s = pbsCluster.scpTo(workingDirectory + File.separator +
"inputs", pomFile);
+ String remoteLocation = workingDirectory + File.separator + "inputs";
+ pbsCluster.scpTo(remoteLocation, pomFile);
+
+ int i = pomFile.lastIndexOf(File.separator);
+ String fileName = pomFile.substring(i + 1);
// constructing the job object
JobDescriptor jobDescriptor = new JobDescriptor();
jobDescriptor.setWorkingDirectory(workingDirectory);
@@ -164,7 +159,7 @@ public class VanilaSSHTest {
jobDescriptor.setMaxWallTime("5");
jobDescriptor.setJobSubmitter("aprun -n 1");
List<String> inputs = new ArrayList<String>();
- inputs.add(s);
+ inputs.add(remoteLocation + File.separator + fileName);
jobDescriptor.setInputValues(inputs);
//finished construction of job object
System.out.println(jobDescriptor.toXML());
@@ -196,4 +191,35 @@ public class VanilaSSHTest {
System.out.println(jobById.getVariableList());
}
+ @Test
+ public void testSCPFrom() throws Exception {
+
+ AuthenticationInfo authenticationInfo = null;
+ if (password != null) {
+ authenticationInfo = new
DefaultPasswordAuthenticationInfo(this.password);
+ } else {
+ new DefaultPublicKeyFileAuthentication(this.publicKeyPath,
this.privateKeyPath,
+ this.passPhrase);
+ }
+ // Server info
+ ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName);
+ Cluster pbsCluster = new PBSCluster(serverInfo, authenticationInfo,
"/opt/torque/torque-4.2.3.1/bin/");
+
+ String date = new Date().toString();
+ date = date.replaceAll(" ", "_");
+ date = date.replaceAll(":", "_");
+
+ String pomFile = System.getProperty("basedir") + File.separator +
"pom.xml";
+
+ // Constructing theworking directory for demonstration and creating
directories in the remote
+ // resource
+ workingDirectory = workingDirectory + File.separator
+ + date + "_" + UUID.randomUUID();
+ pbsCluster.makeDirectory(workingDirectory);
+ pbsCluster.scpTo(workingDirectory, pomFile);
+ Thread.sleep(1000);
+ pbsCluster.scpFrom(workingDirectory + File.separator + "pom.xml",
System.getProperty("basedir"));
+ }
+
+
}
Modified: airavata/sandbox/gsissh/src/test/resources/sleep.pbs
URL:
http://svn.apache.org/viewvc/airavata/sandbox/gsissh/src/test/resources/sleep.pbs?rev=1531421&r1=1531420&r2=1531421&view=diff
==============================================================================
--- airavata/sandbox/gsissh/src/test/resources/sleep.pbs (original)
+++ airavata/sandbox/gsissh/src/test/resources/sleep.pbs Fri Oct 11 21:13:06
2013
@@ -6,7 +6,7 @@
#$ -pe 1way 32
#$ -m n
#$ -q normal
-#$ -A <ACCOUNT>
+#$ -A
#$ -l h_rt=0:60:00
#$ -o application.stdout
#$ -e application.stderr