Salome HOME
updated copyright message
[modules/kernel.git] / src / Launcher / SALOME_Launcher.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SALOME_Launcher.hxx"
24 #include "BatchTest.hxx"
25 #include "OpUtil.hxx"
26 #include "SALOME_ContainerManager.hxx"
27 #include "SALOME_NamingService.hxx"
28 #include "SALOME_ResourcesManager.hxx"
29 #include "Utils_CorbaException.hxx"
30
31
32 #include "Launcher_Job_Command.hxx"
33 #include "Launcher_Job_YACSFile.hxx"
34 #include "Launcher_Job_PythonSALOME.hxx"
35 #include "Launcher_Job_CommandSALOME.hxx"
36
37 #include "utilities.h"
38
39 #ifdef WIN32
40 # include <process.h>
41 #else
42 # include <unistd.h>
43 #endif
44 #include <sys/types.h>
45 #include <vector>
46 #include <list>
47
48 #include <stdio.h>
49 #include <sstream>
50
51 using namespace std;
52
53 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
54
55 //=============================================================================
56 /*!
57  *  Constructor
58  *  \param orb
59  */
60 //=============================================================================
61 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa)
62 {
63   MESSAGE("SALOME_Launcher constructor");
64   _NS = new SALOME_NamingService(orb);
65   init(orb,poa);
66   MESSAGE("SALOME_Launcher constructor end");
67 }
68
69 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *externalNS):_NS(externalNS)
70 {
71   init(orb,poa);
72 }
73
74 void SALOME_Launcher::init(CORBA::ORB_ptr orb, PortableServer::POA_var poa)
75 {
76   _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
77   _l.SetResourcesManager(_ResManager->GetImpl());
78   _ContManager = new SALOME_ContainerManager(orb,poa,_NS);
79   _ResManager->_remove_ref();
80   _ContManager->_remove_ref();
81
82   _orb = CORBA::ORB::_duplicate(orb) ;
83   _poa = PortableServer::POA::_duplicate(poa) ;
84   PortableServer::ObjectId_var id = _poa->activate_object(this);
85   CORBA::Object_var obj = _poa->id_to_reference(id);
86   Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
87   _NS->Register(refContMan,_LauncherNameInNS);
88 }
89
90 //=============================================================================
91 /*!
92  * destructor
93  */
94 //=============================================================================
95 SALOME_Launcher::~SALOME_Launcher()
96 {
97   MESSAGE("SALOME_Launcher destructor");
98   delete _NS;
99   MESSAGE("SALOME_Launcher destructor end");
100 }
101
102
103 CORBA::Long
104 SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
105 {
106   JobParameters_cpp cpp_parameters = JobParameters_CORBA2CPP(job_parameters);
107   CORBA::Long jobNumber = -1;
108   try
109   {
110     jobNumber = _l.createJob(cpp_parameters);
111     std::ostringstream job_id;
112     job_id << jobNumber;
113     notifyObservers("NEW_JOB", job_id.str());
114   }
115   catch(const LauncherException &ex)
116   {
117     INFOS(ex.msg.c_str());
118     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
119   }
120   return jobNumber;
121 }
122
123 void
124 SALOME_Launcher::launchJob(CORBA::Long job_id)
125 {
126   try
127   {
128     _l.launchJob(job_id);
129   }
130   catch(const LauncherException &ex)
131   {
132     INFOS(ex.msg.c_str());
133     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
134   }
135 }
136
137 char *
138 SALOME_Launcher::getJobState(CORBA::Long job_id)
139 {
140   std::string result;
141   try
142   {
143     result = _l.getJobState(job_id);
144   }
145   catch(const LauncherException &ex)
146   {
147     INFOS(ex.msg.c_str());
148     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
149   }
150   return CORBA::string_dup(result.c_str());
151 }
152
153 // Get names or ids of hosts assigned to the job
154 char *
155 SALOME_Launcher::getAssignedHostnames(CORBA::Long job_id)
156 {
157   std::string result;
158   try
159   {
160     result = _l.getAssignedHostnames(job_id);
161   }
162   catch(const LauncherException &ex)
163   {
164     INFOS(ex.msg.c_str());
165     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
166   }
167   return CORBA::string_dup(result.c_str());
168 }
169
170 void
171 SALOME_Launcher::exportInputFiles(CORBA::Long job_id)
172 {
173   try
174   {
175     _l.exportInputFiles(job_id);
176   }
177   catch(const LauncherException &ex)
178   {
179     INFOS(ex.msg.c_str());
180     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
181   }
182 }
183
184 void
185 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
186 {
187   try
188   {
189     _l.getJobResults(job_id, directory);
190   }
191   catch(const LauncherException &ex)
192   {
193     INFOS(ex.msg.c_str());
194     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
195   }
196 }
197
198 void
199 SALOME_Launcher::clearJobWorkingDir(CORBA::Long job_id)
200 {
201   try
202   {
203     _l.clearJobWorkingDir(job_id);
204   }
205   catch(const LauncherException &ex)
206   {
207     INFOS(ex.msg.c_str());
208     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
209   }
210 }
211
212 CORBA::Boolean
213 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
214 {
215   CORBA::Boolean rtn = false;
216   try
217   {
218     rtn = _l.getJobDumpState(job_id, directory);
219   }
220   catch(const LauncherException &ex)
221   {
222     INFOS(ex.msg.c_str());
223     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
224   }
225   return rtn;
226 }
227
228 CORBA::Boolean
229 SALOME_Launcher::getJobWorkFile(CORBA::Long job_id, const char * work_file, const char * directory)
230 {
231   CORBA::Boolean rtn = false;
232   try
233   {
234     rtn = _l.getJobWorkFile(job_id, work_file, directory);
235   }
236   catch(const LauncherException &ex)
237   {
238     INFOS(ex.msg.c_str());
239     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
240   }
241   return rtn;
242 }
243
244 void SALOME_Launcher::DeclareUsingSalomeSession()
245 {
246   this->_ContManager->DeclareUsingSalomeSession();
247 }
248
249 void
250 SALOME_Launcher::removeJob(CORBA::Long job_id)
251 {
252   try
253   {
254     _l.removeJob(job_id);
255     std::ostringstream job_id_str;
256     job_id_str << job_id;
257     notifyObservers("REMOVE_JOB", job_id_str.str());
258   }
259   catch(const LauncherException &ex)
260   {
261     INFOS(ex.msg.c_str());
262     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
263   }
264 }
265
266 void
267 SALOME_Launcher::stopJob(CORBA::Long job_id)
268 {
269   try
270   {
271     _l.stopJob(job_id);
272     std::ostringstream job_id_str;
273     job_id_str << job_id;
274     notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
275   }
276   catch(const LauncherException &ex)
277   {
278     INFOS(ex.msg.c_str());
279     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
280   }
281 }
282
283 char *
284 SALOME_Launcher::dumpJob(CORBA::Long job_id)
285 {
286   std::string result;
287   try
288   {
289     result = _l.dumpJob(job_id);
290   }
291   catch(const LauncherException &ex)
292   {
293     INFOS(ex.msg.c_str());
294     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
295   }
296   return CORBA::string_dup(result.c_str());
297 }
298
299 CORBA::Long
300 SALOME_Launcher::restoreJob(const char * dumpedJob)
301 {
302   CORBA::Long jobId;
303   try{
304     jobId = _l.restoreJob(dumpedJob);
305     if(jobId >= 0)
306     {
307       std::ostringstream job_str;
308       job_str << jobId;
309       notifyObservers("NEW_JOB", job_str.str());
310     }
311   }
312   catch(const LauncherException &ex){
313     INFOS(ex.msg.c_str());
314     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
315   }
316
317   return jobId;
318 }
319
320 //=============================================================================
321 /*! CORBA Method:
322  *  Create a job in the launcher with a file
323  *  \param xmlExecuteFile     : .xml to parse that contains job description
324  *  \param clusterName        : machine chosen
325  */
326 //=============================================================================
327 CORBA::Long
328 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
329                                    const char * clusterName)
330 {
331   CORBA::Long jobId;
332   try{
333     jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
334   }
335   catch(const LauncherException &ex){
336     INFOS(ex.msg.c_str());
337     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
338   }
339
340   return jobId;
341 }
342
343 //=============================================================================
344 /*! CORBA Method:
345  *  the test batch configuration
346  *  \param params             : The batch cluster
347  */
348 //=============================================================================
349 CORBA::Boolean
350 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
351 {
352   MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
353   CORBA::Boolean rtn = false;
354   try
355   {
356     // Consider only resources that can run batch jobs
357     Engines::ResourceParameters new_params(params);
358     new_params.can_launch_batch_jobs = true;
359
360     // find a resource matching the required parameters
361     Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(new_params);
362     if (aMachineList->length() == 0)
363       throw SALOME_Exception("No resources have been found with your parameters");
364
365     const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
366         std::string resource_name(p->name);
367     INFOS("Choose resource for test: " <<  resource_name);
368
369     BatchTest t(*p);
370     if (t.test())
371     {
372       rtn = true;
373     }
374   }
375   catch(const LauncherException &ex){
376     INFOS(ex.msg.c_str());
377     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
378   }
379   return rtn;
380 }
381
382 //=============================================================================
383 /*! CORBA method:
384  *  shutdown all the containers, then the ContainerManager servant
385  */
386 //=============================================================================
387 void SALOME_Launcher::Shutdown()
388 {
389   MESSAGE("Shutdown");
390   if(!_NS)
391     return;
392   _NS->Destroy_Name(_LauncherNameInNS);
393   _ContManager->Shutdown();
394   _ResManager->Shutdown();
395   PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
396   _poa->deactivate_object(oid);
397   if(!CORBA::is_nil(_orb))
398     _orb->shutdown(0);
399 }
400
401 //=============================================================================
402 /*! CORBA Method:
403  *  Returns the PID of the process
404  */
405 //=============================================================================
406 CORBA::Long SALOME_Launcher::getPID()
407 {
408   return
409 #ifndef WIN32
410     (CORBA::Long)getpid();
411 #else
412     (CORBA::Long)_getpid();
413 #endif
414 }
415
416 //=============================================================================
417 /*! CORBA Method:
418  *  Returns current launcher jobs list
419  */
420 //=============================================================================
421 Engines::JobsList *
422 SALOME_Launcher::getJobsList()
423 {
424   Engines::JobsList_var jobs_list = new Engines::JobsList();
425   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
426   std::map<int, Launcher::Job *>::const_iterator it_job;
427   int list_id = 0;
428   for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
429   {
430     int number          = it_job->first;
431     try
432     {
433       // Prepare CORBA job description
434       Engines::JobDescription_var job_descr = new Engines::JobDescription();
435       Engines::JobParameters_var job_parameters = getJobParameters(number);
436       job_descr->job_id = number;
437       job_descr->job_parameters = job_parameters;
438
439       // Add job description to the sequence
440       jobs_list->length(list_id + 1);
441       jobs_list[list_id] = job_descr;
442       list_id++;
443     }
444     catch (...) {}
445   }
446   return jobs_list._retn();
447 }
448
449 //=============================================================================
450 /*! CORBA Method:
451  * Returns the job description
452  */
453 //=============================================================================
454 Engines::JobParameters *
455 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
456 {
457   Engines::JobParameters_var job_parameters;
458   try
459   {
460     JobParameters_cpp cpp_parameters = _l.getJobParameters(job_id);
461     job_parameters = JobParameters_CPP2CORBA(cpp_parameters);
462   }
463   catch(const LauncherException &ex)
464   {
465     INFOS(ex.msg.c_str());
466     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
467   }
468
469   return job_parameters._retn();
470 }
471
472 //=============================================================================
473 /*! CORBA Method:
474  *  Loads jobs saved in jobs_file
475  */
476 //=============================================================================
477 void
478 SALOME_Launcher::loadJobs(const char* jobs_file)
479 {
480   list<int> new_jobs_id_list;
481   try
482   {
483     // Load the jobs in Launcher
484     new_jobs_id_list = _l.loadJobs(jobs_file);
485   }
486   catch (const LauncherException & ex)
487   {
488     INFOS(ex.msg.c_str());
489     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(), SALOME::INTERNAL_ERROR);
490   }
491
492   // Notify observers of the new jobs
493   list<int>::const_iterator it_jobs_id;
494   for (it_jobs_id = new_jobs_id_list.begin(); it_jobs_id != new_jobs_id_list.end(); it_jobs_id++)
495   {
496     ostringstream job_id_sstr;
497     job_id_sstr << *it_jobs_id;
498     notifyObservers("NEW_JOB", job_id_sstr.str());
499   }
500   notifyObservers("LOAD_JOBS", jobs_file);
501 }
502
503 //=============================================================================
504 /*! CORBA Method:
505  *  Save jobs of Launcher (in any steps) in file jobs_file
506  */
507 //=============================================================================
508 void
509 SALOME_Launcher::saveJobs(const char* jobs_file)
510 {
511   _l.saveJobs(jobs_file);
512   notifyObservers("SAVE_JOBS", jobs_file);
513 }
514
515 //=============================================================================
516 /*! CORBA Method:
517  *  Add a new observer to the launcher
518  */
519 //=============================================================================
520 void
521 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
522 {
523   bool new_observer = true;
524   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
525   while(iter != _observers.end())
526   {
527     if (std::string(_orb->object_to_string(*iter)) ==
528         std::string(_orb->object_to_string(observer)))
529     {
530       new_observer = false;
531       break;
532     }
533     iter++;
534   }
535   if (new_observer)
536     _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
537
538   // We notify the new observer with all jobs that are currently in the Launcher
539   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
540   std::map<int, Launcher::Job *>::const_iterator it_job;
541   for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
542   {
543     int number = it_job->first;
544     std::ostringstream job_id;
545     job_id << number;
546     try
547     {
548       observer->notify("NEW_JOB", job_id.str().c_str());
549     }
550     catch (...)
551     {
552        MESSAGE("Notify Observer, exception catch");
553     }
554
555   }
556 }
557
558 //=============================================================================
559 /*! CORBA Method:
560  *  Add a new observer to the launcher
561  */
562 //=============================================================================
563 void
564 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
565 {
566   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
567   while(iter != _observers.end())
568   {
569     if (std::string(_orb->object_to_string(*iter)) ==
570         std::string(_orb->object_to_string(observer)))
571     {
572       // Observer found
573       iter =_observers.erase(iter++);
574     }
575     else
576     {
577       iter++;
578     }
579   }
580 }
581
582 //=============================================================================
583 /*! Internal Method:
584  *  Notify observers on a new event
585  */
586 //=============================================================================
587 void
588 SALOME_Launcher::notifyObservers(const std::string & event_name,
589                                  const std::string & event_data)
590 {
591   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
592   while(iter != _observers.end())
593   {
594     try
595     {
596       (*iter)->notify(CORBA::string_dup(event_name.c_str()),
597                       CORBA::string_dup(event_data.c_str()));
598     }
599     catch (...)
600     {
601        MESSAGE("Notify Observer, exception catch");
602     }
603     iter++;
604   }
605
606 }
607
608 JobParameters_cpp
609 SALOME_Launcher::JobParameters_CORBA2CPP(
610                                    const Engines::JobParameters& job_parameters)
611 {
612   JobParameters_cpp result;
613
614   result.job_name = job_parameters.job_name.in();
615   result.job_type = job_parameters.job_type.in();
616   result.job_file = job_parameters.job_file.in();
617   result.pre_command = job_parameters.pre_command.in();
618   result.env_file = job_parameters.env_file.in();
619
620   result.in_files.clear();
621   for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
622     result.in_files.push_back(job_parameters.in_files[i].in());
623   result.out_files.clear();
624   for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
625     result.out_files.push_back(job_parameters.out_files[i].in());
626
627   result.work_directory = job_parameters.work_directory.in();
628   result.local_directory = job_parameters.local_directory.in();
629   result.result_directory = job_parameters.result_directory.in();
630   result.maximum_duration = job_parameters.maximum_duration.in();
631
632   result.resource_required = resourceParameters_CORBAtoCPP(job_parameters.resource_required);
633
634   result.queue = job_parameters.queue.in();
635   result.partition = job_parameters.partition.in();
636   result.exclusive = job_parameters.exclusive;
637   result.mem_per_cpu = job_parameters.mem_per_cpu;
638   result.wckey = job_parameters.wckey.in();
639   result.extra_params = job_parameters.extra_params.in();
640
641   result.specific_parameters.clear();
642   for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
643     result.specific_parameters[job_parameters.specific_parameters[i].name.in()]
644                              = job_parameters.specific_parameters[i].value.in();
645
646   result.launcher_file = job_parameters.launcher_file.in();
647   result.launcher_args = job_parameters.launcher_args.in();
648   return result;
649 }
650
651 Engines::JobParameters_var
652 SALOME_Launcher::JobParameters_CPP2CORBA(const JobParameters_cpp& job_parameters)
653 {
654   Engines::JobParameters_var result = new Engines::JobParameters;
655   result->job_name = CORBA::string_dup(job_parameters.job_name.c_str());
656   result->job_type = CORBA::string_dup(job_parameters.job_type.c_str());
657   result->job_file = CORBA::string_dup(job_parameters.job_file.c_str());
658   result->pre_command = CORBA::string_dup(job_parameters.pre_command.c_str());
659   result->env_file = CORBA::string_dup(job_parameters.env_file.c_str());
660   result->in_files.length((CORBA::ULong)job_parameters.in_files.size()); //!< TODO: conversion from size_t to CORBA::ULong
661
662   int i = 0;
663   for(const std::string& it : job_parameters.in_files)
664   {
665     result->in_files[i] = CORBA::string_dup(it.c_str());
666     i++;
667   }
668   result->out_files.length((CORBA::ULong)job_parameters.out_files.size()); //!< TODO: conversion from size_t to CORBA::ULong
669   i = 0;
670   for(const std::string& it : job_parameters.out_files)
671   {
672     result->out_files[i] = CORBA::string_dup(it.c_str());
673     i++;
674   }
675
676   result->work_directory = CORBA::string_dup(job_parameters.work_directory.c_str());
677   result->local_directory = CORBA::string_dup(job_parameters.local_directory.c_str());
678   result->result_directory = CORBA::string_dup(job_parameters.result_directory.c_str());
679   result->maximum_duration = CORBA::string_dup(job_parameters.maximum_duration.c_str());
680
681   result->resource_required = resourceParameters_CPPtoCORBA(job_parameters.resource_required);
682
683   result->queue = CORBA::string_dup(job_parameters.queue.c_str());
684   result->partition = CORBA::string_dup(job_parameters.partition.c_str());
685   result->exclusive = job_parameters.exclusive;
686   result->mem_per_cpu = job_parameters.mem_per_cpu;
687   result->wckey = CORBA::string_dup(job_parameters.wckey.c_str());
688   result->extra_params = CORBA::string_dup(job_parameters.extra_params.c_str());
689
690   const std::map<std::string, std::string>& specific_parameters
691                                        = job_parameters.specific_parameters;
692   if (!specific_parameters.empty())
693   {
694     result->specific_parameters.length((CORBA::ULong)specific_parameters.size()); //!< TODO: conversion from size_t to CORBA::ULong
695     CORBA::ULong i = 0;
696     for (const auto& it_specific : specific_parameters)
697     {
698       Engines::Parameter_var new_param = new Engines::Parameter;
699       new_param->name  = CORBA::string_dup(it_specific.first.c_str());
700       new_param->value = CORBA::string_dup(it_specific.second.c_str());
701       result->specific_parameters[i] = new_param;
702       i++;
703     }
704   }
705
706   result->launcher_file = CORBA::string_dup(job_parameters.launcher_file.c_str());
707   result->launcher_args = CORBA::string_dup(job_parameters.launcher_args.c_str());
708   return result;
709 }
710
711 static SALOME_Launcher *_launcher_singleton_ssl = nullptr;
712
713 #include "SALOME_Fake_NamingService.hxx"
714
715 SALOME_Launcher *KERNEL::getLauncherSA()
716 {
717   if(!_launcher_singleton_ssl)
718   {
719     CORBA::ORB_var orb = KERNEL::GetRefToORB();
720     //[EDF26673] : do not release the POA object returned by _the_root_poa.
721     PortableServer::POA_ptr root_poa = PortableServer::POA::_the_root_poa();
722     PortableServer::POAManager_var pman = root_poa->the_POAManager();
723     CORBA::PolicyList policies;
724     policies.length(1);
725     PortableServer::ThreadPolicy_var threadPol(root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
726     policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
727     PortableServer::POA_var safePOA = root_poa->create_POA("SingleThreadPOA",
728                                                            pman,
729                                                            policies);
730     threadPol->destroy();
731     SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService(orb);
732     _launcher_singleton_ssl = new SALOME_Launcher(orb,safePOA,ns);//3rd arg is important to skip NS !
733   }
734   return _launcher_singleton_ssl;
735 }