Salome HOME
Porting SALOME KERNEL to CMake
[modules/kernel.git] / src / Launcher / SALOME_Launcher.cxx
index 27956bded60145793c8afe4658d8f0ff80fc0dbc..433c30b1480433bdf8a403a6bcae3a02d43d7334 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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
 //
 
 #include "SALOME_Launcher.hxx"
@@ -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,6 +170,20 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
   }
 
+  // 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
   {
     _l.createJob(new_job);
@@ -229,6 +243,22 @@ SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
   }
 }
 
+CORBA::Boolean
+SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
+{
+  CORBA::Boolean rtn = false;
+  try
+  {
+    rtn = _l.getJobDumpState(job_id, directory);
+  }
+  catch(const LauncherException &ex)
+  {
+    INFOS(ex.msg.c_str());
+    THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
+  }
+  return rtn;
+}
+
 void 
 SALOME_Launcher::removeJob(CORBA::Long job_id)
 {
@@ -246,6 +276,23 @@ SALOME_Launcher::removeJob(CORBA::Long job_id)
   }
 }
 
+void 
+SALOME_Launcher::stopJob(CORBA::Long job_id)
+{
+  try
+  {
+    _l.stopJob(job_id);
+    std::ostringstream job_id_str;
+    job_id_str << job_id;
+    notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
+  }
+  catch(const LauncherException &ex)
+  {
+    INFOS(ex.msg.c_str());
+    THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
+  }
+}
+
 //=============================================================================
 /*! CORBA Method:
  *  Create a job in the launcher with a file
@@ -288,7 +335,7 @@ SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
       throw SALOME_Exception("No resources have been found with your parameters");
 
     const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
-       std::string resource_name(p->name);
+        std::string resource_name(p->name);
     INFOS("Choose resource for test: " <<  resource_name);
     
     BatchTest t(*p);
@@ -425,6 +472,22 @@ SALOME_Launcher::getJobParameters(CORBA::Long job_id)
   job_parameters->resource_required.cpu_clock        = resource_params.cpu_clock;
   job_parameters->resource_required.mem_mb           = resource_params.mem_mb;
 
+  std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
+  if (!specific_parameters.empty())
+  {
+    job_parameters->specific_parameters.length(specific_parameters.size());
+    std::map<std::string, std::string>::const_iterator it_specific;
+    CORBA::ULong i = 0;
+    for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
+    {
+      Engines::Parameter_var new_param = new Engines::Parameter;
+      new_param->name  = CORBA::string_dup((it_specific->first).c_str());
+      new_param->value = CORBA::string_dup((it_specific->second).c_str());
+      job_parameters->specific_parameters[i] = new_param;
+      i++;
+    }
+  }
+
   return job_parameters._retn();
 }
 
@@ -631,6 +694,61 @@ SALOME_Launcher::loadJobs(const char* jobs_file)
         xmlFree(maximum_duration);
         xmlFree(queue);
 
+        xmlNodePtr specific_node = xmlNextElementSibling(queue_node);
+        if (specific_node == NULL)
+        {
+          INFOS("A bad job is found, specific_parameters part is not found");
+          delete new_job;
+          break;
+        }
+        xmlNodePtr parameter_node = xmlFirstElementChild(specific_node);
+        while (parameter_node != NULL)
+        {
+          if (!xmlStrcmp(parameter_node->name, xmlCharStrdup("specific_parameter")))
+          {
+            xmlNodePtr name_node = xmlFirstElementChild(parameter_node);
+            xmlNodePtr value_node = xmlNextElementSibling(name_node);
+            if (name_node == NULL ||
+                value_node == NULL)
+            {
+              INFOS("A bad job is found, specific_parameter parts are not found");
+              delete new_job;
+              break;
+            }
+            if (xmlStrcmp(name_node->name, xmlCharStrdup("name")) ||
+                xmlStrcmp(value_node->name, xmlCharStrdup("value")))
+            {
+              INFOS("A bad job is found, specific_parameter bad parts are found");
+              delete new_job;
+              break;
+            }
+
+            xmlChar* name  = xmlNodeGetContent(name_node);
+            xmlChar* value = xmlNodeGetContent(value_node);
+            try
+            {
+              new_job->addSpecificParameter(std::string((const char*)name), std::string((const char*)value));
+              xmlFree(name);
+              xmlFree(value);
+            }
+            catch(const LauncherException &ex)
+            {
+              INFOS("Exception receice for a specific parameter, cannot add the job" << ex.msg.c_str());
+              delete new_job;
+              xmlFree(name);
+              xmlFree(value);
+              break;
+            }
+          }
+          else
+          {
+            INFOS("A bad job is found, specific_parameters part is bad, a node that is not a specific parameter is found");
+            delete new_job;
+            break;
+          }
+          parameter_node = xmlNextElementSibling(parameter_node);
+        }
+
         xmlNodePtr res_name_node             = xmlFirstElementChild(res_node);
         xmlNodePtr res_hostname_node         = xmlNextElementSibling(res_name_node);
         xmlNodePtr res_os_node               = xmlNextElementSibling(res_hostname_node);
@@ -758,7 +876,6 @@ SALOME_Launcher::loadJobs(const char* jobs_file)
           try
           {
             _l.createJob(new_job);
-
             std::ostringstream job_id;
             job_id << new_job->getNumber();
             notifyObservers("NEW_JOB", job_id.str());
@@ -775,26 +892,18 @@ SALOME_Launcher::loadJobs(const char* jobs_file)
         {
           try
           {
-            // Step 1: Add the resource to the launcher C++ map
-            _l.checkFactoryForResource(resource_choosed_name);
-
-            // Step 2: We add run_part informations
             new_job->setState(job_state);
-
-            // Step 3: We add the job to the launcher
-            ParserResourcesType resource_definition;
-            resource_definition.Name = resource_choosed_name;
-            new_job->setResourceDefinition(resource_definition);
             _l.addJobDirectlyToMap(new_job, job_reference);
 
             // Step 4: We check that the BatchManager could resume
             // the job
+#ifdef WITH_LIBBATCH
             if (new_job->getBatchManagerJobId().getReference() != job_reference)
             {
               INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
               new_job->setState("ERROR");
             }
-
+#endif
             std::ostringstream job_id;
             job_id << new_job->getNumber();
             notifyObservers("NEW_JOB", job_id.str());
@@ -811,18 +920,9 @@ SALOME_Launcher::loadJobs(const char* jobs_file)
         {
           try
           {
-            // Step 1: Add the resource to the launcher C++ map
-            _l.checkFactoryForResource(resource_choosed_name);
-
             // Step 2: We add run_part informations
             new_job->setState(job_state);
-
-            // Step 3: We add the job to the launcher
-            ParserResourcesType resource_definition;
-            resource_definition.Name = resource_choosed_name;
-            new_job->setResourceDefinition(resource_definition);
             _l.addJobDirectlyToMap(new_job, job_reference);
-
             std::ostringstream job_id;
             job_id << new_job->getNumber();
             notifyObservers("NEW_JOB", job_id.str());