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