Author: chatellier Date: 2009-01-27 12:12:42 +0000 (Tue, 27 Jan 2009) New Revision: 1756 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUserInfo.java Log: Store ssh session in static context to not ask for passphrase at each connection Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-01-26 10:39:35 UTC (rev 1755) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-01-27 12:12:42 UTC (rev 1756) @@ -76,6 +76,13 @@ protected Configuration freemarkerConfiguration; /** + * Opened session. + * Stored in static context to not reask passphrase + * at each connection. + */ + protected static Session sshSession; + + /** * Constructor. * * Init freemarker. @@ -164,7 +171,7 @@ // connection message(control, _("isisfish.simulation.remote.message.connection")); - Session sshSession = openSSHSession(); + Session sshSession = getSSHSession(); //openSSHSession(); // upload simulation on server message(control, _("isisfish.simulation.remote.message.upload")); @@ -210,6 +217,23 @@ } /** + * Get opened ssh session or try to open a new one. + * + * This method must synchronized. + * + * @return opened ssh session. + * @throws JSchException + */ + protected synchronized Session getSSHSession() throws JSchException { + + if(sshSession == null || !sshSession.isConnected()) { + sshSession = openSSHSession(); + } + + return sshSession; + } + + /** * Connect to remote server throw SSH, and return session. * * @return valid opened session @@ -392,42 +416,6 @@ SSHUtils.scpFrom(session, remoteFile, localFile); } - - /* - * Launch simulation on remote server. - * - * @param session opened ssh session - * @param simulationService simulation service - * @param control control - * @param remotePath remote zip simulation path - * @throws JSchException - * - protected void launchSimulation(Session session, - SimulationService simulationService, SimulationControl control, - String remotePath) throws JSchException { - - String simulationId = control.getId(); - - String command = String.format("%s %s %s %s '%s' '%s' %s '%s' '%s'", - "java", // java command - "-jar", // java jar option - IsisFish.config.getSimulatorSshJarPath(), // remote jar path - "--option", "launch.ui", "false", // additionnal option ui - "--simulateWithSimulation", simulationId, remotePath // add option simulation - ); - - if (log.isDebugEnabled()) { - log.debug("Launch : " + command); - } - - try { - SSHUtils.exec(session, command); - } catch (SSHException e) { - if (log.isErrorEnabled()) { - log.error(_("Error while launching simulation"), e); - } - } - }*/ /** * Upload script on remote server. @@ -642,7 +630,7 @@ // file doesn't exist if(log.isDebugEnabled()) { // not add ,e plz :) - log.debug(_("Remote control file doen't exists %s", e.getMessage())); + log.debug(_("Remote control file doesn't exists %s", e.getMessage())); } } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUserInfo.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUserInfo.java 2009-01-26 10:39:35 UTC (rev 1755) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUserInfo.java 2009-01-27 12:12:42 UTC (rev 1756) @@ -50,7 +50,7 @@ * * Static to be stored on multiple connexion. */ - protected static String passphrase; + protected String passphrase; /** * Passphrase text field. @@ -160,18 +160,6 @@ response = new String[prompt.length]; for (int i = 0; i < prompt.length; i++) { response[i] = texts[i].getText(); - - // hack to remember password - if (prompt[i] != null - && prompt[i].toLowerCase().indexOf("password") >= 0) { - passwd = response[i]; - } - - // hack to remember passphrase - if (prompt[i] != null - && prompt[i].toLowerCase().indexOf("passphrase") >= 0) { - passphrase = response[i]; - } } } // else = cancel