Salome HOME
Kernel evolution for salome gui without neither NS nor other servers.
[modules/kernel.git] / src / Container / SALOME_ContainerManager.cxx
index 608fda19d53d5b3477825ecd53ed604fe56e7837..8134f28cd0e818d22926d00d9f1ac19cab13a20a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -99,10 +99,9 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer
   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);
+  Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj);
+  if(_NS)
+    _NS->Register(refContMan,_ContainerManagerNameInNS);
   _isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0);
 
 #ifdef HAVE_MPI2
@@ -195,7 +194,8 @@ void SALOME_ContainerManager::Shutdown()
 {
   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);
 }
@@ -209,7 +209,8 @@ void SALOME_ContainerManager::Shutdown()
 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");
@@ -235,7 +236,7 @@ void SALOME_ContainerManager::ShutdownContainers()
             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
           }
@@ -368,7 +369,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
             break;
           }
       }
-      catch(const SALOME_Exception &ex)
+      catch(const SALOME_Exception &ex) //!< TODO: unused variable
       {
         MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
         return ret;
@@ -380,11 +381,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
       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( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
@@ -531,7 +528,8 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par
 
         // Launch remote command
           command += " \"ls /tmp >/dev/null 2>&1\"";
-        int status = SystemThreadSafe(command.c_str());
+        // 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
@@ -683,7 +681,7 @@ SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& param
     else
       return Engines::Container::_narrow(obj);
   }
-  catch(const CORBA::Exception& e)
+  catch(const CORBA::Exception&)
   {
     return Engines::Container::_nil();
   }
@@ -701,7 +699,7 @@ 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)
@@ -741,21 +739,12 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string&
     command = BuildTempFileToLaunchRemoteContainer(resource_name, params, tmpFileName);
   else
   {
-    int nbproc;
     const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
 
-    if (params.isMPI)
-    {
-      if ( params.nb_proc <= 0 )
-        nbproc = 1;
-      else
-        nbproc = params.nb_proc;
-    }
-
     std::string wdir = params.workingdir.in();
 
-    // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
-    //  SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
+    // "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..."
@@ -765,6 +754,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string&
 
     if(params.isMPI)
     {
+      int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
       command += " mpirun -np ";
       std::ostringstream o;
       o << nbproc << " ";
@@ -805,18 +795,14 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En
 {
   tmpFileName = BuildTemporaryFileName();
   std::string command;
-  int nbproc = 0;
 
   std::ostringstream o;
 
   if (params.isMPI)
     {
-      o << "mpirun -np ";
+      int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
 
-      if ( params.nb_proc <= 0 )
-        nbproc = 1;
-      else
-        nbproc = params.nb_proc;
+      o << "mpirun -np ";
 
       o << nbproc << " ";
 
@@ -907,7 +893,7 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En
 
 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
 {
-  int length = tmpFileName.size();
+  size_t length = tmpFileName.size();
   if ( length  > 0)
     {
 #ifdef WIN32
@@ -1059,15 +1045,9 @@ std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const
 
   if (params.isMPI)
     {
-      tempOutputFile << "mpirun -np ";
-      int nbproc;
-
-      if ( params.nb_proc <= 0 )
-        nbproc = 1;
-      else
-        nbproc = params.nb_proc;
+      int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
 
-      std::ostringstream o;
+      tempOutputFile << "mpirun -np ";
 
       tempOutputFile << nbproc << " ";
 #ifdef LAM_MPI
@@ -1141,7 +1121,7 @@ std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const
 
   else if (resInfo.Protocol == srun)
     {
-      command = "srun -n 1 -N 1 --share --mem-per-cpu=0 --nodelist=";
+      command = "srun -n 1 -N 1 -s --mem-per-cpu=0 --nodelist=";
       std::string commandRcp = "rcp ";
       commandRcp += tmpFileName;
       commandRcp += " ";
@@ -1261,7 +1241,7 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol
   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 --mem-per-cpu=0 --nodelist=" << hostname << " ";
+    command << "srun -n 1 -N 1 -s --mem-per-cpu=0 --nodelist=" << hostname << " ";
     break;
   case pbsdsh:
     command << "pbsdsh -o -h " << hostname << " ";
@@ -1404,7 +1384,11 @@ long SALOME_ContainerManager::SystemWithPIDThreadSafe(const std::vector<std::str
   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());
@@ -1412,7 +1396,7 @@ long SALOME_ContainerManager::SystemWithPIDThreadSafe(const std::vector<std::str
       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 );
+      execvp( command[0].c_str() , args ); 
       std::ostringstream oss;
       oss << "Error when launching " << command[0];
       throw SALOME_Exception(oss.str().c_str()); // execvp failed
@@ -2005,8 +1989,8 @@ SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
 #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 !");
@@ -2015,45 +1999,45 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters
 }
 
 std::string
-SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
-                                                                std::string machine_file_name,
-                                                                std::string & proxy_hostname)
+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)
+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)
+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)
+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)
+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;
 }