Salome HOME
16988 [CEA] Use of SALOME_Launcher with sat launcher files
authorrnv <rnv@opencascade.com>
Tue, 28 May 2019 08:46:05 +0000 (11:46 +0300)
committerrnv <rnv@opencascade.com>
Tue, 28 May 2019 08:46:05 +0000 (11:46 +0300)
src/Launcher/Launcher_Job_CommandSALOME.cxx
src/Launcher/Launcher_Job_PythonSALOME.cxx
src/Launcher/Launcher_Job_SALOME.cxx
src/Launcher/Launcher_Job_YACSFile.cxx
src/ResourcesManager/ResourcesManager.cxx

index 59db9e09f5d00d96c2daeaf2fb22d23fd64b7493..4e5502691f98d7bf69fa5bd21214f9bb5f2b3eee 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include <sstream>
+#include <sys/stat.h>
 
 const char Launcher::Job_CommandSALOME::TYPE_NAME[] = "command_salome";
 
@@ -42,9 +43,17 @@ Launcher::Job_CommandSALOME::~Job_CommandSALOME() {}
 std::string Launcher::Job_CommandSALOME::runCommandString()
 {
   std::ostringstream result;
-  result << _resource_definition.AppliPath
-         << "/salome shell ./"
-         << _job_file_name_complete;
+  struct stat statbuf;
+  if(stat(getenv("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode))
+      // case of a salome launcher file
+      result << _resource_definition.AppliPath
+             << " shell ./"
+             << _job_file_name_complete;
+  else
+      // case of a salome appli dir
+      result << _resource_definition.AppliPath
+             << "/salome shell ./"
+             << _job_file_name_complete;
   return result.str();
 }
 #endif
index 46c362fbf0f16dc4d0c388120dea5ce988de310e..42a80501a85bd38e690b90043913ff87e64d6d7d 100644 (file)
@@ -20,6 +20,7 @@
 // Author: AndrĂ© RIBES - EDF R&D
 //
 #include "Launcher_Job_PythonSALOME.hxx"
+#include <sys/stat.h>
 
 const char Launcher::Job_PythonSALOME::TYPE_NAME[] = "python_salome";
 
@@ -39,5 +40,10 @@ Launcher::Job_PythonSALOME::setJobFile(const std::string & job_file)
 void
 Launcher::Job_PythonSALOME::addJobTypeSpecificScript(std::ofstream & launch_script_stream)
 {
-  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p \"$appli_port\" python " << _job_file_name_complete << " > logs/python_" << _launch_date << ".log 2>&1" << std::endl;
+  struct stat statbuf;
+  if(stat(getenv("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode))
+      // case where AppliPath hold a salome launcher file
+      launch_script_stream << _resource_definition.AppliPath << " shell -p \"$appli_port\" python " << _job_file_name_complete << " > logs/python_" << _launch_date << ".log 2>&1" << std::endl;
+  else
+      launch_script_stream << _resource_definition.AppliPath << "/salome shell -p \"$appli_port\" python " << _job_file_name_complete << " > logs/python_" << _launch_date << ".log 2>&1" << std::endl;
 }
index 492875a7465056be6f3f224c604d2758a6f75555..2c377ce9619067635f381827f76939035d6a1336 100644 (file)
@@ -31,6 +31,7 @@
 #define _chmod chmod
 #include <process.h>
 #endif
+#include <sys/stat.h>
 
 #include <sstream>
 
@@ -72,7 +73,11 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params)
 #else
   str_pid << ::getpid();
 #endif
-  std::string launch_script = Kernel_Utils::GetTmpDir() + "runSalome_" + _job_file_name + "_" + _launch_date + "-" + str_pid.str() + ".sh";
+  struct stat statbuf;
+  // true if APPLI holds a salome file launcher (in state of an application directory)
+  bool is_launcher_file=stat(getenv("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode);
+  std::string launch_tmp_dir = Kernel_Utils::GetTmpDir();
+  std::string launch_script = launch_tmp_dir + "runSalome_" + _job_file_name + "_" + _launch_date + "-" + str_pid.str() + ".sh";
   std::ofstream launch_script_stream;
   launch_script_stream.open(launch_script.c_str(),
                             std::ofstream::out
@@ -125,10 +130,17 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params)
   launch_script_stream << "fi" << std::endl;
 
   // Create file for ns-port-log
-  launch_script_stream << "NS_PORT_FILE_PATH=$(mktemp " << _resource_definition.AppliPath << "/USERS/nsport_XXXXXX) &&\n";
+  if (is_launcher_file)
+      // for a salome application file, we write NS_PORT_FILE_PATH in launch_tmp_dir
+      launch_script_stream << "NS_PORT_FILE_PATH=$(mktemp " << launch_tmp_dir << "nsport_XXXXXX) &&\n";
+  else
+      launch_script_stream << "NS_PORT_FILE_PATH=$(mktemp " << _resource_definition.AppliPath << "/USERS/nsport_XXXXXX) &&\n";
 
   // Launch SALOME with an appli
-  launch_script_stream << _resource_definition.AppliPath << "/salome start --terminal --ns-port-log=\"$NS_PORT_FILE_PATH\" --server-launch-mode=fork ";
+  if (is_launcher_file)
+      launch_script_stream << _resource_definition.AppliPath << " start --terminal --ns-port-log=\"$NS_PORT_FILE_PATH\" --server-launch-mode=fork ";
+  else
+      launch_script_stream << _resource_definition.AppliPath << "/salome start --terminal --ns-port-log=\"$NS_PORT_FILE_PATH\" --server-launch-mode=fork ";
   launch_script_stream << "> logs/salome_" << _launch_date << ".log 2>&1 &&" << std::endl;
   launch_script_stream << "current=0 &&\n"
                        << "stop=20 &&\n"
@@ -150,7 +162,10 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params)
   launch_script_stream << "echo $? > logs/exit_code.log" << std::endl;
 
   // End
-  launch_script_stream << _resource_definition.AppliPath << "/salome kill \"$appli_port\"" << std::endl;
+  if (is_launcher_file)
+      launch_script_stream << _resource_definition.AppliPath << " kill \"$appli_port\"" << std::endl;
+  else
+      launch_script_stream << _resource_definition.AppliPath << "/salome kill \"$appli_port\"" << std::endl;
 
   // Return
   launch_script_stream.flush();
index 286cc5e4af9782d23cc8e89db2cf0994cbe8e663..05cfbf1061809041bc42cdbc5012d162ffc97746 100644 (file)
@@ -21,6 +21,7 @@
 //
 #include "Launcher_Job_YACSFile.hxx"
 #include <sstream>
+#include <sys/stat.h>
 
 const char Launcher::Job_YACSFile::TYPE_NAME[] = "yacs_file";
 
@@ -42,7 +43,12 @@ Launcher::Job_YACSFile::setJobFile(const std::string & job_file)
 void
 Launcher::Job_YACSFile::addJobTypeSpecificScript(std::ofstream & launch_script_stream)
 {
-  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p \"$appli_port\" -- driver -k\"$appli_port\" " << _job_file_name_complete;
+  struct stat statbuf;
+  if(stat(getenv("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode))
+      // case of a salome launcher file
+      launch_script_stream << _resource_definition.AppliPath << " shell -p \"$appli_port\" -- driver -k\"$appli_port\" " << _job_file_name_complete;
+  else
+      launch_script_stream << _resource_definition.AppliPath << "/salome shell -p \"$appli_port\" -- driver -k\"$appli_port\" " << _job_file_name_complete;
   if (_dumpState > 0)
     launch_script_stream << " --dump=" << _dumpState;
   if(! _yacsDriverOptions.empty())
index 650160d617f5df8e0f87addcd61ae89b47e03151..6ff79f3fdfc6c659e2debf41ad28b948aa42f733 100644 (file)
@@ -622,9 +622,18 @@ void ResourcesManager_cpp::AddDefaultResourceInCatalog()
   resource.Protocol = sh;
   resource.Batch = none;
 #ifndef WIN32
+  struct stat statbuf;
   if (getenv("HOME") != NULL && getenv("APPLI") != NULL)
   {
-    resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI");
+    if (stat(getenv("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode))
+    {
+        // if $APPLI is a regular file, we asume it's a salome Launcher file
+        resource.AppliPath = string(getenv("APPLI"));
+    }
+    else
+    {
+        resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI");
+    }
   }
   string tmpdir = "/tmp";
   if (getenv("TMPDIR") != NULL)