]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF27562] : Management of remote container launch in no APPLI mode.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 31 May 2023 09:17:12 +0000 (11:17 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 31 May 2023 12:35:04 +0000 (14:35 +0200)
src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerManager.hxx
src/Container/ScriptsTemplate/SALOME_CM_REMOTE.py
src/Container/ScriptsTemplate/SALOME_CM_REMOTE_OLD.py [new file with mode: 0644]

index 006578eea7f78d98e99e9bca98dfcfdcad41f850..f56ad70dd98bad263193612e9a7f71ac0a8f54d0 100644 (file)
@@ -750,14 +750,16 @@ std::string
 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& resource_name, const Engines::ContainerParameters& params, const std::string& container_exe) const
 {
   std::string command,tmpFileName;
+  const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
+  std::string wdir = params.workingdir.in();
   if (!_isAppliSalomeDefined)
-    command = BuildTempFileToLaunchRemoteContainer(resource_name, params, tmpFileName);
+  {
+      command = getCommandToRunRemoteProcessNoAppli(resInfo.Protocol, resInfo.HostName, 
+                                                    resInfo.UserName, resInfo.AppliPath,
+                                                    wdir);
+  }
   else
   {
-    const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
-
-    std::string wdir = params.workingdir.in();
-
     // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
     //      SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
     //  or 
@@ -766,45 +768,44 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string&
     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();
+  }
+  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 ";
+    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");
-      }
+    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();
+    command += "-nameserver " + Kernel_Utils::GetHostname();
 #endif
-      command += " SALOME_MPIContainer ";
-    }
-    else
-      command += " " +container_exe+ " ";
+    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);
+  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);
 
   return command;
 }
@@ -1352,7 +1353,19 @@ std::string SALOME_ContainerManager::machinesFile(const int nbproc)
 
 }
 
-std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
+std::string SALOME_ContainerManager::getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
+{
+  return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE","salome shell --",protocol,hostname,username,applipath,workdir);
+}
+
+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 & applipath,
@@ -1415,7 +1428,6 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol
   script_parameters.push(nsport.empty() ? "NULL" : nsport);
 
   // ===== Remote script (key = "remote_script")
-  std::string remoteScript = this->GetRunRemoteExecutableScript();
   script_parameters.push(remoteScript.empty() ? "NONE" : remoteScript);
   
   // ===== Naming service (key = "naming_service")
@@ -1433,108 +1445,7 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol
   // we prepare the remote command according to the case
   script_parameters.push(appli_mode);
 
-  command << GetCommandFromTemplate("SALOME_CM_REMOTE", script_parameters);
-  
-  /* //====================================================================================
-  bool envd = true; // source the environment
-  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 -s --mem-per-cpu=0 --cpu-bind=none --nodelist=" << hostname << " ";
-    envd = false;
-    break;
-  case pbsdsh:
-    command << "pbsdsh -o -h " << hostname << " ";
-    break;
-  case blaunch:
-    command << "blaunch -no-shell " << hostname << " ";
-    break;
-  default:
-    throw SALOME_Exception("Unknown protocol");
-  }
-
-  std::string remoteapplipath;
-  if (applipath=="")
-    remoteapplipath = GetenvThreadSafeAsString("APPLI");
-  else
-    remoteapplipath = applipath;
-
-  if(!this->_isSSL)
-  {
-    ASSERT(GetenvThreadSafe("NSHOST"));
-    ASSERT(GetenvThreadSafe("NSPORT"));
-  }
-  // $APPLI points either to an application directory, or to a salome launcher file
-  // we prepare the remote command according to the case
-  struct stat statbuf;
-  if (stat(GetenvThreadSafe("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode))
-  {
-    // if $APPLI is a regular file, we asume it's a salome Launcher
-    // generate a command with a salome launcher
-    command << remoteapplipath 
-            << " remote" ;
-    if(!this->_isSSL)
-    {
-      command << " -m "
-              <<  GetenvThreadSafeAsString("NSHOST") // hostname of CORBA name server
-              << " -p "
-              <<  GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-    }
-    if (workdir != "")
-      command << "-d " << workdir;
-    command <<  " -- " ;
-  }
-  else  // we assume it's a salome application directory
-  {
-    // generate a command with runRemote.sh
-    command <<  remoteapplipath;
-    command <<  "/" << this->GetRunRemoteExecutableScript() << " ";
-    if (!envd)
-      command <<  "--noenvd ";
-
-    if(this->_isSSL)
-    {
-      Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
-      CORBA::String_var iorNS = _orb->object_to_string(ns);
-      command << iorNS;
-    }
-    else
-    {
-      command <<  GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
-      command <<  " ";
-      command <<  GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-    }
-    
-    if(workdir != "")
-    {
-      command << " WORKINGDIR ";
-      command << " '";
-      if(workdir == "$TEMPDIR")
-          command << "\\$TEMPDIR";
-      else
-        command << workdir; // requested working directory
-      command << "'";
-    }
-  }
-  //==================================================================================== */
+  command << GetCommandFromTemplate(templateName, script_parameters);
 
   return command.str();
 }
index 61ff2294e33f3b5a99e20c56a5e7f5e988f1e94d..908a4894c2d5a0838d365e8c1d584a40140f4e93 100644 (file)
@@ -94,12 +94,25 @@ protected:
   std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
 
   std::string machinesFile(const int nbproc);
+  
+  std::string getCommandToRunRemoteProcessCommon(const std::string& templateName, const std::string& remoteScript, 
+                                          AccessProtocolType protocol, 
+                                          const std::string & hostname, 
+                                          const std::string & username,
+                                          const std::string & applipath,
+                                          const std::string & workdir) const;
 
   std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, 
                                           const std::string & hostname, 
                                           const std::string & username,
                                           const std::string & applipath,
                                           const std::string & workdir="") const;
+                                          
+  std::string getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, 
+                                          const std::string & hostname, 
+                                          const std::string & username,
+                                          const std::string & applipath,
+                                          const std::string & workdir="") const;
 
   Engines::Container_ptr
   LaunchContainer(const Engines::ContainerParameters& params,
index 9be7bd72e17f4f3e4505818c30a288b20773a395..c4a33b1960a673ef853cc5f684d48c1b61b9d7fa 100644 (file)
@@ -91,14 +91,7 @@ def command(args):
 
     if options.appli_mode == "dir":
         cmd.append(options.appli + "/" + options.remote_script)
-        if not envd:
-            cmd.append("--noenvd")
-        if options.ssl:
-            cmd.append(options.naming_service)
-        else:
-            cmd.append(options.nshost)
-            cmd.append(options.nsport)
-
+            
         if options.workdir:
             cmd.append(" WORKINGDIR '%s'" % options.workdir)
 
diff --git a/src/Container/ScriptsTemplate/SALOME_CM_REMOTE_OLD.py b/src/Container/ScriptsTemplate/SALOME_CM_REMOTE_OLD.py
new file mode 100644 (file)
index 0000000..9be7bd7
--- /dev/null
@@ -0,0 +1,116 @@
+import sys
+
+class ScriptRemoteParameters:
+    def __init__(self, args):
+        self.debug = False
+        if args[0] == "-d":
+            self.debug = True
+            args = args[1:]
+
+        self.protocol = args[0]
+        self.user = self._read_arg(args[1], "NULL")
+        self.host = self._read_arg(args[2], "NULL")
+        self.appli = self._read_arg(args[3], "NULL")
+        self.workdir = self._read_arg(args[4], "NULL")
+        self.ssl = True if args[5] == "1" else False
+        self.nshost = args[6]
+        self.nsport = args[7]
+        self.remote_script = self._read_arg(args[8], "NULL")
+        self.naming_service = self._read_arg(args[9], "NULL")
+        self.appli_mode = args[10]
+
+        import platform
+        self.Windows = platform.system() == "Windows"
+
+    def _read_arg(self, value, null_value):
+        if value == null_value:
+            return None
+        return value
+
+    def __str__(self):
+        str = []
+        str.append("protocol: %s" % self.protocol)
+        str.append("user: %s" % self.user)
+        str.append("hostname: %s" % self.host)
+        str.append("appli: %s" % self.appli)
+        str.append("workdir: %s" % self.workdir)
+        str.append("ssl: %s" % self.ssl)
+        str.append("nshost: %s" % self.nshost)
+        str.append("nsport: %s" % self.nsport)
+        str.append("remote_script: %s" % self.remote_script)
+        str.append("naming_service: %s" % self.naming_service)
+        str.append("appil_mode: %s" % self.appli_mode)
+        str.append("--")
+        return "\n".join(str)
+
+# ----------------------------------------------
+def command(args):
+    options = ScriptRemoteParameters(args)
+    if options.debug: print(options)
+
+    # build command depending on protocol
+    cmd = []
+    envd = (options.protocol != "srun")
+
+    if options.protocol == "rsh":
+        # RSH command
+        cmd.append("rsh")
+        if options.user:
+            cmd.append("-l " + options.user)
+        cmd.append(options.host)
+
+    elif options.protocol == "ssh":
+        # SSH command
+        cmd.append("ssh")
+        if options.user:
+            cmd.append("-l " + options.user)
+        cmd.append(options.host)
+
+    elif options.protocol == "srun":
+        # srun command
+        cmd.append("srun")
+        cmd.append("-n 1 -N 1 -s --mem-per-cpu=0 --cpu-bind=none")
+        cmd.append("--nodelist=" + options.host)
+
+    elif options.protocol == "pbsdsh":
+        # pbsdh command
+        cmd.append("pbsdsh")
+        cmd.append("-o -h")
+        cmd.append(options.host)
+
+    elif options.protocol == "blaunch":
+        # blaunch command
+        cmd.append("blaunch")
+        cmd.append("-no-shell")
+        cmd.append(options.host)
+
+    else:
+        # unknown protocol
+        raise ValueError("Unknown protocol: %s" % options.protocol)
+
+
+    if options.appli_mode == "dir":
+        cmd.append(options.appli + "/" + options.remote_script)
+        if not envd:
+            cmd.append("--noenvd")
+        if options.ssl:
+            cmd.append(options.naming_service)
+        else:
+            cmd.append(options.nshost)
+            cmd.append(options.nsport)
+
+        if options.workdir:
+            cmd.append(" WORKINGDIR '%s'" % options.workdir)
+
+    elif options.appli_mode == "launcher":
+        cmd.append(options.appli + " remote")
+        if not options.ssl:
+            cmd.append("-m %s -p %s" % (options.nshost, options.nsport))
+
+        if options.workdir:
+            cmd.append("-d " + options.workdir)
+            cmd.append("--")
+
+    # elif ignore other appli_mode value
+
+    return " ".join(cmd)
\ No newline at end of file