-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
#include "SALOME_ContainerManager.hxx"
+#include "SALOME_ResourcesManager.hxx"
+#include "SALOME_LoadRateManager.hxx"
#include "SALOME_NamingService.hxx"
+#include "SALOME_ResourcesManager_Client.hxx"
+#include "SALOME_Embedded_NamingService.hxx"
#include "SALOME_ModuleCatalog.hh"
#include "Basics_Utils.hxx"
#include "Basics_DirUtils.hxx"
+#include "PythonCppUtils.hxx"
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "Utils_CorbaException.hxx"
#include <sstream>
#include <string>
+#include <queue>
#include <SALOMEconfig.h>
#include CORBA_CLIENT_HEADER(SALOME_Session)
+#ifdef HAVE_MPI2
+#include <mpi.h>
+#include <sys/wait.h>
+#endif
+
#ifdef WIN32
#include <process.h>
#define getpid _getpid
+
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
#endif
#ifdef WITH_PACO_PARALLEL
#include "PaCOPP.hxx"
#endif
-#define TIME_OUT_TO_LAUNCH_CONT 60
+const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60;
-const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
+const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
"/ContainerManager";
omni_mutex SALOME_ContainerManager::_numInstanceMutex;
+Utils_Mutex SALOME_ContainerManager::_getenvMutex;
+
+Utils_Mutex SALOME_ContainerManager::_systemMutex;
//=============================================================================
-/*!
+/*!
* Constructor
* \param orb
* Define a CORBA single thread policy for the server, which avoid to deal
*/
//=============================================================================
-SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns):_nbprocUsed(1)
+SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns)
+ : _nbprocUsed(1)
{
MESSAGE("constructor");
_NS = ns;
- _ResManager = rm;
+ _resManager = new SALOME_ResourcesManager_Client(ns);
PortableServer::POAManager_var pman = poa->the_POAManager();
_orb = CORBA::ORB::_duplicate(orb) ;
CORBA::PolicyList policies;
policies.length(1);
- PortableServer::ThreadPolicy_var threadPol =
- poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
+ PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL));
policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
- _poa = poa->create_POA("SThreadPOA",pman,policies);
+ _poa = poa->create_POA("MThreadPOA",pman,policies);
threadPol->destroy();
PortableServer::ObjectId_var id = _poa->activate_object(this);
CORBA::Object_var obj = _poa->id_to_reference(id);
- Engines::ContainerManager_var refContMan =
- Engines::ContainerManager::_narrow(obj);
-
- _NS->Register(refContMan,_ContainerManagerNameInNS);
- _isAppliSalomeDefined = (getenv("APPLI") != 0);
+ Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj);
+ if(_NS)
+ _NS->Register(refContMan,_ContainerManagerNameInNS);
+ _isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0);
#ifdef HAVE_MPI2
-#ifdef WITHOPENMPI
+#ifdef OPEN_MPI
_pid_mpiServer = -1;
// the urifile name depends on pid of the process
std::stringstream urifile;
- urifile << getenv("HOME") << "/.urifile_" << getpid();
+ urifile << GetenvThreadSafeAsString("HOME") << "/.urifile_" << getpid();
setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
- if( getenv("OMPI_URI_FILE") != NULL ){
- // get the pid of all ompi-server
- std::set<pid_t> thepids1 = getpidofprogram("ompi-server");
- // launch a new ompi-server
- std::string command;
- command = "ompi-server -r ";
- command += getenv("OMPI_URI_FILE");
- int status=system(command.c_str());
- if(status!=0)
- throw SALOME_Exception("Error when launching ompi-server");
- // get the pid of all ompi-server
- std::set<pid_t> thepids2 = getpidofprogram("ompi-server");
- // my ompi-server is the new one
- std::set<pid_t>::const_iterator it;
- for(it=thepids2.begin();it!=thepids2.end();it++)
- if(thepids1.find(*it) == thepids1.end())
- _pid_mpiServer = *it;
- if(_pid_mpiServer < 0)
- throw SALOME_Exception("Error when getting ompi-server id");
- }
-#elif defined(WITHMPICH)
+ if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
+ // Linux specific code
+ pid_t pid = fork(); // spawn a child process, following code is executed in both processes
+ if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
+ {
+ std::string uriarg = GetenvThreadSafeAsString("OMPI_URI_FILE");
+ execlp( "ompi-server", "ompi-server", "-r", uriarg.c_str(), NULL );
+ throw SALOME_Exception("Error when launching ompi-server"); // execlp failed
+ }
+ else if ( pid < 0 )
+ {
+ throw SALOME_Exception("fork() failed");
+ }
+ else // I'm a parent
+ {
+ //wait(NULL); // wait(?) for a child end
+ _pid_mpiServer = pid;
+ }
+ }
+#elif defined(MPICH)
_pid_mpiServer = -1;
- // get the pid of all hydra_nameserver
- std::set<pid_t> thepids1 = getpidofprogram("hydra_nameserver");
- // launch a new hydra_nameserver
- std::string command;
- command = "hydra_nameserver &";
- system(command.c_str());
- // get the pid of all hydra_nameserver
- std::set<pid_t> thepids2 = getpidofprogram("hydra_nameserver");
- // my hydra_nameserver is the new one
- std::set<pid_t>::const_iterator it;
- for(it=thepids2.begin();it!=thepids2.end();it++)
- if(thepids1.find(*it) == thepids1.end())
- _pid_mpiServer = *it;
+ // Linux specific code
+ pid_t pid = fork(); // spawn a child process, following code is executed in both processes
+ if ( pid == 0 ) // I'm a child, replace myself with a new hydra_nameserver
+ {
+ execlp( "hydra_nameserver", "hydra_nameserver", NULL );
+ throw SALOME_Exception("Error when launching hydra_nameserver"); // execlp failed
+ }
+ else if ( pid < 0 )
+ {
+ throw SALOME_Exception("fork() failed");
+ }
+ else // I'm a parent
+ {
+ //wait(NULL);
+ _pid_mpiServer = pid;
+ }
#endif
#endif
}
//=============================================================================
-/*!
+/*!
* destructor
*/
//=============================================================================
SALOME_ContainerManager::~SALOME_ContainerManager()
{
MESSAGE("destructor");
+ delete _resManager;
#ifdef HAVE_MPI2
-#ifdef WITHOPENMPI
- if( getenv("OMPI_URI_FILE") != NULL ){
+#ifdef OPEN_MPI
+ if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
// kill my ompi-server
if( kill(_pid_mpiServer,SIGTERM) != 0 )
throw SALOME_Exception("Error when killing ompi-server");
// delete my urifile
- int status=system("rm -f ${OMPI_URI_FILE}");
+ int status=SystemThreadSafe("rm -f ${OMPI_URI_FILE}");
if(status!=0)
throw SALOME_Exception("Error when removing urifile");
}
-#elif defined(WITHMPICH)
+#elif defined(MPICH)
// kill my hydra_nameserver
if(_pid_mpiServer > -1)
if( kill(_pid_mpiServer,SIGTERM) != 0 )
{
MESSAGE("Shutdown");
ShutdownContainers();
- _NS->Destroy_Name(_ContainerManagerNameInNS);
+ if(_NS)
+ _NS->Destroy_Name(_ContainerManagerNameInNS);
PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
_poa->deactivate_object(oid);
}
void SALOME_ContainerManager::ShutdownContainers()
{
MESSAGE("ShutdownContainers");
-
+ if(!_NS)
+ return ;
SALOME::Session_var session = SALOME::Session::_nil();
CORBA::Long pid = 0;
CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
if(!CORBA::is_nil(cont) && pid != cont->getPID())
lstCont.push_back((*iter));
}
- catch(const CORBA::Exception& e)
+ catch(const CORBA::Exception&)
{
// ignore this entry and continue
}
MESSAGE("ShutdownContainers: " << (*iter));
cont->Shutdown();
}
- else
+ else
MESSAGE("ShutdownContainers: no container ref for " << (*iter));
}
catch(CORBA::SystemException& e)
}
}
+void SALOME_ContainerManager::SetOverrideEnvForContainers(const Engines::KeyValDict& env)
+{
+ this->_override_env.clear();
+ auto sz = env.length();
+ for(auto i = 0 ; i < sz ; ++i)
+ _override_env.emplace_back(env[i].key.in(), env[i].val.in());
+}
+
+Engines::KeyValDict *SALOME_ContainerManager::GetOverrideEnvForContainers()
+{
+ std::unique_ptr<Engines::KeyValDict> ret( new Engines::KeyValDict );
+ auto sz = _override_env.size();
+ ret->length(sz);
+ for(auto i = 0 ; i < sz ; ++i)
+ {
+ (*ret)[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
+ (*ret)[i].val = CORBA::string_dup( _override_env[i].second.c_str() );
+ }
+ return ret.release();
+}
+
//=============================================================================
//! Give a suitable Container given constraints
/*! CORBA Method:
* \return the container or nil
*/
//=============================================================================
-Engines::Container_ptr
-SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
+Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
{
std::string machFile;
- Engines::Container_ptr ret = Engines::Container::_nil();
+ Engines::Container_ptr ret(Engines::Container::_nil());
// Step 0: Default mode is start
Engines::ContainerParameters local_params(params);
// Step 2: Get all possibleResources from the parameters
// Consider only resources that can run containers
- local_params.resource_params.can_run_containers = true;
- Engines::ResourceList_var possibleResources = _ResManager->GetFittingResources(local_params.resource_params);
- MESSAGE("[GiveContainer] - length of possible resources " << possibleResources->length());
+ resourceParams resource_params = resourceParameters_CORBAtoCPP(local_params.resource_params);
+ resource_params.can_run_containers = true;
+ std::vector<std::string> possibleResources = _resManager->GetFittingResources(resource_params);
+ MESSAGE("[GiveContainer] - length of possible resources " << possibleResources.size());
std::vector<std::string> local_resources;
- // Step 3: if mode is "get" keep only machines with existing containers
+ // Step 3: if mode is "get" keep only machines with existing containers
if(mode == "get")
{
- for(unsigned int i=0; i < possibleResources->length(); i++)
+ for(unsigned int i=0; i < possibleResources.size(); i++)
{
- Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
+ Engines::Container_ptr cont = FindContainer(params, possibleResources[i]);
try
{
if(!cont->_non_existent())
- local_resources.push_back(std::string(possibleResources[i]));
+ local_resources.push_back(possibleResources[i]);
}
catch(CORBA::Exception&) {}
}
}
}
else
- for(unsigned int i=0; i < possibleResources->length(); i++)
- local_resources.push_back(std::string(possibleResources[i]));
+ local_resources = possibleResources;
// Step 4: select the resource where to get/start the container
bool resource_available = true;
{
try
{
- resource_selected = _ResManager->GetImpl()->Find(params.resource_params.policy.in(), resources);
+ resource_selected = _resManager->Find(params.resource_params.policy.in(), resources);
// Remove resource_selected from vector
std::vector<std::string>::iterator it;
for (it=resources.begin() ; it < resources.end(); it++ )
break;
}
}
- catch(const SALOME_Exception &ex)
+ catch(const SALOME_Exception &ex) //!< TODO: unused variable
{
MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
return ret;
MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
// Step 5: Create container name
- Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
- std::string hostname(resource_definition->hostname.in());
+ ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
+ std::string hostname(resource_definition.HostName);
std::string containerNameInNS;
if(params.isMPI){
- int nbproc;
- if ( params.nb_proc <= 0 )
- nbproc = 1;
- else
- nbproc = params.nb_proc;
+ int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
try
{
- if( getenv("LIBBATCH_NODEFILE") != NULL )
+ if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
machFile = machinesFile(nbproc);
}
catch(const SALOME_Exception & ex)
return ret;
}
// A mpi parallel container register on zero node in NS
- containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
+ std::string mpiZeroNode = GetMPIZeroNode(resource_selected,machFile).c_str();
+ containerNameInNS = _NS->BuildContainerNameForNS(params, mpiZeroNode.c_str());
}
else
containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
// Step 6: check if the name exists in naming service
//if params.mode == "getorstart" or "get" use the existing container
//if params.mode == "start" shutdown the existing container before launching a new one with that name
- CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
- if (!CORBA::is_nil(obj))
- {
- try
- {
- Engines::Container_var cont=Engines::Container::_narrow(obj);
- if(!cont->_non_existent())
+
+ { // critical section
+ Utils_Locker lock (&_giveContainerMutex1);
+ CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
+ if (!CORBA::is_nil(obj))
{
- if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
- return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
+ try
+ {
+ Engines::Container_var cont=Engines::Container::_narrow(obj);
+ if(!cont->_non_existent())
+ {
+ if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
+ return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
+ }
+ else
+ {
+ INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
+ cont->Shutdown(); // shutdown the registered container if it exists
+ }
+ }
}
- else
+ catch(CORBA::Exception&)
{
- INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
- cont->Shutdown(); // shutdown the registered container if it exists
+ INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
}
}
- }
- catch(CORBA::Exception&)
- {
- INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
- }
- }
+ } // end critical section
Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
if (!CORBA::is_nil(cont))
{
INFOS("[GiveContainer] container " << containerNameInNS << " launched");
+ std::ostringstream envInfo;
+ std::for_each( _override_env.begin(), _override_env.end(), [&envInfo](const std::pair<std::string,std::string>& p) { envInfo << p.first << " = " << p.second << std::endl; } );
+ INFOS("[GiveContainer] container " << containerNameInNS << " override " << envInfo.str());
+ Engines::FieldsDict envCorba;
+ {
+ auto sz = _override_env.size();
+ envCorba.length(sz);
+ for(auto i = 0 ; i < sz ; ++i)
+ {
+ envCorba[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
+ envCorba[i].value <<= CORBA::string_dup( _override_env[i].second.c_str() );
+ }
+ }
+ cont->override_environment_python( envCorba );
return cont._retn();
}
else
return ret;
}
+std::string SALOME_ContainerManager::GetCppBinaryOfKernelContainer() const
+{
+ std::string ret = this->_isSSL ? "SALOME_Container_No_NS_Serv" : "SALOME_Container";
+ return ret;
+}
+
+std::string SALOME_ContainerManager::GetRunRemoteExecutableScript() const
+{
+ std::string ret = this->_isSSL ? "runRemoteSSL.sh" : "runRemote.sh";
+ return ret;
+}
+
Engines::Container_ptr
SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
const std::string & resource_selected,
const std::string & machFile,
const std::string & containerNameInNS)
{
-
- // Step 1: type of container: PaCO, Exe, Mpi or Classic
- // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
- // TODO -> separates Mpi from Classic/Exe
- // Classic or Exe ?
- std::string container_exe = "SALOME_Container"; // Classic container
- Engines::ContainerParameters local_params(params);
- Engines::Container_ptr ret = Engines::Container::_nil();
- int found=0;
- try
- {
- CORBA::String_var container_exe_tmp;
- CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
- SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
- if (CORBA::is_nil (Catalog))
+ std::string user,command,logFilename,tmpFileName;
+ int status;
+ Engines::Container_ptr ret(Engines::Container::_nil());
+ {//start of critical section
+ Utils_Locker lock (&_giveContainerMutex1);
+ // Step 1: type of container: PaCO, Exe, Mpi or Classic
+ // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
+ // TODO -> separates Mpi from Classic/Exe
+ // Classic or Exe ?
+ std::string container_exe = this->GetCppBinaryOfKernelContainer();
+ Engines::ContainerParameters local_params(params);
+ int found=0;
+ try
{
- INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
- return ret;
+ CORBA::String_var container_exe_tmp;
+ CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
+ SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
+ if (CORBA::is_nil (Catalog))
+ {
+ INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
+ return ret;
+ }
+ // Loop through component list
+ for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
+ {
+ const char* compoi = local_params.resource_params.componentList[i];
+ SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
+ if (CORBA::is_nil (compoInfo))
+ {
+ continue;
+ }
+ SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
+ container_exe_tmp=compoInfo->implementation_name();
+ if(impl==SALOME_ModuleCatalog::CEXE)
+ {
+ if(found)
+ {
+ INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
+ return Engines::Container::_nil();
+ }
+ MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
+ container_exe = container_exe_tmp.in();
+ found=1;
+ }
+ }
+ }
+ catch (ServiceUnreachable&)
+ {
+ INFOS("Caught exception: Naming Service Unreachable");
+ return ret;
}
- // Loop through component list
- for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
+ catch (...)
{
- const char* compoi = local_params.resource_params.componentList[i];
- SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
- if (CORBA::is_nil (compoInfo))
+ INFOS("Caught unknown exception.");
+ return ret;
+ }
+
+ // Step 2: test resource
+ // Only if an application directory is set
+ if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
{
- continue;
+
+ const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
+ std::string command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
+ resInfo.UserName, resInfo.AppliPath);
+
+ // Launch remote command
+ command += " \"ls /tmp >/dev/null 2>&1\"";
+ // Anthony : command is NO MORE launched to improve dramatically time to launch containers
+ int status = 0;
+ if (status != 0)
+ {
+ // Error on resource - cannot launch commands
+ INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
+ INFOS("[LaunchContainer] Command was " << command);
+#ifndef WIN32
+ INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
+#endif
+ return Engines::Container::_nil();
+ }
}
- SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
- container_exe_tmp=compoInfo->implementation_name();
- if(impl==SALOME_ModuleCatalog::CEXE)
+
+ // Step 3: start a new container
+ // Check if a PaCO container
+ // PaCO++
+ if (std::string(local_params.parallelLib.in()) != "")
{
- if(found)
- {
- INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
- return Engines::Container::_nil();
- }
- MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
- container_exe = container_exe_tmp.in();
- found=1;
+ ret = StartPaCOPPContainer(params, resource_selected);
+ return ret;
}
+ // Other type of containers...
+ MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
+ // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
+ if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL && params.isMPI )
+ {
+ command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
+ MESSAGE("[LaunchContainer] LIBBATCH_NODEFILE : \"" << command << "\"");
}
- }
- catch (ServiceUnreachable&)
- {
- INFOS("Caught exception: Naming Service Unreachable");
- return ret;
- }
- catch (...)
- {
- INFOS("Caught unknown exception.");
- return ret;
- }
-
- // Step 2: test resource
- // Only if an application directory is set
- if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
- {
- // Preparing remote command
- std::string command = "";
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_selected);
- command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
- if (resInfo.AppliPath != "")
- command += resInfo.AppliPath;
- else
+ // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
+ else if(hostname == Kernel_Utils::GetHostname())
{
- ASSERT(getenv("APPLI"));
- command += getenv("APPLI");
+ command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
+ MESSAGE("[LaunchContainer] hostname local : \"" << command << "\"");
}
- command += "/runRemote.sh ";
- ASSERT(getenv("NSHOST"));
- command += getenv("NSHOST"); // hostname of CORBA name server
- command += " ";
- ASSERT(getenv("NSPORT"));
- command += getenv("NSPORT"); // port of CORBA name server
- command += " \"ls /tmp >/dev/null 2>&1\"";
-
- // Launch remote command
- int status = system(command.c_str());
- if (status != 0)
+ // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
+ else
{
- // Error on resource - cannot launch commands
- INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
- INFOS("[LaunchContainer] Command was " << command);
-#ifndef WIN32
- INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
-#endif
- return Engines::Container::_nil();
+ command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
+ MESSAGE("[LaunchContainer] remote : \"" << command << "\"");
}
- }
-
- // Step 3: start a new container
- // Check if a PaCO container
- // PaCO++
- if (std::string(local_params.parallelLib.in()) != "")
- {
- ret = StartPaCOPPContainer(params, resource_selected);
- return ret;
- }
- // Other type of containers...
- MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
- std::string command;
- // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
- if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI )
- command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
- // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
- else if(hostname == Kernel_Utils::GetHostname())
- command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
- // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
- else
- command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
- //redirect stdout and stderr in a file
+ //redirect stdout and stderr in a file
#ifdef WIN32
- std::string logFilename=getenv("TEMP");
- logFilename += "\\";
- std::string user = getenv( "USERNAME" );
+ logFilename=GetenvThreadSafeAsString("TEMP");
+ logFilename += "\\";
+ user = GetenvThreadSafeAsString( "USERNAME" );
#else
- std::string user = getenv( "USER" );
- std::string logFilename="/tmp";
- char* val = getenv("SALOME_TMP_DIR");
- if(val)
- {
- struct stat file_info;
- stat(val, &file_info);
- bool is_dir = S_ISDIR(file_info.st_mode);
- if (is_dir)logFilename=val;
- else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
- }
- logFilename += "/";
-#endif
- logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
- std::ostringstream tmp;
- tmp << "_" << getpid();
- logFilename += tmp.str();
- logFilename += ".log" ;
- command += " > " + logFilename + " 2>&1";
-#ifdef WIN32
- command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
-#else
- command += " &";
-#endif
-
- // launch container with a system call
- int status=system(command.c_str());
-
- if (status == -1){
- INFOS("[LaunchContainer] command failed (system command status -1): " << command);
- RmTmpFile(_TmpFileName); // command file can be removed here
- _TmpFileName="";
- return Engines::Container::_nil();
- }
- else if (status == 217){
- INFOS("[LaunchContainer] command failed (system command status 217): " << command);
- RmTmpFile(_TmpFileName); // command file can be removed here
- _TmpFileName="";
- return Engines::Container::_nil();
- }
- else
- {
- // Step 4: Wait for the container
- int count = TIME_OUT_TO_LAUNCH_CONT;
- if (getenv("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
- {
- std::string new_count_str = getenv("TIMEOUT_TO_LAUNCH_CONTAINER");
- int new_count;
- std::istringstream ss(new_count_str);
- if (!(ss >> new_count))
+ user = GetenvThreadSafeAsString( "USER" );
+ if (user.empty())
+ user = GetenvThreadSafeAsString( "LOGNAME" );
+ logFilename="/tmp";
+ char* val = GetenvThreadSafe("SALOME_TMP_DIR");
+ if(val)
{
- INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
+ struct stat file_info;
+ stat(val, &file_info);
+ bool is_dir = S_ISDIR(file_info.st_mode);
+ if (is_dir)logFilename=val;
+ else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
}
- else
- count = new_count;
- }
- INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS);
- while (CORBA::is_nil(ret) && count)
- {
-#ifndef WIN32
- sleep( 1 ) ;
-#else
- Sleep(1000);
+ logFilename += "/";
#endif
- count--;
- MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected);
- CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
- ret=Engines::Container::_narrow(obj);
+ logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
+ std::ostringstream tmp;
+ tmp << "_" << getpid();
+ logFilename += tmp.str();
+ logFilename += ".log" ;
+ command += " > " + logFilename + " 2>&1";
+ MakeTheCommandToBeLaunchedASync(command);
+
+ MESSAGE("[LaunchContainer] SYSTEM COMMAND that will be launched : \"" << command << "\"");
+ // launch container with a system call
+ status=SystemThreadSafe(command.c_str());
+ }//end of critical of section
+
+ if (status == -1)
+ {
+ INFOS("[LaunchContainer] command failed (system command status -1): " << command);
+ RmTmpFile(tmpFileName); // command file can be removed here
+ return Engines::Container::_nil();
}
- if (CORBA::is_nil(ret))
+ else if (status == 217)
{
- INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
+ INFOS("[LaunchContainer] command failed (system command status 217): " << command);
+ RmTmpFile(tmpFileName); // command file can be removed here
+ return Engines::Container::_nil();
}
- else
+ else
{
- // Setting log file name
- logFilename=":"+logFilename;
- logFilename="@"+Kernel_Utils::GetHostname()+logFilename;
- logFilename=user+logFilename;
- ret->logfilename(logFilename.c_str());
- RmTmpFile(_TmpFileName); // command file can be removed here
- _TmpFileName="";
+ // Step 4: Wait for the container
+ int count(GetTimeOutToLoaunchServer());
+ INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS);
+ while (CORBA::is_nil(ret) && count)
+ {
+ SleepInSecond(1);
+ count--;
+ MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected);
+ CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str()));
+ ret=Engines::Container::_narrow(obj);
+ }
+ if (CORBA::is_nil(ret))
+ {
+ INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
+ }
+ else
+ {
+ // Setting log file name
+ logFilename=":"+logFilename;
+ logFilename="@"+Kernel_Utils::GetHostname()+logFilename;//threadsafe
+ logFilename=user+logFilename;
+ ret->logfilename(logFilename.c_str());
+ RmTmpFile(tmpFileName); // command file can be removed here
+ }
}
- }
return ret;
}
//=============================================================================
//! Find a container given constraints (params) on a list of machines (possibleComputers)
+//! agy : this method is ThreadSafe
/*!
*
*/
//=============================================================================
-Engines::Container_ptr
-SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
- const Engines::ResourceList& possibleResources)
+Engines::Container_ptr SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const Engines::ResourceList& possibleResources)
{
MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
for(unsigned int i=0; i < possibleResources.length();i++)
//=============================================================================
//! Find a container given constraints (params) on a machine (theMachine)
+//! agy : this method is ThreadSafe
/*!
*
*/
//=============================================================================
Engines::Container_ptr
-SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
- const std::string& resource)
+SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const std::string& resource)
{
- Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource.c_str());
- std::string hostname(resource_definition->hostname.in());
+ ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource);
+ std::string hostname(resource_definition.HostName);
std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
else
return Engines::Container::_narrow(obj);
}
- catch(const CORBA::Exception& e)
+ catch(const CORBA::Exception&)
{
return Engines::Container::_nil();
}
//=============================================================================
/*!
* This is no longer valid (C++ container are also python containers)
- */
+ */
//=============================================================================
bool isPythonContainer(const char* ContainerName)
{
return false; // VSR 02/08/2013: Python containers are no more supported
bool ret = false;
- int len = strlen(ContainerName);
+ size_t len = strlen(ContainerName);
if (len >= 2)
if (strcmp(ContainerName + len - 2, "Py") == 0)
* ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
* SALOME_Container containerName &"
- * - where user is ommited if not specified in CatalogResources,
+ * - where user is omitted if not specified in CatalogResources,
* - where distant path is always relative to user@machine $HOME, and
* equal to $APPLI if not specified in CatalogResources,
* - where hostNS is the hostname of CORBA naming server (set by scripts to
* use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
* - where workingdir is the requested working directory for the container.
* If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
- */
+ */
//=============================================================================
std::string
-SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
-(const std::string& resource_name,
- const Engines::ContainerParameters& params, const std::string& container_exe)
+SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& resource_name, const Engines::ContainerParameters& params, const std::string& container_exe) const
{
-
- std::string command;
+ std::string command,tmpFileName;
+ const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
+ std::string wdir = params.workingdir.in();
if (!_isAppliSalomeDefined)
- command = BuildTempFileToLaunchRemoteContainer(resource_name, params);
+ {
+ MESSAGE("[BuildCommandToLaunchRemoteContainer] NO APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
+ command = getCommandToRunRemoteProcessNoAppli(resInfo.Protocol, resInfo.HostName,
+ resInfo.UserName, resInfo.AppliPath,
+ wdir);
+ }
else
{
- int nbproc;
- Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_name.c_str());
- std::string hostname(resource_definition->hostname.in());
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
-
- if (params.isMPI)
- {
- if ( params.nb_proc <= 0 )
- nbproc = 1;
- else
- nbproc = params.nb_proc;
+ MESSAGE("[BuildCommandToLaunchRemoteContainer] WITH APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
+ // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
+ // SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
+ // or
+ // "ssh -l user machine distantLauncher remote -p hostNS -m portNS -d dir
+ // -- SALOME_Container contName -ORBInitRef NameService=IOR:01000..."
+ command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
+ resInfo.UserName, resInfo.AppliPath,
+ wdir);
+ }
+ if(params.isMPI)
+ {
+ int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
+ command += " mpirun -np ";
+ std::ostringstream o;
+ o << nbproc << " ";
+ command += o.str();
+#ifdef LAM_MPI
+ command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
+#elif defined(OPEN_MPI)
+ if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
+ command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
+ else{
+ command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
+ command += GetenvThreadSafeAsString("OMPI_URI_FILE");
}
+#elif defined(MPICH)
+ command += "-nameserver " + Kernel_Utils::GetHostname();
+#endif
+ command += " SALOME_MPIContainer ";
+ }
+ else
+ command += " " +container_exe+ " ";
+
+ command += _NS->ContainerName(params) + " ";
+ if(this->_isSSL)
+ {
+ Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+ CORBA::String_var iorNS = _orb->object_to_string(ns);
+ command += std::string(iorNS);
+ }
+ else //if(!this->_isSSL)
+ {
+ command += " -";
+ AddOmninamesParams(command);
+ }
+ MESSAGE("command =" << command);
- // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
- // SALOME_Container containerName &"
- command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
+ return command;
+}
- if (resInfo.AppliPath != "")
- command += resInfo.AppliPath; // path relative to user@machine $HOME
- else
+//=============================================================================
+//! Return a path to the directory with scripts templates
+/*!
+ * \return the path pointed by SALOME_KERNEL_SCRIPTS_DIR environment variable, if it is defined,
+ * ${KERNEL_ROOT_DIR}/share/salome/resources/separator/kernel/ScriptsTemplate - otherwise
+ */
+//=============================================================================
+std::string getScriptTemplateFilePath()
+{
+ auto parseScriptTemplateFilePath = []() -> std::string
+ {
+ std::string scriptTemplateFilePath = SALOME_ContainerManager::GetenvThreadSafeAsString("SALOME_KERNEL_SCRIPTS_DIR");
+ if (!scriptTemplateFilePath.empty())
{
- ASSERT(getenv("APPLI"));
- command += getenv("APPLI"); // path relative to user@machine $HOME
+ return scriptTemplateFilePath;
+ }
+ else {
+ return SALOME_ContainerManager::GetenvThreadSafeAsString("KERNEL_ROOT_DIR") +
+ "/share/salome/resources/kernel/ScriptsTemplate";
}
+ };
- command += "/runRemote.sh ";
+ static const std::string scriptTemplateFilePath = parseScriptTemplateFilePath();
+ return scriptTemplateFilePath;
+}
- ASSERT(getenv("NSHOST"));
- command += getenv("NSHOST"); // hostname of CORBA name server
+//=============================================================================
+//! Return a command line constructed based on Python scripts templates
+/*!
+ * \param theScriptName the name of Python script template
+ * \param theScriptParameters the queue of parameter values
+ * \return the command line constructed according to the given parameters
+ */
+//=============================================================================
+std::string GetCommandFromTemplate(const std::string& theScriptName,
+ std::queue<std::string>& theScriptParameters)
+{
+ std::string command;
+ AutoGIL agil;
+ // manage GIL
- command += " ";
- ASSERT(getenv("NSPORT"));
- command += getenv("NSPORT"); // port of CORBA name server
+ PyObject* mod(PyImport_ImportModule(theScriptName.c_str()));
+ if (!mod)
+ {
+ PyObject* sys = PyImport_ImportModule("sys");
+ PyObject* sys_path = PyObject_GetAttrString(sys, "path");
+ PyObject* folder_path = PyUnicode_FromString(getScriptTemplateFilePath().c_str());
+ PyList_Append(sys_path, folder_path);
- std::string wdir = params.workingdir.in();
- if(wdir != "")
- {
- command += " WORKINGDIR ";
- command += " '";
- if(wdir == "$TEMPDIR")
- wdir="\\$TEMPDIR";
- command += wdir; // requested working directory
- command += "'";
- }
+ mod = PyImport_ImportModule(theScriptName.c_str());
+
+ Py_XDECREF(folder_path);
+ Py_XDECREF(sys_path);
+ Py_XDECREF(sys);
+ }
- if(params.isMPI)
+ if (mod)
+ {
+ PyObject* meth(PyObject_GetAttrString(mod, "command"));
+ if (!meth)
{
- command += " mpirun -np ";
- std::ostringstream o;
- o << nbproc << " ";
- command += o.str();
-#ifdef WITHLAM
- command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
-#elif defined(WITHOPENMPI)
- if( getenv("OMPI_URI_FILE") == NULL )
- command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
- else{
- command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
- command += getenv("OMPI_URI_FILE");
- }
-#elif defined(WITHMPICH)
- command += "-nameserver " + Kernel_Utils::GetHostname();
-#endif
- command += " SALOME_MPIContainer ";
+ Py_XDECREF(mod);
}
else
- command += " " +container_exe+ " ";
+ {
+ int id = -1;
+ PyObject* tuple(PyTuple_New(theScriptParameters.size()));
- command += _NS->ContainerName(params);
- command += " -";
- AddOmninamesParams(command);
+ auto insert_parameter = [&tuple, &theScriptParameters, &id]()
+ {
+ if (!theScriptParameters.empty())
+ {
+ PyTuple_SetItem(tuple, ++id, PyUnicode_FromString(theScriptParameters.front().c_str()));
+ theScriptParameters.pop();
+ }
+ };
- MESSAGE("command =" << command);
+ while (!theScriptParameters.empty())
+ {
+ insert_parameter();
+ }
+
+ PyObject *args(PyTuple_New(1));
+ PyTuple_SetItem(args, 0, tuple);
+
+ PyObject *res(PyObject_CallObject(meth, args));
+ if (res)
+ {
+ command = PyUnicode_AsUTF8(res);
+ Py_XDECREF(res);
+ }
+
+ Py_XDECREF(args);
+ Py_XDECREF(tuple);
+ Py_XDECREF(meth);
+ Py_XDECREF(mod);
+ }
}
+ MESSAGE("Command from template is ... " << command << std::endl);
return command;
}
+//=============================================================================
//=============================================================================
/*!
* builds the command to be launched.
- */
+ */
//=============================================================================
-std::string
-SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
-(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
+std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe, std::string& tmpFileName) const
{
- _TmpFileName = BuildTemporaryFileName();
- std::string command;
- int nbproc = 0;
-
- std::ostringstream o;
-
+ // Prepare name of the script to be used
+ std::string script_name = "SALOME_CM_LOCAL_NO_MPI";
if (params.isMPI)
- {
- o << "mpirun -np ";
-
- if ( params.nb_proc <= 0 )
- nbproc = 1;
- else
- nbproc = params.nb_proc;
-
- o << nbproc << " ";
-
- if( getenv("LIBBATCH_NODEFILE") != NULL )
- o << "-machinefile " << machinesFile << " ";
-
-#ifdef WITHLAM
- o << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
-#elif defined(WITHOPENMPI)
- if( getenv("OMPI_URI_FILE") == NULL )
- o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
- else
- {
- o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
- o << getenv("OMPI_URI_FILE");
- }
-#elif defined(WITHMPICH)
- o << "-nameserver " + Kernel_Utils::GetHostname();
+ {
+#ifdef LAM_MPI
+ script_name = "SALOME_CM_LOCAL_MPI_LAN";
+#elif defined(OPEN_MPI)
+ script_name = "SALOME_CM_LOCAL_MPI_OPENMPI";
+#elif defined(MPICH)
+ script_name = "SALOME_CM_LOCAL_MPI_MPICH";
#endif
+ }
+
+ // Prepare parameters to use in the Python script:
+ // 1. All parameters are strings.
+ // 2. For some booleans use "1" = True, "0" = False.
+ // 3. If a parameter is NULL, then its value is "NULL".
- if (isPythonContainer(params.container_name))
- o << " pyMPI SALOME_ContainerPy.py ";
- else
- o << " SALOME_MPIContainer ";
- }
+ std::queue<std::string> script_parameters;
+
+ // ===== Number of processes (key = "nb_proc")
+ script_parameters.push(params.isMPI ? std::to_string(params.nb_proc <= 0 ? 1 : params.nb_proc) : "NULL");
+
+ // ===== Working directory (key = "workdir") and temporary directory flag (key = "isTmpDir")
+ // A working directory is requested
+ std::string workdir = params.workingdir.in();
+ std::string isTmpDir = std::to_string(0);
+ if (workdir == "$TEMPDIR")
+ {
+ // A new temporary directory is requested
+ isTmpDir = std::to_string(1);
+ workdir = Kernel_Utils::GetTmpDir();
+ }
+ script_parameters.push(workdir);
+ script_parameters.push(isTmpDir);
+
+ // ===== Server name (key = "name_server")
+ script_parameters.push(Kernel_Utils::GetHostname());
+ // ===== Container (key = "container")
+ std::string container;
+ if (params.isMPI)
+ {
+ container = isPythonContainer(params.container_name) ? "pyMPI SALOME_ContainerPy.py" : "SALOME_MPIContainer";
+ }
else
- {
- std::string wdir=params.workingdir.in();
- if(wdir != "")
- {
- // a working directory is requested
- if(wdir == "$TEMPDIR")
- {
- // a new temporary directory is requested
- std::string dir = Kernel_Utils::GetTmpDir();
-#ifdef WIN32
- o << "cd /d " << dir << std::endl;
-#else
- o << "cd " << dir << ";";
-#endif
+ {
+ container = isPythonContainer(params.container_name) ? "SALOME_ContainerPy.py" : container_exe;
+ }
+ script_parameters.push(container);
- }
- else
- {
- // a permanent directory is requested use it or create it
-#ifdef WIN32
- o << "mkdir " + wdir << std::endl;
- o << "cd /D " + wdir << std::endl;
-#else
- o << "mkdir -p " << wdir << " && cd " << wdir + ";";
-#endif
- }
- }
+ // ===== Container name (key = "container_name")
+ script_parameters.push(_NS->ContainerName(params));
- if (isPythonContainer(params.container_name))
- o << "SALOME_ContainerPy.py ";
- else
- o << container_exe + " ";
+ // ===== LIBBATCH node file (key = "libbatch_nodefile")
+ script_parameters.push(std::to_string(GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL ? 1 : 0));
- }
+ // ===== Machine file (key = "machine_file")
+ script_parameters.push(machinesFile.empty() ? "NULL" : machinesFile);
+
+ // ===== OMPI uri file (key = "ompi_uri_file")
+ std::string ompi_uri_file = GetenvThreadSafeAsString("OMPI_URI_FILE");
+ script_parameters.push(ompi_uri_file.empty() ? "NULL" : ompi_uri_file);
- o << _NS->ContainerName(params);
- o << " -";
- AddOmninamesParams(o);
+ std::string command_from_template = GetCommandFromTemplate(script_name, script_parameters);
- std::ofstream command_file( _TmpFileName.c_str() );
+ std::ostringstream o;
+ o << command_from_template << " ";
+
+ //==================================================================================== */
+
+ if( this->_isSSL )
+ {
+ Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+ CORBA::String_var iorNS = _orb->object_to_string(ns);
+ o << iorNS;
+ }
+ else
+ {
+ o << "-";
+ AddOmninamesParams(o);
+ }
+
+ tmpFileName = BuildTemporaryFileName();
+ std::ofstream command_file( tmpFileName.c_str() );
command_file << o.str();
command_file.close();
#ifndef WIN32
- chmod(_TmpFileName.c_str(), 0x1ED);
+ chmod(tmpFileName.c_str(), 0x1ED);
#endif
- command = _TmpFileName;
-
+
+ std::string command = tmpFileName;
MESSAGE("Command is file ... " << command);
MESSAGE("Command is ... " << o.str());
return command;
//=============================================================================
/*!
* removes the generated temporary file in case of a remote launch.
- */
+ * This method is thread safe
+ */
//=============================================================================
void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
{
- int lenght = tmpFileName.size();
- if ( lenght > 0)
+ size_t length = tmpFileName.size();
+ if ( length > 0)
{
#ifdef WIN32
std::string command = "del /F ";
#else
- std::string command = "rm ";
+ std::string command = "rm ";
#endif
- if ( lenght > 4 )
- command += tmpFileName.substr(0, lenght - 3 );
+ if ( length > 4 )
+ command += tmpFileName.substr(0, length - 3 );
else
command += tmpFileName;
command += '*';
- system(command.c_str());
+ SystemThreadSafe(command.c_str());
//if dir is empty - remove it
std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
#else
command = "rmdir " + tmp_dir;
#endif
- system(command.c_str());
+ SystemThreadSafe(command.c_str());
}
}
}
//=============================================================================
/*!
* add to command all options relative to naming service.
- */
+ */
//=============================================================================
void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
{
- CORBA::String_var iorstr = _NS->getIORaddr();
- command += "ORBInitRef NameService=";
- command += iorstr;
+ std::ostringstream oss;
+ AddOmninamesParams(oss);
+ command+=oss.str();
}
//=============================================================================
/*!
* add to command all options relative to naming service.
- */
+ */
//=============================================================================
-void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) const
+void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const
{
- CORBA::String_var iorstr = _NS->getIORaddr();
- fileStream << "ORBInitRef NameService=";
- fileStream << iorstr;
+ AddOmninamesParams(fileStream,_NS);
}
//=============================================================================
/*!
* add to command all options relative to naming service.
- */
+ */
//=============================================================================
-void SALOME_ContainerManager::AddOmninamesParams(std::ostringstream& oss) const
+void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns)
+{
+ SALOME_NamingService *nsTrad(dynamic_cast<SALOME_NamingService *>(ns));
+ if(nsTrad)
+ {
+ CORBA::String_var iorstr(nsTrad->getIORaddr());
+ fileStream << "ORBInitRef NameService=";
+ fileStream << iorstr;
+ }
+}
+
+void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command)
{
- CORBA::String_var iorstr = _NS->getIORaddr();
- oss << "ORBInitRef NameService=";
- oss << iorstr;
+#ifdef WIN32
+ command = "%PYTHONBIN% -c \"import subprocess ; subprocess.Popen(r'" + command + "').pid\"";
+#else
+ command += " &";
+#endif
+}
+
+int SALOME_ContainerManager::GetTimeOutToLoaunchServer()
+{
+ int count(TIME_OUT_TO_LAUNCH_CONT);
+ if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
+ {
+ std::string new_count_str(GetenvThreadSafeAsString("TIMEOUT_TO_LAUNCH_CONTAINER"));
+ int new_count;
+ std::istringstream ss(new_count_str);
+ if (!(ss >> new_count))
+ {
+ INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
+ }
+ else
+ count = new_count;
+ }
+ return count;
+}
+
+void SALOME_ContainerManager::SleepInSecond(int ellapseTimeInSecond)
+{
+#ifndef WIN32
+ sleep( ellapseTimeInSecond ) ;
+#else
+ int timeInMS(1000*ellapseTimeInSecond);
+ Sleep(timeInMS);
+#endif
}
//=============================================================================
/*!
* generate a file name in /tmp directory
- */
+ */
//=============================================================================
-std::string SALOME_ContainerManager::BuildTemporaryFileName() const
+std::string SALOME_ContainerManager::BuildTemporaryFileName()
{
//build more complex file name to support multiple salome session
std::string aFileName = Kernel_Utils::GetTmpFileName();
+ std::ostringstream str_pid;
+ str_pid << ::getpid();
+ aFileName = aFileName + "-" + str_pid.str();
#ifndef WIN32
aFileName += ".sh";
#else
//=============================================================================
/*!
* Builds in a temporary file the script to be launched.
- *
+ *
* Used if SALOME Application ($APPLI) is not defined.
* The command is build with data from CatalogResources, in which every path
* used on remote computer must be defined.
- */
+ */
//=============================================================================
-std::string
-SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer
-(const std::string& resource_name,
- const Engines::ContainerParameters& params) throw(SALOME_Exception)
+std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const
{
int status;
- _TmpFileName = BuildTemporaryFileName();
+ tmpFileName = BuildTemporaryFileName();
std::ofstream tempOutputFile;
- tempOutputFile.open(_TmpFileName.c_str(), std::ofstream::out );
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
+ tempOutputFile.open(tmpFileName.c_str(), std::ofstream::out );
+ const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
tempOutputFile << "#! /bin/sh" << std::endl;
// --- set env vars
if (params.isMPI)
{
- tempOutputFile << "mpirun -np ";
- int nbproc;
+ int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
- if ( params.nb_proc <= 0 )
- nbproc = 1;
- else
- nbproc = params.nb_proc;
-
- std::ostringstream o;
+ tempOutputFile << "mpirun -np ";
tempOutputFile << nbproc << " ";
-#ifdef WITHLAM
+#ifdef LAM_MPI
tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
-#elif defined(WITHOPENMPI)
- if( getenv("OMPI_URI_FILE") == NULL )
+#elif defined(OPEN_MPI)
+ if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
else{
tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
- tempOutputFile << getenv("OMPI_URI_FILE");
+ tempOutputFile << GetenvThreadSafeAsString("OMPI_URI_FILE");
}
-#elif defined(WITHMPICH)
+#elif defined(MPICH)
tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
#endif
}
- tempOutputFile << getenv("KERNEL_ROOT_DIR") << "/bin/salome/";
+ tempOutputFile << GetenvThreadSafeAsString("KERNEL_ROOT_DIR") << "/bin/salome/";
if (params.isMPI)
{
tempOutputFile.flush();
tempOutputFile.close();
#ifndef WIN32
- chmod(_TmpFileName.c_str(), 0x1ED);
+ chmod(tmpFileName.c_str(), 0x1ED);
#endif
// --- Build command
{
command = "rsh ";
std::string commandRcp = "rcp ";
- commandRcp += _TmpFileName;
+ commandRcp += tmpFileName;
commandRcp += " ";
commandRcp += resInfo.HostName;
commandRcp += ":";
- commandRcp += _TmpFileName;
- status = system(commandRcp.c_str());
+ commandRcp += tmpFileName;
+ status = SystemThreadSafe(commandRcp.c_str());
}
else if (resInfo.Protocol == ssh)
{
command = "ssh ";
std::string commandRcp = "scp ";
- commandRcp += _TmpFileName;
+ commandRcp += tmpFileName;
commandRcp += " ";
commandRcp += resInfo.HostName;
commandRcp += ":";
- commandRcp += _TmpFileName;
- status = system(commandRcp.c_str());
+ commandRcp += tmpFileName;
+ status = SystemThreadSafe(commandRcp.c_str());
}
else if (resInfo.Protocol == srun)
{
- command = "srun -n 1 -N 1 --share --nodelist=";
+ command = "srun -n 1 -N 1 -s --mem-per-cpu=0 --cpu-bind=none --nodelist=";
std::string commandRcp = "rcp ";
- commandRcp += _TmpFileName;
+ commandRcp += tmpFileName;
commandRcp += " ";
commandRcp += resInfo.HostName;
commandRcp += ":";
- commandRcp += _TmpFileName;
- status = system(commandRcp.c_str());
+ commandRcp += tmpFileName;
+ status = SystemThreadSafe(commandRcp.c_str());
}
else
throw SALOME_Exception("Unknown protocol");
if(status)
- throw SALOME_Exception("Error of connection on remote host");
+ throw SALOME_Exception("Error of connection on remote host");
command += resInfo.HostName;
- _CommandForRemAccess = command;
command += " ";
- command += _TmpFileName;
+ command += tmpFileName;
SCRUTE(command);
}
-std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile)
+std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile) const
{
int status;
std::string zeronode;
std::string command;
std::string tmpFile = BuildTemporaryFileName();
+ const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
- if( getenv("LIBBATCH_NODEFILE") == NULL )
+ if(resInfo.Protocol == sh)
+ {
+ return resInfo.HostName;
+ }
+
+ if( GetenvThreadSafe("LIBBATCH_NODEFILE") == NULL )
{
if (_isAppliSalomeDefined)
{
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(machine);
-
- if (resInfo.Protocol == rsh)
- command = "rsh ";
- else if (resInfo.Protocol == ssh)
- command = "ssh ";
- else if (resInfo.Protocol == srun)
- command = "srun -n 1 -N 1 --share --nodelist=";
- else
- throw SALOME_Exception("Unknown protocol");
-
- if (resInfo.UserName != "")
- {
- command += "-l ";
- command += resInfo.UserName;
- command += " ";
- }
-
- command += resInfo.HostName;
- command += " ";
-
- if (resInfo.AppliPath != "")
- command += resInfo.AppliPath; // path relative to user@machine $HOME
- else
- {
- ASSERT(getenv("APPLI"));
- command += getenv("APPLI"); // path relative to user@machine $HOME
- }
-
- command += "/runRemote.sh ";
-
- ASSERT(getenv("NSHOST"));
- command += getenv("NSHOST"); // hostname of CORBA name server
-
- command += " ";
- ASSERT(getenv("NSPORT"));
- command += getenv("NSPORT"); // port of CORBA name server
-
+ command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
+ resInfo.UserName, resInfo.AppliPath);
command += " mpirun -np 1 hostname -s > " + tmpFile;
}
else
else
command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
- status = system(command.c_str());
+ status = SystemThreadSafe(command.c_str());
if( status == 0 ){
std::ifstream fp(tmpFile.c_str(),std::ios::in);
while(fp >> zeronode);
std::string SALOME_ContainerManager::machinesFile(const int nbproc)
{
std::string tmp;
- std::string nodesFile = getenv("LIBBATCH_NODEFILE");
+ std::string nodesFile = GetenvThreadSafeAsString("LIBBATCH_NODEFILE");
std::string machinesFile = Kernel_Utils::GetTmpFileName();
std::ifstream fpi(nodesFile.c_str(),std::ios::in);
std::ofstream fpo(machinesFile.c_str(),std::ios::out);
}
-std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string program)
+std::string SALOME_ContainerManager::getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
{
- std::set<pid_t> thepids;
- std::string tmpFile = Kernel_Utils::GetTmpFileName();
- std::string cmd;
- std::string thepid;
- cmd = "pidof " + program + " > " + tmpFile;
- system(cmd.c_str());
- std::ifstream fpi(tmpFile.c_str(),std::ios::in);
- while(fpi >> thepid){
- thepids.insert(atoi(thepid.c_str()));
- }
- return thepids;
+ return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE","salome shell --",protocol,hostname,username,applipath,workdir);
}
-std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
+std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
+{
+ return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE_OLD",this->GetRunRemoteExecutableScript(),protocol,hostname,username,applipath,workdir);
+}
+
+std::string SALOME_ContainerManager::getCommandToRunRemoteProcessCommon(const std::string& templateName,
+ const std::string& remoteScript,
+ AccessProtocolType protocol,
const std::string & hostname,
- const std::string & username)
+ const std::string & username,
+ const std::string & applipath,
+ const std::string & workdir) const
{
std::ostringstream command;
+
+ // Prepare parameters to use in the Python script:
+ // 1. All parameters are strings.
+ // 2. For some booleans use "1" = True, "0" = False.
+ // 3. If a parameter is NULL, then its value is "NULL".
+
+ std::queue<std::string> script_parameters;
+
+ // ===== Protocol (key = "protocol")
+ std::string strProtocol;
switch (protocol)
{
- case rsh:
- command << "rsh ";
- if (username != "")
- {
- command << "-l " << username << " ";
- }
- command << hostname << " ";
- break;
- case ssh:
- command << "ssh ";
- if (username != "")
- {
- command << "-l " << username << " ";
- }
- command << hostname << " ";
- break;
- case srun:
- // no need to redefine the user with srun, the job user is taken by default
- // (note: for srun, user id can be specified with " --uid=<user>")
- command << "srun -n 1 -N 1 --share --nodelist=" << hostname << " ";
- break;
- case pbsdsh:
- command << "pbsdsh -o -h " << hostname << " ";
- break;
- case blaunch:
- command << "blaunch -no-shell " << hostname << " ";
- break;
+ case rsh: strProtocol = "rsh"; break;
+ case ssh: strProtocol = "ssh"; break;
+ case srun: strProtocol = "srun"; break;
+ case pbsdsh: strProtocol = "pbsdsh"; break;
+ case blaunch: strProtocol = "blaunch"; break;
default:
throw SALOME_Exception("Unknown protocol");
}
+ script_parameters.push(strProtocol);
+
+ // ===== User name (key = "user")
+ script_parameters.push(username.empty() ? "NULL" : username);
+
+ // ===== Host name (key = "host")
+ script_parameters.push(hostname.empty() ? "NULL" : hostname);
+
+
+ // ===== Remote APPLI path (key = "appli")
+ script_parameters.push(applipath.empty() ? GetenvThreadSafeAsString("APPLI") : applipath);
+
+ if(!this->_isSSL)
+ {
+ ASSERT(GetenvThreadSafe("NSHOST"));
+ ASSERT(GetenvThreadSafe("NSPORT"));
+ }
+
+ struct stat statbuf;
+ std::string appli_mode = (stat(GetenvThreadSafe("APPLI"), &statbuf) == 0 && S_ISREG(statbuf.st_mode)) ? "launcher" : "dir";
+
+ // ===== Working directory (key = "workdir")
+ script_parameters.push(workdir == "$TEMPDIR" ? "\\$TEMPDIR" : workdir);
+
+ // ===== SSL (key = "ssl")
+ script_parameters.push(this->_isSSL ? "1" : "0");
+
+ // ===== Hostname of CORBA name server (key = "nshost")
+ std::string nshost = GetenvThreadSafeAsString("NSHOST");
+ script_parameters.push(nshost.empty() ? "NULL" : nshost);
+
+ // ===== Port of CORBA name server (key = "nsport")
+ std::string nsport = GetenvThreadSafeAsString("NSPORT");
+ script_parameters.push(nsport.empty() ? "NULL" : nsport);
+
+ // ===== Remote script (key = "remote_script")
+ script_parameters.push(remoteScript.empty() ? "NONE" : remoteScript);
+
+ // ===== Naming service (key = "naming_service")
+ std::string namingService = "NONE";
+ if(this->_isSSL)
+ {
+ Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+ CORBA::String_var iorNS = _orb->object_to_string(ns);
+ namingService = iorNS;
+ }
+ script_parameters.push(namingService);
+
+ // ===== APPLI mode (key = "appli_mode")
+ // $APPLI points either to an application directory, or to a salome launcher file
+ // we prepare the remote command according to the case
+ script_parameters.push(appli_mode);
+
+ command << GetCommandFromTemplate(templateName, script_parameters);
return command.str();
}
-bool
+bool
SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
{
bool result = true;
-
+
// Step 1 : check ContainerParameters
// Check container_name, has to be defined
if (std::string(params.container_name.in()) == "")
}
// Step 2 : check resource_selected
- Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
- std::string protocol = resource_definition->protocol.in();
- std::string username = resource_definition->username.in();
- std::string applipath = resource_definition->applipath.in();
+ const ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
+ //std::string protocol = resource_definition->protocol.in();
+ std::string username = resource_definition.UserName;
+ std::string applipath = resource_definition.AppliPath;
- if (protocol == "" || username == "" || applipath == "")
+ //if (protocol == "" || username == "" || applipath == "")
+ if (username == "" || applipath == "")
{
INFOS("[checkPaCOParameters] resource selected is not well defined");
- INFOS("[checkPaCOParameters] resource name: " << resource_definition->name.in());
- INFOS("[checkPaCOParameters] resource hostname: " << resource_definition->hostname.in());
- INFOS("[checkPaCOParameters] resource protocol: " << protocol);
+ INFOS("[checkPaCOParameters] resource name: " << resource_definition.Name);
+ INFOS("[checkPaCOParameters] resource hostname: " << resource_definition.HostName);
+ INFOS("[checkPaCOParameters] resource protocol: " << resource_definition.getAccessProtocolTypeStr());
INFOS("[checkPaCOParameters] resource username: " << username);
INFOS("[checkPaCOParameters] resource applipath: " << applipath);
result = false;
return result;
}
+
+/*
+ * :WARNING: Do not directly convert returned value to std::string
+ * This function may return NULL if env variable is not defined.
+ * And std::string(NULL) causes undefined behavior.
+ * Use GetenvThreadSafeAsString to properly get a std::string.
+*/
+char *SALOME_ContainerManager::GetenvThreadSafe(const char *name)
+{// getenv is not thread safe. See man 7 pthread.
+ Utils_Locker lock (&_getenvMutex);
+ return getenv(name);
+}
+
+/*
+ * Return env variable as a std::string.
+ * Return empty string if env variable is not set.
+ */
+std::string SALOME_ContainerManager::GetenvThreadSafeAsString(const char *name)
+{
+ char* var = GetenvThreadSafe(name);
+ return var ? std::string(var) : std::string();
+}
+
+int SALOME_ContainerManager::SystemThreadSafe(const char *command)
+{
+ Utils_Locker lock (&_systemMutex);
+ return system(command);
+}
+
+long SALOME_ContainerManager::SystemWithPIDThreadSafe(const std::vector<std::string>& command)
+{
+ Utils_Locker lock(&_systemMutex);
+ if(command.size()<1)
+ throw SALOME_Exception("SystemWithPIDThreadSafe : command is expected to have a length of size 1 at least !");
+#ifndef WIN32
+ pid_t pid ( fork() ) ; // spawn a child process, following code is executed in both processes
+#else
+ pid_t pid = -1; //Throw SALOME_Exception on Windows
+#endif
+ if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
+ {
+ std::size_t sz(command.size());
+ char **args = new char *[sz+1];
+ for(std::size_t i=0;i<sz;i++)
+ args[i] = strdup(command[i].c_str());
+ args[sz] = nullptr;
+ execvp( command[0].c_str() , args );
+ std::ostringstream oss;
+ oss << "Error when launching " << command[0];
+ throw SALOME_Exception(oss.str().c_str()); // execvp failed
+ }
+ else if ( pid < 0 )
+ {
+ throw SALOME_Exception("fork() failed");
+ }
+ else // I'm a parent
+ {
+ return pid;
+ }
+}
+
#ifdef WITH_PACO_PARALLEL
//=============================================================================
INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
// Step 2 : Get a MachineFile for the parallel container
- std::string machine_file_name = _ResManager->getMachineFile(resource_selected,
+ std::string machine_file_name = _resManager->getMachineFile(resource_selected,
params.nb_proc,
params.parallelLib.in());
// Step 3 : starting parallel container proxy
std::string command_proxy("");
std::string proxy_machine;
- try
+ try
{
command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
}
// Step 4 : starting parallel container nodes
std::string command_nodes("");
SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
- try
+ try
{
command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
}
{
INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
// Il faut tuer le proxy
- try
+ try
{
Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
proxy->Shutdown();
}
catch (...)
{
- INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
+ INFOS("[StarPaCOPPContainer] Exception caught from proxy Shutdown...");
}
return ret;
}
// Step 4 : connecting nodes and the proxy to actually create a parallel container
- for (int i = 0; i < params.nb_proc; i++)
+ for (int i = 0; i < params.nb_proc; i++)
{
std::ostringstream tmp;
tmp << i;
std::string theNodeMachine(nodes_machines[i]);
std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
obj = _NS->Resolve(containerNameInNS.c_str());
- if (CORBA::is_nil(obj))
+ if (CORBA::is_nil(obj))
{
INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
}
// Step 5 : starting parallel container
- try
+ try
{
MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
container_proxy->start();
}
catch(std::exception& exc)
{
- INFOS("Caught std::exception - "<<exc.what());
+ INFOS("Caught std::exception - "<<exc.what());
}
catch(...)
{
return ret;
}
-std::string
+std::string
SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
std::string machine_file_name,
std::string & proxy_hostname)
std::string nb_proc_str = tmp_string.str();
// Get resource definition
- Engines::ResourceDefinition_var resource_definition =
- _ResManager->GetResourceDefinition(params.resource_params.name);
+ ParserResourcesType resource_definition =
+ _resManager->GetResourceDefinition(params.resource_params.name.in());
// Choose hostname
std::string hostname;
MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
remote_execution = true;
}
-
- // Log environnement
+
+ // Log environment
std::string log_type("");
- char * get_val = getenv("PARALLEL_LOG");
+ char * get_val = GetenvThreadSafe("PARALLEL_LOG");
if (get_val)
log_type = get_val;
// a SALOME application
if (remote_execution)
{
- ASSERT(getenv("NSHOST"));
- ASSERT(getenv("NSPORT"));
+ ASSERT(GetenvThreadSafe("NSHOST"));
+ ASSERT(GetenvThreadSafe("NSPORT"));
- command << resource_definition->protocol.in();
+ command << resource_definition.getAccessProtocolTypeStr();
command << " -l ";
- command << resource_definition->username.in();
+ command << resource_definition.UserName;
command << " " << hostname;
- command << " " << resource_definition->applipath.in();
+ command << " " << resource_definition.AppliPath;
command << "/runRemote.sh ";
- command << getenv("NSHOST") << " "; // hostname of CORBA name server
- command << getenv("NSPORT") << " "; // port of CORBA name server
+ command << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
+ command << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
}
command << exe_name;
return command.str();
}
-std::string
+std::string
SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
const std::string & machine_file_name,
SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
nb_proc_stream << params.nb_proc;
// Get resource definition
- Engines::ResourceDefinition_var resource_definition =
- _ResManager->GetResourceDefinition(params.resource_params.name);
-
- // Log environnement
+ ParserResourcesType resource_definition =
+ _resManager->GetResourceDefinition(params.resource_params.name.in());
+
+ // Log environment
std::string log_type("");
- char * get_val = getenv("PARALLEL_LOG");
+ char * get_val = GetenvThreadSafe("PARALLEL_LOG");
if (get_val)
log_type = get_val;
// a SALOME application
if (remote_execution)
{
- ASSERT(getenv("NSHOST"));
- ASSERT(getenv("NSPORT"));
+ ASSERT(GetenvThreadSafe("NSHOST"));
+ ASSERT(GetenvThreadSafe("NSPORT"));
- command_node_stream << resource_definition->protocol.in();
+ command_node_stream << resource_definition.getAccessProtocolTypeStr();
command_node_stream << " -l ";
- command_node_stream << resource_definition->username.in();
+ command_node_stream << resource_definition.UserName;
command_node_stream << " " << hostname;
- command_node_stream << " " << resource_definition->applipath.in();
+ command_node_stream << " " << resource_definition.AppliPath;
command_node_stream << "/runRemote.sh ";
- command_node_stream << getenv("NSHOST") << " "; // hostname of CORBA name server
- command_node_stream << getenv("NSPORT") << " "; // port of CORBA name server
+ command_node_stream << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
+ command_node_stream << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
}
command_node_stream << exe_name;
if (last == std::string::npos)
last = -1;
- std::string protocol = resource_definition->protocol.in();
- if (protocol == "rsh")
+ if (resource_definition.Protocol == rsh)
command_remote_stream << "rcp ";
- else
+ else
command_remote_stream << "scp ";
command_remote_stream << machine_file_name << " ";
- command_remote_stream << resource_definition->username.in() << "@";
- command_remote_stream << hostname << ":" << resource_definition->applipath.in();
+ command_remote_stream << resource_definition.UserName << "@";
+ command_remote_stream << hostname << ":" << resource_definition.AppliPath;
command_remote_stream << "/" << machine_file_name.substr(last+1);
- int status = system(command_remote_stream.str().c_str());
+ int status = SystemThreadSafe(command_remote_stream.str().c_str());
if (status == -1)
{
INFOS("copy of the MPI machine file failed ! - sorry !");
// a SALOME application
if (remote_execution)
{
- ASSERT(getenv("NSHOST"));
- ASSERT(getenv("NSPORT"));
+ ASSERT(GetenvThreadSafe("NSHOST"));
+ ASSERT(GetenvThreadSafe("NSPORT"));
- command_nodes << resource_definition->protocol.in();
+ command_nodes << resource_definition.getAccessProtocolTypeStr();
command_nodes << " -l ";
- command_nodes << resource_definition->username.in();
+ command_nodes << resource_definition.UserName;
command_nodes << " " << hostname;
- command_nodes << " " << resource_definition->applipath.in();
+ command_nodes << " " << resource_definition.AppliPath;
command_nodes << "/runRemote.sh ";
- command_nodes << getenv("NSHOST") << " "; // hostname of CORBA name server
- command_nodes << getenv("NSPORT") << " "; // port of CORBA name server
+ command_nodes << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
+ command_nodes << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
}
- if (std::string(resource_definition->mpiImpl.in()) == "lam")
+ if (resource_definition.mpi == lam)
{
command_nodes << "mpiexec -ssi boot ";
- command_nodes << "-machinefile " << machine_file_name << " ";
+ command_nodes << "-machinefile " << machine_file_name << " ";
command_nodes << "-n " << params.nb_proc;
}
else
// We don't put hostname, because nodes are registered in the resource of the proxy
for (int i= 0; i < params.nb_proc; i++)
- vect_machine.push_back(proxy_hostname);
+ vect_machine.push_back(proxy_hostname);
command_nodes << command_end;
}
const std::string & exe_type,
const std::string & container_name,
const std::string & hostname,
- std::string & begin,
+ std::string & begin,
std::string & end)
{
if(log_type == "xterm")
{
// default into a file...
std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
- logFilename += std::string(getenv("USER")) + ".log";
+ std::string user = GetenvThreadSafeAsString("USER");
+ if (user.empty())
+ user = GetenvThreadSafeAsString("LOGNAME");
+ logFilename += user + ".log";
end = " > " + logFilename + " 2>&1 & ";
}
}
-CORBA::Object_ptr
-SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
+CORBA::Object_ptr
+SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
const Engines::ContainerParameters& params,
const std::string & hostname)
{
PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
MESSAGE("[LaunchPaCOProxyContainer] Launch command");
- int status = system(command.c_str());
+ int status = SystemThreadSafe(command.c_str());
if (status == -1) {
INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
return container_proxy;
return container_proxy;
}
- int count = TIME_OUT_TO_LAUNCH_CONT;
+ int count(GetTimeOutToLoaunchServer());
CORBA::Object_var obj = CORBA::Object::_nil();
- std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
+ std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
hostname.c_str());
MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
- while (CORBA::is_nil(obj) && count)
+ while (CORBA::is_nil(obj) && count)
{
sleep(1);
count--;
obj = _NS->Resolve(containerNameInNS.c_str());
}
- try
+ try
{
container_proxy = PaCO::InterfaceManager::_narrow(obj);
}
//=============================================================================
/*! This method launches the parallel container.
- * It will may be placed on the ressources manager.
+ * It will may be placed on the resources manager.
*
* \param command to launch
* \param container's parameters
*/
//=============================================================================
bool
-SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
+SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
const Engines::ContainerParameters& params,
const std::string& name,
SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
{
INFOS("[LaunchPaCONodeContainer] Launch command");
- int status = system(command.c_str());
+ int status = SystemThreadSafe(command.c_str());
if (status == -1) {
INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
return false;
INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
// We are waiting all the nodes
- for (int i = 0; i < params.nb_proc; i++)
+ for (int i = 0; i < params.nb_proc; i++)
{
CORBA::Object_var obj = CORBA::Object::_nil();
std::string theMachine(vect_machine[i]);
std::string container_node_name = name + proc_number;
std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
- int count = TIME_OUT_TO_LAUNCH_CONT;
+ int count(GetTimeOutToLoaunchServer());
while (CORBA::is_nil(obj) && count) {
- sleep(1) ;
+ SleepInSecond(1);
count-- ;
obj = _NS->Resolve(containerNameInNS.c_str());
}
#else
Engines::Container_ptr
-SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params,
- std::string resource_selected)
+SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& /*params*/,
+ std::string /*resource_selected*/)
{
Engines::Container_ptr ret = Engines::Container::_nil();
INFOS("[StarPaCOPPContainer] is disabled !");
return ret;
}
-std::string
-SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
- std::string machine_file_name,
- std::string & proxy_hostname)
+std::string
+SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& /*params*/,
+ std::string /*machine_file_name*/,
+ std::string & /*proxy_hostname*/)
{
return "";
}
-std::string
-SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
- const std::string & machine_file_name,
- SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
- const std::string & proxy_hostname)
+std::string
+SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& /*params*/,
+ const std::string & /*machine_file_name*/,
+ SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/,
+ const std::string & /*proxy_hostname*/)
{
return "";
}
-void
-SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
- const std::string & exe_type,
- const std::string & container_name,
- const std::string & hostname,
- std::string & begin,
- std::string & end)
+void
+SALOME_ContainerManager::LogConfiguration(const std::string & /*log_type*/,
+ const std::string & /*exe_type*/,
+ const std::string & /*container_name*/,
+ const std::string & /*hostname*/,
+ std::string & /*begin*/,
+ std::string & /*end*/)
{
}
-CORBA::Object_ptr
-SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
- const Engines::ContainerParameters& params,
- const std::string& hostname)
+CORBA::Object_ptr
+SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& /*command*/,
+ const Engines::ContainerParameters& /*params*/,
+ const std::string& /*hostname*/)
{
CORBA::Object_ptr ret = CORBA::Object::_nil();
return ret;
}
-bool
-SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
- const Engines::ContainerParameters& params,
- const std::string& name,
- SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
+bool
+SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& /*command*/,
+ const Engines::ContainerParameters& /*params*/,
+ const std::string& /*name*/,
+ SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/)
{
return false;
}
#endif
-