Salome HOME
First version before plugging.
[modules/kernel.git] / src / Container / SALOME_ContainerManager.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, 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_ContainerManager.hxx"
24 #include "SALOME_ResourcesManager.hxx"
25 #include "SALOME_LoadRateManager.hxx"
26 #include "SALOME_NamingService.hxx"
27 #include "SALOME_ResourcesManager_Client.hxx"
28 #include "SALOME_ModuleCatalog.hh"
29 #include "Basics_Utils.hxx"
30 #include "Basics_DirUtils.hxx"
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <signal.h>
34 #ifndef WIN32
35 #include <unistd.h>
36 #endif
37 #include <vector>
38 #include "Utils_CorbaException.hxx"
39 #include <sstream>
40 #include <string>
41
42 #include <SALOMEconfig.h>
43 #include CORBA_CLIENT_HEADER(SALOME_Session)
44
45 #ifdef WIN32
46 #include <process.h>
47 #define getpid _getpid
48 #endif
49
50 #ifdef WITH_PACO_PARALLEL
51 #include "PaCOPP.hxx"
52 #endif
53
54 const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60;
55
56 const char *SALOME_ContainerManager::_ContainerManagerNameInNS = 
57   "/ContainerManager";
58
59 omni_mutex SALOME_ContainerManager::_numInstanceMutex;
60
61 Utils_Mutex SALOME_ContainerManager::_getenvMutex;
62
63 Utils_Mutex SALOME_ContainerManager::_systemMutex;
64
65 //=============================================================================
66 /*! 
67  *  Constructor
68  *  \param orb
69  *  Define a CORBA single thread policy for the server, which avoid to deal
70  *  with non thread-safe usage like Change_Directory in SALOME naming service
71  */
72 //=============================================================================
73
74 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns)
75   : _nbprocUsed(1)
76 {
77   MESSAGE("constructor");
78   _NS = ns;
79   _resManager = new SALOME_ResourcesManager_Client(ns);
80
81   PortableServer::POAManager_var pman = poa->the_POAManager();
82   _orb = CORBA::ORB::_duplicate(orb) ;
83   CORBA::PolicyList policies;
84   policies.length(1);
85   PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL));
86   policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
87
88   _poa = poa->create_POA("MThreadPOA",pman,policies);
89   threadPol->destroy();
90   PortableServer::ObjectId_var id = _poa->activate_object(this);
91   CORBA::Object_var obj = _poa->id_to_reference(id);
92   Engines::ContainerManager_var refContMan =
93     Engines::ContainerManager::_narrow(obj);
94
95   _NS->Register(refContMan,_ContainerManagerNameInNS);
96   _isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0);
97
98 #ifdef HAVE_MPI2
99 #ifdef WITHOPENMPI
100   _pid_mpiServer = -1;
101   // the urifile name depends on pid of the process
102   std::stringstream urifile;
103   urifile << GetenvThreadSafe("HOME") << "/.urifile_" << getpid();
104   setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
105   if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
106     // get the pid of all ompi-server
107     std::set<pid_t> thepids1 = getpidofprogram("ompi-server");
108     // launch a new ompi-server
109     std::string command;
110     command = "ompi-server -r ";
111     command += GetenvThreadSafe("OMPI_URI_FILE");
112     int status=SystemThreadSafe(command.c_str());
113     if(status!=0)
114       throw SALOME_Exception("Error when launching ompi-server");
115     // get the pid of all ompi-server
116     std::set<pid_t> thepids2 = getpidofprogram("ompi-server");
117     // my ompi-server is the new one
118     std::set<pid_t>::const_iterator it;
119     for(it=thepids2.begin();it!=thepids2.end();it++)
120       if(thepids1.find(*it) == thepids1.end())
121         _pid_mpiServer = *it;
122     if(_pid_mpiServer < 0)
123       throw SALOME_Exception("Error when getting ompi-server id");
124   }
125 #elif defined(WITHMPICH)
126   _pid_mpiServer = -1;
127   // get the pid of all hydra_nameserver
128   std::set<pid_t> thepids1 = getpidofprogram("hydra_nameserver");
129   // launch a new hydra_nameserver
130   std::string command;
131   command = "hydra_nameserver &";
132   SystemThreadSafe(command.c_str());
133   // get the pid of all hydra_nameserver
134   std::set<pid_t> thepids2 = getpidofprogram("hydra_nameserver");
135   // my hydra_nameserver is the new one
136   std::set<pid_t>::const_iterator it;
137   for(it=thepids2.begin();it!=thepids2.end();it++)
138     if(thepids1.find(*it) == thepids1.end())
139       _pid_mpiServer = *it;
140 #endif
141 #endif
142
143   MESSAGE("constructor end");
144 }
145
146 //=============================================================================
147 /*! 
148  * destructor
149  */
150 //=============================================================================
151
152 SALOME_ContainerManager::~SALOME_ContainerManager()
153 {
154   MESSAGE("destructor");
155   delete _resManager;
156 #ifdef HAVE_MPI2
157 #ifdef WITHOPENMPI
158   if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
159     // kill my ompi-server
160     if( kill(_pid_mpiServer,SIGTERM) != 0 )
161       throw SALOME_Exception("Error when killing ompi-server");
162     // delete my urifile
163     int status=SystemThreadSafe("rm -f ${OMPI_URI_FILE}");
164     if(status!=0)
165       throw SALOME_Exception("Error when removing urifile");
166   }
167 #elif defined(WITHMPICH)
168   // kill my hydra_nameserver
169   if(_pid_mpiServer > -1)
170     if( kill(_pid_mpiServer,SIGTERM) != 0 )
171       throw SALOME_Exception("Error when killing hydra_nameserver");
172 #endif
173 #endif
174 }
175
176 //=============================================================================
177 //! shutdown all the containers, then the ContainerManager servant
178 /*! CORBA method:
179  */
180 //=============================================================================
181
182 void SALOME_ContainerManager::Shutdown()
183 {
184   MESSAGE("Shutdown");
185   ShutdownContainers();
186   _NS->Destroy_Name(_ContainerManagerNameInNS);
187   PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
188   _poa->deactivate_object(oid);
189 }
190
191 //=============================================================================
192 //! Loop on all the containers listed in naming service, ask shutdown on each
193 /*! CORBA Method:
194  */
195 //=============================================================================
196
197 void SALOME_ContainerManager::ShutdownContainers()
198 {
199   MESSAGE("ShutdownContainers");
200
201   SALOME::Session_var session = SALOME::Session::_nil();
202   CORBA::Long pid = 0;
203   CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
204   if (!CORBA::is_nil(objS))
205   {
206     session = SALOME::Session::_narrow(objS);
207     if (!CORBA::is_nil(session))
208       pid = session->getPID();
209   }
210
211   bool isOK;
212   isOK = _NS->Change_Directory("/Containers");
213   if( isOK ){
214     std::vector<std::string> vec = _NS->list_directory_recurs();
215     std::list<std::string> lstCont;
216     for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
217       {
218         SCRUTE((*iter));
219         CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
220         try
221           {
222             Engines::Container_var cont=Engines::Container::_narrow(obj);
223             if(!CORBA::is_nil(cont) && pid != cont->getPID())
224               lstCont.push_back((*iter));
225           }
226         catch(const CORBA::Exception& e)
227           {
228             // ignore this entry and continue
229           }
230       }
231     MESSAGE("Container list: ");
232     for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
233       SCRUTE((*iter));
234     }
235     for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
236     {
237       try
238       {
239         SCRUTE((*iter));
240         CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
241         Engines::Container_var cont=Engines::Container::_narrow(obj);
242         if(!CORBA::is_nil(cont))
243         {
244           MESSAGE("ShutdownContainers: " << (*iter));
245           cont->Shutdown();
246         }
247         else 
248           MESSAGE("ShutdownContainers: no container ref for " << (*iter));
249       }
250       catch(CORBA::SystemException& e)
251       {
252         INFOS("CORBA::SystemException ignored : " << e);
253       }
254       catch(CORBA::Exception&)
255       {
256         INFOS("CORBA::Exception ignored.");
257       }
258       catch(...)
259       {
260         INFOS("Unknown exception ignored.");
261       }
262     }
263   }
264 }
265
266 //=============================================================================
267 //! Give a suitable Container given constraints
268 /*! CORBA Method:
269  *  \param params Container Parameters required for the container
270  *  \return the container or nil
271  */
272 //=============================================================================
273 Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
274 {
275   std::string machFile;
276   Engines::Container_ptr ret(Engines::Container::_nil());
277
278   // Step 0: Default mode is start
279   Engines::ContainerParameters local_params(params);
280   if (std::string(local_params.mode.in()) == "")
281     local_params.mode = CORBA::string_dup("start");
282   std::string mode = local_params.mode.in();
283   MESSAGE("[GiveContainer] starting with mode: " << mode);
284
285   // Step 1: Find Container for find and findorstart mode
286   if (mode == "find" || mode == "findorstart")
287   {
288     ret = FindContainer(params, params.resource_params.resList);
289     if(!CORBA::is_nil(ret))
290       return ret;
291     else
292     {
293       if (mode == "find")
294       {
295         MESSAGE("[GiveContainer] no container found");
296         return ret;
297       }
298       else
299       {
300         mode = "start";
301       }
302     }
303   }
304
305   // Step 2: Get all possibleResources from the parameters
306   // Consider only resources that can run containers
307   resourceParams resource_params = resourceParameters_CORBAtoCPP(local_params.resource_params);
308   resource_params.can_run_containers = true;
309   std::vector<std::string> possibleResources = _resManager->GetFittingResources(resource_params);
310   MESSAGE("[GiveContainer] - length of possible resources " << possibleResources.size());
311   std::vector<std::string> local_resources;
312
313   // Step 3: if mode is "get" keep only machines with existing containers 
314   if(mode == "get")
315   {
316     for(unsigned int i=0; i < possibleResources.size(); i++)
317     {
318       Engines::Container_ptr cont = FindContainer(params, possibleResources[i]);
319       try
320       {
321         if(!cont->_non_existent())
322           local_resources.push_back(possibleResources[i]);
323       }
324       catch(CORBA::Exception&) {}
325     }
326
327     // if local_resources is empty, we cannot give a container
328     if (local_resources.size() == 0)
329     {
330       MESSAGE("[GiveContainer] cannot find a container for mode get");
331       return ret;
332     }
333   }
334   else
335     local_resources = possibleResources;
336
337   // Step 4: select the resource where to get/start the container
338   bool resource_available = true;
339   std::string resource_selected;
340   std::vector<std::string> resources = local_resources;
341   while (resource_available)
342   {
343     if (resources.size() == 0)
344       resource_available = false;
345     else
346     {
347       try
348       {
349         resource_selected = _resManager->Find(params.resource_params.policy.in(), resources);
350         // Remove resource_selected from vector
351         std::vector<std::string>::iterator it;
352         for (it=resources.begin() ; it < resources.end(); it++ )
353           if (*it == resource_selected)
354           {
355             resources.erase(it);
356             break;
357           }
358       }
359       catch(const SALOME_Exception &ex)
360       {
361         MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
362         return ret;
363       }
364       MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
365
366       // Step 5: Create container name
367       ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
368       std::string hostname(resource_definition.HostName);
369       std::string containerNameInNS;
370       if(params.isMPI){
371         int nbproc;
372         if ( params.nb_proc <= 0 )
373           nbproc = 1;
374         else
375           nbproc = params.nb_proc;
376         try
377         {
378           if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
379             machFile = machinesFile(nbproc);
380         }
381         catch(const SALOME_Exception & ex)
382         {
383           std::string err_msg = ex.what();
384           err_msg += params.container_name;
385           INFOS(err_msg.c_str());
386           return ret;
387         }
388         // A mpi parallel container register on zero node in NS
389         containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
390       }
391       else
392         containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
393       MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
394
395       // Step 6: check if the name exists in naming service
396       //if params.mode == "getorstart" or "get" use the existing container
397       //if params.mode == "start" shutdown the existing container before launching a new one with that name
398
399       { // critical section
400         Utils_Locker lock (&_giveContainerMutex1);
401         CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
402         if (!CORBA::is_nil(obj))
403           {
404             try
405             {
406                 Engines::Container_var cont=Engines::Container::_narrow(obj);
407                 if(!cont->_non_existent())
408                   {
409                     if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
410                         return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
411                     }
412                     else
413                       {
414                         INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
415                         cont->Shutdown(); // shutdown the registered container if it exists
416                       }
417                   }
418             }
419             catch(CORBA::Exception&)
420             {
421                 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
422             }
423           }
424       } // end critical section
425       Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
426       if (!CORBA::is_nil(cont))
427       {
428         INFOS("[GiveContainer] container " << containerNameInNS << " launched");
429         return cont._retn();
430       }
431       else
432       {
433         INFOS("[GiveContainer] Failed to launch container on resource " << resource_selected);
434       }
435     }
436   }
437
438   // We were not able to launch the container
439   INFOS("[GiveContainer] Cannot launch the container on the following selected resources:")
440   std::vector<std::string>::iterator it;
441   for (it=local_resources.begin() ; it < local_resources.end(); it++ )
442     INFOS("[GiveContainer] " << *it)
443   return ret;
444 }
445
446 Engines::Container_ptr
447 SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
448                                          const std::string & resource_selected,
449                                          const std::string & hostname,
450                                          const std::string & machFile,
451                                          const std::string & containerNameInNS)
452 {
453   std::string user,command,logFilename,tmpFileName;
454   int status;
455   Engines::Container_ptr ret(Engines::Container::_nil());
456   {//start of critical section
457     Utils_Locker lock (&_giveContainerMutex1);
458     // Step 1: type of container: PaCO, Exe, Mpi or Classic
459     // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
460     // TODO -> separates Mpi from Classic/Exe
461     // Classic or Exe ?
462     std::string container_exe = "SALOME_Container"; // Classic container
463     Engines::ContainerParameters local_params(params);
464     int found=0;
465     try
466     {
467         CORBA::String_var container_exe_tmp;
468         CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
469         SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
470         if (CORBA::is_nil (Catalog))
471           {
472             INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
473             return ret;
474           }
475         // Loop through component list
476         for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
477           {
478             const char* compoi = local_params.resource_params.componentList[i];
479             SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
480             if (CORBA::is_nil (compoInfo))
481               {
482                 continue;
483               }
484             SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
485             container_exe_tmp=compoInfo->implementation_name();
486             if(impl==SALOME_ModuleCatalog::CEXE)
487               {
488                 if(found)
489                   {
490                     INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
491                     return Engines::Container::_nil();
492                   }
493                 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
494                 container_exe = container_exe_tmp.in();
495                 found=1;
496               }
497           }
498     }
499     catch (ServiceUnreachable&)
500     {
501         INFOS("Caught exception: Naming Service Unreachable");
502         return ret;
503     }
504     catch (...)
505     {
506         INFOS("Caught unknown exception.");
507         return ret;
508     }
509
510     // Step 2: test resource
511     // Only if an application directory is set
512     if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
513       {
514         // Preparing remote command
515         std::string command = "";
516         const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
517         command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
518         if (resInfo.AppliPath != "")
519           command += resInfo.AppliPath;
520         else
521           {
522             ASSERT(GetenvThreadSafe("APPLI"));
523             command += GetenvThreadSafe("APPLI");
524           }
525         command += "/runRemote.sh ";
526         ASSERT(GetenvThreadSafe("NSHOST"));
527         command += GetenvThreadSafe("NSHOST"); // hostname of CORBA name server
528         command += " ";
529         ASSERT(GetenvThreadSafe("NSPORT"));
530         command += GetenvThreadSafe("NSPORT"); // port of CORBA name server
531         command += " \"ls /tmp >/dev/null 2>&1\"";
532
533         // Launch remote command
534         int status = SystemThreadSafe(command.c_str());
535         if (status != 0)
536           {
537             // Error on resource - cannot launch commands
538             INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
539             INFOS("[LaunchContainer] Command was " << command);
540 #ifndef WIN32
541             INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
542 #endif
543             return Engines::Container::_nil();
544           }
545       }
546
547     // Step 3: start a new container
548     // Check if a PaCO container
549     // PaCO++
550     if (std::string(local_params.parallelLib.in()) != "")
551       {
552         ret = StartPaCOPPContainer(params, resource_selected);
553         return ret;
554       }
555     // Other type of containers...
556     MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
557     // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
558     if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL && params.isMPI )
559       command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
560     // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
561     else if(hostname == Kernel_Utils::GetHostname())
562       command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
563     // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
564     else
565       command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
566
567     //redirect stdout and stderr in a file
568 #ifdef WIN32
569     logFilename=GetenvThreadSafe("TEMP");
570     logFilename += "\\";
571     user = GetenvThreadSafe( "USERNAME" );
572 #else
573     user = GetenvThreadSafe( "USER" );
574     logFilename="/tmp";
575     char* val = GetenvThreadSafe("SALOME_TMP_DIR");
576     if(val)
577       {
578         struct stat file_info;
579         stat(val, &file_info);
580         bool is_dir = S_ISDIR(file_info.st_mode);
581         if (is_dir)logFilename=val;
582         else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
583       }
584     logFilename += "/";
585 #endif
586     logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
587     std::ostringstream tmp;
588     tmp << "_" << getpid();
589     logFilename += tmp.str();
590     logFilename += ".log" ;
591     command += " > " + logFilename + " 2>&1";
592     MakeTheCommandToBeLaunchedASync(command);
593
594     // launch container with a system call
595     status=SystemThreadSafe(command.c_str());
596   }//end of critical of section
597
598   if (status == -1)
599     {
600       INFOS("[LaunchContainer] command failed (system command status -1): " << command);
601       RmTmpFile(tmpFileName); // command file can be removed here
602       return Engines::Container::_nil();
603     }
604   else if (status == 217)
605     {
606       INFOS("[LaunchContainer] command failed (system command status 217): " << command);
607       RmTmpFile(tmpFileName); // command file can be removed here
608       return Engines::Container::_nil();
609     }
610   else
611     {
612       // Step 4: Wait for the container
613       int count(GetTimeOutToLoaunchServer());
614       INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS);
615       while (CORBA::is_nil(ret) && count)
616         {
617           SleepInSecond(1);
618           count--;
619           MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected);
620           CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str()));
621           ret=Engines::Container::_narrow(obj);
622         }
623       if (CORBA::is_nil(ret))
624         {
625           INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
626         }
627       else
628         {
629           // Setting log file name
630           logFilename=":"+logFilename;
631           logFilename="@"+Kernel_Utils::GetHostname()+logFilename;//threadsafe
632           logFilename=user+logFilename;
633           ret->logfilename(logFilename.c_str());
634           RmTmpFile(tmpFileName); // command file can be removed here
635         }
636     }
637   return ret;
638 }
639
640 //=============================================================================
641 //! Find a container given constraints (params) on a list of machines (possibleComputers)
642 //! agy : this method is ThreadSafe
643 /*!
644  *
645  */
646 //=============================================================================
647
648 Engines::Container_ptr SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const Engines::ResourceList& possibleResources)
649 {
650   MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
651   for(unsigned int i=0; i < possibleResources.length();i++)
652     {
653       Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
654       if(!CORBA::is_nil(cont))
655         return cont;
656     }
657   MESSAGE("[FindContainer] no container found");
658   return Engines::Container::_nil();
659 }
660
661 //=============================================================================
662 //! Find a container given constraints (params) on a machine (theMachine)
663 //! agy : this method is ThreadSafe
664 /*!
665  *
666  */
667 //=============================================================================
668
669 Engines::Container_ptr
670 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const std::string& resource)
671 {
672   ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource);
673   std::string hostname(resource_definition.HostName);
674   std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
675   MESSAGE("[FindContainer] Try to find a container  " << containerNameInNS << " on resource " << resource);
676   CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
677   try
678   {
679     if(obj->_non_existent())
680       return Engines::Container::_nil();
681     else
682       return Engines::Container::_narrow(obj);
683   }
684   catch(const CORBA::Exception& e)
685   {
686     return Engines::Container::_nil();
687   }
688 }
689
690
691 bool isPythonContainer(const char* ContainerName);
692
693 //=============================================================================
694 /*!
695  *  This is no longer valid (C++ container are also python containers)
696  */ 
697 //=============================================================================
698 bool isPythonContainer(const char* ContainerName)
699 {
700   return false; // VSR 02/08/2013: Python containers are no more supported
701   bool ret = false;
702   int len = strlen(ContainerName);
703
704   if (len >= 2)
705     if (strcmp(ContainerName + len - 2, "Py") == 0)
706       ret = true;
707
708   return ret;
709 }
710
711 //=============================================================================
712 /*!
713  *  Builds the script to be launched
714  *
715  *  If SALOME Application not defined ($APPLI),
716  *  see BuildTempFileToLaunchRemoteContainer()
717  *
718  *  Else rely on distant configuration. Command is under the form (example):
719  *  ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
720  *                   SALOME_Container containerName &"
721
722  *  - where user is ommited if not specified in CatalogResources,
723  *  - where distant path is always relative to user@machine $HOME, and
724  *    equal to $APPLI if not specified in CatalogResources,
725  *  - where hostNS is the hostname of CORBA naming server (set by scripts to
726  *    use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
727  *  - where portNS is the port used by CORBA naming server (set by scripts to
728  *    use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
729  *  - where workingdir is the requested working directory for the container.
730  *    If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
731  */ 
732 //=============================================================================
733
734 std::string
735 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& resource_name, const Engines::ContainerParameters& params, const std::string& container_exe) const
736 {
737   std::string command,tmpFileName;
738   if (!_isAppliSalomeDefined)
739     command = BuildTempFileToLaunchRemoteContainer(resource_name, params, tmpFileName);
740   else
741   {
742     int nbproc;
743     const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
744
745     if (params.isMPI)
746     {
747       if ( params.nb_proc <= 0 )
748         nbproc = 1;
749       else
750         nbproc = params.nb_proc;
751     }
752
753     // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
754     //  SALOME_Container containerName &"
755     command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
756
757     if (resInfo.AppliPath != "")
758       command += resInfo.AppliPath; // path relative to user@machine $HOME
759     else
760     {
761       ASSERT(GetenvThreadSafe("APPLI"));
762       command += GetenvThreadSafe("APPLI"); // path relative to user@machine $HOME
763     }
764
765     command += "/runRemote.sh ";
766
767     ASSERT(GetenvThreadSafe("NSHOST"));
768     command += GetenvThreadSafe("NSHOST"); // hostname of CORBA name server
769
770     command += " ";
771     ASSERT(GetenvThreadSafe("NSPORT"));
772     command += GetenvThreadSafe("NSPORT"); // port of CORBA name server
773
774     std::string wdir = params.workingdir.in();
775     if(wdir != "")
776     {
777       command += " WORKINGDIR ";
778       command += " '";
779       if(wdir == "$TEMPDIR")
780         wdir="\\$TEMPDIR";
781       command += wdir; // requested working directory
782       command += "'"; 
783     }
784
785     if(params.isMPI)
786     {
787       command += " mpirun -np ";
788       std::ostringstream o;
789       o << nbproc << " ";
790       command += o.str();
791 #ifdef WITHLAM
792       command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
793 #elif defined(WITHOPENMPI)
794       if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
795         command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
796       else{
797         command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
798         command += GetenvThreadSafe("OMPI_URI_FILE");
799       }
800 #elif defined(WITHMPICH)
801       command += "-nameserver " + Kernel_Utils::GetHostname();
802 #endif        
803       command += " SALOME_MPIContainer ";
804     }
805     else
806       command += " " +container_exe+ " ";
807
808     command += _NS->ContainerName(params);
809     command += " -";
810     AddOmninamesParams(command);
811
812     MESSAGE("command =" << command);
813   }
814
815   return command;
816 }
817
818 //=============================================================================
819 /*!
820  *  builds the command to be launched.
821  */ 
822 //=============================================================================
823 std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe, std::string& tmpFileName) const
824 {
825   tmpFileName = BuildTemporaryFileName();
826   std::string command;
827   int nbproc = 0;
828
829   std::ostringstream o;
830
831   if (params.isMPI)
832     {
833       o << "mpirun -np ";
834
835       if ( params.nb_proc <= 0 )
836         nbproc = 1;
837       else
838         nbproc = params.nb_proc;
839
840       o << nbproc << " ";
841
842       if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
843         o << "-machinefile " << machinesFile << " ";
844
845 #ifdef WITHLAM
846       o << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
847 #elif defined(WITHOPENMPI)
848       if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
849         o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
850       else
851         {
852           o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
853           o << GetenvThreadSafe("OMPI_URI_FILE");
854         }
855 #elif defined(WITHMPICH)
856       o << "-nameserver " + Kernel_Utils::GetHostname();
857 #endif
858
859       if (isPythonContainer(params.container_name))
860         o << " pyMPI SALOME_ContainerPy.py ";
861       else
862         o << " SALOME_MPIContainer ";
863     }
864
865   else
866     {
867       std::string wdir=params.workingdir.in();
868       if(wdir != "")
869         {
870           // a working directory is requested
871           if(wdir == "$TEMPDIR")
872             {
873               // a new temporary directory is requested
874               std::string dir = Kernel_Utils::GetTmpDir();
875 #ifdef WIN32
876               o << "cd /d " << dir << std::endl;
877 #else
878               o << "cd " << dir << ";";
879 #endif
880
881             }
882           else
883             {
884               // a permanent directory is requested use it or create it
885 #ifdef WIN32
886               o << "mkdir " + wdir << std::endl;
887               o << "cd /D " + wdir << std::endl;
888 #else
889               o << "mkdir -p " << wdir << " && cd " << wdir + ";";
890 #endif
891             }
892         }
893
894       if (isPythonContainer(params.container_name))
895         o << "SALOME_ContainerPy.py ";
896       else
897         o << container_exe + " ";
898
899     }
900
901   o << _NS->ContainerName(params);
902   o << " -";
903   AddOmninamesParams(o);
904
905   std::ofstream command_file( tmpFileName.c_str() );
906   command_file << o.str();
907   command_file.close();
908
909 #ifndef WIN32
910   chmod(tmpFileName.c_str(), 0x1ED);
911 #endif
912   command = tmpFileName;
913
914   MESSAGE("Command is file ... " << command);
915   MESSAGE("Command is ... " << o.str());
916   return command;
917 }
918
919
920 //=============================================================================
921 /*!
922  *  removes the generated temporary file in case of a remote launch.
923  *  This method is thread safe
924  */ 
925 //=============================================================================
926
927 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
928 {
929   int lenght = tmpFileName.size();
930   if ( lenght  > 0)
931     {
932 #ifdef WIN32
933       std::string command = "del /F ";
934 #else
935       std::string command = "rm ";      
936 #endif
937       if ( lenght > 4 )
938         command += tmpFileName.substr(0, lenght - 3 );
939       else
940         command += tmpFileName;
941       command += '*';
942       SystemThreadSafe(command.c_str());
943       //if dir is empty - remove it
944       std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
945       if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
946         {
947 #ifdef WIN32
948           command = "del /F " + tmp_dir;
949 #else
950           command = "rmdir " + tmp_dir;
951 #endif
952           SystemThreadSafe(command.c_str());
953         }
954     }
955 }
956
957 //=============================================================================
958 /*!
959  *   add to command all options relative to naming service.
960  */ 
961 //=============================================================================
962
963 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
964 {
965   std::ostringstream oss;
966   AddOmninamesParams(oss);
967   command+=oss.str();
968 }
969
970 //=============================================================================
971 /*!
972  *  add to command all options relative to naming service.
973  */ 
974 //=============================================================================
975
976 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const
977 {
978   AddOmninamesParams(fileStream,_NS);
979 }
980
981 //=============================================================================
982 /*!
983  *  add to command all options relative to naming service.
984  */ 
985 //=============================================================================
986
987 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns)
988 {
989   CORBA::String_var iorstr(ns->getIORaddr());
990   fileStream << "ORBInitRef NameService=";
991   fileStream << iorstr;
992 }
993
994 void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command)
995 {
996 #ifdef WIN32
997     command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
998 #else
999     command += " &";
1000 #endif
1001 }
1002
1003 int SALOME_ContainerManager::GetTimeOutToLoaunchServer()
1004 {
1005   int count(TIME_OUT_TO_LAUNCH_CONT);
1006   if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
1007     {
1008       std::string new_count_str(GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER"));
1009       int new_count;
1010       std::istringstream ss(new_count_str);
1011       if (!(ss >> new_count))
1012         {
1013           INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
1014         }
1015       else
1016         count = new_count;
1017     }
1018   return count;
1019 }
1020
1021 void SALOME_ContainerManager::SleepInSecond(int ellapseTimeInSecond)
1022 {
1023 #ifndef WIN32
1024   sleep( ellapseTimeInSecond ) ;
1025 #else
1026   int timeInMS(1000*ellapseTimeInSecond);
1027   Sleep(timeInMS);
1028 #endif
1029 }
1030
1031 //=============================================================================
1032 /*!
1033  *  generate a file name in /tmp directory
1034  */ 
1035 //=============================================================================
1036
1037 std::string SALOME_ContainerManager::BuildTemporaryFileName()
1038 {
1039   //build more complex file name to support multiple salome session
1040   std::string aFileName = Kernel_Utils::GetTmpFileName();
1041 #ifndef WIN32
1042   aFileName += ".sh";
1043 #else
1044   aFileName += ".bat";
1045 #endif
1046   return aFileName;
1047 }
1048
1049 //=============================================================================
1050 /*!
1051  *  Builds in a temporary file the script to be launched.
1052  *  
1053  *  Used if SALOME Application ($APPLI) is not defined.
1054  *  The command is build with data from CatalogResources, in which every path
1055  *  used on remote computer must be defined.
1056  */ 
1057 //=============================================================================
1058
1059 std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const
1060 {
1061   int status;
1062
1063   tmpFileName = BuildTemporaryFileName();
1064   std::ofstream tempOutputFile;
1065   tempOutputFile.open(tmpFileName.c_str(), std::ofstream::out );
1066   const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
1067   tempOutputFile << "#! /bin/sh" << std::endl;
1068
1069   // --- set env vars
1070
1071   tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1072   //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1073
1074   // ! env vars
1075
1076   if (params.isMPI)
1077     {
1078       tempOutputFile << "mpirun -np ";
1079       int nbproc;
1080
1081       if ( params.nb_proc <= 0 )
1082         nbproc = 1;
1083       else
1084         nbproc = params.nb_proc;
1085
1086       std::ostringstream o;
1087
1088       tempOutputFile << nbproc << " ";
1089 #ifdef WITHLAM
1090       tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1091 #elif defined(WITHOPENMPI)
1092       if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
1093         tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1094       else{
1095         tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1096         tempOutputFile << GetenvThreadSafe("OMPI_URI_FILE");
1097       }
1098 #elif defined(WITHMPICH)
1099       tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
1100 #endif
1101     }
1102
1103   tempOutputFile << GetenvThreadSafe("KERNEL_ROOT_DIR") << "/bin/salome/";
1104
1105   if (params.isMPI)
1106     {
1107       if (isPythonContainer(params.container_name))
1108         tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1109       else
1110         tempOutputFile << " SALOME_MPIContainer ";
1111     }
1112
1113   else
1114     {
1115       if (isPythonContainer(params.container_name))
1116         tempOutputFile << "SALOME_ContainerPy.py ";
1117       else
1118         tempOutputFile << "SALOME_Container ";
1119     }
1120
1121   tempOutputFile << _NS->ContainerName(params) << " -";
1122   AddOmninamesParams(tempOutputFile);
1123   tempOutputFile << " &" << std::endl;
1124   tempOutputFile.flush();
1125   tempOutputFile.close();
1126 #ifndef WIN32
1127   chmod(tmpFileName.c_str(), 0x1ED);
1128 #endif
1129
1130   // --- Build command
1131
1132   std::string command;
1133
1134   if (resInfo.Protocol == rsh)
1135     {
1136       command = "rsh ";
1137       std::string commandRcp = "rcp ";
1138       commandRcp += tmpFileName;
1139       commandRcp += " ";
1140       commandRcp += resInfo.HostName;
1141       commandRcp += ":";
1142       commandRcp += tmpFileName;
1143       status = SystemThreadSafe(commandRcp.c_str());
1144     }
1145
1146   else if (resInfo.Protocol == ssh)
1147     {
1148       command = "ssh ";
1149       std::string commandRcp = "scp ";
1150       commandRcp += tmpFileName;
1151       commandRcp += " ";
1152       commandRcp += resInfo.HostName;
1153       commandRcp += ":";
1154       commandRcp += tmpFileName;
1155       status = SystemThreadSafe(commandRcp.c_str());
1156     }
1157
1158   else if (resInfo.Protocol == srun)
1159     {
1160       command = "srun -n 1 -N 1 --share --nodelist=";
1161       std::string commandRcp = "rcp ";
1162       commandRcp += tmpFileName;
1163       commandRcp += " ";
1164       commandRcp += resInfo.HostName;
1165       commandRcp += ":";
1166       commandRcp += tmpFileName;
1167       status = SystemThreadSafe(commandRcp.c_str());
1168     }
1169   else
1170     throw SALOME_Exception("Unknown protocol");
1171
1172   if(status)
1173     throw SALOME_Exception("Error of connection on remote host");    
1174
1175   command += resInfo.HostName;
1176   command += " ";
1177   command += tmpFileName;
1178
1179   SCRUTE(command);
1180
1181   return command;
1182
1183 }
1184
1185 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile) const
1186 {
1187   int status;
1188   std::string zeronode;
1189   std::string command;
1190   std::string tmpFile = BuildTemporaryFileName();
1191
1192   if( GetenvThreadSafe("LIBBATCH_NODEFILE") == NULL )
1193     {
1194       if (_isAppliSalomeDefined)
1195         {
1196           const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
1197
1198           if (resInfo.Protocol == rsh)
1199             command = "rsh ";
1200           else if (resInfo.Protocol == ssh)
1201             command = "ssh ";
1202           else if (resInfo.Protocol == srun)
1203             command = "srun -n 1 -N 1 --share --nodelist=";
1204           else
1205             throw SALOME_Exception("Unknown protocol");
1206
1207           if (resInfo.UserName != "")
1208             {
1209               command += "-l ";
1210               command += resInfo.UserName;
1211               command += " ";
1212             }
1213
1214           command += resInfo.HostName;
1215           command += " ";
1216
1217           if (resInfo.AppliPath != "")
1218             command += resInfo.AppliPath; // path relative to user@machine $HOME
1219           else
1220             {
1221               ASSERT(GetenvThreadSafe("APPLI"));
1222               command += GetenvThreadSafe("APPLI"); // path relative to user@machine $HOME
1223             }
1224
1225           command += "/runRemote.sh ";
1226
1227           ASSERT(GetenvThreadSafe("NSHOST"));
1228           command += GetenvThreadSafe("NSHOST"); // hostname of CORBA name server
1229
1230           command += " ";
1231           ASSERT(GetenvThreadSafe("NSPORT"));
1232           command += GetenvThreadSafe("NSPORT"); // port of CORBA name server
1233
1234           command += " mpirun -np 1 hostname -s > " + tmpFile;
1235         }
1236       else
1237         command = "mpirun -np 1 hostname -s > " + tmpFile;
1238     }
1239   else
1240     command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
1241
1242   status = SystemThreadSafe(command.c_str());
1243   if( status == 0 ){
1244     std::ifstream fp(tmpFile.c_str(),std::ios::in);
1245     while(fp >> zeronode);
1246   }
1247
1248   RmTmpFile(tmpFile);
1249
1250   return zeronode;
1251 }
1252
1253 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1254 {
1255   std::string tmp;
1256   std::string nodesFile = GetenvThreadSafe("LIBBATCH_NODEFILE");
1257   std::string machinesFile = Kernel_Utils::GetTmpFileName();
1258   std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1259   std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1260
1261   _numInstanceMutex.lock();
1262
1263   for(int i=0;i<_nbprocUsed;i++)
1264     fpi >> tmp;
1265
1266   for(int i=0;i<nbproc;i++)
1267     if( fpi >> tmp )
1268       fpo << tmp << std::endl;
1269     else
1270       throw SALOME_Exception("You need more processors than batch session have allocated for you! Unable to launch the mpi container: ");
1271
1272   _nbprocUsed += nbproc;
1273   fpi.close();
1274   fpo.close();
1275
1276   _numInstanceMutex.unlock();
1277
1278   return machinesFile;
1279
1280 }
1281
1282 std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string program)
1283 {
1284   std::set<pid_t> thepids;
1285   std::string tmpFile = Kernel_Utils::GetTmpFileName();
1286   std::string cmd;
1287   std::string thepid;
1288   cmd = "pidof " + program + " > " + tmpFile;
1289   SystemThreadSafe(cmd.c_str());
1290   std::ifstream fpi(tmpFile.c_str(),std::ios::in);
1291   while(fpi >> thepid){
1292     thepids.insert(atoi(thepid.c_str()));
1293   }
1294   return thepids;
1295 }
1296
1297 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
1298                                                                   const std::string & hostname,
1299                                                                   const std::string & username)
1300 {
1301   std::ostringstream command;
1302   switch (protocol)
1303   {
1304   case rsh:
1305     command << "rsh ";
1306     if (username != "")
1307     {
1308       command << "-l " << username << " ";
1309     }
1310     command << hostname << " ";
1311     break;
1312   case ssh:
1313     command << "ssh ";
1314     if (username != "")
1315     {
1316       command << "-l " << username << " ";
1317     }
1318     command << hostname << " ";
1319     break;
1320   case srun:
1321     // no need to redefine the user with srun, the job user is taken by default
1322     // (note: for srun, user id can be specified with " --uid=<user>")
1323     command << "srun -n 1 -N 1 --share --nodelist=" << hostname << " ";
1324     break;
1325   case pbsdsh:
1326     command << "pbsdsh -o -h " << hostname << " ";
1327     break;
1328   case blaunch:
1329     command << "blaunch -no-shell " << hostname << " ";
1330     break;
1331   default:
1332     throw SALOME_Exception("Unknown protocol");
1333   }
1334
1335   return command.str();
1336 }
1337
1338 bool 
1339 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1340 {
1341   bool result = true;
1342  
1343   // Step 1 : check ContainerParameters
1344   // Check container_name, has to be defined
1345   if (std::string(params.container_name.in()) == "")
1346   {
1347     INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1348     result = false;
1349   }
1350   // Check parallelLib
1351   std::string parallelLib = params.parallelLib.in();
1352   if (parallelLib != "Mpi" && parallelLib != "Dummy")
1353   {
1354     INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1355     INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1356     INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1357     result = false;
1358   }
1359   // Check nb_proc
1360   if (params.nb_proc <= 0)
1361   {
1362     INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1363     result = false;
1364   }
1365
1366   // Step 2 : check resource_selected
1367   const ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
1368   //std::string protocol = resource_definition->protocol.in();
1369   std::string username = resource_definition.UserName;
1370   std::string applipath = resource_definition.AppliPath;
1371
1372   //if (protocol == "" || username == "" || applipath == "")
1373   if (username == "" || applipath == "")
1374   {
1375     INFOS("[checkPaCOParameters] resource selected is not well defined");
1376     INFOS("[checkPaCOParameters] resource name: " << resource_definition.Name);
1377     INFOS("[checkPaCOParameters] resource hostname: " << resource_definition.HostName);
1378     INFOS("[checkPaCOParameters] resource protocol: " << resource_definition.getAccessProtocolTypeStr());
1379     INFOS("[checkPaCOParameters] resource username: " << username);
1380     INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1381     result = false;
1382   }
1383
1384   return result;
1385 }
1386
1387 char *SALOME_ContainerManager::GetenvThreadSafe(const char *name)
1388 {// getenv is not thread safe. See man 7 pthread.
1389   Utils_Locker lock (&_getenvMutex);
1390   return getenv(name);
1391 }
1392
1393 int SALOME_ContainerManager::SystemThreadSafe(const char *command)
1394 {
1395   Utils_Locker lock (&_systemMutex);
1396   return system(command);
1397 }
1398
1399 #ifdef WITH_PACO_PARALLEL
1400
1401 //=============================================================================
1402 /*! CORBA Method:
1403  *  Start a suitable PaCO++ Parallel Container in a list of machines.
1404  *  \param params           Container Parameters required for the container
1405  *  \return CORBA container reference.
1406  */
1407 //=============================================================================
1408 Engines::Container_ptr
1409 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1410                                               std::string resource_selected)
1411 {
1412   CORBA::Object_var obj;
1413   PaCO::InterfaceManager_var container_proxy;
1414   Engines::Container_ptr ret = Engines::Container::_nil();
1415   Engines::ContainerParameters params(params_const);
1416   params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1417
1418   // Step 0 : Check parameters
1419   if (!checkPaCOParameters(params, resource_selected))
1420   {
1421     INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1422     return ret;
1423   }
1424
1425   // Step 1 : Starting a new parallel container !
1426   INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1427   INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1428
1429   // Step 2 : Get a MachineFile for the parallel container
1430   std::string machine_file_name = _ResManager->getMachineFile(resource_selected, 
1431                                                               params.nb_proc,
1432                                                               params.parallelLib.in());
1433
1434   if (machine_file_name == "")
1435   {
1436     INFOS("[StartPaCOPPContainer] Machine file generation failed");
1437     return ret;
1438   }
1439
1440   // Step 3 : starting parallel container proxy
1441   std::string command_proxy("");
1442   std::string proxy_machine;
1443   try 
1444   {
1445     command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1446   }
1447   catch(const SALOME_Exception & ex)
1448   {
1449     INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1450     INFOS(ex.what());
1451     return ret;
1452   }
1453   obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1454   if (CORBA::is_nil(obj))
1455   {
1456     INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1457     return ret;
1458   }
1459   container_proxy = PaCO::InterfaceManager::_narrow(obj);
1460   MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1461
1462   // Step 4 : starting parallel container nodes
1463   std::string command_nodes("");
1464   SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1465   try 
1466   {
1467     command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1468   }
1469   catch(const SALOME_Exception & ex)
1470   {
1471     INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1472     INFOS(ex.what());
1473     return ret;
1474   }
1475
1476   std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1477   bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1478   if (!result)
1479   {
1480     INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1481     // Il faut tuer le proxy
1482     try 
1483     {
1484       Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1485       proxy->Shutdown();
1486     }
1487     catch (...)
1488     {
1489       INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
1490     }
1491     return ret;
1492   }
1493
1494   // Step 4 : connecting nodes and the proxy to actually create a parallel container
1495   for (int i = 0; i < params.nb_proc; i++) 
1496   {
1497     std::ostringstream tmp;
1498     tmp << i;
1499     std::string proc_number = tmp.str();
1500     std::string container_node_name = container_generic_node_name + proc_number;
1501
1502     std::string theNodeMachine(nodes_machines[i]);
1503     std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1504     obj = _NS->Resolve(containerNameInNS.c_str());
1505     if (CORBA::is_nil(obj)) 
1506     {
1507       INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1508       INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1509       return ret;
1510     }
1511     try
1512     {
1513       MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1514       PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1515       node->deploy();
1516       MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1517     }
1518     catch(CORBA::SystemException& e)
1519     {
1520       INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1521       INFOS("CORBA::SystemException : " << e);
1522       return ret;
1523     }
1524     catch(CORBA::Exception& e)
1525     {
1526       INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1527       INFOS("CORBA::Exception" << e);
1528       return ret;
1529     }
1530     catch(...)
1531     {
1532       INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1533       INFOS("Unknown exception !");
1534       return ret;
1535     }
1536   }
1537
1538   // Step 5 : starting parallel container
1539   try 
1540   {
1541     MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1542     container_proxy->start();
1543     MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1544     ret = Engines::Container::_narrow(container_proxy);
1545   }
1546   catch(CORBA::SystemException& e)
1547   {
1548     INFOS("Caught CORBA::SystemException. : " << e);
1549   }
1550   catch(PortableServer::POA::ServantAlreadyActive&)
1551   {
1552     INFOS("Caught CORBA::ServantAlreadyActiveException");
1553   }
1554   catch(CORBA::Exception&)
1555   {
1556     INFOS("Caught CORBA::Exception.");
1557   }
1558   catch(std::exception& exc)
1559   {
1560     INFOS("Caught std::exception - "<<exc.what()); 
1561   }
1562   catch(...)
1563   {
1564     INFOS("Caught unknown exception.");
1565   }
1566   return ret;
1567 }
1568
1569 std::string 
1570 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1571                                                                 std::string machine_file_name,
1572                                                                 std::string & proxy_hostname)
1573 {
1574   // In the proxy case, we always launch a Dummy Proxy
1575   std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1576   std::string container_name = params.container_name.in();
1577
1578   // Convert nb_proc in string
1579   std::ostringstream tmp_string;
1580   tmp_string << params.nb_proc;
1581   std::string nb_proc_str = tmp_string.str();
1582
1583   // Get resource definition
1584   Engines::ResourceDefinition_var resource_definition = 
1585     _ResManager->GetResourceDefinition(params.resource_params.name);
1586
1587   // Choose hostname
1588   std::string hostname;
1589   std::ifstream machine_file(machine_file_name.c_str());
1590   std::getline(machine_file, hostname, ' ');
1591   size_t found = hostname.find('\n');
1592   if (found!=std::string::npos)
1593     hostname.erase(found, 1); // Remove \n
1594   proxy_hostname = hostname;
1595   MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1596
1597   // Remote execution
1598   bool remote_execution = false;
1599   if (hostname != std::string(Kernel_Utils::GetHostname()))
1600   {
1601     MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1602     remote_execution = true;
1603   }
1604   
1605   // Log environnement
1606   std::string log_type("");
1607   char * get_val = GetenvThreadSafe("PARALLEL_LOG");
1608   if (get_val)
1609     log_type = get_val;
1610
1611   // Generating the command
1612   std::string command_begin("");
1613   std::string command_end("");
1614   std::ostringstream command;
1615
1616   LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1617   command << command_begin;
1618
1619   // Adding connection command
1620   // We can only have a remote execution with
1621   // a SALOME application
1622   if (remote_execution)
1623   {
1624     ASSERT(GetenvThreadSafe("NSHOST"));
1625     ASSERT(GetenvThreadSafe("NSPORT"));
1626
1627     command << resource_definition->protocol.in();
1628     command << " -l ";
1629     command << resource_definition->username.in();
1630     command << " " << hostname;
1631     command << " " << resource_definition->applipath.in();
1632     command << "/runRemote.sh ";
1633     command << GetenvThreadSafe("NSHOST") << " "; // hostname of CORBA name server
1634     command << GetenvThreadSafe("NSPORT") << " "; // port of CORBA name server
1635   }
1636
1637   command << exe_name;
1638   command << " " << container_name;
1639   command << " Dummy";
1640   command << " " << hostname;
1641   command << " " << nb_proc_str;
1642   command << " -";
1643   AddOmninamesParams(command);
1644
1645   // Final command
1646   command << command_end;
1647   MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1648
1649   return command.str();
1650 }
1651
1652 std::string 
1653 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1654                                                                const std::string & machine_file_name,
1655                                                                SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1656                                                                const std::string & proxy_hostname)
1657 {
1658   // Name of exe
1659   std::string exe_name = "SALOME_ParallelContainerNode";
1660   exe_name += params.parallelLib.in();
1661   std::string container_name = params.container_name.in();
1662
1663   // Convert nb_proc in string
1664   std::ostringstream nb_proc_stream;
1665   nb_proc_stream << params.nb_proc;
1666
1667   // Get resource definition
1668   Engines::ResourceDefinition_var resource_definition = 
1669     _ResManager->GetResourceDefinition(params.resource_params.name);
1670   
1671   // Log environnement
1672   std::string log_type("");
1673   char * get_val = GetenvThreadSafe("PARALLEL_LOG");
1674   if (get_val)
1675     log_type = get_val;
1676
1677   // Now the command is different according to paralleLib
1678   std::ostringstream command_nodes;
1679   std::ifstream machine_file(machine_file_name.c_str());
1680   if (std::string(params.parallelLib.in()) == "Dummy")
1681   {
1682     for (int i= 0; i < params.nb_proc; i++)
1683     {
1684       // Choose hostname
1685       std::string hostname;
1686       std::getline(machine_file, hostname);
1687       MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1688
1689       // Remote execution
1690       bool remote_execution = false;
1691       if (hostname != std::string(Kernel_Utils::GetHostname()))
1692       {
1693         MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1694         remote_execution = true;
1695       }
1696
1697       // For each node we have a new command
1698       // Generating the command
1699       std::ostringstream command_node_stream;
1700       std::string command_node_begin("");
1701       std::string command_node_end("");
1702       std::ostringstream node_number;
1703       node_number << i;
1704       std::string container_node_name = container_name + node_number.str();
1705       LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
1706
1707       // Adding connection command
1708       // We can only have a remote execution with
1709       // a SALOME application
1710       if (remote_execution)
1711       {
1712         ASSERT(GetenvThreadSafe("NSHOST"));
1713         ASSERT(GetenvThreadSafe("NSPORT"));
1714
1715         command_node_stream << resource_definition->protocol.in();
1716         command_node_stream << " -l ";
1717         command_node_stream << resource_definition->username.in();
1718         command_node_stream << " " << hostname;
1719         command_node_stream << " " << resource_definition->applipath.in();
1720         command_node_stream << "/runRemote.sh ";
1721         command_node_stream << GetenvThreadSafe("NSHOST") << " "; // hostname of CORBA name server
1722         command_node_stream << GetenvThreadSafe("NSPORT") << " "; // port of CORBA name server
1723       }
1724
1725       command_node_stream << exe_name;
1726       command_node_stream << " " << container_name;
1727       command_node_stream << " " << params.parallelLib.in();
1728       command_node_stream << " " << proxy_hostname;
1729       command_node_stream << " " << node_number.str();
1730       command_node_stream << " -";
1731       AddOmninamesParams(command_node_stream);
1732
1733       command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
1734       vect_machine.push_back(hostname);
1735     }
1736   }
1737
1738   else if (std::string(params.parallelLib.in()) == "Mpi")
1739   {
1740     // Choose hostname
1741     std::string hostname;
1742     std::getline(machine_file, hostname, ' ');
1743     MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1744
1745     // Remote execution
1746     bool remote_execution = false;
1747     if (hostname != std::string(Kernel_Utils::GetHostname()))
1748     {
1749       MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1750       remote_execution = true;
1751     }
1752
1753     // In case of Mpi and Remote, we copy machine_file in the applipath
1754     // scp mpi_machine_file user@machine:Path
1755     std::ostringstream command_remote_stream;
1756     std::string::size_type last = machine_file_name.find_last_of("/");
1757     if (last == std::string::npos)
1758       last = -1;
1759
1760     std::string protocol = resource_definition->protocol.in();
1761     if (protocol == "rsh")
1762       command_remote_stream << "rcp ";
1763     else 
1764       command_remote_stream << "scp ";
1765     command_remote_stream << machine_file_name << " ";
1766     command_remote_stream << resource_definition->username.in() << "@";
1767     command_remote_stream << hostname << ":" << resource_definition->applipath.in();
1768     command_remote_stream <<  "/" << machine_file_name.substr(last+1);
1769
1770     int status = SystemThreadSafe(command_remote_stream.str().c_str());
1771     if (status == -1)
1772     {
1773       INFOS("copy of the MPI machine file failed ! - sorry !");
1774       return "";
1775     }
1776
1777     // Generating the command
1778     std::string command_begin("");
1779     std::string command_end("");
1780
1781     LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
1782     command_nodes << command_begin;
1783
1784     // Adding connection command
1785     // We can only have a remote execution with
1786     // a SALOME application
1787     if (remote_execution)
1788     {
1789       ASSERT(GetenvThreadSafe("NSHOST"));
1790       ASSERT(GetenvThreadSafe("NSPORT"));
1791
1792       command_nodes << resource_definition->protocol.in();
1793       command_nodes << " -l ";
1794       command_nodes << resource_definition->username.in();
1795       command_nodes << " " << hostname;
1796       command_nodes << " " << resource_definition->applipath.in();
1797       command_nodes << "/runRemote.sh ";
1798       command_nodes << GetenvThreadSafe("NSHOST") << " "; // hostname of CORBA name server
1799       command_nodes << GetenvThreadSafe("NSPORT") << " "; // port of CORBA name server
1800     }
1801
1802     if (std::string(resource_definition->mpiImpl.in()) == "lam")
1803     {
1804       command_nodes << "mpiexec -ssi boot ";
1805       command_nodes << "-machinefile "  << machine_file_name << " "; 
1806       command_nodes <<  "-n " << params.nb_proc;
1807     }
1808     else
1809     {
1810       command_nodes << "mpirun -np " << params.nb_proc;
1811     }
1812     command_nodes << " " << exe_name;
1813     command_nodes << " " << container_name;
1814     command_nodes << " " << params.parallelLib.in();
1815     command_nodes << " " << proxy_hostname;
1816     command_nodes << " -";
1817     AddOmninamesParams(command_nodes);
1818
1819     // We don't put hostname, because nodes are registered in the resource of the proxy
1820     for (int i= 0; i < params.nb_proc; i++)
1821       vect_machine.push_back(proxy_hostname); 
1822
1823     command_nodes << command_end;
1824   }
1825   return command_nodes.str();
1826 }
1827
1828 void
1829 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1830                                           const std::string & exe_type,
1831                                           const std::string & container_name,
1832                                           const std::string & hostname,
1833                                           std::string & begin, 
1834                                           std::string & end)
1835 {
1836   if(log_type == "xterm")
1837   {
1838     begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1839     end   = "\"&";
1840   }
1841   else if(log_type == "xterm_debug")
1842   {
1843     begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1844     end   = "; cat \" &";
1845   }
1846   else
1847   {
1848     // default into a file...
1849     std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
1850     logFilename += std::string(GetenvThreadSafe("USER")) + ".log";
1851     end = " > " + logFilename + " 2>&1 & ";
1852   }
1853 }
1854
1855 CORBA::Object_ptr 
1856 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, 
1857                                                   const Engines::ContainerParameters& params,
1858                                                   const std::string & hostname)
1859 {
1860   PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
1861
1862   MESSAGE("[LaunchPaCOProxyContainer] Launch command");
1863   int status = SystemThreadSafe(command.c_str());
1864   if (status == -1) {
1865     INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
1866     return container_proxy;
1867   }
1868   else if (status == 217) {
1869     INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
1870     return container_proxy;
1871   }
1872
1873   int count(GetTimeOutToLoaunchServer());
1874   CORBA::Object_var obj = CORBA::Object::_nil();
1875   std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(), 
1876                                                                hostname.c_str());
1877   MESSAGE("[LaunchParallelContainer]  Waiting for Parallel Container proxy : " << containerNameInNS);
1878
1879   while (CORBA::is_nil(obj) && count) 
1880   {
1881     sleep(1);
1882     count--;
1883     obj = _NS->Resolve(containerNameInNS.c_str());
1884   }
1885
1886   try 
1887   {
1888     container_proxy = PaCO::InterfaceManager::_narrow(obj);
1889   }
1890   catch(CORBA::SystemException& e)
1891   {
1892     INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1893     INFOS("CORBA::SystemException : " << e);
1894     return container_proxy;
1895   }
1896   catch(CORBA::Exception& e)
1897   {
1898     INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1899     INFOS("CORBA::Exception" << e);
1900     return container_proxy;
1901   }
1902   catch(...)
1903   {
1904     INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1905     INFOS("Unknown exception !");
1906     return container_proxy;
1907   }
1908   if (CORBA::is_nil(container_proxy))
1909   {
1910     INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
1911     return container_proxy;
1912   }
1913   return obj._retn();
1914 }
1915
1916 //=============================================================================
1917 /*! This method launches the parallel container.
1918  *  It will may be placed on the ressources manager.
1919  *
1920  * \param command to launch
1921  * \param container's parameters
1922  * \param name of the container
1923  *
1924  * \return CORBA container reference
1925  */
1926 //=============================================================================
1927 bool
1928 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, 
1929                                                  const Engines::ContainerParameters& params,
1930                                                  const std::string& name,
1931                                                  SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
1932 {
1933   INFOS("[LaunchPaCONodeContainer] Launch command");
1934   int status = SystemThreadSafe(command.c_str());
1935   if (status == -1) {
1936     INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
1937     return false;
1938   }
1939   else if (status == 217) {
1940     INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
1941     return false;
1942   }
1943
1944   INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
1945   // We are waiting all the nodes
1946   for (int i = 0; i < params.nb_proc; i++) 
1947   {
1948     CORBA::Object_var obj = CORBA::Object::_nil();
1949     std::string theMachine(vect_machine[i]);
1950     // Name of the node
1951     std::ostringstream tmp;
1952     tmp << i;
1953     std::string proc_number = tmp.str();
1954     std::string container_node_name = name + proc_number;
1955     std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
1956     INFOS("[LaunchPaCONodeContainer]  Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
1957     int count(GetTimeOutToLoaunchServer());
1958     while (CORBA::is_nil(obj) && count) {
1959       SleepInSecond(1);
1960       count-- ;
1961       obj = _NS->Resolve(containerNameInNS.c_str());
1962     }
1963     if (CORBA::is_nil(obj))
1964     {
1965       INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
1966       return false;
1967     }
1968   }
1969   return true;
1970 }
1971
1972 #else
1973
1974 Engines::Container_ptr
1975 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params,
1976                                               std::string resource_selected)
1977 {
1978   Engines::Container_ptr ret = Engines::Container::_nil();
1979   INFOS("[StarPaCOPPContainer] is disabled !");
1980   INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
1981   return ret;
1982 }
1983
1984 std::string 
1985 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1986                                                                 std::string machine_file_name,
1987                                                                 std::string & proxy_hostname)
1988 {
1989   return "";
1990 }
1991
1992 std::string 
1993 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1994                                                                const std::string & machine_file_name,
1995                                                                SALOME_ContainerManager::actual_launch_machine_t & vect_machine, 
1996                                                                const std::string & proxy_hostname) 
1997 {
1998   return "";
1999 }
2000 void 
2001 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
2002                                           const std::string & exe_type,
2003                                           const std::string & container_name,
2004                                           const std::string & hostname,
2005                                           std::string & begin, 
2006                                           std::string & end)
2007 {
2008 }
2009
2010 CORBA::Object_ptr 
2011 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, 
2012                                                   const Engines::ContainerParameters& params,
2013                                                   const std::string& hostname)
2014 {
2015   CORBA::Object_ptr ret = CORBA::Object::_nil();
2016   return ret;
2017 }
2018
2019 bool 
2020 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, 
2021                         const Engines::ContainerParameters& params,
2022                         const std::string& name,
2023                         SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
2024 {
2025   return false;
2026 }
2027 #endif
2028