]> SALOME platform Git repositories - modules/kernel.git/blob - src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx
Salome HOME
Merge from mergeto_V5_1_main_19Jan10
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesCatalog_Handler.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
23 //  File   : SALOME_ResourcesCatalog_Handler.cxx
24 //  Author : Estelle Deville
25 //  Module : SALOME
26 //$Header$
27 //
28 #include "SALOME_ResourcesCatalog_Handler.hxx"
29 #include "Basics_Utils.hxx"
30 #include <iostream>
31 #include <map>
32
33 using namespace std;
34
35 //=============================================================================
36 /*!
37  *  Constructor
38  *  \param listOfResources: map of ParserResourcesType to fill when parsing
39  */ 
40 //=============================================================================
41
42 SALOME_ResourcesCatalog_Handler::
43 SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& resources_list): _resources_list(resources_list)
44 {
45   //XML tags initialisation
46   test_machine = "machine";
47   test_cluster = "cluster";
48   test_name = "name";
49   test_hostname = "hostname";
50   test_protocol = "protocol";
51   test_cluster_internal_protocol = "iprotocol";
52   test_mode = "mode";
53   test_batch = "batch";
54   test_mpi = "mpi";
55   test_user_name = "userName";
56   test_appli_path = "appliPath";
57   test_modules = "modules";
58   test_module_name = "moduleName";
59   test_components = "component";
60   test_component_name = "name";
61   test_os = "OS";
62   test_mem_in_mb = "memInMB";
63   test_cpu_freq_mhz = "CPUFreqMHz";
64   test_nb_of_nodes = "nbOfNodes";
65   test_nb_of_proc = "nbOfProc";
66   test_nb_of_proc_per_node = "nbOfProcPerNode";
67   test_batch_queue = "batchQueue";
68   test_user_commands = "userCommands";
69   test_use = "use";
70   test_members = "members";
71 }
72
73 //=============================================================================
74 /*!
75  *  Destructor
76  */ 
77 //=============================================================================
78
79 SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
80 {
81   //  cout << "SALOME_ResourcesCatalog_Handler destruction") << endl;
82 }
83
84 //=============================================================================
85 /*!
86  *  Retrieves DS after the file parse.
87  */ 
88 //=============================================================================
89
90 const MapOfParserResourcesType&
91 SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
92 {
93   return _resources_list;
94 }
95
96 //=============================================================================
97 /*!
98  *  Processes XML document and fills the list of resources
99  */ 
100 //=============================================================================
101
102 void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
103 {
104   // Empty private elements
105   _resources_list.clear();
106
107   // Get the document root node
108   xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
109
110   aCurNode = aCurNode->xmlChildrenNode;
111  
112   // Processing the document nodes
113   while(aCurNode != NULL)
114   {
115     // Cas d'une machine ou d'une machine batch
116     if (!xmlStrcmp(aCurNode->name,(const xmlChar*)test_machine))
117     {
118       _resource.Clear();
119       bool Ok = ProcessMachine(aCurNode, _resource);
120       if (Ok)
121       {
122         // Adding a resource
123         if(_resource.HostName == "localhost")
124         {
125           _resource.HostName = Kernel_Utils::GetHostname();
126           if (_resource.Name == "localhost")
127           {
128             _resource.Name = Kernel_Utils::GetHostname();
129             _resource.DataForSort._Name = Kernel_Utils::GetHostname();
130           }
131         }
132         map<string, ParserResourcesType>::const_iterator iter = _resources_list.find(_resource.Name);
133         if (iter != _resources_list.end())
134           RES_INFOS("Warning resource " << _resource.Name << " already added, keep last resource found !");
135         _resources_list[_resource.Name] = _resource;
136       }
137     }
138     // Cas de la déclaration d'un cluster
139     if (!xmlStrcmp(aCurNode->name,(const xmlChar*)test_cluster))
140     {
141       _resource.Clear();
142       if(ProcessCluster(aCurNode, _resource))
143       {
144         map<string, ParserResourcesType>::const_iterator iter = _resources_list.find(_resource.Name);
145         if (iter != _resources_list.end())
146           RES_INFOS("Warning resource " << _resource.Name << " already added, keep last resource found !");
147         _resources_list[_resource.Name] = _resource;
148       }
149     }
150     aCurNode = aCurNode->next;
151   }
152
153 #ifdef _DEBUG_
154   for (map<string, ParserResourcesType>::const_iterator iter = _resources_list.begin();
155        iter != _resources_list.end();
156        iter++)
157   {
158     std::cerr << "************************************************" << std::endl;
159     std::cerr << "Resource " << (*iter).first << " found:" << std::endl;
160     std::cerr << " Name: " << (*iter).second.Name << std::endl;
161     std::cerr << " Hostname: " << (*iter).second.HostName << std::endl;
162     std::cerr << " Username: " << (*iter).second.UserName << std::endl;
163     std::cerr << " Appli path: " <<(*iter).second.AppliPath << std::endl;
164     std::cerr << " OS: " << (*iter).second.OS << std::endl;
165     std::cerr << " Protocol: " << (*iter).second.PrintAccessProtocolType() << std::endl;
166     std::cerr << " Internal Protocol: " <<(*iter).second.PrintClusterInternalProtocol() << std::endl;
167     std::cerr << " Mode: " << (*iter).second.PrintAccessModeType() << std::endl;
168     std::cerr << " Batch Type: " << (*iter).second.PrintBatchType() << std::endl;
169     std::cerr << " MPI Impl: " << (*iter).second.PrintMpiImplType() << std::endl;
170     std::cerr << "************************************************" << std::endl;
171   }
172 #endif
173 }
174
175 bool
176 SALOME_ResourcesCatalog_Handler::ProcessCluster(xmlNodePtr cluster_descr, ParserResourcesType & resource)
177 {
178   // Ajout d'un cluster
179   // hostname, use et nbOfProc sont obligatoires
180   if (xmlHasProp(cluster_descr, (const xmlChar*)test_hostname))
181   {
182     xmlChar* hostname = xmlGetProp(cluster_descr, (const xmlChar*)test_hostname);
183     resource.HostName = (const char*)hostname;
184     xmlFree(hostname);
185   }
186   else
187   {
188     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a hostname" << std::endl;
189     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
190     return false;
191   }
192
193   if (xmlHasProp(cluster_descr, (const xmlChar*)test_name))
194   {
195     xmlChar* name = xmlGetProp(cluster_descr, (const xmlChar*)test_name);
196     resource.Name = (const char*)name;
197     resource.DataForSort._Name = (const char*)name;
198     xmlFree(name);
199   }
200   else
201   {
202     resource.Name = resource.HostName;
203     resource.DataForSort._Name = resource.HostName;
204     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
205   }
206
207   if (xmlHasProp(cluster_descr, (const xmlChar*)test_use))
208   {
209     xmlChar* use = xmlGetProp(cluster_descr, (const xmlChar*)test_use);
210     resource.use = (const char*)use;
211     xmlFree(use);
212   }
213   else
214   {
215     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a use" << std::endl;
216     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
217     return false;
218   }
219
220   if (xmlHasProp(cluster_descr, (const xmlChar*)test_nb_of_proc))
221   {
222     xmlChar* nb_of_proc = xmlGetProp(cluster_descr, (const xmlChar*)test_nb_of_proc);
223     resource.nbOfProc = atoi((const char*)nb_of_proc);
224     xmlFree(nb_of_proc);
225   }
226   else
227   {
228     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a nbOfProc" << std::endl;
229     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
230     return false;
231   }
232
233   if (xmlHasProp(cluster_descr, (const xmlChar*)test_mpi))
234   {
235     xmlChar* mpi = xmlGetProp(cluster_descr, (const xmlChar*)test_mpi);
236     std::string anMpi = (const char*)mpi;
237     xmlFree(mpi);
238     if (anMpi == "lam")
239       resource.mpi = lam;
240     else if (anMpi == "mpich1")
241       resource.mpi = mpich1;
242     else if (anMpi == "mpich2")
243       resource.mpi = mpich2;
244     else if (anMpi == "openmpi")
245       resource.mpi = openmpi;
246     else if  (anMpi == "slurm")
247       resource.mpi = slurm;
248     else if  (anMpi == "prun")
249       resource.mpi = prun;
250     else
251       resource.mpi = nompi;
252   }
253
254   // Parsing des membres du cluster 
255   xmlNodePtr aCurSubNode = cluster_descr->xmlChildrenNode;
256   while(aCurSubNode != NULL)
257   {
258     if (!xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_members))
259     {
260        xmlNodePtr members = aCurSubNode->xmlChildrenNode;
261        while (members != NULL)
262        {
263          // Process members
264          if (!xmlStrcmp(members->name, (const xmlChar*)test_machine))
265          {
266            ParserResourcesClusterMembersType new_member;
267            if (ProcessMember(members, new_member))
268              resource.ClusterMembersList.push_back(new_member);
269          }
270          members = members->next;
271        }
272     }
273     aCurSubNode = aCurSubNode->next;
274   }
275
276   // Test: Il faut au moins un membre pour que le cluster soit correct !
277   if (resource.ClusterMembersList.empty())
278   {
279     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a member" << std::endl;
280     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
281     return false;
282   }
283   return true;
284 }
285
286 bool
287 SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserResourcesClusterMembersType & resource)
288 {
289   if (xmlHasProp(member_descr, (const xmlChar*)test_hostname))
290   {
291     xmlChar* hostname = xmlGetProp(member_descr, (const xmlChar*)test_hostname);
292     resource.HostName = (const char*)hostname;
293     xmlFree(hostname);
294   }
295   else
296   {
297     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a hostname" << std::endl;
298     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
299     return false;
300   }
301
302   if (xmlHasProp(member_descr, (const xmlChar*)test_protocol))
303   {
304     xmlChar* protocol= xmlGetProp(member_descr, (const xmlChar*)test_protocol);
305     switch (protocol[0])
306     {
307       case 'r':
308         resource.Protocol = rsh;
309         break;
310       case 's':
311         resource.Protocol = ssh;
312         break;
313       default:
314         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
315         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
316         return false;
317     }
318     xmlFree(protocol);
319   }
320   else
321   {
322     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
323     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
324     return false;
325   }
326
327   if (xmlHasProp(member_descr, (const xmlChar*)test_cluster_internal_protocol))
328   {
329     xmlChar* iprotocol= xmlGetProp(member_descr, (const xmlChar*)test_cluster_internal_protocol);
330     switch (iprotocol[0])
331     {
332       case 'r':
333         resource.ClusterInternalProtocol = rsh;
334         break;
335       case 's':
336         resource.ClusterInternalProtocol = ssh;
337         break;
338       default:
339         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
340         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
341         return false;
342     }
343     xmlFree(iprotocol);
344   }
345   else
346   {
347     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
348     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
349     return false;
350   }
351
352   if (xmlHasProp(member_descr, (const xmlChar*)test_user_name))
353   {
354     xmlChar* user_name= xmlGetProp(member_descr, (const xmlChar*)test_user_name);
355     resource.UserName = (const char*)user_name;
356     xmlFree(user_name);
357   }
358   else
359   {
360     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a user name" << std::endl;
361     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
362     return false;
363   }
364
365   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_nodes))
366   {
367     xmlChar* nb_of_nodes = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_nodes);
368     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
369     xmlFree(nb_of_nodes);
370   }
371   else
372   {
373     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfNodes" << std::endl;
374     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
375     return false;
376   }
377
378   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node))
379   {
380     xmlChar* nb_of_proc_per_node = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node);
381     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
382     xmlFree(nb_of_proc_per_node);
383   }
384   else
385   {
386     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfProcPerNode" << std::endl;
387     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
388     return false;
389   }
390
391   if (xmlHasProp(member_descr, (const xmlChar*)test_appli_path))
392   {
393     xmlChar* appli_path = xmlGetProp(member_descr, (const xmlChar*)test_appli_path);
394     resource.AppliPath = (const char*)appli_path;
395     xmlFree(appli_path);
396   }
397   else
398   {
399     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a AppliPath" << std::endl;
400     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
401     return false;
402   }
403   return true;
404 }
405
406 bool
407 SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, ParserResourcesType & resource)
408 {
409   if (xmlHasProp(machine_descr, (const xmlChar*)test_hostname))
410   {
411     xmlChar* hostname = xmlGetProp(machine_descr, (const xmlChar*)test_hostname);
412     resource.HostName = (const char*)hostname;
413     xmlFree(hostname);
414   }
415   else
416   {
417     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning found a machine without a hostname" << std::endl;
418     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning this machine will not be added" << std::endl;
419     return false;
420   }
421
422   if (xmlHasProp(machine_descr, (const xmlChar*)test_name))
423   {
424     xmlChar* name = xmlGetProp(machine_descr, (const xmlChar*)test_name);
425     resource.Name = (const char*)name;
426     resource.DataForSort._Name = (const char*)name;
427     xmlFree(name);
428   }
429   else
430   {
431     resource.Name = resource.HostName;
432     resource.DataForSort._Name = resource.HostName;
433     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
434   }
435
436   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch_queue))
437   {
438     xmlChar* batch_queue = xmlGetProp(machine_descr, (const xmlChar*)test_batch_queue);
439     resource.batchQueue = (const char*)batch_queue;
440     xmlFree(batch_queue);
441   }
442   else
443     resource.batchQueue = "";
444
445   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_commands))
446   {
447     xmlChar* user_commands= xmlGetProp(machine_descr, (const xmlChar*)test_user_commands);
448     resource.userCommands = (const char*)user_commands;
449     xmlFree(user_commands);
450   }
451   else
452     resource.userCommands = "";
453
454   if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
455   {
456     xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
457     switch ( protocol[0])
458     {
459       case 'r':
460         resource.Protocol = rsh;
461         break;
462       case 's':
463         resource.Protocol = ssh;
464         break;
465       default:
466         // If it'not in all theses cases, the protocol is affected to rsh
467         resource.Protocol = rsh;
468         break;
469     }
470     xmlFree(protocol);
471   }
472   else
473     resource.Protocol = rsh;
474
475   if (xmlHasProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol))
476   {
477     xmlChar* iprotocol= xmlGetProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol);
478     switch ( iprotocol[0])
479     {
480       case 'r':
481         resource.ClusterInternalProtocol = rsh;
482         break;
483       case 's':
484         resource.ClusterInternalProtocol = ssh;
485         break;
486       default:
487         // If it'not in all theses cases, the protocol is affected to rsh
488         resource.ClusterInternalProtocol = rsh;
489         break;
490     }
491     xmlFree(iprotocol);
492   }
493   else
494     resource.ClusterInternalProtocol = resource.Protocol;
495
496   if (xmlHasProp(machine_descr, (const xmlChar*)test_mode))
497   {
498     xmlChar* mode=xmlGetProp(machine_descr, (const xmlChar*)test_mode);
499     switch ( mode[0] )
500     {
501       case 'i':
502         resource.Mode = interactive;
503         break;
504       case 'b':
505         resource.Mode = batch;
506         break;
507       default:
508         // If it'not in all theses cases, the mode is affected to interactive
509         resource.Mode = interactive;
510         break;
511     }
512     xmlFree(mode);
513   }
514   else
515     resource.Mode = interactive;
516
517   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch))
518   {
519     xmlChar* batch = xmlGetProp(machine_descr, (const xmlChar*)test_batch);
520     std::string aBatch = (const char*)batch;
521     xmlFree(batch);
522     if (aBatch == "pbs")
523       resource.Batch = pbs;
524     else if  (aBatch == "lsf")
525       resource.Batch = lsf;
526     else if  (aBatch == "sge")
527       resource.Batch = sge;
528     else if  (aBatch == "ssh_batch")
529       resource.Batch = ssh_batch;
530     else
531       resource.Batch = none;
532   }
533
534   if (xmlHasProp(machine_descr, (const xmlChar*)test_mpi))
535   {
536     xmlChar* mpi = xmlGetProp(machine_descr, (const xmlChar*)test_mpi);
537     std::string anMpi = (const char*)mpi;
538     xmlFree(mpi);
539     if (anMpi == "lam")
540       resource.mpi = lam;
541     else if (anMpi == "mpich1")
542       resource.mpi = mpich1;
543     else if (anMpi == "mpich2")
544       resource.mpi = mpich2;
545     else if (anMpi == "openmpi")
546       resource.mpi = openmpi;
547     else if  (anMpi == "slurm")
548       resource.mpi = slurm;
549     else if  (anMpi == "prun")
550       resource.mpi = prun;
551     else
552       resource.mpi = nompi;
553   }
554
555   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_name))
556   {
557     xmlChar* user_name= xmlGetProp(machine_descr, (const xmlChar*)test_user_name);
558     resource.UserName = (const char*)user_name;
559     xmlFree(user_name);
560   }
561
562   if (xmlHasProp(machine_descr, (const xmlChar*)test_appli_path))
563   {
564     xmlChar* appli_path = xmlGetProp(machine_descr, (const xmlChar*)test_appli_path);
565     resource.AppliPath = (const char*)appli_path;
566     xmlFree(appli_path);
567   }
568
569   if (xmlHasProp(machine_descr, (const xmlChar*)test_os))
570   {
571     xmlChar* os = xmlGetProp(machine_descr, (const xmlChar*)test_os);
572     resource.OS = (const char*)os;
573     xmlFree(os);
574   }
575
576   if (xmlHasProp(machine_descr, (const xmlChar*)test_mem_in_mb))
577   {
578     xmlChar* mem_in_mb = xmlGetProp(machine_descr, (const xmlChar*)test_mem_in_mb);
579     resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
580     xmlFree(mem_in_mb);
581   }
582
583   if (xmlHasProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz))
584   {
585     xmlChar* cpu_freq_mhz = xmlGetProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz);
586     resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
587     xmlFree(cpu_freq_mhz);
588   }
589
590   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_nodes))
591   {
592     xmlChar* nb_of_nodes = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_nodes);
593     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
594     xmlFree(nb_of_nodes);
595   }
596
597   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node))
598   {
599     xmlChar* nb_of_proc_per_node = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node);
600     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
601     xmlFree(nb_of_proc_per_node);
602   }
603
604   // Process children nodes
605   xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
606   while(aCurSubNode != NULL)
607   {
608     // Process components
609     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
610     {
611       //If a component is given, it is in a module with the same name
612       //except if the module name is given
613       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
614       {
615         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
616         std::string aComponentName = (const char*)component_name;
617         _resource.ComponentsList.push_back(aComponentName);
618         if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
619         {
620           xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
621           std::string aModuleName = (const char*)module_name;
622           _resource.ModulesList.push_back(aModuleName);
623           xmlFree(module_name);
624         }
625         else
626           _resource.ModulesList.push_back(aComponentName);
627         xmlFree(component_name);
628       }
629     }
630     // Process modules
631     else if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
632     {
633       // If a module is given, we create an entry in componentsList and modulesList
634       // with the same name (module == component)
635       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
636       {
637         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
638         std::string aComponentName = (const char*)component_name;
639         _resource.ComponentsList.push_back(aComponentName);
640         _resource.ModulesList.push_back(aComponentName);
641         xmlFree(component_name);
642       }
643     }
644     aCurSubNode = aCurSubNode->next;
645   }
646   return true;
647 }
648
649 //=============================================================================
650 /*!
651  *  Fill the document tree in xml file, used to write in an xml file.
652  *  \param theDoc document to fill.
653  */ 
654 //=============================================================================
655
656 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
657 {
658   // Node pointers
659   xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
660   char string_buf[80];
661
662   root_node = xmlNewNode(NULL, BAD_CAST "resources");
663   xmlDocSetRootElement(theDoc, root_node);
664     
665   std::map<std::string, ParserResourcesType>::iterator iter = _resources_list.begin();
666   for (; iter != _resources_list.end(); iter++)
667   {
668     node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
669     xmlNewProp(node, BAD_CAST test_name, BAD_CAST (*iter).second.Name.c_str());
670     xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
671     xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
672     xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
673
674     switch ((*iter).second.Protocol)
675     {
676       case rsh:
677         xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
678         break;
679       case ssh:
680         xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
681         break;
682       default:
683         xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
684     }
685
686     switch ((*iter).second.ClusterInternalProtocol)
687     {
688       case rsh:
689         xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
690         break;
691       case ssh:
692         xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "ssh");
693         break;
694       default:
695         xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
696     }
697
698     switch ((*iter).second.Mode)
699     {
700       case interactive:
701         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
702         break;
703       case batch:
704         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
705         break;
706       default:
707         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
708     }
709
710     switch ((*iter).second.Batch)
711     {
712       case pbs:
713         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
714         break;
715       case lsf:
716         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
717         break;
718       case sge:
719         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
720         break;
721       case ssh_batch:
722         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ssh_batch");
723         break;
724       default:
725         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
726     }
727
728     switch ((*iter).second.mpi)
729     {
730       case lam:
731         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
732         break;
733       case mpich1:
734         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
735         break;
736       case mpich2:
737         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
738         break;
739       case openmpi:
740         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
741         break;
742       case slurm:
743         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
744         break;
745       case prun:
746         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
747         break;
748       default:
749         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
750     }
751
752     xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
753
754     std::vector<std::string>::const_iterator iter2 = (*iter).second.ComponentsList.begin();
755     for(;iter2 != (*iter).second.ComponentsList.end(); iter2++)
756     {
757       node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
758       xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
759     }
760
761     xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
762     xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
763     xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
764     xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
765     xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
766   }
767 }