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 void SALOME_ContainerManager::SetDirectoryForReplayFiles(const char *directory)
251 SALOME::SetDirectoryForReplayFiles( directory );
254 void SALOME_ContainerManager::SetNumberOfRetry(CORBA::Long nbRetry)
256 SALOME::SetNumberOfRetry( nbRetry );
259 CORBA::Long SALOME_ContainerManager::GetNumberOfRetry()
261 return SALOME::GetNumberOfRetry();
264 //=============================================================================
265 //! Loop on all the containers listed in naming service, ask shutdown on each
268 //=============================================================================
270 void SALOME_ContainerManager::ShutdownContainersGeneric(std::function<void(Engines::Container_ptr)> funcToBeCalledOnContainer)
272 MESSAGE("ShutdownContainersGeneric");
275 SALOME::Session_var session = SALOME::Session::_nil();
277 CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
278 if (!CORBA::is_nil(objS))
280 session = SALOME::Session::_narrow(objS);
281 if (!CORBA::is_nil(session))
282 pid = session->getPID();
286 isOK = _NS->Change_Directory("/Containers");
288 std::vector<std::string> vec = _NS->list_directory_recurs();
289 std::list<std::string> lstCont;
290 for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
293 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
296 Engines::Container_var cont=Engines::Container::_narrow(obj);
297 if(!CORBA::is_nil(cont) && pid != cont->getPID())
298 lstCont.push_back((*iter));
300 catch(const CORBA::Exception&)
302 // ignore this entry and continue
305 MESSAGE("Container list: ");
306 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
309 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
314 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
315 Engines::Container_var cont=Engines::Container::_narrow(obj);
316 if(!CORBA::is_nil(cont))
318 MESSAGE("ShutdownContainersGeneric: " << (*iter));
319 funcToBeCalledOnContainer( cont );
320 MESSAGE("ShutdownContainersGeneric: after call of shutdown" << (*iter));
323 MESSAGE("ShutdownContainersGeneric: no container ref for " << (*iter));
325 catch(CORBA::SystemException& e)
327 INFOS("CORBA::SystemException ignored : " << e);
329 catch(CORBA::Exception&)
331 INFOS("CORBA::Exception ignored.");
335 INFOS("Unknown exception ignored.");
341 void SALOME_ContainerManager::ShutdownContainers()
343 this->ShutdownContainersGeneric( [](Engines::Container_ptr cont) { cont->Shutdown(); } );
346 void SALOME_ContainerManager::ShutdownContainersNow()
348 this->ShutdownContainersGeneric( [](Engines::Container_ptr cont)
361 void SALOME_ContainerManager::SetOverrideEnvForContainers(const Engines::KeyValDict& env)
363 this->_override_env.clear();
364 auto sz = env.length();
365 for(auto i = 0 ; i < sz ; ++i)
366 _override_env.emplace_back(env[i].key.in(), env[i].val.in());
369 Engines::KeyValDict *SALOME_ContainerManager::GetOverrideEnvForContainers()
371 std::unique_ptr<Engines::KeyValDict> ret( new Engines::KeyValDict );
372 auto sz = _override_env.size();
374 for(auto i = 0 ; i < sz ; ++i)
376 (*ret)[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
377 (*ret)[i].val = CORBA::string_dup( _override_env[i].second.c_str() );
379 return ret.release();
382 void SALOME_ContainerManager::SetCodeOnContainerStartUp(const char *code)
384 _code_to_exe_on_startup = code;
387 char *SALOME_ContainerManager::GetCodeOnContainerStartUp()
389 return CORBA::string_dup( _code_to_exe_on_startup.c_str() );
392 //=============================================================================
393 //! Give a suitable Container given constraints
395 * \param params Container Parameters required for the container
396 * \return the container or nil
398 //=============================================================================
399 Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
401 std::string machFile;
402 Engines::Container_ptr ret(Engines::Container::_nil());
404 // Step 0: Default mode is start
405 Engines::ContainerParameters local_params(params);
406 if (std::string(local_params.mode.in()) == "")
407 local_params.mode = CORBA::string_dup("start");
408 std::string mode = local_params.mode.in();
409 MESSAGE("[GiveContainer] starting with mode: " << mode);
411 // Step 1: Find Container for find and findorstart mode
412 if (mode == "find" || mode == "findorstart")
414 ret = FindContainer(params, params.resource_params.resList);
415 if(!CORBA::is_nil(ret))
421 MESSAGE("[GiveContainer] no container found");
431 // Step 2: Get all possibleResources from the parameters
432 // Consider only resources that can run containers
433 resourceParams resource_params = resourceParameters_CORBAtoCPP(local_params.resource_params);
434 resource_params.can_run_containers = true;
435 std::vector<std::string> possibleResources = _resManager->GetFittingResources(resource_params);
436 MESSAGE("[GiveContainer] - length of possible resources " << possibleResources.size());
437 std::vector<std::string> local_resources;
439 // Step 3: if mode is "get" keep only machines with existing containers
442 for(unsigned int i=0; i < possibleResources.size(); i++)
444 Engines::Container_ptr cont = FindContainer(params, possibleResources[i]);
447 if(!cont->_non_existent())
448 local_resources.push_back(possibleResources[i]);
450 catch(CORBA::Exception&) {}
453 // if local_resources is empty, we cannot give a container
454 if (local_resources.size() == 0)
456 MESSAGE("[GiveContainer] cannot find a container for mode get");
461 local_resources = possibleResources;
463 // Step 4: select the resource where to get/start the container
464 bool resource_available = true;
465 std::string resource_selected;
466 std::vector<std::string> resources = local_resources;
467 while (resource_available)
469 if (resources.size() == 0)
470 resource_available = false;
475 resource_selected = _resManager->Find(params.resource_params.policy.in(), resources);
476 // Remove resource_selected from vector
477 std::vector<std::string>::iterator it;
478 for (it=resources.begin() ; it < resources.end(); it++ )
479 if (*it == resource_selected)
485 catch(const SALOME_Exception &ex) //!< TODO: unused variable
487 MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
490 MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
492 // Step 5: Create container name
493 ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
494 std::string hostname(resource_definition.HostName);
495 std::string containerNameInNS;
497 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
500 if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
501 machFile = machinesFile(nbproc);
503 catch(const SALOME_Exception & ex)
505 std::string err_msg = ex.what();
506 err_msg += params.container_name;
507 INFOS(err_msg.c_str());
510 // A mpi parallel container register on zero node in NS
511 std::string mpiZeroNode = GetMPIZeroNode(resource_selected,machFile).c_str();
512 containerNameInNS = _NS->BuildContainerNameForNS(params, mpiZeroNode.c_str());
515 containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
516 MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
518 // Step 6: check if the name exists in naming service
519 //if params.mode == "getorstart" or "get" use the existing container
520 //if params.mode == "start" shutdown the existing container before launching a new one with that name
522 { // critical section
523 Utils_Locker lock (&_giveContainerMutex1);
524 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
525 if (!CORBA::is_nil(obj))
529 Engines::Container_var cont=Engines::Container::_narrow(obj);
530 if(!cont->_non_existent())
532 if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
533 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
537 INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
538 cont->Shutdown(); // shutdown the registered container if it exists
542 catch(CORBA::Exception&)
544 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
547 } // end critical section
548 Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
549 if (!CORBA::is_nil(cont))
551 INFOS("[GiveContainer] container " << containerNameInNS << " launched");
552 cont->monitoringtimeresms( this->_delta_time_measure_in_ms );
553 INFOS("[GiveContainer] container " << containerNameInNS << " first CORBA invocation OK");
554 std::ostringstream envInfo;
555 std::for_each( _override_env.begin(), _override_env.end(), [&envInfo](const std::pair<std::string,std::string>& p) { envInfo << p.first << " = " << p.second << " "; } );
556 INFOS("[GiveContainer] container " << containerNameInNS << " override " << envInfo.str());
557 cont->set_big_obj_on_disk_directory( SALOME::GetBigObjOnDiskDirectoryCoarse().c_str() );
558 cont->set_big_obj_on_disk_threshold( SALOME::GetBigObjOnDiskThreshold() );
559 cont->set_directory_for_replay_files( SALOME::GetDirectoryForReplayFiles().c_str() );
560 cont->set_number_of_retry( SALOME::GetNumberOfRetry() );
561 Engines::FieldsDict envCorba;
563 auto sz = _override_env.size();
565 for(auto i = 0 ; i < sz ; ++i)
567 envCorba[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
568 envCorba[i].value <<= CORBA::string_dup( _override_env[i].second.c_str() );
571 cont->override_environment_python( envCorba );
572 if( SALOME::GetForwardCurrentDirectoryStatus() )
573 cont->set_current_directory( SALOME::GetCurrentWorkingDirectory().c_str() );
574 if( !_code_to_exe_on_startup.empty() )
576 INFOS("[GiveContainer] container " << containerNameInNS << " python code executed " << _code_to_exe_on_startup);
577 cont->set_startup_code( _code_to_exe_on_startup.c_str() );
578 cont->execute_python_code( _code_to_exe_on_startup.c_str() );
580 INFOS("[GiveContainer] container " << containerNameInNS << " verbosity positionning Activation = " << SALOME::VerbosityActivated() << " Verbosity Level = " << SALOME::VerbosityLevelStr());
581 cont->setVerbosity( SALOME::VerbosityActivated(), SALOME::VerbosityLevelStr().c_str() );
586 INFOS("[GiveContainer] Failed to launch container on resource " << resource_selected);
591 // We were not able to launch the container
592 INFOS("[GiveContainer] Cannot launch the container on the following selected resources:")
593 std::vector<std::string>::iterator it;
594 for (it=local_resources.begin() ; it < local_resources.end(); it++ )
595 INFOS("[GiveContainer] " << *it)
599 std::string SALOME_ContainerManager::GetCppBinaryOfKernelSSLContainer() const
601 switch( SALOME::GetPyExecutionMode() )
603 case SALOME::PyExecutionMode::InProcess:
604 return "SALOME_Container_No_NS_Serv";
605 case SALOME::PyExecutionMode::OutOfProcessNoReplay:
606 return "SALOME_Container_No_NS_Serv_OutProcess";
607 case SALOME::PyExecutionMode::OutOfProcessWithReplay:
608 return "SALOME_Container_No_NS_Serv_OutProcess_Replay";
609 case SALOME::PyExecutionMode::OutOfProcessNoReplayFT:
610 return "SALOME_Container_No_NS_Serv_OutProcess_FT";
611 case SALOME::PyExecutionMode::OutOfProcessWithReplayFT:
612 return "SALOME_Container_No_NS_Serv_OutProcess_Replay_FT";
615 ERROR_MESSAGE("Not manager py execution mode");
616 THROW_SALOME_EXCEPTION("GetCppBinaryOfKernelSSLContainer : Not manager py execution mode");
621 std::string SALOME_ContainerManager::GetCppBinaryOfKernelContainer() const
623 std::string ret = this->_isSSL ? GetCppBinaryOfKernelSSLContainer() : "SALOME_Container";
627 std::string SALOME_ContainerManager::GetRunRemoteExecutableScript() const
629 std::string ret = this->_isSSL ? "runRemoteSSL.sh" : "runRemote.sh";
633 Engines::Container_ptr
634 SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
635 const std::string & resource_selected,
636 const std::string & hostname,
637 const std::string & machFile,
638 const std::string & containerNameInNS)
640 std::string user,command,logFilename,tmpFileName;
642 Engines::Container_ptr ret(Engines::Container::_nil());
643 {//start of critical section
644 Utils_Locker lock (&_giveContainerMutex1);
645 // Step 1: type of container: PaCO, Exe, Mpi or Classic
646 // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
647 // TODO -> separates Mpi from Classic/Exe
649 std::string container_exe = this->GetCppBinaryOfKernelContainer();
650 Engines::ContainerParameters local_params(params);
654 CORBA::String_var container_exe_tmp;
655 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
656 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
657 if (CORBA::is_nil (Catalog))
659 INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
662 // Loop through component list
663 for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
665 const char* compoi = local_params.resource_params.componentList[i];
666 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
667 if (CORBA::is_nil (compoInfo))
671 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
672 container_exe_tmp=compoInfo->implementation_name();
673 if(impl==SALOME_ModuleCatalog::CEXE)
677 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
678 return Engines::Container::_nil();
680 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
681 container_exe = container_exe_tmp.in();
686 catch (ServiceUnreachable&)
688 INFOS("Caught exception: Naming Service Unreachable");
693 INFOS("Caught unknown exception.");
697 // Step 2: test resource
698 // Only if an application directory is set
699 if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
702 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
703 std::string command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
704 resInfo.UserName, resInfo.AppliPath);
706 // Launch remote command
707 command += " \"ls /tmp >/dev/null 2>&1\"";
708 // Anthony : command is NO MORE launched to improve dramatically time to launch containers
712 // Error on resource - cannot launch commands
713 INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
714 INFOS("[LaunchContainer] Command was " << command);
716 INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
718 return Engines::Container::_nil();
722 // Step 3: start a new container
723 // Check if a PaCO container
725 if (std::string(local_params.parallelLib.in()) != "")
727 ret = StartPaCOPPContainer(params, resource_selected);
730 // Other type of containers...
731 MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
732 // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
733 if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL && params.isMPI )
735 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
736 MESSAGE("[LaunchContainer] LIBBATCH_NODEFILE : \"" << command << "\"");
738 // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
739 else if(hostname == Kernel_Utils::GetHostname())
741 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
742 MESSAGE("[LaunchContainer] hostname local : \"" << command << "\"");
744 // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
747 command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
748 MESSAGE("[LaunchContainer] remote : \"" << command << "\"");
751 //redirect stdout and stderr in a file
753 logFilename=GetenvThreadSafeAsString("TEMP");
755 user = GetenvThreadSafeAsString( "USERNAME" );
757 user = GetenvThreadSafeAsString( "USER" );
759 user = GetenvThreadSafeAsString( "LOGNAME" );
761 char* val = GetenvThreadSafe("SALOME_TMP_DIR");
764 struct stat file_info;
765 stat(val, &file_info);
766 bool is_dir = S_ISDIR(file_info.st_mode);
770 MESSAGE( "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl );
774 logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
775 std::ostringstream tmp;
776 tmp << "_" << getpid();
777 logFilename += tmp.str();
778 logFilename += ".log" ;
779 command += " > " + logFilename + " 2>&1";
780 MakeTheCommandToBeLaunchedASync(command);
782 MESSAGE("[LaunchContainer] SYSTEM COMMAND that will be launched : \"" << command << "\"");
783 // launch container with a system call
784 status=SystemThreadSafe(command.c_str());
785 }//end of critical of section
789 INFOS("[LaunchContainer] command failed (system command status -1): " << command);
790 RmTmpFile(tmpFileName); // command file can be removed here
791 return Engines::Container::_nil();
793 else if (status == 217)
795 INFOS("[LaunchContainer] command failed (system command status 217): " << command);
796 RmTmpFile(tmpFileName); // command file can be removed here
797 return Engines::Container::_nil();
801 // Step 4: Wait for the container
802 double nbTurn = ( (double)this->_time_out_in_second ) * ( 1000.0 / ( (double) this->_delta_time_ns_lookup_in_ms) );
803 int count( (int)nbTurn );
804 INFOS("[GiveContainer] # attempts : " << count << " name in NS : \"" << containerNameInNS << "\"");
805 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);
806 while (CORBA::is_nil(ret) && count)
808 std::this_thread::sleep_for(std::chrono::milliseconds(_delta_time_ns_lookup_in_ms));
810 MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected << " with entry in NS = \"" << containerNameInNS << "\"" );
811 CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str()));
812 ret=Engines::Container::_narrow(obj);
814 if (CORBA::is_nil(ret))
816 INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
820 // Setting log file name
821 ret->locallogfilename( logFilename.c_str() );
822 logFilename=":"+logFilename;
823 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;//threadsafe
824 logFilename=user+logFilename;
825 ret->logfilename(logFilename.c_str());
826 RmTmpFile(tmpFileName); // command file can be removed here
832 //=============================================================================
833 //! Find a container given constraints (params) on a list of machines (possibleComputers)
834 //! agy : this method is ThreadSafe
838 //=============================================================================
840 Engines::Container_ptr SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const Engines::ResourceList& possibleResources)
842 MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
843 for(unsigned int i=0; i < possibleResources.length();i++)
845 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
846 if(!CORBA::is_nil(cont))
849 MESSAGE("[FindContainer] no container found");
850 return Engines::Container::_nil();
853 //=============================================================================
854 //! Find a container given constraints (params) on a machine (theMachine)
855 //! agy : this method is ThreadSafe
859 //=============================================================================
861 Engines::Container_ptr
862 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const std::string& resource)
864 ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource);
865 std::string hostname(resource_definition.HostName);
866 std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
867 MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
868 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
871 if(obj->_non_existent())
872 return Engines::Container::_nil();
874 return Engines::Container::_narrow(obj);
876 catch(const CORBA::Exception&)
878 return Engines::Container::_nil();
883 bool isPythonContainer(const char* ContainerName);
885 //=============================================================================
887 * This is no longer valid (C++ container are also python containers)
889 //=============================================================================
890 bool isPythonContainer(const char* ContainerName)
892 return false; // VSR 02/08/2013: Python containers are no more supported
894 size_t len = strlen(ContainerName);
897 if (strcmp(ContainerName + len - 2, "Py") == 0)
903 //=============================================================================
905 * Builds the script to be launched
907 * If SALOME Application not defined ($APPLI),
908 * see BuildTempFileToLaunchRemoteContainer()
910 * Else rely on distant configuration. Command is under the form (example):
911 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
912 * SALOME_Container containerName &"
914 * - where user is omitted if not specified in CatalogResources,
915 * - where distant path is always relative to user@machine $HOME, and
916 * equal to $APPLI if not specified in CatalogResources,
917 * - where hostNS is the hostname of CORBA naming server (set by scripts to
918 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
919 * - where portNS is the port used by CORBA naming server (set by scripts to
920 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
921 * - where workingdir is the requested working directory for the container.
922 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
924 //=============================================================================
927 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& resource_name, const Engines::ContainerParameters& params, const std::string& container_exe) const
929 std::string command,tmpFileName;
930 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
931 std::string wdir = params.workingdir.in();
932 if (!_isAppliSalomeDefined)
934 MESSAGE("[BuildCommandToLaunchRemoteContainer] NO APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
935 command = getCommandToRunRemoteProcessNoAppli(resInfo.Protocol, resInfo.HostName,
936 resInfo.UserName, resInfo.AppliPath,
941 MESSAGE("[BuildCommandToLaunchRemoteContainer] WITH APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
942 // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
943 // SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
945 // "ssh -l user machine distantLauncher remote -p hostNS -m portNS -d dir
946 // -- SALOME_Container contName -ORBInitRef NameService=IOR:01000..."
947 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
948 resInfo.UserName, resInfo.AppliPath,
953 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
954 command += " mpirun -np ";
955 std::ostringstream o;
959 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
960 #elif defined(OPEN_MPI)
961 if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
962 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
964 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
965 command += GetenvThreadSafeAsString("OMPI_URI_FILE");
968 command += "-nameserver " + Kernel_Utils::GetHostname();
970 command += " SALOME_MPIContainer ";
973 command += " " +container_exe+ " ";
975 command += _NS->ContainerName(params) + " ";
978 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
979 CORBA::String_var iorNS = _orb->object_to_string(ns);
980 command += std::string(iorNS);
982 else //if(!this->_isSSL)
985 AddOmninamesParams(command);
987 MESSAGE("command =" << command);
992 //=============================================================================
993 //! Return a path to the directory with scripts templates
995 * \return the path pointed by SALOME_KERNEL_SCRIPTS_DIR environment variable, if it is defined,
996 * ${KERNEL_ROOT_DIR}/share/salome/resources/separator/kernel/ScriptsTemplate - otherwise
998 //=============================================================================
999 std::string getScriptTemplateFilePath()
1001 auto parseScriptTemplateFilePath = []() -> std::string
1003 std::string scriptTemplateFilePath = SALOME_ContainerManager::GetenvThreadSafeAsString("SALOME_KERNEL_SCRIPTS_DIR");
1004 if (!scriptTemplateFilePath.empty())
1006 return scriptTemplateFilePath;
1009 return SALOME_ContainerManager::GetenvThreadSafeAsString("KERNEL_ROOT_DIR") +
1010 "/share/salome/resources/kernel/ScriptsTemplate";
1014 static const std::string scriptTemplateFilePath = parseScriptTemplateFilePath();
1015 return scriptTemplateFilePath;
1018 //=============================================================================
1019 //! Return a command line constructed based on Python scripts templates
1021 * \param theScriptName the name of Python script template
1022 * \param theScriptParameters the queue of parameter values
1023 * \return the command line constructed according to the given parameters
1025 //=============================================================================
1026 std::string GetCommandFromTemplate(const std::string& theScriptName,
1027 std::queue<std::string>& theScriptParameters)
1029 std::string command;
1033 PyObject* mod(PyImport_ImportModule(theScriptName.c_str()));
1034 MESSAGE("Template name :"<< theScriptName.c_str());
1038 AutoPyRef sys = PyImport_ImportModule("sys");
1039 AutoPyRef sys_path = PyObject_GetAttrString(sys, "path");
1040 AutoPyRef folder_path = PyUnicode_FromString(getScriptTemplateFilePath().c_str());
1041 PyList_Append(sys_path, folder_path);
1043 mod = PyImport_ImportModule(theScriptName.c_str());
1049 PyObject* meth(PyObject_GetAttrString(mod, "command"));
1057 PyObject* tuple(PyTuple_New(theScriptParameters.size()));
1059 auto insert_parameter = [&tuple, &theScriptParameters, &id]()
1061 if (!theScriptParameters.empty())
1063 PyTuple_SetItem(tuple, ++id, PyUnicode_FromString(theScriptParameters.front().c_str()));
1064 theScriptParameters.pop();
1068 while (!theScriptParameters.empty())
1073 PyObject *args(PyTuple_New(1));
1074 PyTuple_SetItem(args, 0, tuple);
1076 PyObject *res(PyObject_CallObject(meth, args));
1079 command = PyUnicode_AsUTF8(res);
1091 ERROR_MESSAGE("Can not import the template script \"" << theScriptName << "\" !");
1094 MESSAGE("Command from template is ... " << command << std::endl);
1097 //=============================================================================
1099 //=============================================================================
1101 * builds the command to be launched.
1103 //=============================================================================
1104 std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe, std::string& tmpFileName) const
1106 // Prepare name of the script to be used
1107 std::string script_name = "SALOME_CM_LOCAL_NO_MPI";
1111 script_name = "SALOME_CM_LOCAL_MPI_LAN";
1112 #elif defined(OPEN_MPI)
1113 script_name = "SALOME_CM_LOCAL_MPI_OPENMPI";
1114 #elif defined(MPICH)
1115 script_name = "SALOME_CM_LOCAL_MPI_MPICH";
1119 // Prepare parameters to use in the Python script:
1120 // 1. All parameters are strings.
1121 // 2. For some booleans use "1" = True, "0" = False.
1122 // 3. If a parameter is NULL, then its value is "NULL".
1124 std::queue<std::string> script_parameters;
1126 // ===== Number of processes (key = "nb_proc")
1127 script_parameters.push(params.isMPI ? std::to_string(params.nb_proc <= 0 ? 1 : params.nb_proc) : "NULL");
1129 // ===== Working directory (key = "workdir") and temporary directory flag (key = "isTmpDir")
1130 // A working directory is requested
1131 std::string workdir = params.workingdir.in();
1132 std::string isTmpDir = std::to_string(0);
1133 if (workdir == "$TEMPDIR")
1135 // A new temporary directory is requested
1136 isTmpDir = std::to_string(1);
1137 workdir = Kernel_Utils::GetTmpDir();
1139 script_parameters.push(workdir);
1140 script_parameters.push(isTmpDir);
1142 // ===== Server name (key = "name_server")
1143 script_parameters.push(Kernel_Utils::GetHostname());
1145 // ===== Container (key = "container")
1146 std::string container;
1149 container = isPythonContainer(params.container_name) ? "pyMPI SALOME_ContainerPy.py" : "SALOME_MPIContainer";
1153 container = isPythonContainer(params.container_name) ? "SALOME_ContainerPy.py" : container_exe;
1155 script_parameters.push(container);
1157 // ===== Container name (key = "container_name")
1158 script_parameters.push(_NS->ContainerName(params));
1160 // ===== LIBBATCH node file (key = "libbatch_nodefile")
1161 script_parameters.push(std::to_string(GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL ? 1 : 0));
1163 // ===== Machine file (key = "machine_file")
1164 script_parameters.push(machinesFile.empty() ? "NULL" : machinesFile);
1166 // ===== OMPI uri file (key = "ompi_uri_file")
1167 std::string ompi_uri_file = GetenvThreadSafeAsString("OMPI_URI_FILE");
1168 script_parameters.push(ompi_uri_file.empty() ? "NULL" : ompi_uri_file);
1170 MESSAGE("Retrieving command from template (python module) \"" << script_name << "\"" << std::endl);
1171 std::string command_from_template = GetCommandFromTemplate(script_name, script_parameters);
1173 std::ostringstream o;
1174 o << command_from_template << " ";
1176 //==================================================================================== */
1180 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1181 CORBA::String_var iorNS = _orb->object_to_string(ns);
1187 AddOmninamesParams(o);
1190 tmpFileName = BuildTemporaryFileName();
1191 std::ofstream command_file( tmpFileName.c_str() );
1192 command_file << o.str();
1193 command_file.close();
1196 chmod(tmpFileName.c_str(), 0x1ED);
1199 std::string command = tmpFileName;
1200 MESSAGE("Command is file ... " << command);
1201 MESSAGE("Command is ... " << o.str());
1206 //=============================================================================
1208 * removes the generated temporary file in case of a remote launch.
1209 * This method is thread safe
1211 //=============================================================================
1213 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
1215 size_t length = tmpFileName.size();
1219 std::string command = "del /F ";
1221 std::string command = "rm ";
1224 command += tmpFileName.substr(0, length - 3 );
1226 command += tmpFileName;
1228 SystemThreadSafe(command.c_str());
1229 //if dir is empty - remove it
1230 std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
1231 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
1234 command = "del /F " + tmp_dir;
1236 command = "rmdir " + tmp_dir;
1238 SystemThreadSafe(command.c_str());
1243 //=============================================================================
1245 * add to command all options relative to naming service.
1247 //=============================================================================
1249 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
1251 std::ostringstream oss;
1252 AddOmninamesParams(oss);
1256 //=============================================================================
1258 * add to command all options relative to naming service.
1260 //=============================================================================
1262 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const
1264 AddOmninamesParams(fileStream,_NS);
1267 //=============================================================================
1269 * add to command all options relative to naming service.
1271 //=============================================================================
1273 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns)
1275 SALOME_NamingService *nsTrad(dynamic_cast<SALOME_NamingService *>(ns));
1278 CORBA::String_var iorstr(nsTrad->getIORaddr());
1279 fileStream << "ORBInitRef NameService=";
1280 fileStream << iorstr;
1284 void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command)
1287 command = "%PYTHONBIN% -c \"import subprocess ; subprocess.Popen(r'" + command + "').pid\"";
1294 * Return in second the time out to give chance to server to be launched and
1295 * to register into NS
1297 int SALOME_ContainerManager::GetTimeOutToLoaunchServer()
1299 int count(TIME_OUT_TO_LAUNCH_CONT);
1300 if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
1302 std::string new_count_str(GetenvThreadSafeAsString("TIMEOUT_TO_LAUNCH_CONTAINER"));
1304 std::istringstream ss(new_count_str);
1305 if (!(ss >> new_count))
1307 INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
1315 void SALOME_ContainerManager::SleepInSecond(int ellapseTimeInSecond)
1318 sleep( ellapseTimeInSecond ) ;
1320 int timeInMS(1000*ellapseTimeInSecond);
1325 //=============================================================================
1327 * generate a file name in /tmp directory
1329 //=============================================================================
1331 std::string SALOME_ContainerManager::BuildTemporaryFileName()
1333 //build more complex file name to support multiple salome session
1334 std::string aFileName = Kernel_Utils::GetTmpFileName();
1335 std::ostringstream str_pid;
1336 str_pid << ::getpid();
1337 aFileName = aFileName + "-" + str_pid.str();
1341 aFileName += ".bat";
1346 //=============================================================================
1348 * Builds in a temporary file the script to be launched.
1350 * Used if SALOME Application ($APPLI) is not defined.
1351 * The command is build with data from CatalogResources, in which every path
1352 * used on remote computer must be defined.
1354 //=============================================================================
1356 std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const
1360 tmpFileName = BuildTemporaryFileName();
1361 std::ofstream tempOutputFile;
1362 tempOutputFile.open(tmpFileName.c_str(), std::ofstream::out );
1363 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
1364 tempOutputFile << "#! /bin/sh" << std::endl;
1368 tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1369 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1375 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
1377 tempOutputFile << "mpirun -np ";
1379 tempOutputFile << nbproc << " ";
1381 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1382 #elif defined(OPEN_MPI)
1383 if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
1384 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1386 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1387 tempOutputFile << GetenvThreadSafeAsString("OMPI_URI_FILE");
1389 #elif defined(MPICH)
1390 tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
1394 tempOutputFile << GetenvThreadSafeAsString("KERNEL_ROOT_DIR") << "/bin/salome/";
1398 if (isPythonContainer(params.container_name))
1399 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1401 tempOutputFile << " SALOME_MPIContainer ";
1406 if (isPythonContainer(params.container_name))
1407 tempOutputFile << "SALOME_ContainerPy.py ";
1409 tempOutputFile << "SALOME_Container ";
1412 tempOutputFile << _NS->ContainerName(params) << " -";
1413 AddOmninamesParams(tempOutputFile);
1414 tempOutputFile << " &" << std::endl;
1415 tempOutputFile.flush();
1416 tempOutputFile.close();
1418 chmod(tmpFileName.c_str(), 0x1ED);
1421 // --- Build command
1423 std::string command;
1425 if (resInfo.Protocol == rsh)
1428 std::string commandRcp = "rcp ";
1429 commandRcp += tmpFileName;
1431 commandRcp += resInfo.HostName;
1433 commandRcp += tmpFileName;
1434 status = SystemThreadSafe(commandRcp.c_str());
1437 else if (resInfo.Protocol == ssh)
1440 std::string commandRcp = "scp ";
1441 commandRcp += tmpFileName;
1443 commandRcp += resInfo.HostName;
1445 commandRcp += tmpFileName;
1446 status = SystemThreadSafe(commandRcp.c_str());
1449 else if (resInfo.Protocol == srun)
1451 command = "srun -n 1 -N 1 --overlap --mem-per-cpu=0 --cpu-bind=none --nodelist=";
1452 std::string commandRcp = "rcp ";
1453 commandRcp += tmpFileName;
1455 commandRcp += resInfo.HostName;
1457 commandRcp += tmpFileName;
1458 status = SystemThreadSafe(commandRcp.c_str());
1461 throw SALOME_Exception("Unknown protocol");
1464 throw SALOME_Exception("Error of connection on remote host");
1466 command += resInfo.HostName;
1468 command += tmpFileName;
1476 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile) const
1479 std::string zeronode;
1480 std::string command;
1481 std::string tmpFile = BuildTemporaryFileName();
1482 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
1484 if(resInfo.Protocol == sh)
1486 return resInfo.HostName;
1489 if( GetenvThreadSafe("LIBBATCH_NODEFILE") == NULL )
1491 if (_isAppliSalomeDefined)
1493 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
1494 resInfo.UserName, resInfo.AppliPath);
1495 command += " mpirun -np 1 hostname -s > " + tmpFile;
1498 command = "mpirun -np 1 hostname -s > " + tmpFile;
1501 command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
1503 status = SystemThreadSafe(command.c_str());
1505 std::ifstream fp(tmpFile.c_str(),std::ios::in);
1506 while(fp >> zeronode);
1514 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1517 std::string nodesFile = GetenvThreadSafeAsString("LIBBATCH_NODEFILE");
1518 std::string machinesFile = Kernel_Utils::GetTmpFileName();
1519 std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1520 std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1522 _numInstanceMutex.lock();
1524 for(int i=0;i<_nbprocUsed;i++)
1527 for(int i=0;i<nbproc;i++)
1529 fpo << tmp << std::endl;
1531 throw SALOME_Exception("You need more processors than batch session have allocated for you! Unable to launch the mpi container: ");
1533 _nbprocUsed += nbproc;
1537 _numInstanceMutex.unlock();
1539 return machinesFile;
1543 std::string SALOME_ContainerManager::getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
1545 return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE","salome shell --",protocol,hostname,username,applipath,workdir);
1548 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
1550 return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE_OLD",this->GetRunRemoteExecutableScript(),protocol,hostname,username,applipath,workdir);
1553 std::string SALOME_ContainerManager::getCommandToRunRemoteProcessCommon(const std::string& templateName,
1554 const std::string& remoteScript,
1555 AccessProtocolType protocol,
1556 const std::string & hostname,
1557 const std::string & username,
1558 const std::string & applipath,
1559 const std::string & workdir) const
1561 std::ostringstream command;
1563 // Prepare parameters to use in the Python script:
1564 // 1. All parameters are strings.
1565 // 2. For some booleans use "1" = True, "0" = False.
1566 // 3. If a parameter is NULL, then its value is "NULL".
1568 std::queue<std::string> script_parameters;
1570 // ===== Protocol (key = "protocol")
1571 std::string strProtocol;
1574 case rsh: strProtocol = "rsh"; break;
1575 case ssh: strProtocol = "ssh"; break;
1576 case srun: strProtocol = "srun"; break;
1577 case pbsdsh: strProtocol = "pbsdsh"; break;
1578 case blaunch: strProtocol = "blaunch"; break;
1580 throw SALOME_Exception("Unknown protocol");
1582 script_parameters.push(strProtocol);
1584 // ===== User name (key = "user")
1585 script_parameters.push(username.empty() ? "NULL" : username);
1587 // ===== Host name (key = "host")
1588 script_parameters.push(hostname.empty() ? "NULL" : hostname);
1591 // ===== Remote APPLI path (key = "appli")
1592 script_parameters.push(applipath.empty() ? GetenvThreadSafeAsString("APPLI") : applipath);
1596 ASSERT(GetenvThreadSafe("NSHOST"));
1597 ASSERT(GetenvThreadSafe("NSPORT"));
1600 struct stat statbuf;
1601 std::string appli_mode = (stat(GetenvThreadSafe("APPLI"), &statbuf) == 0 && S_ISREG(statbuf.st_mode)) ? "launcher" : "dir";
1603 // ===== Working directory (key = "workdir")
1604 script_parameters.push(workdir == "$TEMPDIR" ? "\\$TEMPDIR" : workdir);
1606 // ===== SSL (key = "ssl")
1607 script_parameters.push(this->_isSSL ? "1" : "0");
1609 // ===== Hostname of CORBA name server (key = "nshost")
1610 std::string nshost = GetenvThreadSafeAsString("NSHOST");
1611 script_parameters.push(nshost.empty() ? "NULL" : nshost);
1613 // ===== Port of CORBA name server (key = "nsport")
1614 std::string nsport = GetenvThreadSafeAsString("NSPORT");
1615 script_parameters.push(nsport.empty() ? "NULL" : nsport);
1617 // ===== Remote script (key = "remote_script")
1618 script_parameters.push(remoteScript.empty() ? "NONE" : remoteScript);
1620 // ===== Naming service (key = "naming_service")
1621 std::string namingService = "NONE";
1624 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1625 CORBA::String_var iorNS = _orb->object_to_string(ns);
1626 namingService = iorNS;
1628 script_parameters.push(namingService);
1630 // ===== APPLI mode (key = "appli_mode")
1631 // $APPLI points either to an application directory, or to a salome launcher file
1632 // we prepare the remote command according to the case
1633 script_parameters.push(appli_mode);
1635 command << GetCommandFromTemplate(templateName, script_parameters);
1637 return command.str();
1641 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1645 // Step 1 : check ContainerParameters
1646 // Check container_name, has to be defined
1647 if (std::string(params.container_name.in()) == "")
1649 INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1652 // Check parallelLib
1653 std::string parallelLib = params.parallelLib.in();
1654 if (parallelLib != "Mpi" && parallelLib != "Dummy")
1656 INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1657 INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1658 INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1662 if (params.nb_proc <= 0)
1664 INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1668 // Step 2 : check resource_selected
1669 const ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
1670 //std::string protocol = resource_definition->protocol.in();
1671 std::string username = resource_definition.UserName;
1672 std::string applipath = resource_definition.AppliPath;
1674 //if (protocol == "" || username == "" || applipath == "")
1675 if (username == "" || applipath == "")
1677 INFOS("[checkPaCOParameters] resource selected is not well defined");
1678 INFOS("[checkPaCOParameters] resource name: " << resource_definition.Name);
1679 INFOS("[checkPaCOParameters] resource hostname: " << resource_definition.HostName);
1680 INFOS("[checkPaCOParameters] resource protocol: " << resource_definition.getAccessProtocolTypeStr());
1681 INFOS("[checkPaCOParameters] resource username: " << username);
1682 INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1690 * :WARNING: Do not directly convert returned value to std::string
1691 * This function may return NULL if env variable is not defined.
1692 * And std::string(NULL) causes undefined behavior.
1693 * Use GetenvThreadSafeAsString to properly get a std::string.
1695 char *SALOME_ContainerManager::GetenvThreadSafe(const char *name)
1696 {// getenv is not thread safe. See man 7 pthread.
1697 Utils_Locker lock (&_getenvMutex);
1698 return getenv(name);
1702 * Return env variable as a std::string.
1703 * Return empty string if env variable is not set.
1705 std::string SALOME_ContainerManager::GetenvThreadSafeAsString(const char *name)
1707 char* var = GetenvThreadSafe(name);
1708 return var ? std::string(var) : std::string();
1711 int SALOME_ContainerManager::SystemThreadSafe(const char *command)
1713 Utils_Locker lock (&_systemMutex);
1714 return system(command);
1717 long SALOME_ContainerManager::SystemWithPIDThreadSafe(const std::vector<std::string>& command)
1719 Utils_Locker lock(&_systemMutex);
1720 if(command.size()<1)
1721 throw SALOME_Exception("SystemWithPIDThreadSafe : command is expected to have a length of size 1 at least !");
1723 pid_t pid ( fork() ) ; // spawn a child process, following code is executed in both processes
1725 pid_t pid = -1; //Throw SALOME_Exception on Windows
1727 if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
1729 std::size_t sz(command.size());
1730 char **args = new char *[sz+1];
1731 for(std::size_t i=0;i<sz;i++)
1732 args[i] = strdup(command[i].c_str());
1734 execvp( command[0].c_str() , args );
1735 std::ostringstream oss;
1736 oss << "Error when launching " << command[0];
1737 throw SALOME_Exception(oss.str().c_str()); // execvp failed
1741 throw SALOME_Exception("fork() failed");
1743 else // I'm a parent
1749 #ifdef WITH_PACO_PARALLEL
1751 //=============================================================================
1753 * Start a suitable PaCO++ Parallel Container in a list of machines.
1754 * \param params Container Parameters required for the container
1755 * \return CORBA container reference.
1757 //=============================================================================
1758 Engines::Container_ptr
1759 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1760 std::string resource_selected)
1762 CORBA::Object_var obj;
1763 PaCO::InterfaceManager_var container_proxy;
1764 Engines::Container_ptr ret = Engines::Container::_nil();
1765 Engines::ContainerParameters params(params_const);
1766 params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1768 // Step 0 : Check parameters
1769 if (!checkPaCOParameters(params, resource_selected))
1771 INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1775 // Step 1 : Starting a new parallel container !
1776 INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1777 INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1779 // Step 2 : Get a MachineFile for the parallel container
1780 std::string machine_file_name = _resManager->getMachineFile(resource_selected,
1782 params.parallelLib.in());
1784 if (machine_file_name == "")
1786 INFOS("[StartPaCOPPContainer] Machine file generation failed");
1790 // Step 3 : starting parallel container proxy
1791 std::string command_proxy("");
1792 std::string proxy_machine;
1795 command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1797 catch(const SALOME_Exception & ex)
1799 INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1803 obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1804 if (CORBA::is_nil(obj))
1806 INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1809 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1810 MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1812 // Step 4 : starting parallel container nodes
1813 std::string command_nodes("");
1814 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1817 command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1819 catch(const SALOME_Exception & ex)
1821 INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1826 std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1827 bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1830 INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1831 // Il faut tuer le proxy
1834 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1839 INFOS("[StarPaCOPPContainer] Exception caught from proxy Shutdown...");
1844 // Step 4 : connecting nodes and the proxy to actually create a parallel container
1845 for (int i = 0; i < params.nb_proc; i++)
1847 std::ostringstream tmp;
1849 std::string proc_number = tmp.str();
1850 std::string container_node_name = container_generic_node_name + proc_number;
1852 std::string theNodeMachine(nodes_machines[i]);
1853 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1854 obj = _NS->Resolve(containerNameInNS.c_str());
1855 if (CORBA::is_nil(obj))
1857 INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1858 INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1863 MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1864 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1866 MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1868 catch(CORBA::SystemException& e)
1870 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1871 INFOS("CORBA::SystemException : " << e);
1874 catch(CORBA::Exception& e)
1876 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1877 INFOS("CORBA::Exception" << e);
1882 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1883 INFOS("Unknown exception !");
1888 // Step 5 : starting parallel container
1891 MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1892 container_proxy->start();
1893 MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1894 ret = Engines::Container::_narrow(container_proxy);
1896 catch(CORBA::SystemException& e)
1898 INFOS("Caught CORBA::SystemException. : " << e);
1900 catch(PortableServer::POA::ServantAlreadyActive&)
1902 INFOS("Caught CORBA::ServantAlreadyActiveException");
1904 catch(CORBA::Exception&)
1906 INFOS("Caught CORBA::Exception.");
1908 catch(std::exception& exc)
1910 INFOS("Caught std::exception - "<<exc.what());
1914 INFOS("Caught unknown exception.");
1920 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1921 std::string machine_file_name,
1922 std::string & proxy_hostname)
1924 // In the proxy case, we always launch a Dummy Proxy
1925 std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1926 std::string container_name = params.container_name.in();
1928 // Convert nb_proc in string
1929 std::ostringstream tmp_string;
1930 tmp_string << params.nb_proc;
1931 std::string nb_proc_str = tmp_string.str();
1933 // Get resource definition
1934 ParserResourcesType resource_definition =
1935 _resManager->GetResourceDefinition(params.resource_params.name.in());
1938 std::string hostname;
1939 std::ifstream machine_file(machine_file_name.c_str());
1940 std::getline(machine_file, hostname, ' ');
1941 size_t found = hostname.find('\n');
1942 if (found!=std::string::npos)
1943 hostname.erase(found, 1); // Remove \n
1944 proxy_hostname = hostname;
1945 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1948 bool remote_execution = false;
1949 if (hostname != std::string(Kernel_Utils::GetHostname()))
1951 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1952 remote_execution = true;
1956 std::string log_type("");
1957 char * get_val = GetenvThreadSafe("PARALLEL_LOG");
1961 // Generating the command
1962 std::string command_begin("");
1963 std::string command_end("");
1964 std::ostringstream command;
1966 LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1967 command << command_begin;
1969 // Adding connection command
1970 // We can only have a remote execution with
1971 // a SALOME application
1972 if (remote_execution)
1974 ASSERT(GetenvThreadSafe("NSHOST"));
1975 ASSERT(GetenvThreadSafe("NSPORT"));
1977 command << resource_definition.getAccessProtocolTypeStr();
1979 command << resource_definition.UserName;
1980 command << " " << hostname;
1981 command << " " << resource_definition.AppliPath;
1982 command << "/runRemote.sh ";
1983 command << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
1984 command << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
1987 command << exe_name;
1988 command << " " << container_name;
1989 command << " Dummy";
1990 command << " " << hostname;
1991 command << " " << nb_proc_str;
1993 AddOmninamesParams(command);
1996 command << command_end;
1997 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1999 return command.str();
2003 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
2004 const std::string & machine_file_name,
2005 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
2006 const std::string & proxy_hostname)
2009 std::string exe_name = "SALOME_ParallelContainerNode";
2010 exe_name += params.parallelLib.in();
2011 std::string container_name = params.container_name.in();
2013 // Convert nb_proc in string
2014 std::ostringstream nb_proc_stream;
2015 nb_proc_stream << params.nb_proc;
2017 // Get resource definition
2018 ParserResourcesType resource_definition =
2019 _resManager->GetResourceDefinition(params.resource_params.name.in());
2022 std::string log_type("");
2023 char * get_val = GetenvThreadSafe("PARALLEL_LOG");
2027 // Now the command is different according to paralleLib
2028 std::ostringstream command_nodes;
2029 std::ifstream machine_file(machine_file_name.c_str());
2030 if (std::string(params.parallelLib.in()) == "Dummy")
2032 for (int i= 0; i < params.nb_proc; i++)
2035 std::string hostname;
2036 std::getline(machine_file, hostname);
2037 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
2040 bool remote_execution = false;
2041 if (hostname != std::string(Kernel_Utils::GetHostname()))
2043 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
2044 remote_execution = true;
2047 // For each node we have a new command
2048 // Generating the command
2049 std::ostringstream command_node_stream;
2050 std::string command_node_begin("");
2051 std::string command_node_end("");
2052 std::ostringstream node_number;
2054 std::string container_node_name = container_name + node_number.str();
2055 LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
2057 // Adding connection command
2058 // We can only have a remote execution with
2059 // a SALOME application
2060 if (remote_execution)
2062 ASSERT(GetenvThreadSafe("NSHOST"));
2063 ASSERT(GetenvThreadSafe("NSPORT"));
2065 command_node_stream << resource_definition.getAccessProtocolTypeStr();
2066 command_node_stream << " -l ";
2067 command_node_stream << resource_definition.UserName;
2068 command_node_stream << " " << hostname;
2069 command_node_stream << " " << resource_definition.AppliPath;
2070 command_node_stream << "/runRemote.sh ";
2071 command_node_stream << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
2072 command_node_stream << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
2075 command_node_stream << exe_name;
2076 command_node_stream << " " << container_name;
2077 command_node_stream << " " << params.parallelLib.in();
2078 command_node_stream << " " << proxy_hostname;
2079 command_node_stream << " " << node_number.str();
2080 command_node_stream << " -";
2081 AddOmninamesParams(command_node_stream);
2083 command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
2084 vect_machine.push_back(hostname);
2088 else if (std::string(params.parallelLib.in()) == "Mpi")
2091 std::string hostname;
2092 std::getline(machine_file, hostname, ' ');
2093 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
2096 bool remote_execution = false;
2097 if (hostname != std::string(Kernel_Utils::GetHostname()))
2099 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
2100 remote_execution = true;
2103 // In case of Mpi and Remote, we copy machine_file in the applipath
2104 // scp mpi_machine_file user@machine:Path
2105 std::ostringstream command_remote_stream;
2106 std::string::size_type last = machine_file_name.find_last_of("/");
2107 if (last == std::string::npos)
2110 if (resource_definition.Protocol == rsh)
2111 command_remote_stream << "rcp ";
2113 command_remote_stream << "scp ";
2114 command_remote_stream << machine_file_name << " ";
2115 command_remote_stream << resource_definition.UserName << "@";
2116 command_remote_stream << hostname << ":" << resource_definition.AppliPath;
2117 command_remote_stream << "/" << machine_file_name.substr(last+1);
2119 int status = SystemThreadSafe(command_remote_stream.str().c_str());
2122 INFOS("copy of the MPI machine file failed ! - sorry !");
2126 // Generating the command
2127 std::string command_begin("");
2128 std::string command_end("");
2130 LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
2131 command_nodes << command_begin;
2133 // Adding connection command
2134 // We can only have a remote execution with
2135 // a SALOME application
2136 if (remote_execution)
2138 ASSERT(GetenvThreadSafe("NSHOST"));
2139 ASSERT(GetenvThreadSafe("NSPORT"));
2141 command_nodes << resource_definition.getAccessProtocolTypeStr();
2142 command_nodes << " -l ";
2143 command_nodes << resource_definition.UserName;
2144 command_nodes << " " << hostname;
2145 command_nodes << " " << resource_definition.AppliPath;
2146 command_nodes << "/runRemote.sh ";
2147 command_nodes << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
2148 command_nodes << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
2151 if (resource_definition.mpi == lam)
2153 command_nodes << "mpiexec -ssi boot ";
2154 command_nodes << "-machinefile " << machine_file_name << " ";
2155 command_nodes << "-n " << params.nb_proc;
2159 command_nodes << "mpirun -np " << params.nb_proc;
2161 command_nodes << " " << exe_name;
2162 command_nodes << " " << container_name;
2163 command_nodes << " " << params.parallelLib.in();
2164 command_nodes << " " << proxy_hostname;
2165 command_nodes << " -";
2166 AddOmninamesParams(command_nodes);
2168 // We don't put hostname, because nodes are registered in the resource of the proxy
2169 for (int i= 0; i < params.nb_proc; i++)
2170 vect_machine.push_back(proxy_hostname);
2172 command_nodes << command_end;
2174 return command_nodes.str();
2178 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
2179 const std::string & exe_type,
2180 const std::string & container_name,
2181 const std::string & hostname,
2182 std::string & begin,
2185 if(log_type == "xterm")
2187 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
2190 else if(log_type == "xterm_debug")
2192 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
2197 // default into a file...
2198 std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
2199 std::string user = GetenvThreadSafeAsString("USER");
2201 user = GetenvThreadSafeAsString("LOGNAME");
2202 logFilename += user + ".log";
2203 end = " > " + logFilename + " 2>&1 & ";
2208 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
2209 const Engines::ContainerParameters& params,
2210 const std::string & hostname)
2212 PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
2214 MESSAGE("[LaunchPaCOProxyContainer] Launch command");
2215 int status = SystemThreadSafe(command.c_str());
2217 INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
2218 return container_proxy;
2220 else if (status == 217) {
2221 INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
2222 return container_proxy;
2225 int count(GetTimeOutToLoaunchServer());
2226 CORBA::Object_var obj = CORBA::Object::_nil();
2227 std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
2229 MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
2231 while (CORBA::is_nil(obj) && count)
2235 obj = _NS->Resolve(containerNameInNS.c_str());
2240 container_proxy = PaCO::InterfaceManager::_narrow(obj);
2242 catch(CORBA::SystemException& e)
2244 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2245 INFOS("CORBA::SystemException : " << e);
2246 return container_proxy;
2248 catch(CORBA::Exception& e)
2250 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2251 INFOS("CORBA::Exception" << e);
2252 return container_proxy;
2256 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2257 INFOS("Unknown exception !");
2258 return container_proxy;
2260 if (CORBA::is_nil(container_proxy))
2262 INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
2263 return container_proxy;
2268 //=============================================================================
2269 /*! This method launches the parallel container.
2270 * It will may be placed on the resources manager.
2272 * \param command to launch
2273 * \param container's parameters
2274 * \param name of the container
2276 * \return CORBA container reference
2278 //=============================================================================
2280 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
2281 const Engines::ContainerParameters& params,
2282 const std::string& name,
2283 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
2285 INFOS("[LaunchPaCONodeContainer] Launch command");
2286 int status = SystemThreadSafe(command.c_str());
2288 INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
2291 else if (status == 217) {
2292 INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
2296 INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
2297 // We are waiting all the nodes
2298 for (int i = 0; i < params.nb_proc; i++)
2300 CORBA::Object_var obj = CORBA::Object::_nil();
2301 std::string theMachine(vect_machine[i]);
2303 std::ostringstream tmp;
2305 std::string proc_number = tmp.str();
2306 std::string container_node_name = name + proc_number;
2307 std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
2308 INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
2309 int count(GetTimeOutToLoaunchServer());
2310 while (CORBA::is_nil(obj) && count) {
2313 obj = _NS->Resolve(containerNameInNS.c_str());
2315 if (CORBA::is_nil(obj))
2317 INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
2326 Engines::Container_ptr
2327 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& /*params*/,
2328 std::string /*resource_selected*/)
2330 Engines::Container_ptr ret = Engines::Container::_nil();
2331 INFOS("[StarPaCOPPContainer] is disabled !");
2332 INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
2337 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& /*params*/,
2338 std::string /*machine_file_name*/,
2339 std::string & /*proxy_hostname*/)
2345 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& /*params*/,
2346 const std::string & /*machine_file_name*/,
2347 SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/,
2348 const std::string & /*proxy_hostname*/)
2353 SALOME_ContainerManager::LogConfiguration(const std::string & /*log_type*/,
2354 const std::string & /*exe_type*/,
2355 const std::string & /*container_name*/,
2356 const std::string & /*hostname*/,
2357 std::string & /*begin*/,
2358 std::string & /*end*/)
2363 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& /*command*/,
2364 const Engines::ContainerParameters& /*params*/,
2365 const std::string& /*hostname*/)
2367 CORBA::Object_ptr ret = CORBA::Object::_nil();
2372 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& /*command*/,
2373 const Engines::ContainerParameters& /*params*/,
2374 const std::string& /*name*/,
2375 SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/)