Skip to content
Snippets Groups Projects
Commit 47818edd authored by tjc's avatar tjc
Browse files

make more modular

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3391 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent f5b702e0
No related branches found
No related tags found
No related merge requests found
...@@ -142,135 +142,13 @@ public class SshPSUClient extends Thread ...@@ -142,135 +142,13 @@ public class SshPSUClient extends Thread
{ {
ConfigurationLoader.initialize(false); ConfigurationLoader.initialize(false);
int result = AuthenticationProtocolState.FAILED; SshClient ssh = login();
if(ssh == null)
return;
SshClient ssh = null; completed = runBlastOrFasta(ssh, program, settings);
// login
while(result != AuthenticationProtocolState.COMPLETE)
{
if(!setLogin())
return;
// Create a password authentication instance
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
user = ufield.getText().trim();
pwd.setUsername(user);
pwd.setPassword(new String(pfield.getPassword()));
// Make a client connection
ssh = new SshClient();
hostname = hostfield.getText().trim();
if(portfield.getText().trim().equals(""))
port = -1;
else
port = Integer.parseInt(portfield.getText().trim());
if(port < 0)
ssh.connect(hostname);
else
ssh.connect(hostname,port);
// Try the authentication
result = ssh.authenticate(pwd);
}
// prompt for local listfile
if(listfilepath == null)
{
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
listfilepath = chooser.getSelectedFile().getAbsolutePath();
else
return;
}
SftpClient sftp = ssh.openSftpClient();
// loop over sequence files in the listfile
Vector seqfile = readListFile(listfilepath);
for(int i=0; i<seqfile.size();i++)
{
String filepath = (String)seqfile.get(i);
int index = filepath.lastIndexOf(System.getProperty("file.separator"));
String filename = filepath;
if(index > -1)
filename = filename.substring(index+1);
try
{
wdir = wdir+"/"+user;
sftp.mkdir(wdir);
wdir = wdir+"/"+program+"/";
sftp.mkdir(wdir);
sftp.put(filepath, wdir+filename);
}
catch(IOException ioe)
{}
SessionChannelClient session = ssh.openSessionChannel();
String outputfile = wdir+filename+".out";
final String actualCMD;
if( (cmd.indexOf("fasta33") > -1) ||
(cmd.indexOf("fastx33") > -1) )
{
if(settings.getProperty(db) != null)
db = settings.getProperty(db);
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+wdir+filename+" "+db;
}
else
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+db+" "+wdir+filename;
// run the application
if(System.getProperty("debug") != null)
System.out.println(actualCMD);
session.executeCommand(actualCMD);
// Reading from the session InputStream
StdoutStdErrHandler stdouth = new StdoutStdErrHandler(session, true);
StdoutStdErrHandler stderrh = new StdoutStdErrHandler(session, false);
stdouth.start();
stderrh.start();
boolean isFile = false;
try
{
// make sure we hang around for stdout
while(stdouth.isAlive() || stderrh.isAlive())
Thread.currentThread().sleep(10);
isFile = waitUntilFileAppears(sftp, filename+".out");
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
if(System.getProperty("debug") != null)
{
// stdout & stderr
System.out.println(stdouth.getOutput());
System.out.println(stderrh.getOutput());
}
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// sftp.get(outputfile, os);
// System.out.println(os.toString());
sftp.get(outputfile, filepath+".out");
completed = true;
session.close();
}
// Quit // Quit
sftp.quit();
ssh.disconnect(); ssh.disconnect();
} }
catch(IOException ioe){} catch(IOException ioe){}
...@@ -338,6 +216,47 @@ public class SshPSUClient extends Thread ...@@ -338,6 +216,47 @@ public class SshPSUClient extends Thread
return false; return false;
} }
/**
*
* Log the user in.
*
*/
private SshClient login()
throws IOException
{
SshClient ssh = null;
int result = AuthenticationProtocolState.FAILED;
while(result != AuthenticationProtocolState.COMPLETE)
{
if(!setLogin())
return null;
// Create a password authentication instance
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
user = ufield.getText().trim();
pwd.setUsername(user);
pwd.setPassword(new String(pfield.getPassword()));
// Make a client connection
ssh = new SshClient();
hostname = hostfield.getText().trim();
if(portfield.getText().trim().equals(""))
port = -1;
else
port = Integer.parseInt(portfield.getText().trim());
if(port < 0)
ssh.connect(hostname);
else
ssh.connect(hostname,port);
// Try the authentication
result = ssh.authenticate(pwd);
}
return ssh;
}
/** /**
* *
* Set the login information. * Set the login information.
...@@ -440,6 +359,111 @@ public class SshPSUClient extends Thread ...@@ -440,6 +359,111 @@ public class SshPSUClient extends Thread
return settings; return settings;
} }
/**
*
* Run fasta or blast on the server ssh'ed into
*
*/
private boolean runBlastOrFasta(SshClient ssh, String program, Properties settings)
throws IOException
{
// prompt for local listfile
if(listfilepath == null)
{
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
listfilepath = chooser.getSelectedFile().getAbsolutePath();
else
return false;
}
SftpClient sftp = ssh.openSftpClient();
// loop over sequence files in the listfile
Vector seqfile = readListFile(listfilepath);
for(int i=0; i<seqfile.size();i++)
{
String filepath = (String)seqfile.get(i);
int index = filepath.lastIndexOf(System.getProperty("file.separator"));
String filename = filepath;
if(index > -1)
filename = filename.substring(index+1);
try
{
wdir = wdir+"/"+user;
sftp.mkdir(wdir);
wdir = wdir+"/"+program+"/";
sftp.mkdir(wdir);
sftp.put(filepath, wdir+filename);
}
catch(IOException ioe)
{}
SessionChannelClient session = ssh.openSessionChannel();
String outputfile = wdir+filename+".out";
final String actualCMD;
if( (cmd.indexOf("fasta33") > -1) ||
(cmd.indexOf("fastx33") > -1) )
{
if(settings.getProperty(db) != null)
db = settings.getProperty(db);
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+wdir+filename+" "+db;
}
else
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+db+" "+wdir+filename;
// run the application
if(System.getProperty("debug") != null)
System.out.println(actualCMD);
session.executeCommand(actualCMD);
// Reading from the session InputStream
StdoutStdErrHandler stdouth = new StdoutStdErrHandler(session, true);
StdoutStdErrHandler stderrh = new StdoutStdErrHandler(session, false);
stdouth.start();
stderrh.start();
boolean isFile = false;
try
{
// make sure we hang around for stdout
while(stdouth.isAlive() || stderrh.isAlive())
Thread.currentThread().sleep(10);
isFile = waitUntilFileAppears(sftp, filename+".out");
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
if(System.getProperty("debug") != null)
{
// stdout & stderr
System.out.println(stdouth.getOutput());
System.out.println(stderrh.getOutput());
}
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// sftp.get(outputfile, os);
// System.out.println(os.toString());
sftp.get(outputfile, filepath+".out");
session.close();
}
sftp.quit();
return true;
}
/** /**
* *
* Thread to handle stdout/stderr reading without blocking. * Thread to handle stdout/stderr reading without blocking.
......
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