]> SALOME platform Git repositories - modules/kernel.git/blob - src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx
Salome HOME
merge from branch BR_V511_PR 15 12 2009
[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         _resources_list[_resource.Name] = _resource;
133       }
134     }
135     // Cas de la déclaration d'un cluster
136     if (!xmlStrcmp(aCurNode->name,(const xmlChar*)test_cluster))
137     {
138       _resource.Clear();
139       if(ProcessCluster(aCurNode, _resource))
140       {
141         _resources_list[_resource.Name] = _resource;
142       }
143     }
144     aCurNode = aCurNode->next;
145   }
146
147 #ifdef _DEBUG_
148   for (map<string, ParserResourcesType>::const_iterator iter = _resources_list.begin();
149        iter != _resources_list.end();
150        iter++)
151   {
152     std::cerr << "************************************************" << std::endl;
153     std::cerr << "Resource " << (*iter).first << " found:" << std::endl;
154     std::cerr << " Name: " << (*iter).second.Name << std::endl;
155     std::cerr << " Hostname: " << (*iter).second.HostName << std::endl;
156     std::cerr << " Username: " << (*iter).second.UserName << std::endl;
157     std::cerr << " Appli path: " <<(*iter).second.AppliPath << std::endl;
158     std::cerr << " OS: " << (*iter).second.OS << std::endl;
159     std::cerr << " Protocol: " << (*iter).second.PrintAccessProtocolType() << std::endl;
160     std::cerr << " Internal Protocol: " <<(*iter).second.PrintClusterInternalProtocol() << std::endl;
161     std::cerr << " Mode: " << (*iter).second.PrintAccessModeType() << std::endl;
162     std::cerr << " Batch Type: " << (*iter).second.PrintBatchType() << std::endl;
163     std::cerr << " MPI Impl: " << (*iter).second.PrintMpiImplType() << std::endl;
164     std::cerr << "************************************************" << std::endl;
165   }
166 #endif
167 }
168
169 bool
170 SALOME_ResourcesCatalog_Handler::ProcessCluster(xmlNodePtr cluster_descr, ParserResourcesType & resource)
171 {
172   // Ajout d'un cluster
173   // hostname, use et nbOfProc sont obligatoires
174   if (xmlHasProp(cluster_descr, (const xmlChar*)test_hostname))
175   {
176     xmlChar* hostname = xmlGetProp(cluster_descr, (const xmlChar*)test_hostname);
177     resource.HostName = (const char*)hostname;
178     xmlFree(hostname);
179   }
180   else
181   {
182     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a hostname" << std::endl;
183     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
184     return false;
185   }
186
187   if (xmlHasProp(cluster_descr, (const xmlChar*)test_name))
188   {
189     xmlChar* name = xmlGetProp(cluster_descr, (const xmlChar*)test_name);
190     resource.Name = (const char*)name;
191     resource.DataForSort._Name = (const char*)name;
192     xmlFree(name);
193   }
194   else
195   {
196     resource.Name = resource.HostName;
197     resource.DataForSort._Name = resource.HostName;
198     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
199   }
200
201   if (xmlHasProp(cluster_descr, (const xmlChar*)test_use))
202   {
203     xmlChar* use = xmlGetProp(cluster_descr, (const xmlChar*)test_use);
204     resource.use = (const char*)use;
205     xmlFree(use);
206   }
207   else
208   {
209     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a use" << std::endl;
210     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
211     return false;
212   }
213
214   if (xmlHasProp(cluster_descr, (const xmlChar*)test_nb_of_proc))
215   {
216     xmlChar* nb_of_proc = xmlGetProp(cluster_descr, (const xmlChar*)test_nb_of_proc);
217     resource.nbOfProc = atoi((const char*)nb_of_proc);
218     xmlFree(nb_of_proc);
219   }
220   else
221   {
222     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a nbOfProc" << std::endl;
223     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
224     return false;
225   }
226
227   if (xmlHasProp(cluster_descr, (const xmlChar*)test_mpi))
228   {
229     xmlChar* mpi = xmlGetProp(cluster_descr, (const xmlChar*)test_mpi);
230     std::string anMpi = (const char*)mpi;
231     xmlFree(mpi);
232     if (anMpi == "lam")
233       resource.mpi = lam;
234     else if (anMpi == "mpich1")
235       resource.mpi = mpich1;
236     else if (anMpi == "mpich2")
237       resource.mpi = mpich2;
238     else if (anMpi == "openmpi")
239       resource.mpi = openmpi;
240     else if  (anMpi == "slurm")
241       resource.mpi = slurm;
242     else if  (anMpi == "prun")
243       resource.mpi = prun;
244     else
245       resource.mpi = nompi;
246   }
247
248   // Parsing des membres du cluster 
249   xmlNodePtr aCurSubNode = cluster_descr->xmlChildrenNode;
250   while(aCurSubNode != NULL)
251   {
252     if (!xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_members))
253     {
254        xmlNodePtr members = aCurSubNode->xmlChildrenNode;
255        while (members != NULL)
256        {
257          // Process members
258          if (!xmlStrcmp(members->name, (const xmlChar*)test_machine))
259          {
260            ParserResourcesClusterMembersType new_member;
261            if (ProcessMember(members, new_member))
262              resource.ClusterMembersList.push_back(new_member);
263          }
264          members = members->next;
265        }
266     }
267     aCurSubNode = aCurSubNode->next;
268   }
269
270   // Test: Il faut au moins un membre pour que le cluster soit correct !
271   if (resource.ClusterMembersList.empty())
272   {
273     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a member" << std::endl;
274     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
275     return false;
276   }
277   return true;
278 }
279
280 bool
281 SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserResourcesClusterMembersType & resource)
282 {
283   if (xmlHasProp(member_descr, (const xmlChar*)test_hostname))
284   {
285     xmlChar* hostname = xmlGetProp(member_descr, (const xmlChar*)test_hostname);
286     resource.HostName = (const char*)hostname;
287     xmlFree(hostname);
288   }
289   else
290   {
291     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a hostname" << std::endl;
292     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
293     return false;
294   }
295
296   if (xmlHasProp(member_descr, (const xmlChar*)test_protocol))
297   {
298     xmlChar* protocol= xmlGetProp(member_descr, (const xmlChar*)test_protocol);
299     switch (protocol[0])
300     {
301       case 'r':
302         resource.Protocol = rsh;
303         break;
304       case 's':
305         resource.Protocol = ssh;
306         break;
307       default:
308         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
309         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
310         return false;
311     }
312     xmlFree(protocol);
313   }
314   else
315   {
316     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
317     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
318     return false;
319   }
320
321   if (xmlHasProp(member_descr, (const xmlChar*)test_cluster_internal_protocol))
322   {
323     xmlChar* iprotocol= xmlGetProp(member_descr, (const xmlChar*)test_cluster_internal_protocol);
324     switch (iprotocol[0])
325     {
326       case 'r':
327         resource.ClusterInternalProtocol = rsh;
328         break;
329       case 's':
330         resource.ClusterInternalProtocol = ssh;
331         break;
332       default:
333         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
334         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
335         return false;
336     }
337     xmlFree(iprotocol);
338   }
339   else
340   {
341     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
342     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
343     return false;
344   }
345
346   if (xmlHasProp(member_descr, (const xmlChar*)test_user_name))
347   {
348     xmlChar* user_name= xmlGetProp(member_descr, (const xmlChar*)test_user_name);
349     resource.UserName = (const char*)user_name;
350     xmlFree(user_name);
351   }
352   else
353   {
354     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a user name" << std::endl;
355     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
356     return false;
357   }
358
359   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_nodes))
360   {
361     xmlChar* nb_of_nodes = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_nodes);
362     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
363     xmlFree(nb_of_nodes);
364   }
365   else
366   {
367     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfNodes" << std::endl;
368     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
369     return false;
370   }
371
372   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node))
373   {
374     xmlChar* nb_of_proc_per_node = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node);
375     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
376     xmlFree(nb_of_proc_per_node);
377   }
378   else
379   {
380     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfProcPerNode" << std::endl;
381     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
382     return false;
383   }
384
385   if (xmlHasProp(member_descr, (const xmlChar*)test_appli_path))
386   {
387     xmlChar* appli_path = xmlGetProp(member_descr, (const xmlChar*)test_appli_path);
388     resource.AppliPath = (const char*)appli_path;
389     xmlFree(appli_path);
390   }
391   else
392   {
393     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a AppliPath" << std::endl;
394     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
395     return false;
396   }
397   return true;
398 }
399
400 bool
401 SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, ParserResourcesType & resource)
402 {
403   if (xmlHasProp(machine_descr, (const xmlChar*)test_hostname))
404   {
405     xmlChar* hostname = xmlGetProp(machine_descr, (const xmlChar*)test_hostname);
406     resource.HostName = (const char*)hostname;
407     xmlFree(hostname);
408   }
409   else
410   {
411     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning found a machine without a hostname" << std::endl;
412     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning this machine will not be added" << std::endl;
413     return false;
414   }
415
416   if (xmlHasProp(machine_descr, (const xmlChar*)test_name))
417   {
418     xmlChar* name = xmlGetProp(machine_descr, (const xmlChar*)test_name);
419     resource.Name = (const char*)name;
420     resource.DataForSort._Name = (const char*)name;
421     xmlFree(name);
422   }
423   else
424   {
425     resource.Name = resource.HostName;
426     resource.DataForSort._Name = resource.HostName;
427     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
428   }
429
430   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch_queue))
431   {
432     xmlChar* batch_queue = xmlGetProp(machine_descr, (const xmlChar*)test_batch_queue);
433     resource.batchQueue = (const char*)batch_queue;
434     xmlFree(batch_queue);
435   }
436   else
437     resource.batchQueue = "";
438
439   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_commands))
440   {
441     xmlChar* user_commands= xmlGetProp(machine_descr, (const xmlChar*)test_user_commands);
442     resource.userCommands = (const char*)user_commands;
443     xmlFree(user_commands);
444   }
445   else
446     resource.userCommands = "";
447
448   if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
449   {
450     xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
451     switch ( protocol[0])
452     {
453       case 'r':
454         resource.Protocol = rsh;
455         break;
456       case 's':
457         resource.Protocol = ssh;
458         break;
459       default:
460         // If it'not in all theses cases, the protocol is affected to rsh
461         resource.Protocol = rsh;
462         break;
463     }
464     xmlFree(protocol);
465   }
466   else
467     resource.Protocol = rsh;
468
469   if (xmlHasProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol))
470   {
471     xmlChar* iprotocol= xmlGetProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol);
472     switch ( iprotocol[0])
473     {
474       case 'r':
475         resource.ClusterInternalProtocol = rsh;
476         break;
477       case 's':
478         resource.ClusterInternalProtocol = ssh;
479         break;
480       default:
481         // If it'not in all theses cases, the protocol is affected to rsh
482         resource.ClusterInternalProtocol = rsh;
483         break;
484     }
485     xmlFree(iprotocol);
486   }
487   else
488     resource.ClusterInternalProtocol = resource.Protocol;
489
490   if (xmlHasProp(machine_descr, (const xmlChar*)test_mode))
491   {
492     xmlChar* mode=xmlGetProp(machine_descr, (const xmlChar*)test_mode);
493     switch ( mode[0] )
494     {
495       case 'i':
496         resource.Mode = interactive;
497         break;
498       case 'b':
499         resource.Mode = batch;
500         break;
501       default:
502         // If it'not in all theses cases, the mode is affected to interactive
503         resource.Mode = interactive;
504         break;
505     }
506     xmlFree(mode);
507   }
508   else
509     resource.Mode = interactive;
510
511   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch))
512   {
513     xmlChar* batch = xmlGetProp(machine_descr, (const xmlChar*)test_batch);
514     std::string aBatch = (const char*)batch;
515     xmlFree(batch);
516     if (aBatch == "pbs")
517       resource.Batch = pbs;
518     else if  (aBatch == "lsf")
519       resource.Batch = lsf;
520     else if  (aBatch == "sge")
521       resource.Batch = sge;
522     else if  (aBatch == "ssh_batch")
523       resource.Batch = ssh_batch;
524     else
525       resource.Batch = none;
526   }
527
528   if (xmlHasProp(machine_descr, (const xmlChar*)test_mpi))
529   {
530     xmlChar* mpi = xmlGetProp(machine_descr, (const xmlChar*)test_mpi);
531     std::string anMpi = (const char*)mpi;
532     xmlFree(mpi);
533     if (anMpi == "lam")
534       resource.mpi = lam;
535     else if (anMpi == "mpich1")
536       resource.mpi = mpich1;
537     else if (anMpi == "mpich2")
538       resource.mpi = mpich2;
539     else if (anMpi == "openmpi")
540       resource.mpi = openmpi;
541     else if  (anMpi == "slurm")
542       resource.mpi = slurm;
543     else if  (anMpi == "prun")
544       resource.mpi = prun;
545     else
546       resource.mpi = nompi;
547   }
548
549   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_name))
550   {
551     xmlChar* user_name= xmlGetProp(machine_descr, (const xmlChar*)test_user_name);
552     resource.UserName = (const char*)user_name;
553     xmlFree(user_name);
554   }
555
556   if (xmlHasProp(machine_descr, (const xmlChar*)test_appli_path))
557   {
558     xmlChar* appli_path = xmlGetProp(machine_descr, (const xmlChar*)test_appli_path);
559     resource.AppliPath = (const char*)appli_path;
560     xmlFree(appli_path);
561   }
562
563   if (xmlHasProp(machine_descr, (const xmlChar*)test_os))
564   {
565     xmlChar* os = xmlGetProp(machine_descr, (const xmlChar*)test_os);
566     resource.OS = (const char*)os;
567     xmlFree(os);
568   }
569
570   if (xmlHasProp(machine_descr, (const xmlChar*)test_mem_in_mb))
571   {
572     xmlChar* mem_in_mb = xmlGetProp(machine_descr, (const xmlChar*)test_mem_in_mb);
573     resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
574     xmlFree(mem_in_mb);
575   }
576
577   if (xmlHasProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz))
578   {
579     xmlChar* cpu_freq_mhz = xmlGetProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz);
580     resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
581     xmlFree(cpu_freq_mhz);
582   }
583
584   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_nodes))
585   {
586     xmlChar* nb_of_nodes = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_nodes);
587     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
588     xmlFree(nb_of_nodes);
589   }
590
591   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node))
592   {
593     xmlChar* nb_of_proc_per_node = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node);
594     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
595     xmlFree(nb_of_proc_per_node);
596   }
597
598   // Process children nodes
599   xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
600   while(aCurSubNode != NULL)
601   {
602     // Process components
603     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
604     {
605       //If a component is given, it is in a module with the same name
606       //except if the module name is given
607       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
608       {
609         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
610         std::string aComponentName = (const char*)component_name;
611         _resource.ComponentsList.push_back(aComponentName);
612         if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
613         {
614           xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
615           std::string aModuleName = (const char*)module_name;
616           _resource.ModulesList.push_back(aModuleName);
617           xmlFree(module_name);
618         }
619         else
620           _resource.ModulesList.push_back(aComponentName);
621         xmlFree(component_name);
622       }
623     }
624     // Process modules
625     else if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
626     {
627       // If a module is given, we create an entry in componentsList and modulesList
628       // with the same name (module == component)
629       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
630       {
631         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
632         std::string aComponentName = (const char*)component_name;
633         _resource.ComponentsList.push_back(aComponentName);
634         _resource.ModulesList.push_back(aComponentName);
635         xmlFree(component_name);
636       }
637     }
638     aCurSubNode = aCurSubNode->next;
639   }
640   return true;
641 }
642
643 //=============================================================================
644 /*!
645  *  Fill the document tree in xml file, used to write in an xml file.
646  *  \param theDoc document to fill.
647  */ 
648 //=============================================================================
649
650 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
651 {
652   // Node pointers
653   xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
654   char string_buf[80];
655
656   root_node = xmlNewNode(NULL, BAD_CAST "resources");
657   xmlDocSetRootElement(theDoc, root_node);
658     
659   std::map<std::string, ParserResourcesType>::iterator iter = _resources_list.begin();
660   for (; iter != _resources_list.end(); iter++)
661   {
662     node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
663     xmlNewProp(node, BAD_CAST test_name, BAD_CAST (*iter).second.Name.c_str());
664     xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
665     xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
666     xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
667
668     switch ((*iter).second.Protocol)
669     {
670       case rsh:
671         xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
672         break;
673       case ssh:
674         xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
675         break;
676       default:
677         xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
678     }
679
680     switch ((*iter).second.ClusterInternalProtocol)
681     {
682       case rsh:
683         xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
684         break;
685       case ssh:
686         xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "ssh");
687         break;
688       default:
689         xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
690     }
691
692     switch ((*iter).second.Mode)
693     {
694       case interactive:
695         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
696         break;
697       case batch:
698         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
699         break;
700       default:
701         xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
702     }
703
704     switch ((*iter).second.Batch)
705     {
706       case pbs:
707         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
708         break;
709       case lsf:
710         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
711         break;
712       case sge:
713         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
714         break;
715       case ssh_batch:
716         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ssh_batch");
717         break;
718       default:
719         xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
720     }
721
722     switch ((*iter).second.mpi)
723     {
724       case lam:
725         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
726         break;
727       case mpich1:
728         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
729         break;
730       case mpich2:
731         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
732         break;
733       case openmpi:
734         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
735         break;
736       case slurm:
737         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
738         break;
739       case prun:
740         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
741         break;
742       default:
743         xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
744     }
745
746     xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
747
748     std::vector<std::string>::const_iterator iter2 = (*iter).second.ComponentsList.begin();
749     for(;iter2 != (*iter).second.ComponentsList.end(); iter2++)
750     {
751       node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
752       xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
753     }
754
755     xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
756     xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
757     xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
758     xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
759     xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
760   }
761 }