Back to index

salome-kernel  6.5.0
SALOME_ResourcesCatalog_Handler.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
00024 //  File   : SALOME_ResourcesCatalog_Handler.cxx
00025 //  Author : Estelle Deville
00026 //  Module : SALOME
00027 //$Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx,v 1.8.2.9.6.9.2.1 2012-04-12 14:05:20 vsr Exp $
00028 //
00029 #include "SALOME_ResourcesCatalog_Handler.hxx"
00030 #include "Basics_Utils.hxx"
00031 #include "Utils_SALOME_Exception.hxx"
00032 #include <iostream>
00033 #include <sstream>
00034 #include <map>
00035 
00036 //=============================================================================
00041 //=============================================================================
00042 
00043 SALOME_ResourcesCatalog_Handler::
00044 SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& resources_list): _resources_list(resources_list)
00045 {
00046   //XML tags initialisation
00047   test_machine = "machine";
00048   test_cluster = "cluster";
00049   test_name = "name";
00050   test_hostname = "hostname";
00051   test_protocol = "protocol";
00052   test_cluster_internal_protocol = "iprotocol";
00053   test_mode = "mode";
00054   test_batch = "batch";
00055   test_mpi = "mpi";
00056   test_user_name = "userName";
00057   test_appli_path = "appliPath";
00058   test_modules = "modules";
00059   test_module_name = "moduleName";
00060   test_components = "component";
00061   test_component_name = "name";
00062   test_os = "OS";
00063   test_mem_in_mb = "memInMB";
00064   test_cpu_freq_mhz = "CPUFreqMHz";
00065   test_nb_of_nodes = "nbOfNodes";
00066   test_nb_of_proc = "nbOfProc";
00067   test_nb_of_proc_per_node = "nbOfProcPerNode";
00068   test_batch_queue = "batchQueue";
00069   test_user_commands = "userCommands";
00070   test_use = "use";
00071   test_members = "members";
00072   test_is_cluster_head = "isClusterHead";
00073   test_working_directory = "workingDirectory";
00074 }
00075 
00076 //=============================================================================
00080 //=============================================================================
00081 
00082 SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
00083 {
00084   //  cout << "SALOME_ResourcesCatalog_Handler destruction") << endl;
00085 }
00086 
00087 //=============================================================================
00091 //=============================================================================
00092 
00093 const MapOfParserResourcesType&
00094 SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
00095 {
00096   return _resources_list;
00097 }
00098 
00099 //=============================================================================
00103 //=============================================================================
00104 
00105 void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
00106 {
00107   // Empty private elements
00108   _resources_list.clear();
00109 
00110   //default resources
00111   _resource.Clear();
00112   _resource.HostName = Kernel_Utils::GetHostname();
00113   _resource.Name = Kernel_Utils::GetHostname();
00114   _resource.DataForSort._Name = Kernel_Utils::GetHostname();
00115   _resources_list[Kernel_Utils::GetHostname()] = _resource;
00116 
00117   // Get the document root node
00118   xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
00119 
00120   aCurNode = aCurNode->xmlChildrenNode;
00121  
00122   // Processing the document nodes
00123   while(aCurNode != NULL)
00124   {
00125     // Cas d'une machine ou d'une machine batch
00126     if (!xmlStrcmp(aCurNode->name,(const xmlChar*)test_machine))
00127     {
00128       _resource.Clear();
00129       bool Ok = ProcessMachine(aCurNode, _resource);
00130       if (Ok)
00131       {
00132         // Adding a resource
00133         if(_resource.HostName == "localhost")
00134         {
00135           _resource.HostName = Kernel_Utils::GetHostname();
00136         }
00137         std::map<std::string, ParserResourcesType>::const_iterator iter = _resources_list.find(_resource.Name);
00138         if (iter != _resources_list.end())
00139           RES_INFOS("Warning resource " << _resource.Name << " already added, keep last resource found !");
00140         _resources_list[_resource.Name] = _resource;
00141       }
00142     }
00143     // Cas de la d├ęclaration d'un cluster
00144     if (!xmlStrcmp(aCurNode->name,(const xmlChar*)test_cluster))
00145     {
00146       _resource.Clear();
00147       if(ProcessCluster(aCurNode, _resource))
00148       {
00149         std::map<std::string, ParserResourcesType>::const_iterator iter = _resources_list.find(_resource.Name);
00150         if (iter != _resources_list.end())
00151           RES_INFOS("Warning resource " << _resource.Name << " already added, keep last resource found !");
00152         _resources_list[_resource.Name] = _resource;
00153       }
00154     }
00155     aCurNode = aCurNode->next;
00156   }
00157 
00158 #ifdef _DEBUG_
00159   for (std::map<std::string, ParserResourcesType>::const_iterator iter = _resources_list.begin();
00160        iter != _resources_list.end();
00161        iter++)
00162   {
00163     std::cerr << "************************************************" << std::endl;
00164     std::cerr << "Resource " << (*iter).first << " found:" << std::endl;
00165     std::cerr << " Name: " << (*iter).second.Name << std::endl;
00166     std::cerr << " Hostname: " << (*iter).second.HostName << std::endl;
00167     std::cerr << " Username: " << (*iter).second.UserName << std::endl;
00168     std::cerr << " Appli path: " <<(*iter).second.AppliPath << std::endl;
00169     std::cerr << " OS: " << (*iter).second.OS << std::endl;
00170     std::cerr << " Protocol: " << (*iter).second.PrintAccessProtocolType() << std::endl;
00171     std::cerr << " Internal Protocol: " <<(*iter).second.PrintClusterInternalProtocol() << std::endl;
00172     std::cerr << " Mode: " << (*iter).second.PrintAccessModeType() << std::endl;
00173     std::cerr << " Batch Type: " << (*iter).second.PrintBatchType() << std::endl;
00174     std::cerr << " MPI Impl: " << (*iter).second.PrintMpiImplType() << std::endl;
00175     std::cerr << "************************************************" << std::endl;
00176   }
00177 #endif
00178 }
00179 
00180 bool
00181 SALOME_ResourcesCatalog_Handler::ProcessCluster(xmlNodePtr cluster_descr, ParserResourcesType & resource)
00182 {
00183   // Ajout d'un cluster
00184   // hostname, use et nbOfProc sont obligatoires
00185   if (xmlHasProp(cluster_descr, (const xmlChar*)test_hostname))
00186   {
00187     xmlChar* hostname = xmlGetProp(cluster_descr, (const xmlChar*)test_hostname);
00188     resource.HostName = (const char*)hostname;
00189     xmlFree(hostname);
00190   }
00191   else
00192   {
00193     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a hostname" << std::endl;
00194     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
00195     return false;
00196   }
00197 
00198   if (xmlHasProp(cluster_descr, (const xmlChar*)test_name))
00199   {
00200     xmlChar* name = xmlGetProp(cluster_descr, (const xmlChar*)test_name);
00201     resource.Name = (const char*)name;
00202     resource.DataForSort._Name = (const char*)name;
00203     xmlFree(name);
00204   }
00205   else
00206   {
00207     resource.Name = resource.HostName;
00208     resource.DataForSort._Name = resource.HostName;
00209     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
00210   }
00211 
00212   if (xmlHasProp(cluster_descr, (const xmlChar*)test_use))
00213   {
00214     xmlChar* use = xmlGetProp(cluster_descr, (const xmlChar*)test_use);
00215     resource.use = (const char*)use;
00216     xmlFree(use);
00217   }
00218   else
00219   {
00220     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a use" << std::endl;
00221     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
00222     return false;
00223   }
00224 
00225   if (xmlHasProp(cluster_descr, (const xmlChar*)test_nb_of_proc))
00226   {
00227     xmlChar* nb_of_proc = xmlGetProp(cluster_descr, (const xmlChar*)test_nb_of_proc);
00228     resource.nbOfProc = atoi((const char*)nb_of_proc);
00229     xmlFree(nb_of_proc);
00230   }
00231   else
00232   {
00233     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a nbOfProc" << std::endl;
00234     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
00235     return false;
00236   }
00237 
00238   if (xmlHasProp(cluster_descr, (const xmlChar*)test_mpi))
00239   {
00240     xmlChar* mpi = xmlGetProp(cluster_descr, (const xmlChar*)test_mpi);
00241     std::string anMpi = (const char*)mpi;
00242     xmlFree(mpi);
00243     if (anMpi == "lam")
00244       resource.mpi = lam;
00245     else if (anMpi == "mpich1")
00246       resource.mpi = mpich1;
00247     else if (anMpi == "mpich2")
00248       resource.mpi = mpich2;
00249     else if (anMpi == "openmpi")
00250       resource.mpi = openmpi;
00251     else if  (anMpi == "slurmmpi")
00252       resource.mpi = slurmmpi;
00253     else if  (anMpi == "prun")
00254       resource.mpi = prun;
00255     else
00256       resource.mpi = nompi;
00257   }
00258 
00259   // Parsing des membres du cluster 
00260   xmlNodePtr aCurSubNode = cluster_descr->xmlChildrenNode;
00261   while(aCurSubNode != NULL)
00262   {
00263     if (!xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_members))
00264     {
00265        xmlNodePtr members = aCurSubNode->xmlChildrenNode;
00266        while (members != NULL)
00267        {
00268          // Process members
00269          if (!xmlStrcmp(members->name, (const xmlChar*)test_machine))
00270          {
00271            ParserResourcesClusterMembersType new_member;
00272            if (ProcessMember(members, new_member))
00273              resource.ClusterMembersList.push_back(new_member);
00274          }
00275          members = members->next;
00276        }
00277     }
00278     aCurSubNode = aCurSubNode->next;
00279   }
00280 
00281   // Test: Il faut au moins un membre pour que le cluster soit correct !
00282   if (resource.ClusterMembersList.empty())
00283   {
00284     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a member" << std::endl;
00285     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
00286     return false;
00287   }
00288   return true;
00289 }
00290 
00291 bool
00292 SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserResourcesClusterMembersType & resource)
00293 {
00294   if (xmlHasProp(member_descr, (const xmlChar*)test_hostname))
00295   {
00296     xmlChar* hostname = xmlGetProp(member_descr, (const xmlChar*)test_hostname);
00297     resource.HostName = (const char*)hostname;
00298     xmlFree(hostname);
00299   }
00300   else
00301   {
00302     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a hostname" << std::endl;
00303     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00304     return false;
00305   }
00306 
00307   if (xmlHasProp(member_descr, (const xmlChar*)test_protocol))
00308   {
00309     xmlChar* protocol= xmlGetProp(member_descr, (const xmlChar*)test_protocol);
00310     try
00311     {
00312       resource.Protocol = ParserResourcesType::stringToProtocol((const char *)protocol);
00313     }
00314     catch (SALOME_Exception e)
00315     {
00316       std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
00317       std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00318       return false;
00319     }
00320     xmlFree(protocol);
00321   }
00322   else
00323   {
00324     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
00325     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00326     return false;
00327   }
00328 
00329   if (xmlHasProp(member_descr, (const xmlChar*)test_cluster_internal_protocol))
00330   {
00331     xmlChar* iprotocol= xmlGetProp(member_descr, (const xmlChar*)test_cluster_internal_protocol);
00332     try
00333     {
00334       resource.ClusterInternalProtocol = ParserResourcesType::stringToProtocol((const char *)iprotocol);
00335     }
00336     catch (SALOME_Exception e)
00337     {
00338       std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
00339       std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00340       return false;
00341     }
00342     xmlFree(iprotocol);
00343   }
00344   else
00345   {
00346     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
00347     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00348     return false;
00349   }
00350 
00351   if (xmlHasProp(member_descr, (const xmlChar*)test_user_name))
00352   {
00353     xmlChar* user_name= xmlGetProp(member_descr, (const xmlChar*)test_user_name);
00354     resource.UserName = (const char*)user_name;
00355     xmlFree(user_name);
00356   }
00357   else
00358   {
00359     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a user name" << std::endl;
00360     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00361     return false;
00362   }
00363 
00364   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_nodes))
00365   {
00366     xmlChar* nb_of_nodes = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_nodes);
00367     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
00368     xmlFree(nb_of_nodes);
00369   }
00370   else
00371   {
00372     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfNodes" << std::endl;
00373     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00374     return false;
00375   }
00376 
00377   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node))
00378   {
00379     xmlChar* nb_of_proc_per_node = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node);
00380     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
00381     xmlFree(nb_of_proc_per_node);
00382   }
00383   else
00384   {
00385     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfProcPerNode" << std::endl;
00386     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00387     return false;
00388   }
00389 
00390   if (xmlHasProp(member_descr, (const xmlChar*)test_appli_path))
00391   {
00392     xmlChar* appli_path = xmlGetProp(member_descr, (const xmlChar*)test_appli_path);
00393     resource.AppliPath = (const char*)appli_path;
00394     xmlFree(appli_path);
00395   }
00396   else
00397   {
00398     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a AppliPath" << std::endl;
00399     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
00400     return false;
00401   }
00402   return true;
00403 }
00404 
00405 bool
00406 SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, ParserResourcesType & resource)
00407 {
00408   if (xmlHasProp(machine_descr, (const xmlChar*)test_hostname))
00409   {
00410     xmlChar* hostname = xmlGetProp(machine_descr, (const xmlChar*)test_hostname);
00411     resource.HostName = (const char*)hostname;
00412     xmlFree(hostname);
00413   }
00414   else
00415   {
00416     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning found a machine without a hostname" << std::endl;
00417     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning this machine will not be added" << std::endl;
00418     return false;
00419   }
00420 
00421   if (xmlHasProp(machine_descr, (const xmlChar*)test_name))
00422   {
00423     xmlChar* name = xmlGetProp(machine_descr, (const xmlChar*)test_name);
00424     resource.Name = (const char*)name;
00425     resource.DataForSort._Name = (const char*)name;
00426     xmlFree(name);
00427   }
00428   else
00429   {
00430     resource.Name = resource.HostName;
00431     resource.DataForSort._Name = resource.HostName;
00432     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
00433   }
00434 
00435   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch_queue))
00436   {
00437     xmlChar* batch_queue = xmlGetProp(machine_descr, (const xmlChar*)test_batch_queue);
00438     resource.batchQueue = (const char*)batch_queue;
00439     xmlFree(batch_queue);
00440   }
00441   else
00442     resource.batchQueue = "";
00443 
00444   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_commands))
00445   {
00446     xmlChar* user_commands= xmlGetProp(machine_descr, (const xmlChar*)test_user_commands);
00447     resource.userCommands = (const char*)user_commands;
00448     xmlFree(user_commands);
00449   }
00450   else
00451     resource.userCommands = "";
00452 
00453   if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
00454   {
00455     xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
00456     try
00457     {
00458       resource.Protocol = ParserResourcesType::stringToProtocol((const char *)protocol);
00459     }
00460     catch (SALOME_Exception e)
00461     {
00462       // If it'not in all theses cases, the protocol is affected to rsh
00463       resource.Protocol = rsh;
00464     }
00465     xmlFree(protocol);
00466   }
00467   else
00468     resource.Protocol = rsh;
00469 
00470   if (xmlHasProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol))
00471   {
00472     xmlChar* iprotocol= xmlGetProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol);
00473     try
00474     {
00475       resource.ClusterInternalProtocol = ParserResourcesType::stringToProtocol((const char *)iprotocol);
00476     }
00477     catch (SALOME_Exception e)
00478     {
00479       // If it'not in all theses cases, the protocol is affected to rsh
00480       resource.ClusterInternalProtocol = rsh;
00481     }
00482     xmlFree(iprotocol);
00483   }
00484   else
00485     resource.ClusterInternalProtocol = resource.Protocol;
00486 
00487   if (xmlHasProp(machine_descr, (const xmlChar*)test_mode))
00488   {
00489     xmlChar* mode=xmlGetProp(machine_descr, (const xmlChar*)test_mode);
00490     switch ( mode[0] )
00491     {
00492       case 'i':
00493         resource.Mode = interactive;
00494         break;
00495       case 'b':
00496         resource.Mode = batch;
00497         break;
00498       default:
00499         // If it'not in all theses cases, the mode is affected to interactive
00500         resource.Mode = interactive;
00501         break;
00502     }
00503     xmlFree(mode);
00504   }
00505   else
00506     resource.Mode = interactive;
00507 
00508   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch))
00509   {
00510     xmlChar* batch = xmlGetProp(machine_descr, (const xmlChar*)test_batch);
00511     std::string aBatch = (const char*)batch;
00512     xmlFree(batch);
00513     if (aBatch == "pbs")
00514       resource.Batch = pbs;
00515     else if  (aBatch == "lsf")
00516       resource.Batch = lsf;
00517     else if  (aBatch == "sge")
00518       resource.Batch = sge;
00519     else if  (aBatch == "ssh_batch")
00520       resource.Batch = ssh_batch;
00521     else if  (aBatch == "ccc")
00522       resource.Batch = ccc;
00523     else if  (aBatch == "slurm")
00524       resource.Batch = slurm;
00525     else if  (aBatch == "ll")
00526       resource.Batch = ll;
00527     else if  (aBatch == "vishnu")
00528       resource.Batch = vishnu;
00529     else
00530       resource.Batch = none;
00531   }
00532 
00533   if (xmlHasProp(machine_descr, (const xmlChar*)test_mpi))
00534   {
00535     xmlChar* mpi = xmlGetProp(machine_descr, (const xmlChar*)test_mpi);
00536     std::string anMpi = (const char*)mpi;
00537     xmlFree(mpi);
00538     if (anMpi == "lam")
00539       resource.mpi = lam;
00540     else if (anMpi == "mpich1")
00541       resource.mpi = mpich1;
00542     else if (anMpi == "mpich2")
00543       resource.mpi = mpich2;
00544     else if (anMpi == "openmpi")
00545       resource.mpi = openmpi;
00546     else if  (anMpi == "slurmmpi")
00547       resource.mpi = slurmmpi;
00548     else if  (anMpi == "prun")
00549       resource.mpi = prun;
00550     else
00551       resource.mpi = nompi;
00552   }
00553 
00554   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_name))
00555   {
00556     xmlChar* user_name= xmlGetProp(machine_descr, (const xmlChar*)test_user_name);
00557     resource.UserName = (const char*)user_name;
00558     xmlFree(user_name);
00559   }
00560 
00561   if (xmlHasProp(machine_descr, (const xmlChar*)test_appli_path))
00562   {
00563     xmlChar* appli_path = xmlGetProp(machine_descr, (const xmlChar*)test_appli_path);
00564     resource.AppliPath = (const char*)appli_path;
00565     xmlFree(appli_path);
00566   }
00567 
00568   if (xmlHasProp(machine_descr, (const xmlChar*)test_os))
00569   {
00570     xmlChar* os = xmlGetProp(machine_descr, (const xmlChar*)test_os);
00571     resource.OS = (const char*)os;
00572     xmlFree(os);
00573   }
00574 
00575   if (xmlHasProp(machine_descr, (const xmlChar*)test_mem_in_mb))
00576   {
00577     xmlChar* mem_in_mb = xmlGetProp(machine_descr, (const xmlChar*)test_mem_in_mb);
00578     resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
00579     xmlFree(mem_in_mb);
00580   }
00581 
00582   if (xmlHasProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz))
00583   {
00584     xmlChar* cpu_freq_mhz = xmlGetProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz);
00585     resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
00586     xmlFree(cpu_freq_mhz);
00587   }
00588 
00589   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_nodes))
00590   {
00591     xmlChar* nb_of_nodes = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_nodes);
00592     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
00593     xmlFree(nb_of_nodes);
00594   }
00595 
00596   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node))
00597   {
00598     xmlChar* nb_of_proc_per_node = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node);
00599     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
00600     xmlFree(nb_of_proc_per_node);
00601   }
00602 
00603   if (xmlHasProp(machine_descr, (const xmlChar*)test_is_cluster_head))
00604   {
00605     xmlChar* is_cluster_head = xmlGetProp(machine_descr, (const xmlChar*)test_is_cluster_head);
00606     std::string str_ich = (const char*)is_cluster_head;
00607     if (str_ich == "true")
00608     {
00609       resource.is_cluster_head = true;
00610     }
00611     else
00612     {
00613       resource.is_cluster_head = false;
00614     }
00615     xmlFree(is_cluster_head);
00616   }
00617   else
00618   {
00619     resource.is_cluster_head = false;
00620   }
00621 
00622   if (xmlHasProp(machine_descr, (const xmlChar*)test_working_directory))
00623   {
00624     xmlChar* working_directory = xmlGetProp(machine_descr, (const xmlChar*)test_working_directory);
00625     resource.working_directory = (const char*)working_directory;
00626     xmlFree(working_directory);
00627   }
00628   else
00629   {
00630     resource.working_directory = "";
00631   }
00632 
00633   // Process children nodes
00634   xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
00635   while(aCurSubNode != NULL)
00636   {
00637     // Process components
00638     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
00639     {
00640       //If a component is given, it is in a module with the same name
00641       //except if the module name is given
00642       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
00643       {
00644         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
00645         std::string aComponentName = (const char*)component_name;
00646         _resource.ComponentsList.push_back(aComponentName);
00647         if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
00648         {
00649           xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
00650           std::string aModuleName = (const char*)module_name;
00651           _resource.ModulesList.push_back(aModuleName);
00652           xmlFree(module_name);
00653         }
00654         else
00655           _resource.ModulesList.push_back(aComponentName);
00656         xmlFree(component_name);
00657       }
00658     }
00659     // Process modules
00660     else if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
00661     {
00662       // If a module is given, we create an entry in componentsList and modulesList
00663       // with the same name (module == component)
00664       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
00665       {
00666         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
00667         std::string aComponentName = (const char*)component_name;
00668         _resource.ComponentsList.push_back(aComponentName);
00669         _resource.ModulesList.push_back(aComponentName);
00670         xmlFree(component_name);
00671       }
00672     }
00673     aCurSubNode = aCurSubNode->next;
00674   }
00675   return true;
00676 }
00677 
00678 //=============================================================================
00683 //=============================================================================
00684 
00685 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
00686 {
00687   // Node pointers
00688   xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
00689 
00690   root_node = xmlNewNode(NULL, BAD_CAST "resources");
00691   xmlDocSetRootElement(theDoc, root_node);
00692     
00693   std::map<std::string, ParserResourcesType>::iterator iter = _resources_list.begin();
00694   for (; iter != _resources_list.end(); iter++)
00695   {
00696     node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
00697     RES_MESSAGE("Add resource name = " << (*iter).second.Name.c_str());
00698     xmlNewProp(node, BAD_CAST test_name, BAD_CAST (*iter).second.Name.c_str());
00699     xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
00700     xmlNewProp(node, BAD_CAST test_appli_path, BAD_CAST (*iter).second.AppliPath.c_str());
00701     xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
00702     xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
00703     xmlNewProp(node,
00704                BAD_CAST test_protocol,
00705                BAD_CAST ParserResourcesType::protocolToString((*iter).second.Protocol).c_str());
00706     xmlNewProp(node,
00707                BAD_CAST test_cluster_internal_protocol,
00708                BAD_CAST ParserResourcesType::protocolToString((*iter).second.ClusterInternalProtocol).c_str());
00709     xmlNewProp(node, BAD_CAST test_working_directory, BAD_CAST (*iter).second.working_directory.c_str());
00710     if ((*iter).second.is_cluster_head)
00711       xmlNewProp(node, BAD_CAST test_is_cluster_head, BAD_CAST "true");
00712     else
00713       xmlNewProp(node, BAD_CAST test_is_cluster_head, BAD_CAST "false");
00714 
00715     switch ((*iter).second.Mode)
00716     {
00717       case interactive:
00718         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
00719         break;
00720       case batch:
00721         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
00722         break;
00723       default:
00724         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
00725     }
00726 
00727     switch ((*iter).second.Batch)
00728     {
00729       case pbs:
00730         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
00731         break;
00732       case lsf:
00733         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
00734         break;
00735       case sge:
00736         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
00737         break;
00738       case ccc:
00739         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ccc");
00740         break;
00741       case slurm:
00742         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "slurm");
00743         break;
00744       case ssh_batch:
00745         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ssh_batch");
00746         break;
00747       case ll:
00748         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ll");
00749         break;
00750       case vishnu:
00751         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "vishnu");
00752         break;
00753       default:
00754         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
00755     }
00756 
00757     switch ((*iter).second.mpi)
00758     {
00759       case lam:
00760         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
00761         break;
00762       case mpich1:
00763         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
00764         break;
00765       case mpich2:
00766         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
00767         break;
00768       case openmpi:
00769         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
00770         break;
00771       case slurmmpi:
00772         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurmmpi");
00773         break;
00774       case prun:
00775         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
00776         break;
00777       default:
00778         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
00779     }
00780 
00781     xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
00782 
00783     std::vector<std::string>::const_iterator iter2 = (*iter).second.ComponentsList.begin();
00784     for(;iter2 != (*iter).second.ComponentsList.end(); iter2++)
00785     {
00786       node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
00787       xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
00788     }
00789 
00790     xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
00791     std::ostringstream mem_stream;
00792     mem_stream << (*iter).second.DataForSort._memInMB;
00793     xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST mem_stream.str().c_str());
00794     std::ostringstream cpu_stream;
00795     cpu_stream << (*iter).second.DataForSort._CPUFreqMHz;
00796     xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST cpu_stream.str().c_str());
00797     std::ostringstream nb_nodes_stream;
00798     nb_nodes_stream << (*iter).second.DataForSort._nbOfNodes;
00799     xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST nb_nodes_stream.str().c_str());
00800     std::ostringstream nb_proc_per_nodes_stream;
00801     nb_proc_per_nodes_stream << (*iter).second.DataForSort._nbOfProcPerNode;
00802     xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST nb_proc_per_nodes_stream.str().c_str());
00803   }
00804 }