Salome HOME
Fix for the "21727: [CEA 584] sending a Yacs graph from Windows to a cluster " issue.
[modules/kernel.git] / src / Launcher / Launcher_Job.cxx
index 19daa34c1c6468708a324fb3c58dc35a6978eeed..1307fbf2274d056c6e57c67214c623024126cddf 100644 (file)
@@ -1,20 +1,20 @@
-//  Copyright (C) 2009-2010  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 // Author: AndrĂ© RIBES - EDF R&D
@@ -61,6 +61,17 @@ Launcher::Job::Job()
 Launcher::Job::~Job() 
 {
   LAUNCHER_MESSAGE("Deleting job number: " << _number);
+#ifdef WITH_LIBBATCH
+  if (_batch_job)
+    delete _batch_job;
+#endif
+}
+
+void
+Launcher::Job::stopJob()
+{
+  LAUNCHER_MESSAGE("Stop resquested for job number: " << _number);
+  setState("FAILED");
 #ifdef WITH_LIBBATCH
   if (_batch_job_id.getReference() != "undefined")
   {
@@ -70,11 +81,29 @@ Launcher::Job::~Job()
     }
     catch (const Batch::EmulationException &ex)
     {
-      LAUNCHER_INFOS("WARNING: exception when deleting the job: " << ex.message);
+      LAUNCHER_INFOS("WARNING: exception when stopping the job: " << ex.message);
+    }
+  }
+#endif
+}
+
+
+void
+Launcher::Job::removeJob()
+{
+  LAUNCHER_MESSAGE("Removing job number: " << _number);
+#ifdef WITH_LIBBATCH
+  if (_batch_job_id.getReference() != "undefined")
+  {
+    try 
+    {
+      _batch_job_id.deleteJob();
+    }
+    catch (const Batch::EmulationException &ex)
+    {
+      LAUNCHER_INFOS("WARNING: exception when removing the job: " << ex.message);
     }
   }
-  if (_batch_job)
-    delete _batch_job;
 #endif
 }
 
@@ -176,9 +205,6 @@ Launcher::Job::setJobFile(const std::string & job_file)
   std::string::size_type p2 = _job_file.find_last_of(".");
   _job_file_name_complete = _job_file.substr(p1+1);
   _job_file_name = _job_file.substr(p1+1,p2-p1-1);
-
-  if (_job_file != "")
-    add_in_file(_job_file);
 }
 
 std::string
@@ -190,8 +216,6 @@ void
 Launcher::Job::setEnvFile(const std::string & env_file)
 {
   _env_file = env_file;
-  if (_env_file != "")
-    add_in_file(_env_file);
 }
 
 std::string
@@ -315,6 +339,9 @@ Launcher::Job::checkMaximumDuration(const std::string & maximum_duration)
   std::size_t pos = edt_value.find(":");
 
   if (edt_value != "") {
+    if (pos == edt_value.npos) {
+      throw LauncherException("[Launcher::Job::checkMaximumDuration] Error on definition: " + edt_value);
+    }
     std::string begin_edt_value = edt_value.substr(0, pos);
     std::string mid_edt_value = edt_value.substr(pos, 1);
     std::string end_edt_value = edt_value.substr(pos + 1, edt_value.npos);
@@ -396,8 +423,8 @@ std::string
 Launcher::Job::updateJobState()
 {
 
-  if (_state != "FINISHED" ||
-      _state != "ERROR"    ||
+  if (_state != "FINISHED" &&
+      _state != "ERROR"    &&
       _state != "FAILED")
   {
 #ifdef WITH_LIBBATCH
@@ -462,7 +489,11 @@ Launcher::Job::common_job_params()
     _result_directory = getenv("HOME");
 
   // _in_files
-  for(std::list<std::string>::iterator it = _in_files.begin(); it != _in_files.end(); it++)
+  std::list<std::string> in_files(_in_files);
+  in_files.push_back(_job_file);
+  if (_env_file != "")
+         in_files.push_back(_env_file);
+  for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
   {
     std::string file = *it;
 
@@ -471,9 +502,13 @@ Launcher::Job::common_job_params()
     if (file.substr(0, 1) == std::string("/"))
       local_file = file;
     else
+#ifndef WIN32
       local_file = _local_directory + "/" + file;
+#else
+         local_file = file;
+#endif
     
-    // remote file -> get only file name from _in_files
+    // remote file -> get only file name from in_files
     size_t found = file.find_last_of("/");
     std::string remote_file = _work_directory + "/" + file.substr(found+1);
 
@@ -507,6 +542,10 @@ Launcher::Job::common_job_params()
   if (_queue != "")
     params[Batch::QUEUE] = _queue;
 
+  // Specific parameters
+  std::map<std::string, std::string>::iterator it = _specific_parameters.find("LoalLevelerJobType");
+  if (it != _specific_parameters.end())
+    params["LL_JOBTYPE"] = it->second;
   return params;
 }
 
@@ -574,6 +613,16 @@ Launcher::Job::addToXmlDocument(xmlNodePtr root_node)
   xmlNewChild(node, NULL, xmlCharStrdup("maximum_duration"), xmlCharStrdup(getMaximumDuration().c_str()));
   xmlNewChild(node, NULL, xmlCharStrdup("queue"),            xmlCharStrdup(getQueue().c_str()));
 
+  // Specific parameters part
+  xmlNodePtr specific_parameters_node = xmlNewChild(node, NULL, xmlCharStrdup("specific_parameters"), NULL);
+  std::map<std::string, std::string> specific_parameters = getSpecificParameters();
+  for(std::map<std::string, std::string>::iterator it = specific_parameters.begin(); it != specific_parameters.end(); it++)
+  {
+    xmlNodePtr specific_parameter_node = xmlNewChild(specific_parameters_node, NULL, xmlCharStrdup("specific_parameter"), NULL);
+    xmlNewChild(specific_parameter_node, NULL, xmlCharStrdup("name"), xmlCharStrdup((it->first).c_str()));
+    xmlNewChild(specific_parameter_node, NULL, xmlCharStrdup("value"), xmlCharStrdup((it->second).c_str()));
+  }
+
   // Run part
   xmlNodePtr run_node = xmlNewChild(job_node, NULL, xmlCharStrdup("run_part"), NULL);
   xmlNewChild(run_node, NULL, xmlCharStrdup("job_state"), xmlCharStrdup(getState().c_str()));
@@ -590,7 +639,6 @@ void
 Launcher::Job::addSpecificParameter(const std::string & name,
                                       const std::string & value)
 {
-  std::cerr << "Adding " << name << " " << value << std::endl;
   _specific_parameters[name] = value;
 }