Salome HOME
PR: default policy
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesCatalog_Handler.cxx
index 0b85c6bfb8286167c4f141a5b0f0b1ff2b395c5a..e990944c05d4a643eda6b7733c223a6b40d1cf57 100755 (executable)
@@ -1,6 +1,6 @@
-//  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  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
 //  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)
 //  File   : SALOME_ResourcesCatalog_Handler.cxx
 //  Author : Estelle Deville
 //  Module : SALOME
 //$Header$
-
+//
 #include "SALOME_ResourcesCatalog_Handler.hxx"
+#include "Basics_Utils.hxx"
 #include <iostream>
 #include <map>
-#include "utilities.h"
 
 using namespace std;
 
-#ifdef _DEBUG_
-static int MYDEBUG = 1;
-#else
-static int MYDEBUG = 0;
-#endif
-
 //=============================================================================
 /*!
  *  Constructor
@@ -47,10 +40,11 @@ static int MYDEBUG = 0;
 //=============================================================================
 
 SALOME_ResourcesCatalog_Handler::
-SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
-    _resources_list(listOfResources)
+SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& resources_list,
+                               MapOfParserResourcesType& resources_batch_list):
+    _resources_list(resources_list),
+    _resources_batch_list(resources_batch_list)
 {
-  MESSAGE("SALOME_ResourcesCatalog_Handler creation");
   //XML tags initialisation
   test_machine = "machine";
   test_resources = "resources";
@@ -65,11 +59,15 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
   test_appli_path = "appliPath";
   test_modules = "modules";
   test_module_name = "moduleName";
+  test_components = "component";
+  test_component_name = "name";
   test_os = "OS";
   test_mem_in_mb = "memInMB";
   test_cpu_freq_mhz = "CPUFreqMHz";
   test_nb_of_nodes = "nbOfNodes";
   test_nb_of_proc_per_node = "nbOfProcPerNode";
+  test_batch_queue = "batchQueue";
+  test_user_commands = "userCommands";
 }
 
 //=============================================================================
@@ -80,7 +78,7 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
 
 SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
 {
-  //  MESSAGE("SALOME_ResourcesCatalog_Handler destruction");
+  //  cout << "SALOME_ResourcesCatalog_Handler destruction") << endl;
 }
 
 //=============================================================================
@@ -103,8 +101,6 @@ SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
 
 void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
 {
-  if (MYDEBUG) MESSAGE("Begin parse document");
-
   // Empty private elements
   _resources_list.clear();
 
@@ -123,6 +119,7 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
             {
              xmlChar* hostname = xmlGetProp(aCurNode, (const xmlChar*)test_hostname);
              _resource.DataForSort._hostName = (const char*)hostname;
+             _resource.HostName = (const char*)hostname;
               xmlFree(hostname);
             }
          else
@@ -137,10 +134,28 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
          else
            _resource.Alias = "";
 
-         if (xmlHasProp(aCurNode, (const xmlChar*)test_protocol))
+          if (xmlHasProp(aCurNode, (const xmlChar*)test_batch_queue))
+            {
+              xmlChar* batch_queue = xmlGetProp(aCurNode, (const xmlChar*)test_batch_queue);
+              _resource.batchQueue = (const char*)batch_queue;
+              xmlFree(batch_queue);
+            }
+          else
+            _resource.batchQueue = "";
+
+          if (xmlHasProp(aCurNode, (const xmlChar*)test_user_commands))
+            {
+              xmlChar* user_commands= xmlGetProp(aCurNode, (const xmlChar*)test_user_commands);
+              _resource.userCommands = (const char*)user_commands;
+              xmlFree(user_commands);
+            }
+          else
+            _resource.userCommands = "";
+          
+          if (xmlHasProp(aCurNode, (const xmlChar*)test_protocol))
             {
-             xmlChar* protocol= xmlGetProp(aCurNode, (const xmlChar*)test_protocol);
-             switch ( protocol[0])
+              xmlChar* protocol= xmlGetProp(aCurNode, (const xmlChar*)test_protocol);
+              switch ( protocol[0])
                {
                case 'r':
                  _resource.Protocol = rsh;
@@ -188,8 +203,8 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
                 _resource.Batch = pbs;
               else if  (aBatch == "lsf")
                 _resource.Batch = lsf;
-              else if  (aBatch == "slurm")
-                _resource.Batch = slurm;
+              else if  (aBatch == "sge")
+                _resource.Batch = sge;
               else
                 _resource.Batch = none;
             }
@@ -207,8 +222,12 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
                 _resource.mpi = mpich2;
               else if (anMpi == "openmpi")
                 _resource.mpi = openmpi;
+              else if  (anMpi == "slurm")
+                _resource.mpi = slurm;
+              else if  (anMpi == "prun")
+                _resource.mpi = prun;
               else
-                _resource.mpi = indif;
+                _resource.mpi = nompi;
             }
 
          if (xmlHasProp(aCurNode, (const xmlChar*)test_user_name))
@@ -260,60 +279,101 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
               xmlFree(nb_of_proc_per_node);
             }
          
-         // Process modules
+         // Process components
          xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
          while(aCurSubNode != NULL)
            {
-             if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
+             if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
+               {
+                  //If a component is given, it is in a module with the same name
+                  //except if the module name is given
+                 if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
+                   {
+                     xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
+                     std::string aComponentName = (const char*)component_name;
+                      _resource.ComponentsList.push_back(aComponentName);
+                     if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
+                        {
+                         xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
+                         std::string aModuleName = (const char*)module_name;
+                          _resource.ModulesList.push_back(aModuleName);
+                          xmlFree(module_name);
+                        }
+                      else
+                        _resource.ModulesList.push_back(aComponentName);
+                      xmlFree(component_name);
+                   }
+               }
+              else if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
                {
+                  // If a module is given, we create an entry in componentsList and modulesList
+                  // with the same name (module == component)
                  if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
                    {
-                     xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
-                     std::string aModuleName = (const char*)module_name;
-                      _resource.ModulesList.push_back(aModuleName);
-                      xmlFree(module_name);
+                     xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
+                     std::string aComponentName = (const char*)component_name;
+                      _resource.ComponentsList.push_back(aComponentName);
+                      _resource.ModulesList.push_back(aComponentName);
+                      xmlFree(component_name);
                    }
                }
              aCurSubNode = aCurSubNode->next;
            }
-         
-         int aNbNodes = _resource.DataForSort._nbOfNodes;
-         if( aNbNodes > 1 ){
-           string clusterNode = _resource.DataForSort._hostName ;
-           for( int i=0; i < aNbNodes; i++ ){
-             char inode[64];
-             inode[0] = '\0' ;
-             sprintf(inode,"%s%d",clusterNode.c_str(),i+1);
-             std::string nodeName(inode);
-             _resource.DataForSort._hostName = nodeName ;
-             _resources_list[nodeName] = _resource;
-           }
-         }
-         else
-           _resources_list[_resource.DataForSort._hostName] = _resource;
-       }
-      
+        
+         // There is two lists
+         // _resources_list for interactive resources
+         // _resources_batch_list for batch resources
+         // This choice is done with Mode parameter
+         if (_resource.Mode == interactive)
+         {
+           int aNbNodes = _resource.DataForSort._nbOfNodes;
+           if( aNbNodes > 1 ){
+             string clusterNode = _resource.DataForSort._hostName ;
+             for( int i=0; i < aNbNodes; i++ ){
+               char inode[64];
+               inode[0] = '\0' ;
+               sprintf(inode,"%s%d",clusterNode.c_str(),i+1);
+               std::string nodeName(inode);
+               _resource.DataForSort._hostName = nodeName ;
+               _resource.HostName = nodeName ;
+               _resources_list[nodeName] = _resource;
+             }
+            }
+            else
+              {
+                if(_resource.HostName == "localhost")
+                  {
+                    _resource.HostName = Kernel_Utils::GetHostname();
+                    _resource.DataForSort._hostName = Kernel_Utils::GetHostname();
+                    _resources_list[Kernel_Utils::GetHostname()] = _resource;
+                  }
+                else
+                  _resources_list[_resource.HostName] = _resource;
+              }
+          }
+          else
+            _resources_batch_list[_resource.HostName] = _resource;
+        }
       aCurNode = aCurNode->next;
     }
 
-  // For debug only
-  if (MYDEBUG)
-    {
-      for (map<string, ParserResourcesType>::const_iterator iter =
-            _resources_list.begin();
-          iter != _resources_list.end();
-          iter++)
-       {
-         SCRUTE((*iter).second.Alias);
-         SCRUTE((*iter).second.UserName);
-         SCRUTE((*iter).second.AppliPath);
-         SCRUTE((*iter).second.OS);
-         SCRUTE((*iter).second.Protocol);
-         SCRUTE((*iter).second.Mode);
-       }
-      
-      MESSAGE("This is the end of document");
-    }
+#ifdef _DEBUG_
+    for (map<string, ParserResourcesType>::const_iterator iter =
+          _resources_list.begin();
+        iter != _resources_list.end();
+        iter++)
+      {
+       std::cerr << (*iter).first << std::endl;
+       std::cerr << (*iter).second.HostName << std::endl;
+       std::cerr << (*iter).second.Alias << std::endl;
+       std::cerr << (*iter).second.UserName << std::endl;
+       std::cerr << (*iter).second.AppliPath << std::endl;
+       std::cerr << (*iter).second.OS << std::endl;
+       std::cerr << (*iter).second.Protocol << std::endl;
+       std::cerr << (*iter).second.Mode << std::endl;
+      }
+#endif
+
 }
 
 
@@ -339,9 +399,11 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
        iter++)
     {
       node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
-      xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).first.c_str());
+      xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
       xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.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:
@@ -374,8 +436,97 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
        case lsf:
          xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
           break;
+       case sge:
+         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
+          break;
+        default:
+         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
+        }
+
+      switch ((*iter).second.mpi)
+        {
+       case lam:
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
+          break;
+       case mpich1:
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
+          break;
+       case mpich2:
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
+          break;
+       case openmpi:
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
+          break;
        case slurm:
-         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "slurm");
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
+          break;
+       case prun:
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
+          break;
+        default:
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
+        }
+
+      xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
+
+     for (vector<string>::const_iterator iter2 =
+             (*iter).second.ComponentsList.begin();
+           iter2 != (*iter).second.ComponentsList.end();
+           iter2++)
+        {
+         node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
+         xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
+        }
+
+      xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
+      xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
+      xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
+      xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
+      xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
+    }
+  for (map<string, ParserResourcesType>::iterator iter =
+         _resources_batch_list.begin();
+       iter != _resources_batch_list.end();
+       iter++)
+    {
+      node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
+      xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
+      xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.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.Mode)
+        {
+       case interactive:
+         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
+          break;
+        case batch:
+         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
+          break;
+        default:
+         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
+        }
+
+      switch ((*iter).second.Batch)
+        {
+       case pbs:
+         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
+          break;
+       case lsf:
+         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
+          break;
+       case sge:
+         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
           break;
         default:
          xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
@@ -395,6 +546,12 @@ 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");
+          break;
+       case prun:
+         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
+          break;
         default:
          xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
         }
@@ -402,12 +559,12 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
       xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
 
      for (vector<string>::const_iterator iter2 =
-             (*iter).second.ModulesList.begin();
-           iter2 != (*iter).second.ModulesList.end();
+             (*iter).second.ComponentsList.begin();
+           iter2 != (*iter).second.ComponentsList.end();
            iter2++)
         {
-         node1 = xmlNewChild(node, NULL, BAD_CAST test_modules, NULL);
-         xmlNewProp(node1, BAD_CAST test_module_name, BAD_CAST (*iter2).c_str());
+         node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
+         xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
         }
 
       xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());