Skip to content
Snippets Groups Projects
Commit 1f99673f authored by tjc's avatar tjc
Browse files

make running searches more robust

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3728 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 2ffbf0b2
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ import java.io.IOException; ...@@ -44,6 +44,7 @@ import java.io.IOException;
import java.util.Vector; import java.util.Vector;
import java.util.Properties; import java.util.Properties;
import com.sshtools.j2ssh.SshException;
import com.sshtools.j2ssh.SshClient; import com.sshtools.j2ssh.SshClient;
import com.sshtools.j2ssh.session.SessionChannelClient; import com.sshtools.j2ssh.session.SessionChannelClient;
import com.sshtools.j2ssh.sftp.SftpFile; import com.sshtools.j2ssh.sftp.SftpFile;
...@@ -101,6 +102,14 @@ public class SshPSUClient extends Thread ...@@ -101,6 +102,14 @@ public class SshPSUClient extends Thread
user = sshLogin.getUser(); user = sshLogin.getUser();
} }
private SshClient rescue()
{
ssh.disconnect();
SshLogin sshLogin = new SshLogin();
ssh = sshLogin.getSshClient();
return ssh;
}
public void run() public void run()
{ {
String program = cmd; String program = cmd;
...@@ -116,7 +125,7 @@ public class SshPSUClient extends Thread ...@@ -116,7 +125,7 @@ public class SshPSUClient extends Thread
if(System.getProperty("debug") != null) if(System.getProperty("debug") != null)
System.out.println("RUN "+program); System.out.println("RUN "+program);
completed = runBlastOrFasta(ssh, program); completed = runBlastOrFasta(program);
// Quit // Quit
//ssh.disconnect(); //ssh.disconnect();
...@@ -173,13 +182,21 @@ public class SshPSUClient extends Thread ...@@ -173,13 +182,21 @@ public class SshPSUClient extends Thread
{ {
for(int i=0; i < 100; i++) for(int i=0; i < 100; i++)
{ {
Thread.currentThread().sleep(5000); Thread.currentThread().sleep(10000);
Object list[] = sftp.ls(wdir).toArray();
try
{
Object list[] = sftp.ls(wdir).toArray();
for(int j=0; j<list.length;j++) for(int j=0; j<list.length;j++)
{
if( ((SftpFile)list[j]).getFilename().equals(file) )
return true;
}
}
catch(SshException sshe)
{ {
if( ((SftpFile)list[j]).getFilename().equals(file) ) rescue();
return true;
} }
} }
...@@ -243,7 +260,7 @@ public class SshPSUClient extends Thread ...@@ -243,7 +260,7 @@ public class SshPSUClient extends Thread
* Run fasta or blast on the server ssh'ed into * Run fasta or blast on the server ssh'ed into
* *
*/ */
private boolean runBlastOrFasta(SshClient ssh, String program) private boolean runBlastOrFasta(String program)
throws IOException throws IOException
{ {
Properties settings = getProperties(); Properties settings = getProperties();
...@@ -279,15 +296,51 @@ public class SshPSUClient extends Thread ...@@ -279,15 +296,51 @@ public class SshPSUClient extends Thread
wdir = wdir+"/"+program+"/"; wdir = wdir+"/"+program+"/";
sftp.mkdir(wdir); sftp.mkdir(wdir);
sftp.put(filepath, wdir+filename); // sftp.put(filepath, wdir+filename);
}
catch(SshException sshe)
{
rescue();
} }
catch(IOException ioe) catch(IOException ioe)
{ {
ioe.printStackTrace(); // directory already created
} }
SessionChannelClient session = ssh.openSessionChannel();
try
{
sftp.put(filepath, wdir+filename);
if(System.getProperty("debug") != null)
System.out.println("PUT SUCCESS "+wdir+filename);
}
catch(SshException ioe)
{
rescue();
sftp.put(filepath, wdir+filename);
}
if(System.getProperty("debug") != null)
System.out.println("STARTING session");
SessionChannelClient session = null;
try
{
if(!ssh.isConnected())
rescue();
session = ssh.openSessionChannel();
}
catch(IOException exp)
{
rescue();
}
if(System.getProperty("debug") != null)
System.out.println("STARTED session");
String outputfile = wdir+filename+".out"; String outputfile = wdir+filename+".out";
final String actualCMD; final String actualCMD;
...@@ -340,7 +393,20 @@ public class SshPSUClient extends Thread ...@@ -340,7 +393,20 @@ public class SshPSUClient extends Thread
// sftp.get(outputfile, os); // sftp.get(outputfile, os);
// System.out.println(os.toString()); // System.out.println(os.toString());
sftp.get(outputfile, filepath+".out");
try
{
sftp.get(outputfile, filepath+".out");
if(System.getProperty("debug") != null)
System.out.println("GET SUCCESS "+filepath+".out");
}
catch(Exception ioe)
{
rescue();
sftp.get(outputfile, filepath+".out");
}
if(!keep) if(!keep)
{ {
...@@ -369,7 +435,10 @@ public class SshPSUClient extends Thread ...@@ -369,7 +435,10 @@ public class SshPSUClient extends Thread
sftp = ssh.getActiveSftpClient(); sftp = ssh.getActiveSftpClient();
return sftp; return sftp;
} }
catch(IOException ioe){} catch(IOException ioe)
{
rescue();
}
return ssh.openSftpClient(); return ssh.openSftpClient();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment