1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOME_ContainerManager.hxx"
24 #include "SALOME_ResourcesManager.hxx"
25 #include "SALOME_LoadRateManager.hxx"
26 #include "SALOME_NamingService.hxx"
27 #include "SALOME_Container_i.hxx"
28 #include "SALOME_ResourcesManager_Client.hxx"
29 #include "SALOME_Embedded_NamingService.hxx"
30 #include "SALOME_ModuleCatalog.hh"
31 #include "Basics_Utils.hxx"
32 #include "Basics_DirUtils.hxx"
33 #include "PythonCppUtils.hxx"
34 #include "KernelBasis.hxx"
35 #include <sys/types.h>
42 #include "Utils_CorbaException.hxx"
49 #include <SALOMEconfig.h>
50 #include CORBA_CLIENT_HEADER(SALOME_Session)
59 #define getpid _getpid
62 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
67 #ifdef WITH_PACO_PARALLEL
71 const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60;
73 const int SALOME_ContainerManager::DFT_DELTA_TIME_NS_LOOKUP_IN_MS=1000;
75 const char *SALOME_ContainerManager::_ContainerManagerNameInNS = "/ContainerManager";
77 omni_mutex SALOME_ContainerManager::_numInstanceMutex;
79 Utils_Mutex SALOME_ContainerManager::_getenvMutex;
81 Utils_Mutex SALOME_ContainerManager::_systemMutex;
83 //=============================================================================
87 * Define a CORBA single thread policy for the server, which avoid to deal
88 * with non thread-safe usage like Change_Directory in SALOME naming service
90 //=============================================================================
92 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns)
93 : _nbprocUsed(1),_delta_time_ns_lookup_in_ms(DFT_DELTA_TIME_NS_LOOKUP_IN_MS),_delta_time_measure_in_ms(Abstract_Engines_Container_i::DFT_TIME_INTERVAL_BTW_MEASURE)
96 _resManager = new SALOME_ResourcesManager_Client(ns);
97 _time_out_in_second = GetTimeOutToLoaunchServer();
99 PortableServer::POAManager_var pman = poa->the_POAManager();
100 _orb = CORBA::ORB::_duplicate(orb) ;
101 CORBA::PolicyList policies;
103 PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL));
104 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
106 _poa = poa->create_POA("MThreadPOA",pman,policies);
107 threadPol->destroy();
108 PortableServer::ObjectId_var id = _poa->activate_object(this);
109 CORBA::Object_var obj = _poa->id_to_reference(id);
110 Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj);
112 _NS->Register(refContMan,_ContainerManagerNameInNS);
113 _isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0);
118 // the urifile name depends on pid of the process
119 std::stringstream urifile;
120 urifile << GetenvThreadSafeAsString("HOME") << "/.urifile_" << getpid();
121 setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
122 if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
123 // Linux specific code
124 pid_t pid = fork(); // spawn a child process, following code is executed in both processes
125 if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
127 std::string uriarg = GetenvThreadSafeAsString("OMPI_URI_FILE");
128 execlp( "ompi-server", "ompi-server", "-r", uriarg.c_str(), NULL );
129 throw SALOME_Exception("Error when launching ompi-server"); // execlp failed
133 throw SALOME_Exception("fork() failed");
137 //wait(NULL); // wait(?) for a child end
138 _pid_mpiServer = pid;
143 // Linux specific code
144 pid_t pid = fork(); // spawn a child process, following code is executed in both processes
145 if ( pid == 0 ) // I'm a child, replace myself with a new hydra_nameserver
147 execlp( "hydra_nameserver", "hydra_nameserver", NULL );
148 throw SALOME_Exception("Error when launching hydra_nameserver"); // execlp failed
152 throw SALOME_Exception("fork() failed");
157 _pid_mpiServer = pid;
163 //=============================================================================
167 //=============================================================================
169 SALOME_ContainerManager::~SALOME_ContainerManager()
171 MESSAGE("destructor");
175 if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
176 // kill my ompi-server
177 if( kill(_pid_mpiServer,SIGTERM) != 0 )
178 throw SALOME_Exception("Error when killing ompi-server");
180 int status=SystemThreadSafe("rm -f ${OMPI_URI_FILE}");
182 throw SALOME_Exception("Error when removing urifile");
185 // kill my hydra_nameserver
186 if(_pid_mpiServer > -1)
187 if( kill(_pid_mpiServer,SIGTERM) != 0 )
188 throw SALOME_Exception("Error when killing hydra_nameserver");
193 //=============================================================================
194 //! shutdown all the containers, then the ContainerManager servant
197 //=============================================================================
199 void SALOME_ContainerManager::Shutdown()
202 ShutdownContainers();
204 _NS->Destroy_Name(_ContainerManagerNameInNS);
205 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
206 _poa->deactivate_object(oid);
209 CORBA::Long SALOME_ContainerManager::GetTimeOutToLaunchServerInSecond()
211 return this->_time_out_in_second;
214 void SALOME_ContainerManager::SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond)
216 this->_time_out_in_second = timeInSecond;
219 CORBA::Long SALOME_ContainerManager::GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond()
221 return this->_delta_time_ns_lookup_in_ms;
224 void SALOME_ContainerManager::SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS)
226 this->_delta_time_ns_lookup_in_ms = timeInMS;
229 CORBA::Long SALOME_ContainerManager::GetDeltaTimeBetweenCPUMemMeasureInMilliSecond()
231 return this->_delta_time_measure_in_ms;
234 void SALOME_ContainerManager::SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(CORBA::Long timeInMS)
236 this->_delta_time_measure_in_ms = timeInMS;
239 void SALOME_ContainerManager::SetBigObjOnDiskThreshold(CORBA::Long thresholdInByte)
241 SALOME::SetBigObjOnDiskThreshold(thresholdInByte);
244 void SALOME_ContainerManager::SetBigObjOnDiskDirectory(const char *directory)
246 SALOME::SetBigObjOnDiskDirectory(directory);
249 //=============================================================================
250 //! Loop on all the containers listed in naming service, ask shutdown on each
253 //=============================================================================
255 void SALOME_ContainerManager::ShutdownContainersGeneric(std::function<void(Engines::Container_ptr)> funcToBeCalledOnContainer)
257 MESSAGE("ShutdownContainersGeneric");
260 SALOME::Session_var session = SALOME::Session::_nil();
262 CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
263 if (!CORBA::is_nil(objS))
265 session = SALOME::Session::_narrow(objS);
266 if (!CORBA::is_nil(session))
267 pid = session->getPID();
271 isOK = _NS->Change_Directory("/Containers");
273 std::vector<std::string> vec = _NS->list_directory_recurs();
274 std::list<std::string> lstCont;
275 for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
278 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
281 Engines::Container_var cont=Engines::Container::_narrow(obj);
282 if(!CORBA::is_nil(cont) && pid != cont->getPID())
283 lstCont.push_back((*iter));
285 catch(const CORBA::Exception&)
287 // ignore this entry and continue
290 MESSAGE("Container list: ");
291 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
294 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
299 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
300 Engines::Container_var cont=Engines::Container::_narrow(obj);
301 if(!CORBA::is_nil(cont))
303 MESSAGE("ShutdownContainersGeneric: " << (*iter));
304 funcToBeCalledOnContainer( cont );
305 MESSAGE("ShutdownContainersGeneric: after call of shutdown" << (*iter));
308 MESSAGE("ShutdownContainersGeneric: no container ref for " << (*iter));
310 catch(CORBA::SystemException& e)
312 INFOS("CORBA::SystemException ignored : " << e);
314 catch(CORBA::Exception&)
316 INFOS("CORBA::Exception ignored.");
320 INFOS("Unknown exception ignored.");
326 void SALOME_ContainerManager::ShutdownContainers()
328 this->ShutdownContainersGeneric( [](Engines::Container_ptr cont) { cont->Shutdown(); } );
331 void SALOME_ContainerManager::ShutdownContainersNow()
333 this->ShutdownContainersGeneric( [](Engines::Container_ptr cont)
346 void SALOME_ContainerManager::SetOverrideEnvForContainers(const Engines::KeyValDict& env)
348 this->_override_env.clear();
349 auto sz = env.length();
350 for(auto i = 0 ; i < sz ; ++i)
351 _override_env.emplace_back(env[i].key.in(), env[i].val.in());
354 Engines::KeyValDict *SALOME_ContainerManager::GetOverrideEnvForContainers()
356 std::unique_ptr<Engines::KeyValDict> ret( new Engines::KeyValDict );
357 auto sz = _override_env.size();
359 for(auto i = 0 ; i < sz ; ++i)
361 (*ret)[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
362 (*ret)[i].val = CORBA::string_dup( _override_env[i].second.c_str() );
364 return ret.release();
367 void SALOME_ContainerManager::SetCodeOnContainerStartUp(const char *code)
369 _code_to_exe_on_startup = code;
372 //=============================================================================
373 //! Give a suitable Container given constraints
375 * \param params Container Parameters required for the container
376 * \return the container or nil
378 //=============================================================================
379 Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
381 std::string machFile;
382 Engines::Container_ptr ret(Engines::Container::_nil());
384 // Step 0: Default mode is start
385 Engines::ContainerParameters local_params(params);
386 if (std::string(local_params.mode.in()) == "")
387 local_params.mode = CORBA::string_dup("start");
388 std::string mode = local_params.mode.in();
389 MESSAGE("[GiveContainer] starting with mode: " << mode);
391 // Step 1: Find Container for find and findorstart mode
392 if (mode == "find" || mode == "findorstart")
394 ret = FindContainer(params, params.resource_params.resList);
395 if(!CORBA::is_nil(ret))
401 MESSAGE("[GiveContainer] no container found");
411 // Step 2: Get all possibleResources from the parameters
412 // Consider only resources that can run containers
413 resourceParams resource_params = resourceParameters_CORBAtoCPP(local_params.resource_params);
414 resource_params.can_run_containers = true;
415 std::vector<std::string> possibleResources = _resManager->GetFittingResources(resource_params);
416 MESSAGE("[GiveContainer] - length of possible resources " << possibleResources.size());
417 std::vector<std::string> local_resources;
419 // Step 3: if mode is "get" keep only machines with existing containers
422 for(unsigned int i=0; i < possibleResources.size(); i++)
424 Engines::Container_ptr cont = FindContainer(params, possibleResources[i]);
427 if(!cont->_non_existent())
428 local_resources.push_back(possibleResources[i]);
430 catch(CORBA::Exception&) {}
433 // if local_resources is empty, we cannot give a container
434 if (local_resources.size() == 0)
436 MESSAGE("[GiveContainer] cannot find a container for mode get");
441 local_resources = possibleResources;
443 // Step 4: select the resource where to get/start the container
444 bool resource_available = true;
445 std::string resource_selected;
446 std::vector<std::string> resources = local_resources;
447 while (resource_available)
449 if (resources.size() == 0)
450 resource_available = false;
455 resource_selected = _resManager->Find(params.resource_params.policy.in(), resources);
456 // Remove resource_selected from vector
457 std::vector<std::string>::iterator it;
458 for (it=resources.begin() ; it < resources.end(); it++ )
459 if (*it == resource_selected)
465 catch(const SALOME_Exception &ex) //!< TODO: unused variable
467 MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
470 MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
472 // Step 5: Create container name
473 ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
474 std::string hostname(resource_definition.HostName);
475 std::string containerNameInNS;
477 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
480 if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
481 machFile = machinesFile(nbproc);
483 catch(const SALOME_Exception & ex)
485 std::string err_msg = ex.what();
486 err_msg += params.container_name;
487 INFOS(err_msg.c_str());
490 // A mpi parallel container register on zero node in NS
491 std::string mpiZeroNode = GetMPIZeroNode(resource_selected,machFile).c_str();
492 containerNameInNS = _NS->BuildContainerNameForNS(params, mpiZeroNode.c_str());
495 containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
496 MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
498 // Step 6: check if the name exists in naming service
499 //if params.mode == "getorstart" or "get" use the existing container
500 //if params.mode == "start" shutdown the existing container before launching a new one with that name
502 { // critical section
503 Utils_Locker lock (&_giveContainerMutex1);
504 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
505 if (!CORBA::is_nil(obj))
509 Engines::Container_var cont=Engines::Container::_narrow(obj);
510 if(!cont->_non_existent())
512 if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
513 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
517 INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
518 cont->Shutdown(); // shutdown the registered container if it exists
522 catch(CORBA::Exception&)
524 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
527 } // end critical section
528 Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
529 if (!CORBA::is_nil(cont))
531 INFOS("[GiveContainer] container " << containerNameInNS << " launched");
532 cont->monitoringtimeresms( this->_delta_time_measure_in_ms );
533 INFOS("[GiveContainer] container " << containerNameInNS << " first CORBA invocation OK");
534 std::ostringstream envInfo;
535 std::for_each( _override_env.begin(), _override_env.end(), [&envInfo](const std::pair<std::string,std::string>& p) { envInfo << p.first << " = " << p.second << " "; } );
536 INFOS("[GiveContainer] container " << containerNameInNS << " override " << envInfo.str());
537 cont->set_big_obj_on_disk_directory( SALOME::GetBigObjOnDiskDirectory().c_str() );
538 cont->set_big_obj_on_disk_threshold( SALOME::GetBigObjOnDiskThreshold() );
539 Engines::FieldsDict envCorba;
541 auto sz = _override_env.size();
543 for(auto i = 0 ; i < sz ; ++i)
545 envCorba[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
546 envCorba[i].value <<= CORBA::string_dup( _override_env[i].second.c_str() );
549 cont->override_environment_python( envCorba );
550 if( !_code_to_exe_on_startup.empty() )
552 INFOS("[GiveContainer] container " << containerNameInNS << " python code executed " << _code_to_exe_on_startup);
553 cont->execute_python_code( _code_to_exe_on_startup.c_str() );
555 INFOS("[GiveContainer] container " << containerNameInNS << " verbosity positionning Activation = " << SALOME::VerbosityActivated() << " Verbosity Level = " << SALOME::VerbosityLevelStr());
556 cont->setVerbosity( SALOME::VerbosityActivated(), SALOME::VerbosityLevelStr().c_str() );
561 INFOS("[GiveContainer] Failed to launch container on resource " << resource_selected);
566 // We were not able to launch the container
567 INFOS("[GiveContainer] Cannot launch the container on the following selected resources:")
568 std::vector<std::string>::iterator it;
569 for (it=local_resources.begin() ; it < local_resources.end(); it++ )
570 INFOS("[GiveContainer] " << *it)
574 std::string SALOME_ContainerManager::GetCppBinaryOfKernelSSLContainer() const
576 switch( SALOME::GetPyExecutionMode() )
578 case SALOME::PyExecutionMode::InProcess:
579 return "SALOME_Container_No_NS_Serv";
580 case SALOME::PyExecutionMode::OutOfProcessNoReplay:
581 return "SALOME_Container_No_NS_Serv_OutProcess";
582 case SALOME::PyExecutionMode::OutOfProcessWithReplay:
583 return "SALOME_Container_No_NS_Serv_OutProcess_Replay";
586 ERROR_MESSAGE("Not manager py execution mode");
587 THROW_SALOME_EXCEPTION("GetCppBinaryOfKernelSSLContainer : Not manager py execution mode");
592 std::string SALOME_ContainerManager::GetCppBinaryOfKernelContainer() const
594 std::string ret = this->_isSSL ? GetCppBinaryOfKernelSSLContainer() : "SALOME_Container";
598 std::string SALOME_ContainerManager::GetRunRemoteExecutableScript() const
600 std::string ret = this->_isSSL ? "runRemoteSSL.sh" : "runRemote.sh";
604 Engines::Container_ptr
605 SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
606 const std::string & resource_selected,
607 const std::string & hostname,
608 const std::string & machFile,
609 const std::string & containerNameInNS)
611 std::string user,command,logFilename,tmpFileName;
613 Engines::Container_ptr ret(Engines::Container::_nil());
614 {//start of critical section
615 Utils_Locker lock (&_giveContainerMutex1);
616 // Step 1: type of container: PaCO, Exe, Mpi or Classic
617 // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
618 // TODO -> separates Mpi from Classic/Exe
620 std::string container_exe = this->GetCppBinaryOfKernelContainer();
621 Engines::ContainerParameters local_params(params);
625 CORBA::String_var container_exe_tmp;
626 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
627 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
628 if (CORBA::is_nil (Catalog))
630 INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
633 // Loop through component list
634 for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
636 const char* compoi = local_params.resource_params.componentList[i];
637 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
638 if (CORBA::is_nil (compoInfo))
642 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
643 container_exe_tmp=compoInfo->implementation_name();
644 if(impl==SALOME_ModuleCatalog::CEXE)
648 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
649 return Engines::Container::_nil();
651 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
652 container_exe = container_exe_tmp.in();
657 catch (ServiceUnreachable&)
659 INFOS("Caught exception: Naming Service Unreachable");
664 INFOS("Caught unknown exception.");
668 // Step 2: test resource
669 // Only if an application directory is set
670 if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
673 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
674 std::string command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
675 resInfo.UserName, resInfo.AppliPath);
677 // Launch remote command
678 command += " \"ls /tmp >/dev/null 2>&1\"";
679 // Anthony : command is NO MORE launched to improve dramatically time to launch containers
683 // Error on resource - cannot launch commands
684 INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
685 INFOS("[LaunchContainer] Command was " << command);
687 INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
689 return Engines::Container::_nil();
693 // Step 3: start a new container
694 // Check if a PaCO container
696 if (std::string(local_params.parallelLib.in()) != "")
698 ret = StartPaCOPPContainer(params, resource_selected);
701 // Other type of containers...
702 MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
703 // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
704 if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL && params.isMPI )
706 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
707 MESSAGE("[LaunchContainer] LIBBATCH_NODEFILE : \"" << command << "\"");
709 // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
710 else if(hostname == Kernel_Utils::GetHostname())
712 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
713 MESSAGE("[LaunchContainer] hostname local : \"" << command << "\"");
715 // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
718 command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
719 MESSAGE("[LaunchContainer] remote : \"" << command << "\"");
722 //redirect stdout and stderr in a file
724 logFilename=GetenvThreadSafeAsString("TEMP");
726 user = GetenvThreadSafeAsString( "USERNAME" );
728 user = GetenvThreadSafeAsString( "USER" );
730 user = GetenvThreadSafeAsString( "LOGNAME" );
732 char* val = GetenvThreadSafe("SALOME_TMP_DIR");
735 struct stat file_info;
736 stat(val, &file_info);
737 bool is_dir = S_ISDIR(file_info.st_mode);
741 MESSAGE( "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl );
745 logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
746 std::ostringstream tmp;
747 tmp << "_" << getpid();
748 logFilename += tmp.str();
749 logFilename += ".log" ;
750 command += " > " + logFilename + " 2>&1";
751 MakeTheCommandToBeLaunchedASync(command);
753 MESSAGE("[LaunchContainer] SYSTEM COMMAND that will be launched : \"" << command << "\"");
754 // launch container with a system call
755 status=SystemThreadSafe(command.c_str());
756 }//end of critical of section
760 INFOS("[LaunchContainer] command failed (system command status -1): " << command);
761 RmTmpFile(tmpFileName); // command file can be removed here
762 return Engines::Container::_nil();
764 else if (status == 217)
766 INFOS("[LaunchContainer] command failed (system command status 217): " << command);
767 RmTmpFile(tmpFileName); // command file can be removed here
768 return Engines::Container::_nil();
772 // Step 4: Wait for the container
773 double nbTurn = ( (double)this->_time_out_in_second ) * ( 1000.0 / ( (double) this->_delta_time_ns_lookup_in_ms) );
774 int count( (int)nbTurn );
775 INFOS("[GiveContainer] # attempts : " << count << " name in NS : \"" << containerNameInNS << "\"");
776 INFOS("[GiveContainer] # attempts : Time in second before time out : " << this->_time_out_in_second << " Delta time in ms between NS lookup : " << this->_delta_time_ns_lookup_in_ms);
777 while (CORBA::is_nil(ret) && count)
779 std::this_thread::sleep_for(std::chrono::milliseconds(_delta_time_ns_lookup_in_ms));
781 MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected << " with entry in NS = \"" << containerNameInNS << "\"" );
782 CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str()));
783 ret=Engines::Container::_narrow(obj);
785 if (CORBA::is_nil(ret))
787 INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
791 // Setting log file name
792 ret->locallogfilename( logFilename.c_str() );
793 logFilename=":"+logFilename;
794 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;//threadsafe
795 logFilename=user+logFilename;
796 ret->logfilename(logFilename.c_str());
797 RmTmpFile(tmpFileName); // command file can be removed here
803 //=============================================================================
804 //! Find a container given constraints (params) on a list of machines (possibleComputers)
805 //! agy : this method is ThreadSafe
809 //=============================================================================
811 Engines::Container_ptr SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const Engines::ResourceList& possibleResources)
813 MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
814 for(unsigned int i=0; i < possibleResources.length();i++)
816 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
817 if(!CORBA::is_nil(cont))
820 MESSAGE("[FindContainer] no container found");
821 return Engines::Container::_nil();
824 //=============================================================================
825 //! Find a container given constraints (params) on a machine (theMachine)
826 //! agy : this method is ThreadSafe
830 //=============================================================================
832 Engines::Container_ptr
833 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const std::string& resource)
835 ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource);
836 std::string hostname(resource_definition.HostName);
837 std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
838 MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
839 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
842 if(obj->_non_existent())
843 return Engines::Container::_nil();
845 return Engines::Container::_narrow(obj);
847 catch(const CORBA::Exception&)
849 return Engines::Container::_nil();
854 bool isPythonContainer(const char* ContainerName);
856 //=============================================================================
858 * This is no longer valid (C++ container are also python containers)
860 //=============================================================================
861 bool isPythonContainer(const char* ContainerName)
863 return false; // VSR 02/08/2013: Python containers are no more supported
865 size_t len = strlen(ContainerName);
868 if (strcmp(ContainerName + len - 2, "Py") == 0)
874 //=============================================================================
876 * Builds the script to be launched
878 * If SALOME Application not defined ($APPLI),
879 * see BuildTempFileToLaunchRemoteContainer()
881 * Else rely on distant configuration. Command is under the form (example):
882 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
883 * SALOME_Container containerName &"
885 * - where user is omitted if not specified in CatalogResources,
886 * - where distant path is always relative to user@machine $HOME, and
887 * equal to $APPLI if not specified in CatalogResources,
888 * - where hostNS is the hostname of CORBA naming server (set by scripts to
889 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
890 * - where portNS is the port used by CORBA naming server (set by scripts to
891 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
892 * - where workingdir is the requested working directory for the container.
893 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
895 //=============================================================================
898 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& resource_name, const Engines::ContainerParameters& params, const std::string& container_exe) const
900 std::string command,tmpFileName;
901 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
902 std::string wdir = params.workingdir.in();
903 if (!_isAppliSalomeDefined)
905 MESSAGE("[BuildCommandToLaunchRemoteContainer] NO APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
906 command = getCommandToRunRemoteProcessNoAppli(resInfo.Protocol, resInfo.HostName,
907 resInfo.UserName, resInfo.AppliPath,
912 MESSAGE("[BuildCommandToLaunchRemoteContainer] WITH APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
913 // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
914 // SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
916 // "ssh -l user machine distantLauncher remote -p hostNS -m portNS -d dir
917 // -- SALOME_Container contName -ORBInitRef NameService=IOR:01000..."
918 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
919 resInfo.UserName, resInfo.AppliPath,
924 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
925 command += " mpirun -np ";
926 std::ostringstream o;
930 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
931 #elif defined(OPEN_MPI)
932 if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
933 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
935 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
936 command += GetenvThreadSafeAsString("OMPI_URI_FILE");
939 command += "-nameserver " + Kernel_Utils::GetHostname();
941 command += " SALOME_MPIContainer ";
944 command += " " +container_exe+ " ";
946 command += _NS->ContainerName(params) + " ";
949 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
950 CORBA::String_var iorNS = _orb->object_to_string(ns);
951 command += std::string(iorNS);
953 else //if(!this->_isSSL)
956 AddOmninamesParams(command);
958 MESSAGE("command =" << command);
963 //=============================================================================
964 //! Return a path to the directory with scripts templates
966 * \return the path pointed by SALOME_KERNEL_SCRIPTS_DIR environment variable, if it is defined,
967 * ${KERNEL_ROOT_DIR}/share/salome/resources/separator/kernel/ScriptsTemplate - otherwise
969 //=============================================================================
970 std::string getScriptTemplateFilePath()
972 auto parseScriptTemplateFilePath = []() -> std::string
974 std::string scriptTemplateFilePath = SALOME_ContainerManager::GetenvThreadSafeAsString("SALOME_KERNEL_SCRIPTS_DIR");
975 if (!scriptTemplateFilePath.empty())
977 return scriptTemplateFilePath;
980 return SALOME_ContainerManager::GetenvThreadSafeAsString("KERNEL_ROOT_DIR") +
981 "/share/salome/resources/kernel/ScriptsTemplate";
985 static const std::string scriptTemplateFilePath = parseScriptTemplateFilePath();
986 return scriptTemplateFilePath;
989 //=============================================================================
990 //! Return a command line constructed based on Python scripts templates
992 * \param theScriptName the name of Python script template
993 * \param theScriptParameters the queue of parameter values
994 * \return the command line constructed according to the given parameters
996 //=============================================================================
997 std::string GetCommandFromTemplate(const std::string& theScriptName,
998 std::queue<std::string>& theScriptParameters)
1000 std::string command;
1004 PyObject* mod(PyImport_ImportModule(theScriptName.c_str()));
1005 MESSAGE("Template name :"<< theScriptName.c_str());
1009 AutoPyRef sys = PyImport_ImportModule("sys");
1010 AutoPyRef sys_path = PyObject_GetAttrString(sys, "path");
1011 AutoPyRef folder_path = PyUnicode_FromString(getScriptTemplateFilePath().c_str());
1012 PyList_Append(sys_path, folder_path);
1014 mod = PyImport_ImportModule(theScriptName.c_str());
1020 PyObject* meth(PyObject_GetAttrString(mod, "command"));
1028 PyObject* tuple(PyTuple_New(theScriptParameters.size()));
1030 auto insert_parameter = [&tuple, &theScriptParameters, &id]()
1032 if (!theScriptParameters.empty())
1034 PyTuple_SetItem(tuple, ++id, PyUnicode_FromString(theScriptParameters.front().c_str()));
1035 theScriptParameters.pop();
1039 while (!theScriptParameters.empty())
1044 PyObject *args(PyTuple_New(1));
1045 PyTuple_SetItem(args, 0, tuple);
1047 PyObject *res(PyObject_CallObject(meth, args));
1050 command = PyUnicode_AsUTF8(res);
1062 ERROR_MESSAGE("Can not import the template script \"" << theScriptName << "\" !");
1065 MESSAGE("Command from template is ... " << command << std::endl);
1068 //=============================================================================
1070 //=============================================================================
1072 * builds the command to be launched.
1074 //=============================================================================
1075 std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe, std::string& tmpFileName) const
1077 // Prepare name of the script to be used
1078 std::string script_name = "SALOME_CM_LOCAL_NO_MPI";
1082 script_name = "SALOME_CM_LOCAL_MPI_LAN";
1083 #elif defined(OPEN_MPI)
1084 script_name = "SALOME_CM_LOCAL_MPI_OPENMPI";
1085 #elif defined(MPICH)
1086 script_name = "SALOME_CM_LOCAL_MPI_MPICH";
1090 // Prepare parameters to use in the Python script:
1091 // 1. All parameters are strings.
1092 // 2. For some booleans use "1" = True, "0" = False.
1093 // 3. If a parameter is NULL, then its value is "NULL".
1095 std::queue<std::string> script_parameters;
1097 // ===== Number of processes (key = "nb_proc")
1098 script_parameters.push(params.isMPI ? std::to_string(params.nb_proc <= 0 ? 1 : params.nb_proc) : "NULL");
1100 // ===== Working directory (key = "workdir") and temporary directory flag (key = "isTmpDir")
1101 // A working directory is requested
1102 std::string workdir = params.workingdir.in();
1103 std::string isTmpDir = std::to_string(0);
1104 if (workdir == "$TEMPDIR")
1106 // A new temporary directory is requested
1107 isTmpDir = std::to_string(1);
1108 workdir = Kernel_Utils::GetTmpDir();
1110 script_parameters.push(workdir);
1111 script_parameters.push(isTmpDir);
1113 // ===== Server name (key = "name_server")
1114 script_parameters.push(Kernel_Utils::GetHostname());
1116 // ===== Container (key = "container")
1117 std::string container;
1120 container = isPythonContainer(params.container_name) ? "pyMPI SALOME_ContainerPy.py" : "SALOME_MPIContainer";
1124 container = isPythonContainer(params.container_name) ? "SALOME_ContainerPy.py" : container_exe;
1126 script_parameters.push(container);
1128 // ===== Container name (key = "container_name")
1129 script_parameters.push(_NS->ContainerName(params));
1131 // ===== LIBBATCH node file (key = "libbatch_nodefile")
1132 script_parameters.push(std::to_string(GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL ? 1 : 0));
1134 // ===== Machine file (key = "machine_file")
1135 script_parameters.push(machinesFile.empty() ? "NULL" : machinesFile);
1137 // ===== OMPI uri file (key = "ompi_uri_file")
1138 std::string ompi_uri_file = GetenvThreadSafeAsString("OMPI_URI_FILE");
1139 script_parameters.push(ompi_uri_file.empty() ? "NULL" : ompi_uri_file);
1141 MESSAGE("Retrieving command from template (python module) \"" << script_name << "\"" << std::endl);
1142 std::string command_from_template = GetCommandFromTemplate(script_name, script_parameters);
1144 std::ostringstream o;
1145 o << command_from_template << " ";
1147 //==================================================================================== */
1151 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1152 CORBA::String_var iorNS = _orb->object_to_string(ns);
1158 AddOmninamesParams(o);
1161 tmpFileName = BuildTemporaryFileName();
1162 std::ofstream command_file( tmpFileName.c_str() );
1163 command_file << o.str();
1164 command_file.close();
1167 chmod(tmpFileName.c_str(), 0x1ED);
1170 std::string command = tmpFileName;
1171 MESSAGE("Command is file ... " << command);
1172 MESSAGE("Command is ... " << o.str());
1177 //=============================================================================
1179 * removes the generated temporary file in case of a remote launch.
1180 * This method is thread safe
1182 //=============================================================================
1184 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
1186 size_t length = tmpFileName.size();
1190 std::string command = "del /F ";
1192 std::string command = "rm ";
1195 command += tmpFileName.substr(0, length - 3 );
1197 command += tmpFileName;
1199 SystemThreadSafe(command.c_str());
1200 //if dir is empty - remove it
1201 std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
1202 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
1205 command = "del /F " + tmp_dir;
1207 command = "rmdir " + tmp_dir;
1209 SystemThreadSafe(command.c_str());
1214 //=============================================================================
1216 * add to command all options relative to naming service.
1218 //=============================================================================
1220 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
1222 std::ostringstream oss;
1223 AddOmninamesParams(oss);
1227 //=============================================================================
1229 * add to command all options relative to naming service.
1231 //=============================================================================
1233 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const
1235 AddOmninamesParams(fileStream,_NS);
1238 //=============================================================================
1240 * add to command all options relative to naming service.
1242 //=============================================================================
1244 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns)
1246 SALOME_NamingService *nsTrad(dynamic_cast<SALOME_NamingService *>(ns));
1249 CORBA::String_var iorstr(nsTrad->getIORaddr());
1250 fileStream << "ORBInitRef NameService=";
1251 fileStream << iorstr;
1255 void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command)
1258 command = "%PYTHONBIN% -c \"import subprocess ; subprocess.Popen(r'" + command + "').pid\"";
1265 * Return in second the time out to give chance to server to be launched and
1266 * to register into NS
1268 int SALOME_ContainerManager::GetTimeOutToLoaunchServer()
1270 int count(TIME_OUT_TO_LAUNCH_CONT);
1271 if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
1273 std::string new_count_str(GetenvThreadSafeAsString("TIMEOUT_TO_LAUNCH_CONTAINER"));
1275 std::istringstream ss(new_count_str);
1276 if (!(ss >> new_count))
1278 INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
1286 void SALOME_ContainerManager::SleepInSecond(int ellapseTimeInSecond)
1289 sleep( ellapseTimeInSecond ) ;
1291 int timeInMS(1000*ellapseTimeInSecond);
1296 //=============================================================================
1298 * generate a file name in /tmp directory
1300 //=============================================================================
1302 std::string SALOME_ContainerManager::BuildTemporaryFileName()
1304 //build more complex file name to support multiple salome session
1305 std::string aFileName = Kernel_Utils::GetTmpFileName();
1306 std::ostringstream str_pid;
1307 str_pid << ::getpid();
1308 aFileName = aFileName + "-" + str_pid.str();
1312 aFileName += ".bat";
1317 //=============================================================================
1319 * Builds in a temporary file the script to be launched.
1321 * Used if SALOME Application ($APPLI) is not defined.
1322 * The command is build with data from CatalogResources, in which every path
1323 * used on remote computer must be defined.
1325 //=============================================================================
1327 std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const
1331 tmpFileName = BuildTemporaryFileName();
1332 std::ofstream tempOutputFile;
1333 tempOutputFile.open(tmpFileName.c_str(), std::ofstream::out );
1334 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
1335 tempOutputFile << "#! /bin/sh" << std::endl;
1339 tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1340 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1346 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
1348 tempOutputFile << "mpirun -np ";
1350 tempOutputFile << nbproc << " ";
1352 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1353 #elif defined(OPEN_MPI)
1354 if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
1355 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1357 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1358 tempOutputFile << GetenvThreadSafeAsString("OMPI_URI_FILE");
1360 #elif defined(MPICH)
1361 tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
1365 tempOutputFile << GetenvThreadSafeAsString("KERNEL_ROOT_DIR") << "/bin/salome/";
1369 if (isPythonContainer(params.container_name))
1370 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1372 tempOutputFile << " SALOME_MPIContainer ";
1377 if (isPythonContainer(params.container_name))
1378 tempOutputFile << "SALOME_ContainerPy.py ";
1380 tempOutputFile << "SALOME_Container ";
1383 tempOutputFile << _NS->ContainerName(params) << " -";
1384 AddOmninamesParams(tempOutputFile);
1385 tempOutputFile << " &" << std::endl;
1386 tempOutputFile.flush();
1387 tempOutputFile.close();
1389 chmod(tmpFileName.c_str(), 0x1ED);
1392 // --- Build command
1394 std::string command;
1396 if (resInfo.Protocol == rsh)
1399 std::string commandRcp = "rcp ";
1400 commandRcp += tmpFileName;
1402 commandRcp += resInfo.HostName;
1404 commandRcp += tmpFileName;
1405 status = SystemThreadSafe(commandRcp.c_str());
1408 else if (resInfo.Protocol == ssh)
1411 std::string commandRcp = "scp ";
1412 commandRcp += tmpFileName;
1414 commandRcp += resInfo.HostName;
1416 commandRcp += tmpFileName;
1417 status = SystemThreadSafe(commandRcp.c_str());
1420 else if (resInfo.Protocol == srun)
1422 command = "srun -n 1 -N 1 --overlap --mem-per-cpu=0 --cpu-bind=none --nodelist=";
1423 std::string commandRcp = "rcp ";
1424 commandRcp += tmpFileName;
1426 commandRcp += resInfo.HostName;
1428 commandRcp += tmpFileName;
1429 status = SystemThreadSafe(commandRcp.c_str());
1432 throw SALOME_Exception("Unknown protocol");
1435 throw SALOME_Exception("Error of connection on remote host");
1437 command += resInfo.HostName;
1439 command += tmpFileName;
1447 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile) const
1450 std::string zeronode;
1451 std::string command;
1452 std::string tmpFile = BuildTemporaryFileName();
1453 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
1455 if(resInfo.Protocol == sh)
1457 return resInfo.HostName;
1460 if( GetenvThreadSafe("LIBBATCH_NODEFILE") == NULL )
1462 if (_isAppliSalomeDefined)
1464 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
1465 resInfo.UserName, resInfo.AppliPath);
1466 command += " mpirun -np 1 hostname -s > " + tmpFile;
1469 command = "mpirun -np 1 hostname -s > " + tmpFile;
1472 command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
1474 status = SystemThreadSafe(command.c_str());
1476 std::ifstream fp(tmpFile.c_str(),std::ios::in);
1477 while(fp >> zeronode);
1485 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1488 std::string nodesFile = GetenvThreadSafeAsString("LIBBATCH_NODEFILE");
1489 std::string machinesFile = Kernel_Utils::GetTmpFileName();
1490 std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1491 std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1493 _numInstanceMutex.lock();
1495 for(int i=0;i<_nbprocUsed;i++)
1498 for(int i=0;i<nbproc;i++)
1500 fpo << tmp << std::endl;
1502 throw SALOME_Exception("You need more processors than batch session have allocated for you! Unable to launch the mpi container: ");
1504 _nbprocUsed += nbproc;
1508 _numInstanceMutex.unlock();
1510 return machinesFile;
1514 std::string SALOME_ContainerManager::getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
1516 return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE","salome shell --",protocol,hostname,username,applipath,workdir);
1519 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
1521 return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE_OLD",this->GetRunRemoteExecutableScript(),protocol,hostname,username,applipath,workdir);
1524 std::string SALOME_ContainerManager::getCommandToRunRemoteProcessCommon(const std::string& templateName,
1525 const std::string& remoteScript,
1526 AccessProtocolType protocol,
1527 const std::string & hostname,
1528 const std::string & username,
1529 const std::string & applipath,
1530 const std::string & workdir) const
1532 std::ostringstream command;
1534 // Prepare parameters to use in the Python script:
1535 // 1. All parameters are strings.
1536 // 2. For some booleans use "1" = True, "0" = False.
1537 // 3. If a parameter is NULL, then its value is "NULL".
1539 std::queue<std::string> script_parameters;
1541 // ===== Protocol (key = "protocol")
1542 std::string strProtocol;
1545 case rsh: strProtocol = "rsh"; break;
1546 case ssh: strProtocol = "ssh"; break;
1547 case srun: strProtocol = "srun"; break;
1548 case pbsdsh: strProtocol = "pbsdsh"; break;
1549 case blaunch: strProtocol = "blaunch"; break;
1551 throw SALOME_Exception("Unknown protocol");
1553 script_parameters.push(strProtocol);
1555 // ===== User name (key = "user")
1556 script_parameters.push(username.empty() ? "NULL" : username);
1558 // ===== Host name (key = "host")
1559 script_parameters.push(hostname.empty() ? "NULL" : hostname);
1562 // ===== Remote APPLI path (key = "appli")
1563 script_parameters.push(applipath.empty() ? GetenvThreadSafeAsString("APPLI") : applipath);
1567 ASSERT(GetenvThreadSafe("NSHOST"));
1568 ASSERT(GetenvThreadSafe("NSPORT"));
1571 struct stat statbuf;
1572 std::string appli_mode = (stat(GetenvThreadSafe("APPLI"), &statbuf) == 0 && S_ISREG(statbuf.st_mode)) ? "launcher" : "dir";
1574 // ===== Working directory (key = "workdir")
1575 script_parameters.push(workdir == "$TEMPDIR" ? "\\$TEMPDIR" : workdir);
1577 // ===== SSL (key = "ssl")
1578 script_parameters.push(this->_isSSL ? "1" : "0");
1580 // ===== Hostname of CORBA name server (key = "nshost")
1581 std::string nshost = GetenvThreadSafeAsString("NSHOST");
1582 script_parameters.push(nshost.empty() ? "NULL" : nshost);
1584 // ===== Port of CORBA name server (key = "nsport")
1585 std::string nsport = GetenvThreadSafeAsString("NSPORT");
1586 script_parameters.push(nsport.empty() ? "NULL" : nsport);
1588 // ===== Remote script (key = "remote_script")
1589 script_parameters.push(remoteScript.empty() ? "NONE" : remoteScript);
1591 // ===== Naming service (key = "naming_service")
1592 std::string namingService = "NONE";
1595 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1596 CORBA::String_var iorNS = _orb->object_to_string(ns);
1597 namingService = iorNS;
1599 script_parameters.push(namingService);
1601 // ===== APPLI mode (key = "appli_mode")
1602 // $APPLI points either to an application directory, or to a salome launcher file
1603 // we prepare the remote command according to the case
1604 script_parameters.push(appli_mode);
1606 command << GetCommandFromTemplate(templateName, script_parameters);
1608 return command.str();
1612 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1616 // Step 1 : check ContainerParameters
1617 // Check container_name, has to be defined
1618 if (std::string(params.container_name.in()) == "")
1620 INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1623 // Check parallelLib
1624 std::string parallelLib = params.parallelLib.in();
1625 if (parallelLib != "Mpi" && parallelLib != "Dummy")
1627 INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1628 INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1629 INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1633 if (params.nb_proc <= 0)
1635 INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1639 // Step 2 : check resource_selected
1640 const ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
1641 //std::string protocol = resource_definition->protocol.in();
1642 std::string username = resource_definition.UserName;
1643 std::string applipath = resource_definition.AppliPath;
1645 //if (protocol == "" || username == "" || applipath == "")
1646 if (username == "" || applipath == "")
1648 INFOS("[checkPaCOParameters] resource selected is not well defined");
1649 INFOS("[checkPaCOParameters] resource name: " << resource_definition.Name);
1650 INFOS("[checkPaCOParameters] resource hostname: " << resource_definition.HostName);
1651 INFOS("[checkPaCOParameters] resource protocol: " << resource_definition.getAccessProtocolTypeStr());
1652 INFOS("[checkPaCOParameters] resource username: " << username);
1653 INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1661 * :WARNING: Do not directly convert returned value to std::string
1662 * This function may return NULL if env variable is not defined.
1663 * And std::string(NULL) causes undefined behavior.
1664 * Use GetenvThreadSafeAsString to properly get a std::string.
1666 char *SALOME_ContainerManager::GetenvThreadSafe(const char *name)
1667 {// getenv is not thread safe. See man 7 pthread.
1668 Utils_Locker lock (&_getenvMutex);
1669 return getenv(name);
1673 * Return env variable as a std::string.
1674 * Return empty string if env variable is not set.
1676 std::string SALOME_ContainerManager::GetenvThreadSafeAsString(const char *name)
1678 char* var = GetenvThreadSafe(name);
1679 return var ? std::string(var) : std::string();
1682 int SALOME_ContainerManager::SystemThreadSafe(const char *command)
1684 Utils_Locker lock (&_systemMutex);
1685 return system(command);
1688 long SALOME_ContainerManager::SystemWithPIDThreadSafe(const std::vector<std::string>& command)
1690 Utils_Locker lock(&_systemMutex);
1691 if(command.size()<1)
1692 throw SALOME_Exception("SystemWithPIDThreadSafe : command is expected to have a length of size 1 at least !");
1694 pid_t pid ( fork() ) ; // spawn a child process, following code is executed in both processes
1696 pid_t pid = -1; //Throw SALOME_Exception on Windows
1698 if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
1700 std::size_t sz(command.size());
1701 char **args = new char *[sz+1];
1702 for(std::size_t i=0;i<sz;i++)
1703 args[i] = strdup(command[i].c_str());
1705 execvp( command[0].c_str() , args );
1706 std::ostringstream oss;
1707 oss << "Error when launching " << command[0];
1708 throw SALOME_Exception(oss.str().c_str()); // execvp failed
1712 throw SALOME_Exception("fork() failed");
1714 else // I'm a parent
1720 #ifdef WITH_PACO_PARALLEL
1722 //=============================================================================
1724 * Start a suitable PaCO++ Parallel Container in a list of machines.
1725 * \param params Container Parameters required for the container
1726 * \return CORBA container reference.
1728 //=============================================================================
1729 Engines::Container_ptr
1730 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1731 std::string resource_selected)
1733 CORBA::Object_var obj;
1734 PaCO::InterfaceManager_var container_proxy;
1735 Engines::Container_ptr ret = Engines::Container::_nil();
1736 Engines::ContainerParameters params(params_const);
1737 params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1739 // Step 0 : Check parameters
1740 if (!checkPaCOParameters(params, resource_selected))
1742 INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1746 // Step 1 : Starting a new parallel container !
1747 INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1748 INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1750 // Step 2 : Get a MachineFile for the parallel container
1751 std::string machine_file_name = _resManager->getMachineFile(resource_selected,
1753 params.parallelLib.in());
1755 if (machine_file_name == "")
1757 INFOS("[StartPaCOPPContainer] Machine file generation failed");
1761 // Step 3 : starting parallel container proxy
1762 std::string command_proxy("");
1763 std::string proxy_machine;
1766 command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1768 catch(const SALOME_Exception & ex)
1770 INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1774 obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1775 if (CORBA::is_nil(obj))
1777 INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1780 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1781 MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1783 // Step 4 : starting parallel container nodes
1784 std::string command_nodes("");
1785 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1788 command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1790 catch(const SALOME_Exception & ex)
1792 INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1797 std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1798 bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1801 INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1802 // Il faut tuer le proxy
1805 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1810 INFOS("[StarPaCOPPContainer] Exception caught from proxy Shutdown...");
1815 // Step 4 : connecting nodes and the proxy to actually create a parallel container
1816 for (int i = 0; i < params.nb_proc; i++)
1818 std::ostringstream tmp;
1820 std::string proc_number = tmp.str();
1821 std::string container_node_name = container_generic_node_name + proc_number;
1823 std::string theNodeMachine(nodes_machines[i]);
1824 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1825 obj = _NS->Resolve(containerNameInNS.c_str());
1826 if (CORBA::is_nil(obj))
1828 INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1829 INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1834 MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1835 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1837 MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1839 catch(CORBA::SystemException& e)
1841 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1842 INFOS("CORBA::SystemException : " << e);
1845 catch(CORBA::Exception& e)
1847 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1848 INFOS("CORBA::Exception" << e);
1853 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1854 INFOS("Unknown exception !");
1859 // Step 5 : starting parallel container
1862 MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1863 container_proxy->start();
1864 MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1865 ret = Engines::Container::_narrow(container_proxy);
1867 catch(CORBA::SystemException& e)
1869 INFOS("Caught CORBA::SystemException. : " << e);
1871 catch(PortableServer::POA::ServantAlreadyActive&)
1873 INFOS("Caught CORBA::ServantAlreadyActiveException");
1875 catch(CORBA::Exception&)
1877 INFOS("Caught CORBA::Exception.");
1879 catch(std::exception& exc)
1881 INFOS("Caught std::exception - "<<exc.what());
1885 INFOS("Caught unknown exception.");
1891 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1892 std::string machine_file_name,
1893 std::string & proxy_hostname)
1895 // In the proxy case, we always launch a Dummy Proxy
1896 std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1897 std::string container_name = params.container_name.in();
1899 // Convert nb_proc in string
1900 std::ostringstream tmp_string;
1901 tmp_string << params.nb_proc;
1902 std::string nb_proc_str = tmp_string.str();
1904 // Get resource definition
1905 ParserResourcesType resource_definition =
1906 _resManager->GetResourceDefinition(params.resource_params.name.in());
1909 std::string hostname;
1910 std::ifstream machine_file(machine_file_name.c_str());
1911 std::getline(machine_file, hostname, ' ');
1912 size_t found = hostname.find('\n');
1913 if (found!=std::string::npos)
1914 hostname.erase(found, 1); // Remove \n
1915 proxy_hostname = hostname;
1916 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1919 bool remote_execution = false;
1920 if (hostname != std::string(Kernel_Utils::GetHostname()))
1922 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1923 remote_execution = true;
1927 std::string log_type("");
1928 char * get_val = GetenvThreadSafe("PARALLEL_LOG");
1932 // Generating the command
1933 std::string command_begin("");
1934 std::string command_end("");
1935 std::ostringstream command;
1937 LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1938 command << command_begin;
1940 // Adding connection command
1941 // We can only have a remote execution with
1942 // a SALOME application
1943 if (remote_execution)
1945 ASSERT(GetenvThreadSafe("NSHOST"));
1946 ASSERT(GetenvThreadSafe("NSPORT"));
1948 command << resource_definition.getAccessProtocolTypeStr();
1950 command << resource_definition.UserName;
1951 command << " " << hostname;
1952 command << " " << resource_definition.AppliPath;
1953 command << "/runRemote.sh ";
1954 command << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
1955 command << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
1958 command << exe_name;
1959 command << " " << container_name;
1960 command << " Dummy";
1961 command << " " << hostname;
1962 command << " " << nb_proc_str;
1964 AddOmninamesParams(command);
1967 command << command_end;
1968 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1970 return command.str();
1974 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1975 const std::string & machine_file_name,
1976 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1977 const std::string & proxy_hostname)
1980 std::string exe_name = "SALOME_ParallelContainerNode";
1981 exe_name += params.parallelLib.in();
1982 std::string container_name = params.container_name.in();
1984 // Convert nb_proc in string
1985 std::ostringstream nb_proc_stream;
1986 nb_proc_stream << params.nb_proc;
1988 // Get resource definition
1989 ParserResourcesType resource_definition =
1990 _resManager->GetResourceDefinition(params.resource_params.name.in());
1993 std::string log_type("");
1994 char * get_val = GetenvThreadSafe("PARALLEL_LOG");
1998 // Now the command is different according to paralleLib
1999 std::ostringstream command_nodes;
2000 std::ifstream machine_file(machine_file_name.c_str());
2001 if (std::string(params.parallelLib.in()) == "Dummy")
2003 for (int i= 0; i < params.nb_proc; i++)
2006 std::string hostname;
2007 std::getline(machine_file, hostname);
2008 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
2011 bool remote_execution = false;
2012 if (hostname != std::string(Kernel_Utils::GetHostname()))
2014 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
2015 remote_execution = true;
2018 // For each node we have a new command
2019 // Generating the command
2020 std::ostringstream command_node_stream;
2021 std::string command_node_begin("");
2022 std::string command_node_end("");
2023 std::ostringstream node_number;
2025 std::string container_node_name = container_name + node_number.str();
2026 LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
2028 // Adding connection command
2029 // We can only have a remote execution with
2030 // a SALOME application
2031 if (remote_execution)
2033 ASSERT(GetenvThreadSafe("NSHOST"));
2034 ASSERT(GetenvThreadSafe("NSPORT"));
2036 command_node_stream << resource_definition.getAccessProtocolTypeStr();
2037 command_node_stream << " -l ";
2038 command_node_stream << resource_definition.UserName;
2039 command_node_stream << " " << hostname;
2040 command_node_stream << " " << resource_definition.AppliPath;
2041 command_node_stream << "/runRemote.sh ";
2042 command_node_stream << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
2043 command_node_stream << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
2046 command_node_stream << exe_name;
2047 command_node_stream << " " << container_name;
2048 command_node_stream << " " << params.parallelLib.in();
2049 command_node_stream << " " << proxy_hostname;
2050 command_node_stream << " " << node_number.str();
2051 command_node_stream << " -";
2052 AddOmninamesParams(command_node_stream);
2054 command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
2055 vect_machine.push_back(hostname);
2059 else if (std::string(params.parallelLib.in()) == "Mpi")
2062 std::string hostname;
2063 std::getline(machine_file, hostname, ' ');
2064 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
2067 bool remote_execution = false;
2068 if (hostname != std::string(Kernel_Utils::GetHostname()))
2070 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
2071 remote_execution = true;
2074 // In case of Mpi and Remote, we copy machine_file in the applipath
2075 // scp mpi_machine_file user@machine:Path
2076 std::ostringstream command_remote_stream;
2077 std::string::size_type last = machine_file_name.find_last_of("/");
2078 if (last == std::string::npos)
2081 if (resource_definition.Protocol == rsh)
2082 command_remote_stream << "rcp ";
2084 command_remote_stream << "scp ";
2085 command_remote_stream << machine_file_name << " ";
2086 command_remote_stream << resource_definition.UserName << "@";
2087 command_remote_stream << hostname << ":" << resource_definition.AppliPath;
2088 command_remote_stream << "/" << machine_file_name.substr(last+1);
2090 int status = SystemThreadSafe(command_remote_stream.str().c_str());
2093 INFOS("copy of the MPI machine file failed ! - sorry !");
2097 // Generating the command
2098 std::string command_begin("");
2099 std::string command_end("");
2101 LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
2102 command_nodes << command_begin;
2104 // Adding connection command
2105 // We can only have a remote execution with
2106 // a SALOME application
2107 if (remote_execution)
2109 ASSERT(GetenvThreadSafe("NSHOST"));
2110 ASSERT(GetenvThreadSafe("NSPORT"));
2112 command_nodes << resource_definition.getAccessProtocolTypeStr();
2113 command_nodes << " -l ";
2114 command_nodes << resource_definition.UserName;
2115 command_nodes << " " << hostname;
2116 command_nodes << " " << resource_definition.AppliPath;
2117 command_nodes << "/runRemote.sh ";
2118 command_nodes << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
2119 command_nodes << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
2122 if (resource_definition.mpi == lam)
2124 command_nodes << "mpiexec -ssi boot ";
2125 command_nodes << "-machinefile " << machine_file_name << " ";
2126 command_nodes << "-n " << params.nb_proc;
2130 command_nodes << "mpirun -np " << params.nb_proc;
2132 command_nodes << " " << exe_name;
2133 command_nodes << " " << container_name;
2134 command_nodes << " " << params.parallelLib.in();
2135 command_nodes << " " << proxy_hostname;
2136 command_nodes << " -";
2137 AddOmninamesParams(command_nodes);
2139 // We don't put hostname, because nodes are registered in the resource of the proxy
2140 for (int i= 0; i < params.nb_proc; i++)
2141 vect_machine.push_back(proxy_hostname);
2143 command_nodes << command_end;
2145 return command_nodes.str();
2149 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
2150 const std::string & exe_type,
2151 const std::string & container_name,
2152 const std::string & hostname,
2153 std::string & begin,
2156 if(log_type == "xterm")
2158 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
2161 else if(log_type == "xterm_debug")
2163 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
2168 // default into a file...
2169 std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
2170 std::string user = GetenvThreadSafeAsString("USER");
2172 user = GetenvThreadSafeAsString("LOGNAME");
2173 logFilename += user + ".log";
2174 end = " > " + logFilename + " 2>&1 & ";
2179 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
2180 const Engines::ContainerParameters& params,
2181 const std::string & hostname)
2183 PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
2185 MESSAGE("[LaunchPaCOProxyContainer] Launch command");
2186 int status = SystemThreadSafe(command.c_str());
2188 INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
2189 return container_proxy;
2191 else if (status == 217) {
2192 INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
2193 return container_proxy;
2196 int count(GetTimeOutToLoaunchServer());
2197 CORBA::Object_var obj = CORBA::Object::_nil();
2198 std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
2200 MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
2202 while (CORBA::is_nil(obj) && count)
2206 obj = _NS->Resolve(containerNameInNS.c_str());
2211 container_proxy = PaCO::InterfaceManager::_narrow(obj);
2213 catch(CORBA::SystemException& e)
2215 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2216 INFOS("CORBA::SystemException : " << e);
2217 return container_proxy;
2219 catch(CORBA::Exception& e)
2221 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2222 INFOS("CORBA::Exception" << e);
2223 return container_proxy;
2227 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2228 INFOS("Unknown exception !");
2229 return container_proxy;
2231 if (CORBA::is_nil(container_proxy))
2233 INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
2234 return container_proxy;
2239 //=============================================================================
2240 /*! This method launches the parallel container.
2241 * It will may be placed on the resources manager.
2243 * \param command to launch
2244 * \param container's parameters
2245 * \param name of the container
2247 * \return CORBA container reference
2249 //=============================================================================
2251 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
2252 const Engines::ContainerParameters& params,
2253 const std::string& name,
2254 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
2256 INFOS("[LaunchPaCONodeContainer] Launch command");
2257 int status = SystemThreadSafe(command.c_str());
2259 INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
2262 else if (status == 217) {
2263 INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
2267 INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
2268 // We are waiting all the nodes
2269 for (int i = 0; i < params.nb_proc; i++)
2271 CORBA::Object_var obj = CORBA::Object::_nil();
2272 std::string theMachine(vect_machine[i]);
2274 std::ostringstream tmp;
2276 std::string proc_number = tmp.str();
2277 std::string container_node_name = name + proc_number;
2278 std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
2279 INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
2280 int count(GetTimeOutToLoaunchServer());
2281 while (CORBA::is_nil(obj) && count) {
2284 obj = _NS->Resolve(containerNameInNS.c_str());
2286 if (CORBA::is_nil(obj))
2288 INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
2297 Engines::Container_ptr
2298 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& /*params*/,
2299 std::string /*resource_selected*/)
2301 Engines::Container_ptr ret = Engines::Container::_nil();
2302 INFOS("[StarPaCOPPContainer] is disabled !");
2303 INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
2308 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& /*params*/,
2309 std::string /*machine_file_name*/,
2310 std::string & /*proxy_hostname*/)
2316 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& /*params*/,
2317 const std::string & /*machine_file_name*/,
2318 SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/,
2319 const std::string & /*proxy_hostname*/)
2324 SALOME_ContainerManager::LogConfiguration(const std::string & /*log_type*/,
2325 const std::string & /*exe_type*/,
2326 const std::string & /*container_name*/,
2327 const std::string & /*hostname*/,
2328 std::string & /*begin*/,
2329 std::string & /*end*/)
2334 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& /*command*/,
2335 const Engines::ContainerParameters& /*params*/,
2336 const std::string& /*hostname*/)
2338 CORBA::Object_ptr ret = CORBA::Object::_nil();
2343 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& /*command*/,
2344 const Engines::ContainerParameters& /*params*/,
2345 const std::string& /*name*/,
2346 SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/)