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