Author: chatellier Date: 2009-05-03 18:22:03 +0000 (Sun, 03 May 2009) New Revision: 2167 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java Log: Get simulation result tbz2 compressed. Global improvement. 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-05-03 18:21:25 UTC (rev 2166) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-05-03 18:22:03 UTC (rev 2167) @@ -40,7 +40,7 @@ import org.codelutin.util.FileUtil; import org.codelutin.util.MD5; import org.codelutin.util.MD5InputStream; -import org.codelutin.util.ZipUtil; +import org.codelutin.util.Tbz2Util; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; @@ -228,6 +228,7 @@ // ask for available resources on caparmor // blocking until available + message(control, _("isisfish.simulation.remote.message.waitingavailable")); simulationStarted(); // start ssh session @@ -241,7 +242,7 @@ String simulationRemotePath = uploadSimulation(sshSession, simulationZip); - String remoteResultZip = getRemoteResultZipPath(control.getId()); + String remoteResultZip = getRemoteResultArchivePath(control.getId()); // build du contenu du script message(control,_("isisfish.simulation.remote.message.waitingstart")); @@ -251,6 +252,8 @@ simulationRemotePath, remoteResultZip, simulationPreScriptPath); String scriptRemotePath = uploadSimulationScript(sshSession, simulationScript); + // prescrit uploaded, delete + simulationScript.delete(); addScriptToQsubQueue(sshSession, scriptRemotePath); @@ -276,8 +279,7 @@ // TODO change, now getSimulationStorage() // is common to all launchers - SimulationStorage simulationStorage = null; - simulationStorage = SimulationStorage + SimulationStorage simulationStorage = SimulationStorage .getSimulation(control.getId()); return simulationStorage; @@ -292,13 +294,21 @@ @Override public void updateControl(SimulationService simulationService, SimulationControl control) throws RemoteException { + + // make sure user is connected + try { + getSSHSession(); + } + catch(JSchException e) { + throw new RemoteException("Can't connect", e); + } try { // CONTROL file try { // download control file - File controlFile = downloadSimulationFile(control.getId(), + File controlFile = downloadControlFile(sshSession, control.getId(), SimulationStorage.CONTROL_FILENAME); if (log.isDebugEnabled()) { log.debug("Control have been downloaded : " @@ -332,7 +342,7 @@ // MD5 + SIMULATION zip file try { - File md5ControlFile = downloadMD5ControlFile(control.getId()); + File md5ControlFile = downloadResultsMD5File(sshSession, control.getId()); if (md5ControlFile != null) { control.setText(_("isisfish.simulation.remote.message.downloadresults")); @@ -343,9 +353,9 @@ log.debug("MD5 Control file have been downloaded : " + md5ControlFile.getAbsolutePath()); } - File resultZipFile = downloadZIPResults(sshSession, control.getId(), md5sum); + File resultArchiveFile = downloadResultsArchive(sshSession, control.getId(), md5sum); - if (resultZipFile != null) { + if (resultArchiveFile != null) { // FIXME done here to not break upload during import // FIXME je pense que les resources ne sont @@ -355,10 +365,10 @@ // FIXME too slow methods //SimulationStorage.importZip(resultZipFile); - ZipUtil.uncompress(resultZipFile, SimulationStorage.getSimulationDirectory()); + Tbz2Util.uncompress(resultArchiveFile, SimulationStorage.getSimulationDirectory()); if (log.isDebugEnabled()) { - log.debug("Simulation imported : " + resultZipFile.getAbsolutePath()); + log.debug("Simulation imported : " + resultArchiveFile.getAbsolutePath()); } // read control from downloaded simulation @@ -366,7 +376,9 @@ SimulationStorage.readControl(control.getId(), control, "stop"); } - resultZipFile.delete(); + resultArchiveFile.delete(); + + // TODO remove remote md5 and zip } else { if (log.isWarnEnabled()) { @@ -380,7 +392,7 @@ } catch(SSHException e) { if (log.isDebugEnabled()) { - log.debug(_("Error while downloading file : %s", e.getMessage())); + log.debug(_("Can't download archive : %s", e.getMessage())); } } /*catch (TopiaException e) { if (log.isErrorEnabled()) { @@ -390,7 +402,7 @@ // INFORMATION file try { - File infoFile = downloadSimulationFile(control.getId(), + File infoFile = downloadControlFile(sshSession, control.getId(), SimulationStorage.INFORMATION_FILENAME); if (log.isDebugEnabled()) { log.debug("Information have been downloaded : " @@ -421,7 +433,7 @@ // file doesn't exist if (log.isDebugEnabled()) { // not add ,e plz :) - log.debug(_("Remote control file doesn't exists %s", e + log.debug(_("Remote information file doesn't exists %s", e .getMessage())); } } @@ -650,10 +662,10 @@ * @throws SSHException if download fail (can happen if remote file doesn't exist * @throws IOException if download fail (can happen if remote file doesn't exist */ - protected File downloadZIPResults(Session session, String simulationId, String md5sum) + protected File downloadResultsArchive(Session session, String simulationId, String md5sum) throws SSHException, IOException { - File localFile = File.createTempFile("simulation-results", ".zip"); + File localFile = File.createTempFile("simulation-results", ".tbz2"); if (log.isDebugEnabled()) { log.debug("Downloading results in " + localFile.getAbsolutePath()); @@ -661,13 +673,20 @@ // build remote file path // FIXME this path should be given by remote IsisFish app - String remoteFile = getRemoteResultZipPath(simulationId); + String remoteFile = getRemoteResultArchivePath(simulationId); - SSHUtils.scpFrom(session, remoteFile, localFile); + try { + SSHUtils.scpFrom(session, remoteFile, localFile); + } + catch(SSHException e) { + localFile.delete(); + throw e; + } if (!StringUtils.isEmpty(md5sum)) { MD5InputStream in = new MD5InputStream(new FileInputStream(localFile)); - while(in.read() != -1) {} + while(in.read() != -1) { + } in.close(); String localMd5 = MD5.asHex(in.hash()); if (!localMd5.equals(md5sum)) { @@ -686,13 +705,14 @@ * Download remote simulation control file and store its content into temp * file. * + * @param sshSession valid opened ssh session * @param simulationId id de la simulation * @param fileName nom du fichier a telecharger * @return downloaded temp file (file have to be manually deleted) * @throws IOException * @throws SSHException if remote file doesn't exists */ - protected File downloadSimulationFile(String simulationId, String fileName) + protected File downloadControlFile(Session sshSession, String simulationId, String fileName) throws IOException, SSHException { File localFile = null; @@ -709,9 +729,10 @@ localFile = File.createTempFile(simulationId, fileName); try { - SSHUtils.scpFrom(getSSHSession(), remoteFile, localFile); - } catch (JSchException e) { - throw new SSHException("Can't connect", e); + SSHUtils.scpFrom(sshSession, remoteFile, localFile); + } catch (SSHException e) { + localFile.delete(); + throw e; } return localFile; @@ -721,26 +742,26 @@ * Download remote simulation md5 control file and store its content into temp * file. * + * @param sshSession valid opened ssh session * @param simulationId id de la simulation * @return downloaded temp file (file have to be manually deleted) * @throws IOException * @throws SSHException if remote file doesn't exists */ - protected File downloadMD5ControlFile(String simulationId) + protected File downloadResultsMD5File(Session sshSession, String simulationId) throws IOException, SSHException { - File localFile = null; - // build remote file path - String remoteFile = getRemoteResultZipPath(simulationId) + ".md5"; + String remoteFile = getRemoteResultArchivePath(simulationId) + ".md5"; // local tmp file - localFile = File.createTempFile(simulationId, ".md5"); + File localFile = File.createTempFile(simulationId, ".md5"); try { - SSHUtils.scpFrom(getSSHSession(), remoteFile, localFile); - } catch (JSchException e) { - throw new SSHException("Can't download file", e); + SSHUtils.scpFrom(sshSession, remoteFile, localFile); + } catch (SSHException e) { + localFile.delete(); + throw e; } return localFile; @@ -791,7 +812,7 @@ * @throws SSHException if upload fail * @throws IOException if upload fail */ - protected String getRemoteResultZipPath(String simulationId) + protected String getRemoteResultArchivePath(String simulationId) throws SSHException, IOException { String remotePath = IsisFish.config.getSimulatorSshTmpPath(); @@ -801,7 +822,7 @@ remotePath += "/"; } - remotePath += "simulation-" + simulationId + "-result.zip"; + remotePath += "simulation-" + simulationId + "-result.tbz2"; return remotePath; } @@ -871,7 +892,7 @@ protected File getLaunchSimulationScriptFile(String simuationId, String simulationZip, String simulationResultZip, String preScriptPath) throws IOException { - File tempScript = File.createTempFile("isis-launch-", ".seq"); + File tempScript = File.createTempFile("isis-launch-" + simuationId + "-", ".seq"); tempScript.deleteOnExit(); // auto delete String fileContent = getSimulationScriptLaunchContent(