]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Add possibility to launch Salome servers and local containers with a specific command...
authorbarate <barate>
Mon, 24 Oct 2011 13:40:24 +0000 (13:40 +0000)
committerbarate <barate>
Mon, 24 Oct 2011 13:40:24 +0000 (13:40 +0000)
bin/launchConfigureParser.py
bin/runSalome.py
bin/server.py
src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerManager.hxx
src/Launcher/Launcher_Job_SALOME.cxx

index 54959618f4e122123ca919329907fe56b36591eb..eddc8f524115c264c011c103f71a85bc5b378175 100755 (executable)
@@ -707,6 +707,15 @@ def CreateOptionParser (theAdditionalOptions=[]):
                                 dest="wake_up_session", default=False,
                                 help=help_str)
 
+    # Launch server processes with a specific command. Default: False.
+    help_str = "Launch server processes with a specific command."
+    o_slc = optparse.Option("--server-launch-cmd",
+                            metavar="<server_launch_cmd>",
+                            type="string",
+                            action="store",
+                            dest="server_launch_cmd",
+                            help=help_str)
+
     # All options
     opt_list = [o_t,o_g, # GUI/Terminal
                 o_d,o_o, # Desktop
@@ -735,6 +744,7 @@ def CreateOptionParser (theAdditionalOptions=[]):
                 o_shutdown,
                 o_foreground,
                 o_wake_up,
+                o_slc,   # Server launch command
                 ]
 
     #std_options = ["gui", "desktop", "log_file", "py_scripts", "resources",
@@ -1082,6 +1092,10 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"):
         filename = cmd_opts.play_script_file
         args[play_nam] += re.split( "[:;,]", filename )
 
+    # Server launch command
+    if cmd_opts.server_launch_cmd is not None:
+      args["server_launch_cmd"] = cmd_opts.server_launch_cmd
+
     # return arguments
     os.environ[config_var] = separator.join(dirs)
     #print "Args: ", args
index 24a71867151f6ca52dec99364e9d429156d5ea6f..5dd6137c6d22c49b405c529485d4535ab5841e80 100755 (executable)
@@ -29,9 +29,8 @@
 import sys, os, string, glob, time, pickle, re
 import orbmodule
 import setenv
-from server import *
 from launchConfigureParser import verbose
-from server import process_id
+from server import process_id, Server
 
 if sys.platform == "win32":
     SEP = ";"
@@ -416,6 +415,12 @@ def startSalome(args, modules_list, modules_root_dir):
 
     if verbose(): print "startSalome ", args
     
+    #
+    # Set server launch command
+    #
+    if args.has_key('server_launch_cmd'):
+        Server.set_server_launch_cmd(args['server_launch_cmd'])
+    
     #
     # Wake up session option
     #
index dbef17779d4b51ce12c94875cc740544bcf41439..3fde06b40c362b49397f0d9c5ae5cf8306b3e041 100755 (executable)
@@ -23,6 +23,7 @@
 #
 
 import os, sys, string
+from salome_utils import getHostName
 process_id = {}
 
 # -----------------------------------------------------------------------------
@@ -32,6 +33,8 @@ process_id = {}
 
 class Server:
     """Generic class for CORBA server launch"""
+    
+    server_launch_args = []
 
     def initArgs(self):
         self.PID=None
@@ -47,6 +50,13 @@ class Server:
         self.args=args
         self.initArgs()
 
+    @staticmethod
+    def set_server_launch_cmd(cmd):
+        if cmd == "srun":
+            Server.server_launch_args = ["srun", "-n", "1", "-N", "1"]
+            Server.server_launch_args += ["--share", "--nodelist=%s" % getHostName()]
+        else:
+            print >>sys.stderr, "Unknown server launch command:%s" % cmd
 
     def run(self):
         global process_id
@@ -124,8 +134,9 @@ class Server:
         #I am a daemon
         os.close(0) #close stdin
         os.open("/dev/null", os.O_RDWR)  # redirect standard input (0) to /dev/null
+        all_args = Server.server_launch_args + args
         try:
-          os.execvp(args[0], args)
+          os.execvp(all_args[0], all_args)
         except OSError, e:
           if args[0] != "notifd":
             print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror)
index 87de588804b53a43a839b432abfa182ff52e8ef1..8ad253294df2c64edc3fdf6e57b9863222531ba8 100644 (file)
@@ -444,10 +444,10 @@ SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& param
   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);
+    command = BuildCommandToLaunchLocalContainer(resource_selected, 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);
+    command = BuildCommandToLaunchLocalContainer(resource_selected, 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);
@@ -652,25 +652,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
 
     // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
     //  SALOME_Container containerName &"
-    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");
-
-    // 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>")
-    if (resInfo.Protocol != srun && resInfo.UserName != "")
-    {
-      command += "-l ";
-      command += resInfo.UserName;
-      command += " ";
-    }
-
-    command += resInfo.HostName;
-    command += " ";
+    command = getCommandToRunProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
 
     if (resInfo.AppliPath != "")
       command += resInfo.AppliPath; // path relative to user@machine $HOME
@@ -740,7 +722,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
 //=============================================================================
 std::string
 SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
-(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
+(const std::string & resource_name, const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
 {
   _TmpFileName = BuildTemporaryFileName();
   std::string command;
@@ -810,6 +792,10 @@ SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
 #endif
             }
         }
+
+      const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
+      o << getCommandToRunProcess(resInfo.Protocol);
+
       if (isPythonContainer(params.container_name))
         o << "SALOME_ContainerPy.py ";
       else
@@ -1181,6 +1167,56 @@ std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string progr
   return thepids;
 }
 
+std::string SALOME_ContainerManager::getCommandToRunProcess(AccessProtocolType protocol,
+                                                            const std::string & hostname,
+                                                            const std::string & username)
+{
+  std::string hostRealName = hostname;
+  std::string localHostRealName = Kernel_Utils::GetHostname();
+  bool isLocal = false;
+  if (hostname == "localhost" || hostname == localHostRealName)
+  {
+    isLocal = true;
+    hostRealName = localHostRealName;
+  }
+
+  std::ostringstream command;
+  switch (protocol)
+  {
+  case rsh:
+    if (!isLocal)
+    {
+      command << "rsh ";
+      if (username != "")
+      {
+        command << "-l " << username << " ";
+      }
+      command << hostRealName << " ";
+    }
+    break;
+  case ssh:
+    if (!isLocal)
+    {
+      command << "ssh ";
+      if (username != "")
+      {
+        command << "-l " << username << " ";
+      }
+      command << hostRealName << " ";
+    }
+    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=" << hostRealName << " ";
+    break;
+  default:
+    throw SALOME_Exception("Unknown protocol");
+  }
+
+  return command.str();
+}
+
 bool 
 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
 {
index 6aff78529c19e212f4bb2ff0d8f43eca11e9bdc1..3aa218c2a1835a401f2eda3a1eab449e718304ad 100644 (file)
@@ -69,7 +69,8 @@ protected:
                                                   const Engines::ContainerParameters& params, 
                                                   const std::string& container_exe="SALOME_Container");
 
-  std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, 
+  std::string BuildCommandToLaunchLocalContainer(const std::string & resource_name,
+                                                 const Engines::ContainerParameters& params,
                                                  const std::string& machinesFile,
                                                  const std::string& container_exe="SALOME_Container");
 
@@ -92,6 +93,10 @@ protected:
 
   std::set<pid_t> getpidofprogram(const std::string program);
 
+  std::string getCommandToRunProcess(AccessProtocolType protocol,
+                                     const std::string & hostname = "localhost",
+                                     const std::string & username = "");
+
   CORBA::ORB_var _orb;
   PortableServer::POA_var _poa;
 
index 56fc41405c0cfe503d9db1eb844902eafea17275..b9005c2e6825237ba15aff5eace01d627818036b 100644 (file)
@@ -111,7 +111,13 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params)
   launch_script_stream << "NS_PORT_FILE_NAME=`basename $NS_PORT_FILE_PATH` &&\n";
 
   // Launch SALOME with an appli
-  launch_script_stream << _resource_definition.AppliPath << "/runAppli --terminal --ns-port-log=$NS_PORT_FILE_NAME > logs/salome_" << _launch_date << ".log 2>&1 &&" << std::endl;
+  launch_script_stream << _resource_definition.AppliPath << "/runAppli --terminal --ns-port-log=$NS_PORT_FILE_NAME ";
+  if (_resource_definition.ClusterInternalProtocol != rsh &&
+      _resource_definition.ClusterInternalProtocol != ssh)
+  {
+    launch_script_stream << "--server-launch-cmd=" << resource_protocol << " ";
+  }
+  launch_script_stream << "> logs/salome_" << _launch_date << ".log 2>&1 &&" << std::endl;
   launch_script_stream << "current=0 &&\n"
                        << "stop=20 &&\n"
                        << "while ! test -s $NS_PORT_FILE_PATH\n"