Salome HOME
Porting SALOME KERNEL to CMake
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesCatalog_Handler.cxx
index 48451739015652c35ddbd812a0b92d18163a12cd..f65db96c038e02206a098dba67123dff16560971 100755 (executable)
@@ -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
 //
 
 //  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
@@ -28,6 +28,7 @@
 //
 #include "SALOME_ResourcesCatalog_Handler.hxx"
 #include "Basics_Utils.hxx"
+#include "Utils_SALOME_Exception.hxx"
 #include <iostream>
 #include <sstream>
 #include <map>
@@ -68,6 +69,8 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& resources_list): _reso
   test_user_commands = "userCommands";
   test_use = "use";
   test_members = "members";
+  test_is_cluster_head = "isClusterHead";
+  test_working_directory = "workingDirectory";
 }
 
 //=============================================================================
@@ -245,8 +248,8 @@ SALOME_ResourcesCatalog_Handler::ProcessCluster(xmlNodePtr cluster_descr, Parser
       resource.mpi = mpich2;
     else if (anMpi == "openmpi")
       resource.mpi = openmpi;
-    else if  (anMpi == "slurm")
-      resource.mpi = slurm;
+    else if  (anMpi == "slurmmpi")
+      resource.mpi = slurmmpi;
     else if  (anMpi == "prun")
       resource.mpi = prun;
     else
@@ -304,18 +307,15 @@ SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserRe
   if (xmlHasProp(member_descr, (const xmlChar*)test_protocol))
   {
     xmlChar* protocol= xmlGetProp(member_descr, (const xmlChar*)test_protocol);
-    switch (protocol[0])
+    try
     {
-      case 'r':
-        resource.Protocol = rsh;
-        break;
-      case 's':
-        resource.Protocol = ssh;
-        break;
-      default:
-        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
-        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
-        return false;
+      resource.Protocol = ParserResourcesType::stringToProtocol((const char *)protocol);
+    }
+    catch (SALOME_Exception e)
+    {
+      std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
+      std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+      return false;
     }
     xmlFree(protocol);
   }
@@ -329,18 +329,15 @@ SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserRe
   if (xmlHasProp(member_descr, (const xmlChar*)test_cluster_internal_protocol))
   {
     xmlChar* iprotocol= xmlGetProp(member_descr, (const xmlChar*)test_cluster_internal_protocol);
-    switch (iprotocol[0])
+    try
     {
-      case 'r':
-        resource.ClusterInternalProtocol = rsh;
-        break;
-      case 's':
-        resource.ClusterInternalProtocol = ssh;
-        break;
-      default:
-        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
-        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
-        return false;
+      resource.ClusterInternalProtocol = ParserResourcesType::stringToProtocol((const char *)iprotocol);
+    }
+    catch (SALOME_Exception e)
+    {
+      std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
+      std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+      return false;
     }
     xmlFree(iprotocol);
   }
@@ -456,18 +453,14 @@ SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, Parser
   if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
   {
     xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
-    switch ( protocol[0])
+    try
     {
-      case 'r':
-        resource.Protocol = rsh;
-        break;
-      case 's':
-        resource.Protocol = ssh;
-        break;
-      default:
-        // If it'not in all theses cases, the protocol is affected to rsh
-        resource.Protocol = rsh;
-        break;
+      resource.Protocol = ParserResourcesType::stringToProtocol((const char *)protocol);
+    }
+    catch (SALOME_Exception e)
+    {
+      // If it'not in all theses cases, the protocol is affected to rsh
+      resource.Protocol = rsh;
     }
     xmlFree(protocol);
   }
@@ -477,18 +470,14 @@ SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, Parser
   if (xmlHasProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol))
   {
     xmlChar* iprotocol= xmlGetProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol);
-    switch ( iprotocol[0])
+    try
     {
-      case 'r':
-        resource.ClusterInternalProtocol = rsh;
-        break;
-      case 's':
-        resource.ClusterInternalProtocol = ssh;
-        break;
-      default:
-        // If it'not in all theses cases, the protocol is affected to rsh
-        resource.ClusterInternalProtocol = rsh;
-        break;
+      resource.ClusterInternalProtocol = ParserResourcesType::stringToProtocol((const char *)iprotocol);
+    }
+    catch (SALOME_Exception e)
+    {
+      // If it'not in all theses cases, the protocol is affected to rsh
+      resource.ClusterInternalProtocol = rsh;
     }
     xmlFree(iprotocol);
   }
@@ -531,8 +520,12 @@ SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, Parser
       resource.Batch = ssh_batch;
     else if  (aBatch == "ccc")
       resource.Batch = ccc;
+    else if  (aBatch == "slurm")
+      resource.Batch = slurm;
     else if  (aBatch == "ll")
       resource.Batch = ll;
+    else if  (aBatch == "vishnu")
+      resource.Batch = vishnu;
     else
       resource.Batch = none;
   }
@@ -550,8 +543,8 @@ SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, Parser
       resource.mpi = mpich2;
     else if (anMpi == "openmpi")
       resource.mpi = openmpi;
-    else if  (anMpi == "slurm")
-      resource.mpi = slurm;
+    else if  (anMpi == "slurmmpi")
+      resource.mpi = slurmmpi;
     else if  (anMpi == "prun")
       resource.mpi = prun;
     else
@@ -607,6 +600,36 @@ SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, Parser
     xmlFree(nb_of_proc_per_node);
   }
 
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_is_cluster_head))
+  {
+    xmlChar* is_cluster_head = xmlGetProp(machine_descr, (const xmlChar*)test_is_cluster_head);
+    std::string str_ich = (const char*)is_cluster_head;
+    if (str_ich == "true")
+    {
+      resource.is_cluster_head = true;
+    }
+    else
+    {
+      resource.is_cluster_head = false;
+    }
+    xmlFree(is_cluster_head);
+  }
+  else
+  {
+    resource.is_cluster_head = false;
+  }
+
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_working_directory))
+  {
+    xmlChar* working_directory = xmlGetProp(machine_descr, (const xmlChar*)test_working_directory);
+    resource.working_directory = (const char*)working_directory;
+    xmlFree(working_directory);
+  }
+  else
+  {
+    resource.working_directory = "";
+  }
+
   // Process children nodes
   xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
   while(aCurSubNode != NULL)
@@ -677,30 +700,17 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
     xmlNewProp(node, BAD_CAST test_appli_path, BAD_CAST (*iter).second.AppliPath.c_str());
     xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
     xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
-
-    switch ((*iter).second.Protocol)
-    {
-      case rsh:
-        xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
-        break;
-      case ssh:
-        xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
-        break;
-      default:
-        xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
-    }
-
-    switch ((*iter).second.ClusterInternalProtocol)
-    {
-      case rsh:
-        xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
-        break;
-      case ssh:
-        xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "ssh");
-        break;
-      default:
-        xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
-    }
+    xmlNewProp(node,
+               BAD_CAST test_protocol,
+               BAD_CAST ParserResourcesType::protocolToString((*iter).second.Protocol).c_str());
+    xmlNewProp(node,
+               BAD_CAST test_cluster_internal_protocol,
+               BAD_CAST ParserResourcesType::protocolToString((*iter).second.ClusterInternalProtocol).c_str());
+    xmlNewProp(node, BAD_CAST test_working_directory, BAD_CAST (*iter).second.working_directory.c_str());
+    if ((*iter).second.is_cluster_head)
+      xmlNewProp(node, BAD_CAST test_is_cluster_head, BAD_CAST "true");
+    else
+      xmlNewProp(node, BAD_CAST test_is_cluster_head, BAD_CAST "false");
 
     switch ((*iter).second.Mode)
     {
@@ -728,12 +738,18 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
       case ccc:
         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ccc");
         break;
+      case slurm:
+        xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "slurm");
+        break;
       case ssh_batch:
         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ssh_batch");
         break;
       case ll:
         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ll");
         break;
+      case vishnu:
+        xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "vishnu");
+        break;
       default:
         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
     }
@@ -752,8 +768,8 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
       case openmpi:
         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
         break;
-      case slurm:
-        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
+      case slurmmpi:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurmmpi");
         break;
       case prun:
         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");