]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Refactoring code EnableDumpYACS
authorribes <ribes>
Wed, 13 Apr 2011 16:18:26 +0000 (16:18 +0000)
committerribes <ribes>
Wed, 13 Apr 2011 16:18:26 +0000 (16:18 +0000)
Add some tests if user does not enter a correct value.

src/Launcher/Launcher_Job.cxx
src/Launcher/Launcher_Job.hxx
src/Launcher/Launcher_Job_YACSFile.cxx
src/Launcher/Launcher_Job_YACSFile.hxx
src/Launcher/SALOME_Launcher.cxx

index 7e8c42fa04a7b204ce7e4377396921c7b1d3d479..19daa34c1c6468708a324fb3c58dc35a6978eeed 100644 (file)
@@ -585,3 +585,22 @@ Launcher::Job::addToXmlDocument(xmlNodePtr root_node)
   xmlNewChild(run_node, NULL, xmlCharStrdup("job_reference"), xmlCharStrdup(job_id.getReference().c_str()));
 #endif
 }
+
+void 
+Launcher::Job::addSpecificParameter(const std::string & name,
+                                      const std::string & value)
+{
+  std::cerr << "Adding " << name << " " << value << std::endl;
+  _specific_parameters[name] = value;
+}
+
+const std::map<std::string, std::string> &
+Launcher::Job::getSpecificParameters()
+{
+  return _specific_parameters;
+}
+
+void
+Launcher::Job::checkSpecificParameters()
+{
+}
index be0284932e3bd32448a3515438a5f7adf224d13b..eeba823a743d65c9d3fc3c05f72ccd657662a2bf 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <string>
 #include <list>
+#include <map>
 #include <iostream>
 #include <sstream>
 #include <algorithm>
@@ -92,6 +93,11 @@ namespace Launcher
 
       std::string updateJobState();
 
+      void addSpecificParameter(const std::string & name,
+                                  const std::string & value);
+      const std::map<std::string, std::string> & getSpecificParameters();
+      virtual void checkSpecificParameters();
+
       // Checks
       void checkMaximumDuration(const std::string & maximum_duration);
       void checkResourceRequiredParams(const resourceParams & resource_required_params);
@@ -127,6 +133,7 @@ namespace Launcher
       std::string _result_directory;
       std::list<std::string> _in_files;
       std::list<std::string> _out_files;
+      std::map<std::string, std::string> _specific_parameters;
       std::string _maximum_duration;
       long _maximum_duration_in_second;
       resourceParams _resource_required_params;
index 31bd4fe14f6348fee9ae897953b953ec062aa99d..7f04d7d17cc4971b3b73084f7c19181fd6bee9f2 100644 (file)
 // Author: André RIBES - EDF R&D
 //
 #include "Launcher_Job_YACSFile.hxx"
+#include <sstream>
 
 
-Launcher::Job_YACSFile::Job_YACSFile() {_job_type = "yacs_file"; _dumpState=0;}
+Launcher::Job_YACSFile::Job_YACSFile() 
+{
+  _job_type = "yacs_file";
+  _dumpState = -1;
+}
 
 Launcher::Job_YACSFile::~Job_YACSFile() {}
 
@@ -36,13 +41,22 @@ void
 Launcher::Job_YACSFile::addJobTypeSpecificScript(std::ofstream & launch_script_stream)
 {
   launch_script_stream << _resource_definition.AppliPath << "/runSession -p $appli_port driver " << _job_file_name_complete;
-  if(_dumpState > 0)
+  if (_dumpState > 0)
     launch_script_stream << " --dump=" << _dumpState;
   launch_script_stream << " > logs/yacs_" << _launch_date << ".log 2>&1" << std::endl;
 }
 
 void
-Launcher::Job_YACSFile::setDumpState(const int dumpState)
+Launcher::Job_YACSFile::checkSpecificParameters()
 {
-  _dumpState = dumpState;
+  // Specific parameters
+  std::map<std::string, std::string>::iterator it = _specific_parameters.find("EnableDumpYACS");
+  if (it != _specific_parameters.end())
+  {
+    // Decode info
+    std::string user_value = it->second;
+    std::istringstream iss(user_value);
+    if (!(iss >> _dumpState))
+      throw LauncherException("Specific parameter EnableDumpYACS is not correctly defined: it should be an integer. Value given is " + user_value);
+  }
 }
index e6226afcf1913a2627461d08a3b3ee4a8941d657..f283eac5b67fdc82b069d4aa4dd3064c639ed9f8 100644 (file)
@@ -34,7 +34,8 @@ namespace Launcher
 
       virtual void setJobFile(const std::string & job_file);
       virtual void addJobTypeSpecificScript(std::ofstream & launch_script_stream);
-      virtual void setDumpState(const int dumpState);
+      virtual void checkSpecificParameters();
+
     protected:
       int _dumpState;
   };
index 379f681b7e85658998fd5afd3cd93db9d86aa784..d16ebcdc063b99f1e6c41222af4d77ba132113f6 100644 (file)
@@ -88,7 +88,7 @@ CORBA::Long
 SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
 {
   std::string job_type = job_parameters.job_type.in();
-  
+
   if (job_type != "command" && job_type != "yacs_file" && job_type != "python_salome")
   {
     std::string message("SALOME_Launcher::createJob: bad job type: ");
@@ -107,7 +107,7 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
 
   // Name
   new_job->setJobName(job_parameters.job_name.in());
+
   // Directories
   std::string work_directory = job_parameters.work_directory.in();
   std::string local_directory = job_parameters.local_directory.in();
@@ -135,7 +135,7 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
     new_job->add_in_file(job_parameters.in_files[i].in());
   for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
     new_job->add_out_file(job_parameters.out_files[i].in());
-  
+
   // Expected During Time
   try
   {
@@ -170,12 +170,18 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
   }
 
-  for(int i=0;i<job_parameters.specific_parameters.length();i++){
-    std::string option = CORBA::string_dup(job_parameters.specific_parameters[i].name);
-    if(option.find("EnableDumpYACS") != std::string::npos){
-      int dumpState = atoi(job_parameters.specific_parameters[i].value);
-      (dynamic_cast<Launcher::Job_YACSFile *>(new_job))->setDumpState(dumpState);
-    }
+  // Adding specific parameters to the job
+  for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
+    new_job->addSpecificParameter(job_parameters.specific_parameters[i].name.in(),
+                                  job_parameters.specific_parameters[i].value.in());
+  try
+  {
+    new_job->checkSpecificParameters();
+  }
+  catch(const LauncherException &ex)
+  {
+    INFOS(ex.msg.c_str());
+    THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
   }
 
   try