Class SSHSimulatorLauncher
java.lang.Object
fr.ifremer.isisfish.simulator.launcher.SSHSimulatorLauncher
- All Implemented Interfaces:
SimulatorLauncher
Use a remote simulation server.
Data are uploaded into /scratch/isis-temp-4/ directory on FTP server. Then, on SSH side, this path is referenced
as $SCRATCH/eftp/isis-temp-4.
On the SSH server, the internal directory $SCRATCH/isis-fish-4 on not available threw FTP path, so we can't download
files from it.
ISIS-Fish must be installed on remote server (configuation option path).
Datarmor file layout ($i = plan/as increment) :
- /scratch/isis-temp-4/simulation-$id-preparation.zip : Simulation input zip file
- /scratch/isis-temp-4/simulation-$id-prescript.bsh : Simulation prescript (optional)
- /scratch/isis-temp-4/simulation-$id-script.seq : Qsub script
- /scratch/isis-temp-4/simulation-$id-result.zip : Simulation output zip
- /scratch/isis-temp-4/simulation-$id-result.zip.md5 : Simulation output zip md5 checksum
- /scratch/isis-temp-4/simulation-$id-output.txt
- /scratch/isis-temp-4/simulation-$id-pbs.id
- /scratch/isis-temp-4/simulation-$id-pbs.out
- /scratch/isis-temp-4/simulation-$id-pbs.err/li>
- standalone zip : /scratch/isis-temp-4/simulation-$shortid-result.zip (uploaded at first simulation)
- standalone simulations : /scratch/isis-temp-4/simulation-$shortid-script.seq (uploaded at last simulation)
$shortid
is id of parent job (without increment), they are not
deleted after result download.- Version:
- $Revision$ Last update : $Date$ By : $Author$
- Author:
- chatellier
- See Also:
-
JSch
-
Field Summary
Modifier and TypeFieldDescriptionprotected freemarker.template.Configuration
Freemarker configurationprotected static final String
Path d'upload sur le FTP qui pointe en fait sur$REMOTE_SSH_TEMP_PATH
du point de vue SSH.protected static org.apache.commons.logging.Log
Class loggerprotected static final String
Freemarker qsub template.protected static final String
Nom du repertoire où sont stockés les fichiers temporaires.protected static final String
Path absolu du repertoire temporaire.protected static com.jcraft.jsch.Session
Opened session to ssh service. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
clearSimulationFiles
(org.apache.commons.net.ftp.FTPClient ftpClient, SimulationControl control) Remove all$ISIS-TMP/simulation-$id-*
files on datarmor.protected void
closeFTPClient
(org.apache.commons.net.ftp.FTPClient ftpClient) Close ftp session.protected void
closeSSHSession
(com.jcraft.jsch.Session session) Close ssh session.protected File
downloadResultsArchive
(org.apache.commons.net.ftp.FTPClient ftpClient, SimulationControl simulationControl, String md5sum) Download simulation zip results.protected File
downloadResultsMD5File
(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationId) Download remote simulation md5 control file and store its content into temp file.protected File
downloadSimulationInformationFile
(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationId) Download remote information.int
Retourne l'intervalle de temps a utiliser entre deux verification de progresssion.protected org.apache.commons.net.ftp.FTPClient
Open new FTP client connected to server and user loggued in.protected String
getLaunchSimulationScriptContent
(String simuationId, String simulationZip, boolean standaloneZip, String simulationResultZip, String preScriptPath, boolean multipleSimulationScript) Retourne un fichier temporaire contenant le script de lancement de simulation.protected String
getResultArchiveName
(String simulationId) Get remote simulation zip name.protected String
getSimulationScriptLaunchContent
(String templateName, String simuationId, String simulationZip, boolean standaloneZip, String simulationZipResult, String preScriptPath, boolean multipleSimulationScript) Utilise freemarker pour recuperer le contenu du script.getSimulationStorage
(SimulationService simulationService, SimulationControl control) Retourne le storage où est stockée la simulation.protected com.jcraft.jsch.Session
Get opened ssh session or try to open a new one.protected void
Init freemarker configuration.int
Retourne le nombre maximal de thread de simulations simultanées supporté.protected void
message
(SimulationControl control, String message) Display message both in commons-logging and control text progress.protected org.apache.commons.net.ftp.FTPClient
Open new FTP client connected to server and user logged in.protected com.jcraft.jsch.Session
Connect to remote server throw SSH, and return session.protected void
putSshKeyOnRemoteServer
(com.jcraft.jsch.Session session, File sshKey) Add ssh key into $HOME/.ssh/authorized_keys file.protected void
sendStartSimulationRequest
(com.jcraft.jsch.Session session, String simulationId, String scriptRemotePath, int lastSimulationNumber) Add script in remote qsub queue.protected void
sendStopSimulationRequest
(com.jcraft.jsch.Session session, String simulationId) Send qdel request on job.void
simulate
(SimulationService simulationService, SimulationItem simulationItem) Execute une simulation.void
Called if a started simulation has been ask to stop.protected void
startSimulation
(com.jcraft.jsch.Session session, org.apache.commons.net.ftp.FTPClient ftpClient, SimulationItem simulationItem, String simulationid, String simulationRemoteZipPath, String remoteResultZip, String simulationPreScriptPath) Start simulation if necessary.toString()
void
updateControl
(SimulationService simulationService, SimulationControl control) Met à jour la progression.protected String
uploadPreScriptIfNecessary
(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationId, String simulationPreScript) Upload pre script on remote server.protected void
uploadSimulation
(org.apache.commons.net.ftp.FTPClient ftpClient, String remoteDirectory, String remoteSimulationZipPath, File simulationFile) Perform simulation upload.protected String
uploadSimulationIfNecessary
(org.apache.commons.net.ftp.FTPClient ftpClient, SimulationItem simulationItem, String simulationid, File simulationFile) Upload simulation if necessary and always return the remote simulation zip path to use.protected String
uploadSimulationScript
(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationid, String simulationScript) Upload script on remote server.
-
Field Details
-
log
protected static org.apache.commons.logging.Log logClass logger -
freemarkerConfiguration
protected freemarker.template.Configuration freemarkerConfigurationFreemarker configuration -
QSUB_SCRIPT_TEMPLATE
Freemarker qsub template.- See Also:
-
REMOTE_TEMP_DIR
Nom du repertoire où sont stockés les fichiers temporaires.- See Also:
-
SSH_TEMP_PATH
Path absolu du repertoire temporaire.- See Also:
-
FTP_TEMP_PATH
Path d'upload sur le FTP qui pointe en fait sur$REMOTE_SSH_TEMP_PATH
du point de vue SSH.- See Also:
-
sshSession
protected static com.jcraft.jsch.Session sshSessionOpened session to ssh service. Stored in static context to not reask passphrase at each connection.
-
-
Constructor Details
-
SSHSimulatorLauncher
public SSHSimulatorLauncher()Constructor. Init freemarker.
-
-
Method Details
-
initFreemarker
protected void initFreemarker()Init freemarker configuration. -
message
Display message both in commons-logging and control text progress.- Parameters:
control
- controlmessage
- message to display
-
maxSimulationThread
public int maxSimulationThread()Description copied from interface:SimulatorLauncher
Retourne le nombre maximal de thread de simulations simultanées supporté.- Specified by:
maxSimulationThread
in interfaceSimulatorLauncher
- Returns:
- un nombre superieur a 0
-
getCheckProgressionInterval
public int getCheckProgressionInterval()Description copied from interface:SimulatorLauncher
Retourne l'intervalle de temps a utiliser entre deux verification de progresssion.- Specified by:
getCheckProgressionInterval
in interfaceSimulatorLauncher
- Returns:
- intervalle (en secondes);
-
toString
-
simulationStopRequest
Called if a started simulation has been ask to stop. Tell launcher to stop simulation if possible. Try to send a qdel command.- Specified by:
simulationStopRequest
in interfaceSimulatorLauncher
- Parameters:
job
- job to stop- Throws:
RemoteException
- Si pour l'execution de la simulation on utilise des resources distantes (serveurs) et que ceux si non pas pu etre contacte.
-
simulate
public void simulate(SimulationService simulationService, SimulationItem simulationItem) throws RemoteException Execute une simulation. Dans le cas de ssh:- upload la simulation
- construit le script pour qsub
- upload le script qsub
- ajoute le script a qsub
- lance le thread de control de la simulation
- Specified by:
simulate
in interfaceSimulatorLauncher
- Parameters:
simulationService
- leSimulationService
qui a initie la simulationsimulationItem
- l'item contenant toutes les infos nécessaire au lancement de la simulation IMPORTANT Quoi qu'il arrive- Throws:
RemoteException
- Si pour l'execution de la simulation on utilise des resources distantes (serveurs) et que ceux si non pas pu etre contacte. Dans ce cas la simulation n'a pas ete faite et cette exception est levee.
-
getSimulationStorage
public SimulationStorage getSimulationStorage(SimulationService simulationService, SimulationControl control) throws RemoteException Retourne le storage où est stockée la simulation. Se connecte au serveur distant et télécharge les résultats de la simulation. Simulation must have been downloaded withupdateControl(SimulationService, SimulationControl)
before calling this method.- Specified by:
getSimulationStorage
in interfaceSimulatorLauncher
- Parameters:
simulationService
- leSimulationService
qui a initie la simulationcontrol
- le control de la simulation- Returns:
- le storage contenant la simulation qui vient d'etre faite ou null en fait au lieu de faire une seul simulation, plusieurs ou ete faite par exemple tout un plan de simulation Cette classe est tout de meme responsable du stockage de chaque simulation dans des storages.
- Throws:
RemoteException
- Si pour l'execution de la simulation on utilise des resources distantes (serveurs) et que ceux si non pas pu etre contacte.
-
updateControl
public void updateControl(SimulationService simulationService, SimulationControl control) throws RemoteException Met à jour la progression. Se connecte au serveur distant et télécharge le fichier de control. Injecte ensuite ce fichier dans leSimulationControl
. Essaye aussi de telecharger le fichier md5 de la simulation, et, s'il est present, l'archive de résultat. Supprime tous les fichiers de la simulations apres avoir télécharger les résultats.- Specified by:
updateControl
in interfaceSimulatorLauncher
- Parameters:
simulationService
- leSimulationService
qui a initie la simulationcontrol
- le control de la simulation- Throws:
RemoteException
- Si pour l'execution de la simulation on utilise des resources distantes (serveurs) et que ceux si non pas pu etre contacte.
-
getSSHSession
protected com.jcraft.jsch.Session getSSHSession() throws com.jcraft.jsch.JSchExceptionGet opened ssh session or try to open a new one. This method must synchronized.- Returns:
- opened ssh session.
- Throws:
com.jcraft.jsch.JSchException
-
openSSHSession
protected com.jcraft.jsch.Session openSSHSession() throws com.jcraft.jsch.JSchExceptionConnect to remote server throw SSH, and return session.- Returns:
- valid opened session
- Throws:
com.jcraft.jsch.JSchException
-
closeSSHSession
protected void closeSSHSession(com.jcraft.jsch.Session session) Close ssh session.- Parameters:
session
- session to close
-
getFtpClient
Open new FTP client connected to server and user loggued in.- Throws:
IOException
-
openFtpClient
Open new FTP client connected to server and user logged in.- Throws:
IOException
-
closeFTPClient
Close ftp session.- Throws:
IOException
-
putSshKeyOnRemoteServer
Add ssh key into $HOME/.ssh/authorized_keys file. Just connect and do an "echo xx >> .ssh/authorized_keys"- Parameters:
session
- opened sessionsshKey
-
-
uploadSimulationIfNecessary
protected String uploadSimulationIfNecessary(org.apache.commons.net.ftp.FTPClient ftpClient, SimulationItem simulationItem, String simulationid, File simulationFile) throws IOException Upload simulation if necessary and always return the remote simulation zip path to use.- Parameters:
ftpClient
- already open valid ftp sessionsimulationItem
- simulation itemsimulationid
- simulation idsimulationFile
- simulation file to upload- Returns:
- remote file path or
null
if errors - Throws:
IOException
-
uploadSimulation
protected void uploadSimulation(org.apache.commons.net.ftp.FTPClient ftpClient, String remoteDirectory, String remoteSimulationZipPath, File simulationFile) throws IOException Perform simulation upload. Create remote temp directory if not exists.- Parameters:
ftpClient
- already open valid ftp sessionremoteDirectory
-remoteSimulationZipPath
-- Throws:
IOException
-
downloadResultsArchive
protected File downloadResultsArchive(org.apache.commons.net.ftp.FTPClient ftpClient, SimulationControl simulationControl, String md5sum) throws IOException Download simulation zip results. MD5 control check sum if done, return null, if checkSum fail. File if configured to auto delete at JVM shutdown.- Throws:
IOException
- if download fail (can happen if remote file doesn't exist)
-
downloadResultsMD5File
protected File downloadResultsMD5File(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationId) throws IOException Download remote simulation md5 control file and store its content into temp file.- Parameters:
ftpClient
- valid opened ftp sessionsimulationId
- id de la simulation- Returns:
- downloaded temp file (file have to be manually deleted)
- Throws:
IOException
-
downloadSimulationInformationFile
protected File downloadSimulationInformationFile(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationId) throws IOException Download remote information.- Parameters:
ftpClient
- valid opened ftp sessionsimulationId
- id de la simulation- Returns:
- downloaded temp file (file have to be manually deleted)
- Throws:
IOException
-
clearSimulationFiles
protected void clearSimulationFiles(org.apache.commons.net.ftp.FTPClient ftpClient, SimulationControl control) throws IOException Remove all$ISIS-TMP/simulation-$id-*
files on datarmor.- Parameters:
ftpClient
- valid opened ssh sessioncontrol
- simulation control- Throws:
IOException
-
uploadSimulationScript
protected String uploadSimulationScript(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationid, String simulationScript) throws IOException Upload script on remote server.- Parameters:
simulationScript
- file to upload- Throws:
IOException
-
getResultArchiveName
Get remote simulation zip name.- Parameters:
simulationId
- simulation id
-
uploadPreScriptIfNecessary
protected String uploadPreScriptIfNecessary(org.apache.commons.net.ftp.FTPClient ftpClient, String simulationId, String simulationPreScript) throws IOException Upload pre script on remote server. Return path if uploaded or null if no upload needed.- Parameters:
ftpClient
- valid opened ftp sessionsimulationId
- simulation idsimulationPreScript
- script content- Throws:
IOException
- if upload fail
-
startSimulation
protected void startSimulation(com.jcraft.jsch.Session session, org.apache.commons.net.ftp.FTPClient ftpClient, SimulationItem simulationItem, String simulationid, String simulationRemoteZipPath, String remoteResultZip, String simulationPreScriptPath) throws Exception Start simulation if necessary. Current simulation can be started later with a PBS multi job.- Parameters:
session
- ssh sessionsimulationItem
- simulation item (needed for additionnal info, simulation, number, indenpendant, etc...)simulationid
- simulation idsimulationRemoteZipPath
- simulation preparation (input) zip pathremoteResultZip
- simulation result (output) zip pathsimulationPreScriptPath
- simulation prescript- Throws:
Exception
-
getLaunchSimulationScriptContent
protected String getLaunchSimulationScriptContent(String simuationId, String simulationZip, boolean standaloneZip, String simulationResultZip, String preScriptPath, boolean multipleSimulationScript) throws IOException Retourne un fichier temporaire contenant le script de lancement de simulation. Le fichier temporaire est configuré pour se supprimer tout seul.- Parameters:
simuationId
- id de la simulationsimulationZip
- zip de la simulationstandaloneZip
- standalone simulation zippreScriptPath
- simulation pre script path (can be null)multipleSimulationScript
- iftrue
build a multijob simulation script- Returns:
- un Fichier temporaire ou
null
en cas d'exception - Throws:
IOException
- if can't build script
-
getSimulationScriptLaunchContent
protected String getSimulationScriptLaunchContent(String templateName, String simuationId, String simulationZip, boolean standaloneZip, String simulationZipResult, String preScriptPath, boolean multipleSimulationScript) throws IOException Utilise freemarker pour recuperer le contenu du script. Remplace aussi la variable $simulation du template.- Parameters:
templateName
- url du templatesimuationId
- id de la simulationsimulationZip
- zip de la simulationstandaloneZip
- standalone simulation zipsimulationZipResult
- zip resultat de la simulationpreScriptPath
- simulation pre script path (can be null)multipleSimulationScript
- iftrue
build a multijob simulation script- Throws:
IOException
- if can't get script content
-
sendStartSimulationRequest
protected void sendStartSimulationRequest(com.jcraft.jsch.Session session, String simulationId, String scriptRemotePath, int lastSimulationNumber) throws SSHException Add script in remote qsub queue.- Parameters:
session
- valid opened sessionsimulationId
- simulation id (short version for a multiple job)scriptRemotePath
- remote script pathlastSimulationNumber
- if>=0
start a multiple pbs job form 0 tolastSimulationNumber
- Throws:
SSHException
- if call fail
-
sendStopSimulationRequest
protected void sendStopSimulationRequest(com.jcraft.jsch.Session session, String simulationId) throws SSHException Send qdel request on job.- Parameters:
session
- valid opened sessionsimulationId
- simulation id- Throws:
SSHException
- if call fail
-