]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Extension to the case where APPLI points at a salome launcher file
authorcrouzet <nicolas.crouzet@cea.fr>
Wed, 5 Dec 2018 16:26:31 +0000 (17:26 +0100)
committerBernard Secher <bernard.secher@cea.fr>
Thu, 28 Mar 2019 13:17:10 +0000 (14:17 +0100)
  - getCommandToRunRemoteProcess api is extended
  - it's use is generalised (code factorisation)
  - salome launcher files are taken into account,
    containers are distributed by calling salome remote command

bin/salomeContextUtils.py.in
src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerManager.hxx
src/ResourcesManager/ResourcesManager.cxx

index 318c40c2bce17514f81f98d6612414f6678ead95..6971315d7da818150370e555a684526e0d9be525 100644 (file)
@@ -308,9 +308,9 @@ def formatScriptsAndArgs(scriptArgs=None):
 # If OMNIORB_USER_PATH is already set, only checks write access to associated directory ;
 # an exception is raised if check fails. It allows users for choosing a specific folder.
 # Else the function sets OMNIORB_USER_PATH this way:
-# - If APPLI environment variable is set, OMNIORB_USER_PATH is set to ${APPLI}/USERS.
-#   The function does not check USERS folder existence or write access. This folder
-#   must exist ; this is the case if SALOME virtual application has been created using
+# - If APPLI environment variable is set, and if ${APPLI}/USERS points at an existing 
+#   folder with write access, then OMNIORB_USER_PATH is set to ${APPLI}/USERS.
+#   This is the case if SALOME virtual application has been created using
 #   appli_gen.py script.
 # - Else OMNIORB_USER_PATH is set to user home directory.
 def setOmniOrbUserPath():
@@ -334,7 +334,9 @@ def setOmniOrbUserPath():
       #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
       defaultOmniorbUserPath = homePath
       if os.getenv("APPLI"):
-        defaultOmniorbUserPath = os.path.join(homePath, os.getenv("APPLI"), "USERS")
+        appli_users_path=os.path.join(homePath, os.getenv("APPLI"), "USERS")
+        if os.access(appli_users_path, os.W_OK):
+          defaultOmniorbUserPath = appli_users_path
         pass
       os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath
 #
index 0d21953b24aed1fdbb0fa9a3107d04adb5c7177e..1837cfc6dc787243f60b2437d26b951abd067151 100644 (file)
@@ -519,26 +519,13 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par
     // Only if an application directory is set
     if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
       {
-        // Preparing remote command
-        std::string command = "";
+
         const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
-        command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
-        if (resInfo.AppliPath != "")
-          command += resInfo.AppliPath;
-        else
-          {
-            ASSERT(GetenvThreadSafe("APPLI"));
-            command += GetenvThreadSafeAsString("APPLI");
-          }
-        command += "/runRemote.sh ";
-        ASSERT(GetenvThreadSafe("NSHOST"));
-        command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
-        command += " ";
-        ASSERT(GetenvThreadSafe("NSPORT"));
-        command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-        command += " \"ls /tmp >/dev/null 2>&1\"";
+        std::string command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, 
+                                                           resInfo.UserName, resInfo.AppliPath);
 
         // Launch remote command
+          command += " \"ls /tmp >/dev/null 2>&1\"";
         int status = SystemThreadSafe(command.c_str());
         if (status != 0)
           {
@@ -760,37 +747,16 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string&
         nbproc = params.nb_proc;
     }
 
-    // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
-    //  SALOME_Container containerName &"
-    command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
-
-    if (resInfo.AppliPath != "")
-      command += resInfo.AppliPath; // path relative to user@machine $HOME
-    else
-    {
-      ASSERT(GetenvThreadSafe("APPLI"));
-      command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME
-    }
-
-    command += "/runRemote.sh ";
-
-    ASSERT(GetenvThreadSafe("NSHOST"));
-    command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
-
-    command += " ";
-    ASSERT(GetenvThreadSafe("NSPORT"));
-    command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-
     std::string wdir = params.workingdir.in();
-    if(wdir != "")
-    {
-      command += " WORKINGDIR ";
-      command += " '";
-      if(wdir == "$TEMPDIR")
-        wdir="\\$TEMPDIR";
-      command += wdir; // requested working directory
-      command += "'";
-    }
+
+    // "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)
     {
@@ -1212,43 +1178,8 @@ std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, c
     {
       if (_isAppliSalomeDefined)
         {
-
-          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 --mem-per-cpu=0 --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(GetenvThreadSafe("APPLI"));
-              command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME
-            }
-
-          command += "/runRemote.sh ";
-
-          ASSERT(GetenvThreadSafe("NSHOST"));
-          command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
-
-          command += " ";
-          ASSERT(GetenvThreadSafe("NSPORT"));
-          command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-
+          command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, 
+                                                 resInfo.UserName, resInfo.AppliPath);
           command += " mpirun -np 1 hostname -s > " + tmpFile;
         }
       else
@@ -1299,7 +1230,9 @@ std::string SALOME_ContainerManager::machinesFile(const int nbproc)
 
 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
                                                                   const std::string & hostname,
-                                                                  const std::string & username)
+                                                                  const std::string & username,
+                                                                  const std::string & applipath,
+                                                                  const std::string & workdir)
 {
   std::ostringstream command;
   switch (protocol)
@@ -1335,6 +1268,52 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol
     throw SALOME_Exception("Unknown protocol");
   }
 
+  std::string remoteapplipath;
+  if (applipath=="")
+    remoteapplipath = GetenvThreadSafeAsString("APPLI");
+  else
+    remoteapplipath = applipath;
+
+  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"
+            << " -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 <<  "/runRemote.sh ";
+    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 << "'";
+    }
+  }
+
   return command.str();
 }
 
index 4c9293e16c5d86da4254075e7b6c0f4c3f6e0e82..941603e936d88a7a4a939af654a6a1e0b39604d5 100644 (file)
@@ -89,7 +89,11 @@ protected:
 
   std::string machinesFile(const int nbproc);
 
- static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username);
+ static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, 
+                                                 const std::string & hostname, 
+                                                 const std::string & username,
+                                                 const std::string & applipath,
+                                                 const std::string & workdir="");
 
   Engines::Container_ptr
   LaunchContainer(const Engines::ContainerParameters& params,
index f53cce8ac73c0b33038aa14337b32cf8b511e042..650160d617f5df8e0f87addcd61ae89b47e03151 100644 (file)
@@ -148,17 +148,23 @@ ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException)
       default_file += "/";
       default_file += getenv("APPLI");
       default_file += "/CatalogResources.xml";
-      _path_resources.push_back(default_file);
-    }
-    else
-    {
-      if(!getenv("KERNEL_ROOT_DIR"))
-        throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml");
-      default_file = getenv("KERNEL_ROOT_DIR");
-      default_file += "/share/salome/resources/kernel/CatalogResources.xml";
-      _path_resources.push_back(default_file);
+      std::ifstream ifile(default_file.c_str(), std::ifstream::in );
+      if (ifile) {
+        // The file exists, and is open for input
+        _path_resources.push_back(default_file);
+        default_catalog_resource=false;
+      }
     }
   }
+  if (default_catalog_resource)
+  {
+    std::string default_file("");
+    if(!getenv("KERNEL_ROOT_DIR"))
+      throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml");
+    default_file = getenv("KERNEL_ROOT_DIR");
+    default_file += "/share/salome/resources/kernel/CatalogResources.xml";
+    _path_resources.push_back(default_file);
+  }
 
   ParseXmlFiles();
   RES_MESSAGE("ResourcesManager_cpp constructor end");