1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "Launcher.hxx"
24 #include "Batch_Date.hxx"
25 #include "Batch_FactBatchManager_eLSF.hxx"
26 #include "Batch_FactBatchManager_ePBS.hxx"
27 #include "Batch_BatchManager_eClient.hxx"
28 #include "Batch_FactBatchManager_eSGE.hxx"
29 #include "SALOME_Launcher_Handler.hxx"
30 #include "Launcher.hxx"
38 //=============================================================================
42 * Define a CORBA single thread policy for the server, which avoid to deal
43 * with non thread-safe usage like Change_Directory in SALOME naming service
45 //=============================================================================
47 Launcher_cpp::Launcher_cpp()
49 #if defined(_DEBUG_) || defined(_DEBUG)
50 cerr << "Launcher_cpp constructor" << endl;
54 //=============================================================================
58 //=============================================================================
60 Launcher_cpp::~Launcher_cpp()
62 #if defined(_DEBUG_) || defined(_DEBUG)
63 cerr << "Launcher_cpp destructor" << endl;
65 std::map < string, Batch::BatchManager_eClient * >::const_iterator it1;
66 for(it1=_batchmap.begin();it1!=_batchmap.end();it1++)
68 std::map < std::pair<std::string,long> , Batch::Job* >::const_iterator it2;
69 for(it2=_jobmap.begin();it2!=_jobmap.end();it2++)
73 //=============================================================================
75 * Submit a batch job on a cluster and returns the JobId
76 * \param xmlExecuteFile : to define the execution on the batch cluster
77 * \param clusterName : name of the batch cluster
79 //=============================================================================
80 long Launcher_cpp::submitJob( const std::string xmlExecuteFile,
81 const std::string clusterName) throw(LauncherException)
83 #if defined(_DEBUG_) || defined(_DEBUG)
84 cout << "BEGIN OF Launcher_cpp::submitJob" << endl;
87 vector<string> aMachineList;
90 throw LauncherException("You must set Resources Manager to Launcher!!");
92 // verify if cluster is in resources catalog
94 params.hostname = clusterName;
95 vector<string> aCompoList ;
97 aMachineList = _ResManager->GetFittingResources(params, aCompoList);
99 catch(const ResourcesException &ex){
100 throw LauncherException(ex.msg.c_str());
102 if (aMachineList.size() == 0)
103 throw LauncherException("This cluster is not in resources catalog");
106 ParseXmlFile(xmlExecuteFile);
108 // verify if clustername is in xml file
109 map<std::string,MachineParameters>::const_iterator it1 = _launch.MachinesList.find(clusterName);
110 if(it1 == _launch.MachinesList.end())
111 throw LauncherException("This cluster is not in xml file");
113 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
114 string cname(p.Alias);
115 #if defined(_DEBUG_) || defined(_DEBUG)
116 cout << "Choose cluster: " << cname << endl;
119 // search batch manager for that cluster in map or instanciate one
120 map < string, Batch::BatchManager_eClient * >::const_iterator it2 = _batchmap.find(cname);
121 if(it2 == _batchmap.end())
123 _batchmap[cname] = FactoryBatchManager(p);
124 // TODO: Add a test for the cluster !
129 // directory on cluster to put files to execute
130 string remotedir = _launch.MachinesList[clusterName].WorkDirectory;
131 // local directory to get files to execute and to put results
132 string localdir = _launch.RefDirectory;
134 int idx1 = xmlExecuteFile.find_last_of("/");
135 if(idx1 == string::npos) idx1 = -1;
136 int idx2 = xmlExecuteFile.find(".xml");
137 string logfile = xmlExecuteFile.substr(idx1+1,idx2-idx1-1);
138 string ologfile = logfile + ".output.log";
139 string elogfile = logfile + ".error.log";
141 // create and submit job on cluster
142 Batch::Parametre param;
143 param[USER] = p.UserName;
144 param[EXECUTABLE] = "";
145 for(int i=0; i<_launch.InputFile.size();i++)
146 param[INFILE] += Batch::Couple( localdir + "/" + _launch.InputFile[i], remotedir + "/" + _launch.InputFile[i] );
147 for(int i=0; i<_launch.OutputFile.size();i++)
148 param[OUTFILE] += Batch::Couple( localdir + "/" + _launch.OutputFile[i], remotedir + "/" + _launch.OutputFile[i] );
149 param[OUTFILE] += Batch::Couple( localdir + "/" + ologfile, remotedir + "/" + ologfile );
150 param[OUTFILE] += Batch::Couple( localdir + "/" + elogfile, remotedir + "/" + elogfile );
151 param[NBPROC] = _launch.NbOfProcesses;
152 param[WORKDIR] = remotedir;
153 param[TMPDIR] = remotedir;
154 param[MAXWALLTIME] = getWallTime("");
155 param[MAXRAMSIZE] = getRamSize("");
158 Batch::Environnement env;
159 env["COMMAND"] = _launch.Command;
160 env["SOURCEFILE"] = _launch.MachinesList[clusterName].EnvFile;
161 env["LOGFILE"] = logfile;
163 Batch::Job* job = new Batch::Job(param,env);
165 // submit job on cluster
166 Batch::JobId jid = _batchmap[cname]->submitJob(*job);
168 // get job id in long
169 istringstream iss(jid.getReference());
172 _jobmap[ pair<string,long>(cname,jobId) ] = job;
174 catch(const Batch::EmulationException &ex){
175 throw LauncherException(ex.msg.c_str());
181 //=============================================================================
183 * Submit a batch job on a cluster and returns the JobId
184 * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster
185 * \param filesToExport : to export on the batch cluster
186 * \param NumberOfProcessors : Number of processors needed on the batch cluster
187 * \param params : Constraints for the choice of the batch cluster
189 //=============================================================================
190 long Launcher_cpp::submitSalomeJob( const string fileToExecute ,
191 const vector<string>& filesToExport ,
192 const vector<string>& filesToImport ,
193 const batchParams& batch_params,
194 const machineParams& params) throw(LauncherException)
196 #if defined(_DEBUG_) || defined(_DEBUG)
197 cerr << "BEGIN OF Launcher_cpp::submitSalomeJob" << endl;
200 vector<string> aMachineList;
203 throw LauncherException("You must set Resources Manager to Launcher!!");
205 // check batch params
206 if ( !check(batch_params) )
207 throw LauncherException("Batch parameters are bad (see informations above)");
209 // find a cluster matching the structure params
210 vector<string> aCompoList ;
212 aMachineList = _ResManager->GetFittingResources(params, aCompoList);
214 catch(const ResourcesException &ex){
215 throw LauncherException(ex.msg.c_str());
217 if (aMachineList.size() == 0)
218 throw LauncherException("No resources have been found with your parameters");
220 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
221 string clustername(p.Alias);
222 #if defined(_DEBUG_) || defined(_DEBUG)
223 cerr << "Choose cluster: " << clustername << endl;
226 // search batch manager for that cluster in map or instanciate one
227 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
228 if(it == _batchmap.end())
230 _batchmap[clustername] = FactoryBatchManager(p);
231 // TODO: Add a test for the cluster !
235 // tmp directory on cluster to put files to execute
236 string tmpdir = getTmpDirForBatchFiles();
238 // create and submit job on cluster
239 Batch::Parametre param;
240 param[USER] = p.UserName;
241 param[EXECUTABLE] = buildSalomeCouplingScript(fileToExecute,tmpdir,p);
242 param[INFILE] = Batch::Couple( fileToExecute, getRemoteFile(tmpdir,fileToExecute) );
243 for(int i=0;i<filesToExport.size();i++)
244 param[INFILE] += Batch::Couple( filesToExport[i], getRemoteFile(tmpdir,filesToExport[i]) );
246 ostringstream file_name_output;
247 file_name_output << "~/" << tmpdir << "/" << "output.log*";
248 ostringstream file_name_error;
249 file_name_error << "~/" << tmpdir << "/" << "error.log*";
250 ostringstream file_container_log;
251 file_container_log << "~/" << tmpdir << "/" << "YACS_Server*";
252 param[OUTFILE] = Batch::Couple( "", file_name_output.str());
253 param[OUTFILE] += Batch::Couple( "", file_name_error.str());
254 param[OUTFILE] += Batch::Couple( "", file_container_log.str());
256 for(int i=0;i<filesToImport.size();i++)
257 param[OUTFILE] += Batch::Couple( "", filesToImport[i] );
259 param[NBPROC] = batch_params.nb_proc;
260 param[WORKDIR] = batch_params.batch_directory;
261 param[TMPDIR] = tmpdir;
262 param[MAXWALLTIME] = getWallTime(batch_params.expected_during_time);
263 param[MAXRAMSIZE] = getRamSize(batch_params.mem);
264 param[HOMEDIR] = getHomeDir(p, tmpdir);
265 param[QUEUE] = p.batchQueue;
267 Batch::Environnement env;
269 Batch::Job* job = new Batch::Job(param,env);
271 // submit job on cluster
272 Batch::JobId jid = _batchmap[clustername]->submitJob(*job);
274 // get job id in long
275 istringstream iss(jid.getReference());
278 _jobmap[ pair<string,long>(clustername,jobId) ] = job;
280 catch(const Batch::EmulationException &ex){
281 throw LauncherException(ex.msg.c_str());
287 //=============================================================================
289 * Query a batch job on a cluster and returns the status of job
290 * \param jobId : identification of Salome job
291 * \param params : Constraints for the choice of the batch cluster
293 //=============================================================================
294 string Launcher_cpp::queryJob( long id,
295 const machineParams& params) throw(LauncherException)
298 throw LauncherException("You must set Resources Manager to Launcher!!");
300 // find a cluster matching params structure
301 vector<string> aCompoList ;
302 vector<string> aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ;
303 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
304 string clustername(p.Alias);
306 // search batch manager for that cluster in map
307 std::map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
308 if(it == _batchmap.end())
309 throw LauncherException("no batchmanager for that cluster");
311 Batch::Parametre par;
315 Batch::JobId jobId( _batchmap[clustername], oss.str() );
317 Batch::JobInfo jinfo = jobId.queryJob();
318 par = jinfo.getParametre();
320 catch(const Batch::EmulationException &ex){
321 throw LauncherException(ex.msg.c_str());
327 string Launcher_cpp::queryJob( long id,
328 const std::string clusterName)
330 machineParams params;
331 params.hostname = clusterName;
332 return queryJob(id,params);
335 //=============================================================================
337 * Delete a batch job on a cluster
338 * \param jobId : identification of Salome job
339 * \param params : Constraints for the choice of the batch cluster
341 //=============================================================================
342 void Launcher_cpp::deleteJob( const long id,
343 const machineParams& params) throw(LauncherException)
346 throw LauncherException("You must set Resources Manager to Launcher!!");
348 // find a cluster matching params structure
349 vector<string> aCompoList ;
350 vector<string> aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ;
351 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
352 string clustername(p.Alias);
354 // search batch manager for that cluster in map
355 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
356 if(it == _batchmap.end())
357 throw LauncherException("no batchmanager for that cluster");
361 Batch::JobId jobId( _batchmap[clustername], oss.str() );
366 void Launcher_cpp::deleteJob( long id,
367 const std::string clusterName)
369 machineParams params;
370 params.hostname = clusterName;
371 deleteJob(id,params);
374 //=============================================================================
376 * Get result files of job on a cluster
377 * \param jobId : identification of Salome job
378 * \param params : Constraints for the choice of the batch cluster
380 //=============================================================================
381 void Launcher_cpp::getResultsJob( const string directory,
383 const machineParams& params) throw(LauncherException)
386 throw LauncherException("You must set Resources Manager to Launcher!!");
388 vector<string> aCompoList ;
389 vector<string> aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ;
390 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
391 string clustername(p.Alias);
393 // search batch manager for that cluster in map
394 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
395 if(it == _batchmap.end())
396 throw LauncherException("no batchmanager for that cluster");
398 Batch::Job* job = _jobmap[ pair<string,long>(clustername,id) ];
400 _batchmap[clustername]->importOutputFiles( *job, directory );
403 void Launcher_cpp::getResultsJob( const std::string directory,
405 const std::string clusterName)
407 machineParams params;
408 params.hostname = clusterName;
409 getResultsJob(directory,id,params);
412 //=============================================================================
414 * Factory to instanciate the good batch manager for choosen cluster.
416 //=============================================================================
418 Batch::BatchManager_eClient *Launcher_cpp::FactoryBatchManager( const ParserResourcesType& params ) throw(LauncherException)
421 std::string hostname, protocol, mpi;
422 Batch::FactBatchManager_eClient* fact;
424 hostname = params.Alias;
425 switch(params.Protocol){
433 throw LauncherException("unknown protocol");
456 throw LauncherException("you must specified an mpi implementation for batch manager");
459 throw LauncherException("unknown mpi implementation");
462 #if defined(_DEBUG_) || defined(_DEBUG)
463 cerr << "Instanciation of batch manager" << endl;
465 switch( params.Batch ){
467 #if defined(_DEBUG_) || defined(_DEBUG)
468 cerr << "Instantiation of PBS batch manager" << endl;
470 fact = new Batch::FactBatchManager_ePBS;
473 #if defined(_DEBUG_) || defined(_DEBUG)
474 cerr << "Instantiation of LSF batch manager" << endl;
476 fact = new Batch::FactBatchManager_eLSF;
479 #if defined(_DEBUG_) || defined(_DEBUG)
480 cout << "Instantiation of SGE batch manager" << endl;
482 fact = new Batch::FactBatchManager_eSGE;
485 #if defined(_DEBUG_) || defined(_DEBUG)
486 cerr << "BATCH = " << params.Batch << endl;
488 throw LauncherException("no batchmanager for that cluster");
490 return (*fact)(hostname.c_str(),protocol.c_str(),mpi.c_str());
493 string Launcher_cpp::buildSalomeCouplingScript(const string fileToExecute, const string dirForTmpFiles, const ParserResourcesType& params)
495 #ifndef WIN32 //TODO: need for porting on Windows
496 int idx = dirForTmpFiles.find("Batch/");
497 std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length());
499 string::size_type p1 = fileToExecute.find_last_of("/");
500 string::size_type p2 = fileToExecute.find_last_of(".");
501 std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
502 std::string TmpFileName = "/tmp/runSalome_" + fileNameToExecute + ".sh";
504 MpiImpl* mpiImpl = FactoryMpiImpl(params.mpi);
506 ofstream tempOutputFile;
507 tempOutputFile.open(TmpFileName.c_str(), ofstream::out );
510 tempOutputFile << "#! /bin/sh -f" << endl ;
511 tempOutputFile << "cd " ;
512 tempOutputFile << params.AppliPath << endl ;
513 tempOutputFile << "export SALOME_BATCH=1\n";
514 tempOutputFile << "export PYTHONPATH=~/" ;
515 tempOutputFile << dirForTmpFiles ;
516 tempOutputFile << ":$PYTHONPATH" << endl ;
518 // Adding user script
519 std::string script = params.userCommands;
521 tempOutputFile << script << endl;
523 tempOutputFile << "if test \"" ;
524 tempOutputFile << mpiImpl->rank() ;
525 tempOutputFile << "\" = \"0\"; then" << endl ;
527 // -----------------------------------------------
528 // Code for rank 0 : launch runAppli and a container
530 if(params.ModulesList.size()>0)
531 tempOutputFile << " ./runAppli --terminal --modules=" ;
533 tempOutputFile << " ./runAppli --terminal ";
534 for ( int i = 0 ; i < params.ModulesList.size() ; i++ ) {
535 tempOutputFile << params.ModulesList[i] ;
536 if ( i != params.ModulesList.size()-1 )
537 tempOutputFile << "," ;
539 tempOutputFile << " --standalone=registry,study,moduleCatalog --ns-port-log="
543 // Wait NamingService
544 tempOutputFile << " current=0\n"
546 << " while ! test -f " << filelogtemp << "\n"
549 << " let current=current+1\n"
550 << " if [ \"$current\" -eq \"$stop\" ] ; then\n"
551 << " echo Error Naming Service failed ! >&2"
555 << " port=`cat " << filelogtemp << "`\n";
557 // Wait other containers
558 tempOutputFile << " for ((ip=1; ip < ";
559 tempOutputFile << mpiImpl->size();
560 tempOutputFile << " ; ip++))" << endl;
561 tempOutputFile << " do" << endl ;
562 tempOutputFile << " arglist=\"$arglist YACS_Server_\"$ip" << endl ;
563 tempOutputFile << " done" << endl ;
564 tempOutputFile << " sleep 5" << endl ;
565 tempOutputFile << " ./runSession waitContainers.py $arglist" << endl ;
567 // Launch user script
568 tempOutputFile << " ./runSession python ~/" << dirForTmpFiles << "/" << fileNameToExecute << ".py" << endl;
571 tempOutputFile << " rm " << filelogtemp << "\n"
572 << " ./runSession shutdownSalome.py" << endl;
574 // -------------------------------------
575 // Other nodes launch a container
576 tempOutputFile << "else" << endl ;
578 // Wait NamingService
579 tempOutputFile << " current=0\n"
581 << " while ! test -f " << filelogtemp << "\n"
584 << " let current=current+1\n"
585 << " if [ \"$current\" -eq \"$stop\" ] ; then\n"
586 << " echo Error Naming Service failed ! >&2"
590 << " port=`cat " << filelogtemp << "`\n";
592 // Launching container
593 tempOutputFile << " ./runSession SALOME_Container YACS_Server_";
594 tempOutputFile << mpiImpl->rank()
595 << " > ~/" << dirForTmpFiles << "/YACS_Server_"
596 << mpiImpl->rank() << "_container_log." << filelogtemp
598 tempOutputFile << "fi" << endl ;
599 tempOutputFile.flush();
600 tempOutputFile.close();
601 chmod(TmpFileName.c_str(), 0x1ED);
602 #if defined(_DEBUG_) || defined(_DEBUG)
603 cerr << TmpFileName.c_str() << endl;
615 MpiImpl *Launcher_cpp::FactoryMpiImpl(MpiImplType mpi) throw(LauncherException)
619 return new MpiImpl_LAM();
621 return new MpiImpl_MPICH1();
623 return new MpiImpl_MPICH2();
625 return new MpiImpl_OPENMPI();
627 return new MpiImpl_SLURM();
629 return new MpiImpl_PRUN();
631 throw LauncherException("you must specify an mpi implementation for batch manager");
634 oss << mpi << " : not yet implemented";
635 throw LauncherException(oss.str().c_str());
640 string Launcher_cpp::getTmpDirForBatchFiles()
645 // Adding date to the directory name
646 Batch::Date date = Batch::Date(time(0));
647 thedate = date.str();
648 int lend = thedate.size() ;
651 if ( thedate[i] == '/' || thedate[i] == '-' || thedate[i] == ':' ) {
657 ret = string("Batch/");
662 string Launcher_cpp::getRemoteFile( std::string remoteDir, std::string localFile )
664 string::size_type pos = localFile.find_last_of("/") + 1;
665 int ln = localFile.length() - pos;
666 string remoteFile = remoteDir + "/" + localFile.substr(pos,ln);
670 bool Launcher_cpp::check(const batchParams& batch_params)
673 #if defined(_DEBUG_) || defined(_DEBUG)
674 cerr << "Job parameters are :" << endl;
675 cerr << "Directory : $HOME/Batch/$date" << endl;
678 // check expected_during_time (check the format)
679 std::string edt_info = batch_params.expected_during_time;
680 std::string edt_value = batch_params.expected_during_time;
681 if (edt_value != "") {
682 std::string begin_edt_value = edt_value.substr(0, 2);
683 std::string mid_edt_value = edt_value.substr(2, 1);
684 std::string end_edt_value = edt_value.substr(3);
687 std::istringstream iss(begin_edt_value);
688 if (!(iss >> value)) {
689 edt_info = "Error on definition ! : " + edt_value;
692 else if (value < 0) {
693 edt_info = "Error on definition time is negative ! : " + value;
696 std::istringstream iss_2(end_edt_value);
697 if (!(iss_2 >> value)) {
698 edt_info = "Error on definition ! : " + edt_value;
701 else if (value < 0) {
702 edt_info = "Error on definition time is negative ! : " + value;
705 if (mid_edt_value != ":") {
706 edt_info = "Error on definition ! :" + edt_value;
711 edt_info = "No value given";
713 #if defined(_DEBUG_) || defined(_DEBUG)
714 cerr << "Expected during time : " << edt_info << endl;;
717 // check memory (check the format)
718 std::string mem_info;
719 std::string mem_value = batch_params.mem;
720 if (mem_value != "") {
721 std::string begin_mem_value = mem_value.substr(0, mem_value.length()-2);
723 std::istringstream iss(begin_mem_value);
724 if (!(iss >> re_mem_value)) {
725 mem_info = "Error on definition ! : " + mem_value;
728 else if (re_mem_value <= 0) {
729 mem_info = "Error on definition memory is negative ! : " + mem_value;
732 std::string end_mem_value = mem_value.substr(mem_value.length()-2);
733 if (end_mem_value != "gb" && end_mem_value != "mb") {
734 mem_info = "Error on definition, type is bad ! " + mem_value;
739 mem_info = "No value given";
741 #if defined(_DEBUG_) || defined(_DEBUG)
742 cerr << "Memory : " << mem_info << endl;
746 std::string nb_proc_info;
747 ostringstream nb_proc_value;
748 nb_proc_value << batch_params.nb_proc;
749 if(batch_params.nb_proc <= 0) {
750 nb_proc_info = "Bad value ! nb_proc = ";
751 nb_proc_info += nb_proc_value.str();
755 nb_proc_info = nb_proc_value.str();
757 #if defined(_DEBUG_) || defined(_DEBUG)
758 cerr << "Nb of processors : " << nb_proc_info << endl;
764 long Launcher_cpp::getWallTime(std::string edt)
768 if( edt.size() == 0 )
771 string::size_type pos = edt.find(":");
772 string h = edt.substr(0,pos);
773 string m = edt.substr(pos+1,edt.size()-pos+1);
774 istringstream issh(h);
776 istringstream issm(m);
782 long Launcher_cpp::getRamSize(std::string mem)
786 if( mem.size() == 0 )
789 string ram = mem.substr(0,mem.size()-2);
790 istringstream iss(ram);
792 string unity = mem.substr(mem.size()-2,2);
793 if( (unity.find("gb") != string::npos) || (unity.find("GB") != string::npos) )
795 else if( (unity.find("mb") != string::npos) || (unity.find("MB") != string::npos) )
797 else if( (unity.find("kb") != string::npos) || (unity.find("KB") != string::npos) )
799 else if( (unity.find("b") != string::npos) || (unity.find("B") != string::npos) )
800 return mv/(1024*1024);
805 void Launcher_cpp::ParseXmlFile(string xmlExecuteFile)
807 SALOME_Launcher_Handler* handler = new SALOME_Launcher_Handler(_launch);
809 const char* aFilePath = xmlExecuteFile.c_str();
810 FILE* aFile = fopen(aFilePath, "r");
814 xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
817 handler->ProcessXmlDocument(aDoc);
819 #if defined(_DEBUG_) || defined(_DEBUG)
820 cout << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl;
830 #if defined(_DEBUG_) || defined(_DEBUG)
831 cout << "Launcher_cpp: file "<<aFilePath<<" is not readable." << endl;
839 std::string Launcher_cpp::getHomeDir(const ParserResourcesType& p, const std::string& tmpdir)
843 int idx = tmpdir.find("Batch/");
844 std::string filelogtemp = tmpdir.substr(idx+6, tmpdir.length());
845 filelogtemp = "/tmp/logs" + filelogtemp + "_home";
847 if( p.Protocol == rsh )
849 else if( p.Protocol == ssh )
852 throw LauncherException("Unknown protocol");
853 if (p.UserName != ""){
854 command += p.UserName;
858 command += " 'echo $HOME' > ";
859 command += filelogtemp;
860 #if defined(_DEBUG_) || defined(_DEBUG)
861 std::cerr << command.c_str() << std::endl;
863 int status = system(command.c_str());
865 throw LauncherException("Error of launching home command on remote host");
867 std::ifstream file_home(filelogtemp.c_str());
868 std::getline(file_home, home);