]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Add "YACSDriverOptions" to the specific parameters list of a "yacs_file" job.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 14 Mar 2016 14:13:54 +0000 (15:13 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 17 Mar 2016 15:06:12 +0000 (16:06 +0100)
The new parameter "YACSDriverOptions" allows to use any option of the command
"driver" when launching a YACS job with SalomeLauncher interface.

idl/SALOME_Launcher.idl
src/Launcher/Launcher_Job_YACSFile.cxx
src/Launcher/Launcher_Job_YACSFile.hxx
src/Launcher/Test/test_launcher.py

index 012c855a45a023b45f4ad7b47c7337c0cb89fc80..b98aaf3e3fea8e035f7923d4d346e4816a8cc91e 100644 (file)
@@ -153,6 +153,8 @@ struct JobParameters
         when the job type is "yacs_file". It gives the number of seconds
         between two updates of the state dump file. There will be no dump file
         if this parameter is missing or if its value is less than 1.
+      - YACSDriverOptions : options of the driver command when the job type is
+        "yacs_file".
   */
   Engines::ParameterList specific_parameters;
 
index 7462e8b0c71561da729a43c9d0ca3018a32c34ca..4d6ff37da4491032180d160d964a53b912652aa4 100644 (file)
@@ -27,6 +27,7 @@ Launcher::Job_YACSFile::Job_YACSFile()
 {
   _job_type = "yacs_file";
   _dumpState = -1;
+  _yacsDriverOptions = "";
 }
 
 Launcher::Job_YACSFile::~Job_YACSFile() {}
@@ -40,9 +41,11 @@ 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 args:-k,\"$appli_port\"," << _job_file_name_complete;
+  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;
+    launch_script_stream << " --dump=" << _dumpState;
+  if(not _yacsDriverOptions.empty())
+    launch_script_stream << " " << _yacsDriverOptions ;
   launch_script_stream << " > logs/yacs_" << _launch_date << ".log 2>&1" << std::endl;
 }
 
@@ -59,4 +62,11 @@ Launcher::Job_YACSFile::checkSpecificParameters()
     if (!(iss >> _dumpState))
       throw LauncherException("Specific parameter EnableDumpYACS is not correctly defined: it should be an integer. Value given is " + user_value);
   }
+  
+  it = _specific_parameters.find("YACSDriverOptions");
+  if (it != _specific_parameters.end())
+  {
+    // Decode info
+    _yacsDriverOptions = it->second;
+  }
 }
index 13cab7984a03079a98548fb419ae461fc7a15ff0..122fcf6ff213fe28001a0256a04bc07b999b2f84 100644 (file)
@@ -38,6 +38,7 @@ namespace Launcher
 
     protected:
       int _dumpState;
+      std::string _yacsDriverOptions;
   };
 }
 
index 86d5d61aa20731fb7f2027d3560d0f7b1e4f9a49..53fe67af54fff949a236ac2290915f7f8255a1be 100755 (executable)
@@ -353,6 +353,101 @@ f.close()
       self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
                       "expected")
     
+  ##############################
+  # test of yacs job type using "--init_port" driver option
+  ##############################
+  def test_yacsopt(self):
+    yacs_path = os.getenv("YACS_ROOT_DIR", "")
+    if not os.path.isdir(yacs_path):
+      self.skipTest("Needs YACS module to run. Please define YACS_ROOT_DIR.")
+    
+    case_test_dir = os.path.join(TestCompo.test_dir, "yacs_opt")
+    os.mkdir(case_test_dir)
+    
+    # job script
+    script_text = """<?xml version='1.0' encoding='iso-8859-1' ?>
+<proc name="myschema">
+   <property name="DefaultStudyID" value="1"/>
+   <type name="string" kind="string"/>
+   <type name="bool" kind="bool"/>
+   <type name="double" kind="double"/>
+   <type name="int" kind="int"/>
+   <container name="DefaultContainer">
+      <property name="container_kind" value="Salome"/>
+      <property name="attached_on_cloning" value="0"/>
+      <property name="container_name" value="FactoryServer"/>
+      <property name="name" value="localhost"/>
+   </container>
+   <inline name="mynode">
+      <script><code><![CDATA[
+text_result = "i=%s,d=%s,b=%s,s=%s" % (i,d,b,s)
+f = open('result.txt', 'w')
+f.write(text_result)
+f.close()
+]]></code></script>
+      <load container="DefaultContainer"/>
+      <inport name="i" type="int"/>
+      <inport name="d" type="double"/>
+      <inport name="b" type="bool"/>
+      <inport name="s" type="string"/>
+   </inline>
+</proc>
+"""
+    yacs_file = "simpleSchema.xml"
+    job_script_file = os.path.join(case_test_dir, yacs_file)
+    f = open(job_script_file, "w")
+    f.write(script_text)
+    f.close()
+    
+    local_result_dir = os.path.join(case_test_dir, "result_yacsopt_job")
+    job_params = salome.JobParameters()
+    job_params.job_type = "yacs_file"
+    job_params.job_file = job_script_file
+    #job_params.env_file = os.path.join(case_test_dir,env_file)
+    job_params.out_files = ["result.txt"]
+    
+    # define the interval between two YACS schema dumps (3 seconds)
+    import Engines
+    job_params.specific_parameters = [Engines.Parameter("YACSDriverOptions",
+               "-imynode.i=5 -imynode.d=3.7 -imynode.b=False -imynode.s=lili")]
+    expected_result="i=5,d=3.7,b=False,s=lili"
+    job_params.resource_required = salome.ResourceParameters()
+    job_params.resource_required.nb_proc = 1
+
+    launcher = salome.naming_service.Resolve('/SalomeLauncher')
+    resManager= salome.lcc.getResourcesManager()
+    
+    for resource in self.ressources:
+      print "Testing yacs job with options on ", resource
+      job_params.result_directory = local_result_dir + resource
+      job_params.job_name = "YacsJobOpt_" + resource
+      job_params.resource_required.name = resource
+
+      # use the working directory of the resource
+      resParams = resManager.GetResourceDefinition(resource)
+      wd = os.path.join(resParams.working_directory,
+                        "YacsJobOpt_" + self.suffix)
+      job_params.work_directory = wd
+
+      job_id = launcher.createJob(job_params)
+      launcher.launchJob(job_id)
+      jobState = launcher.getJobState(job_id)
+
+      yacs_dump_success = False
+      print "Job %d state: %s" % (job_id,jobState)
+      while jobState != "FINISHED" and jobState != "FAILED" :
+        time.sleep(5)
+        jobState = launcher.getJobState(job_id)
+        print "Job %d state: %s " % (job_id,jobState)
+        pass
+
+      self.assertEqual(jobState, "FINISHED")
+
+      # getJobResults to default directory (result_directory)
+      launcher.getJobResults(job_id, "")
+      self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
+                      expected_result)
+
 if __name__ == '__main__':
     # creat study
     import salome