Salome HOME
merge from BR_V51_AR 7 may 09
[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,
44                                 MapOfParserResourcesType& resources_batch_list):
45     _resources_list(resources_list),
46     _resources_batch_list(resources_batch_list)
47 {
48   //XML tags initialisation
49   test_machine = "machine";
50   test_cluster = "cluster";
51   test_hostname = "hostname";
52   test_alias = "alias";
53   test_protocol = "protocol";
54   test_mode = "mode";
55   test_batch = "batch";
56   test_mpi = "mpi";
57   test_user_name = "userName";
58   test_appli_path = "appliPath";
59   test_modules = "modules";
60   test_module_name = "moduleName";
61   test_components = "component";
62   test_component_name = "name";
63   test_os = "OS";
64   test_mem_in_mb = "memInMB";
65   test_cpu_freq_mhz = "CPUFreqMHz";
66   test_nb_of_nodes = "nbOfNodes";
67   test_nb_of_proc = "nbOfProc";
68   test_nb_of_proc_per_node = "nbOfProcPerNode";
69   test_batch_queue = "batchQueue";
70   test_user_commands = "userCommands";
71   test_use = "use";
72   test_members = "members";
73 }
74
75 //=============================================================================
76 /*!
77  *  Destructor
78  */ 
79 //=============================================================================
80
81 SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
82 {
83   //  cout << "SALOME_ResourcesCatalog_Handler destruction") << endl;
84 }
85
86 //=============================================================================
87 /*!
88  *  Retrieves DS after the file parse.
89  */ 
90 //=============================================================================
91
92 const MapOfParserResourcesType&
93 SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
94 {
95   return _resources_list;
96 }
97
98 //=============================================================================
99 /*!
100  *  Processes XML document and fills the list of resources
101  */ 
102 //=============================================================================
103
104 void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
105 {
106   // Empty private elements
107   _resources_list.clear();
108
109   // Get the document root node
110   xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
111
112   aCurNode = aCurNode->xmlChildrenNode;
113  
114   // Processing the document nodes
115   while(aCurNode != NULL)
116   {
117     // Cas d'une machine ou d'une machine batch
118     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_machine) )
119     {
120       _resource.Clear();
121       bool Ok = ProcessMachine(aCurNode, _resource);
122       if (Ok)
123       {
124         // There is two lists
125         // _resources_list for interactive resources
126         // _resources_batch_list for batch resources
127         // This choice is done with Mode parameter
128         if (_resource.Mode == interactive)
129         {
130           // Adding a generic cluster
131           int aNbNodes = _resource.DataForSort._nbOfNodes;
132           if( aNbNodes > 1 ){
133             string clusterNode = _resource.DataForSort._hostName ;
134             for( int i=0; i < aNbNodes; i++ ){
135               char inode[64];
136               inode[0] = '\0' ;
137               sprintf(inode,"%s%d",clusterNode.c_str(),i+1);
138               std::string nodeName(inode);
139               _resource.DataForSort._hostName = nodeName ;
140               _resource.HostName = nodeName ;
141               _resources_list[nodeName] = _resource;
142             }
143           }
144           else
145           {
146             // Adding a machine
147             _resources_list[_resource.HostName] = _resource;
148             if(_resource.HostName == "localhost")
149             {
150               _resource.HostName = Kernel_Utils::GetHostname();
151               _resource.DataForSort._hostName = Kernel_Utils::GetHostname();
152               _resources_list[Kernel_Utils::GetHostname()] = _resource;
153             }
154           }
155         }
156         else
157           // Adding a batch machine/cluster
158           _resources_batch_list[_resource.HostName] = _resource;
159       }
160     }
161     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_cluster) )
162     {
163       // Cas de la déclaration d'un cluster
164       _resource.Clear();
165       if(ProcessCluster(aCurNode, _resource))
166         _resources_list[_resource.HostName] = _resource;
167     }
168     aCurNode = aCurNode->next;
169   }
170
171 #ifdef _DEBUG_
172   for (map<string, ParserResourcesType>::const_iterator iter = _resources_list.begin();
173        iter != _resources_list.end();
174        iter++)
175   {
176     std::cerr << (*iter).first << std::endl;
177     std::cerr << (*iter).second.HostName << std::endl;
178     std::cerr << (*iter).second.Alias << std::endl;
179     std::cerr << (*iter).second.UserName << std::endl;
180     std::cerr << (*iter).second.AppliPath << std::endl;
181     std::cerr << (*iter).second.OS << std::endl;
182     std::cerr << (*iter).second.Protocol << std::endl;
183     std::cerr << (*iter).second.Mode << std::endl;
184   }
185 #endif
186
187 }
188
189 bool
190 SALOME_ResourcesCatalog_Handler::ProcessCluster(xmlNodePtr cluster_descr, ParserResourcesType & resource)
191 {
192   // Ajout d'un cluster
193   // hostname, use et nbOfProc sont obligatoires
194   if (xmlHasProp(cluster_descr, (const xmlChar*)test_hostname))
195   {
196     xmlChar* hostname = xmlGetProp(cluster_descr, (const xmlChar*)test_hostname);
197     resource.DataForSort._hostName = (const char*)hostname;
198     resource.HostName = (const char*)hostname;
199     xmlFree(hostname);
200   }
201   else
202   {
203     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a hostname" << std::endl;
204     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
205     return false;
206   }
207
208   if (xmlHasProp(cluster_descr, (const xmlChar*)test_use))
209   {
210     xmlChar* use = xmlGetProp(cluster_descr, (const xmlChar*)test_use);
211     resource.use = (const char*)use;
212     xmlFree(use);
213   }
214   else
215   {
216     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a use" << std::endl;
217     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
218     return false;
219   }
220
221   if (xmlHasProp(cluster_descr, (const xmlChar*)test_nb_of_proc))
222   {
223     xmlChar* nb_of_proc = xmlGetProp(cluster_descr, (const xmlChar*)test_nb_of_proc);
224     resource.nbOfProc = atoi((const char*)nb_of_proc);
225     xmlFree(nb_of_proc);
226   }
227   else
228   {
229     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a nbOfProc" << std::endl;
230     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
231     return false;
232   }
233
234   if (xmlHasProp(cluster_descr, (const xmlChar*)test_mpi))
235   {
236     xmlChar* mpi = xmlGetProp(cluster_descr, (const xmlChar*)test_mpi);
237     std::string anMpi = (const char*)mpi;
238     xmlFree(mpi);
239     if (anMpi == "lam")
240       resource.mpi = lam;
241     else if (anMpi == "mpich1")
242       resource.mpi = mpich1;
243     else if (anMpi == "mpich2")
244       resource.mpi = mpich2;
245     else if (anMpi == "openmpi")
246       resource.mpi = openmpi;
247     else if  (anMpi == "slurm")
248       resource.mpi = slurm;
249     else if  (anMpi == "prun")
250       resource.mpi = prun;
251     else
252       resource.mpi = nompi;
253   }
254
255   // Parsing des membres du cluster 
256   xmlNodePtr aCurSubNode = cluster_descr->xmlChildrenNode;
257   while(aCurSubNode != NULL)
258   {
259     if (!xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_members))
260     {
261        xmlNodePtr members = aCurSubNode->xmlChildrenNode;
262        while (members != NULL)
263        {
264          // Process members
265          if (!xmlStrcmp(members->name, (const xmlChar*)test_machine))
266          {
267            ParserResourcesClusterMembersType new_member;
268            if (ProcessMember(members, new_member))
269              resource.ClusterMembersList.push_back(new_member);
270          }
271          members = members->next;
272        }
273     }
274     aCurSubNode = aCurSubNode->next;
275   }
276
277   // Test: Il faut au moins un membre pour que le cluster soit correct !
278   if (resource.ClusterMembersList.empty())
279   {
280     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a member" << std::endl;
281     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
282     return false;
283   }
284   return true;
285 }
286
287 bool
288 SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserResourcesClusterMembersType & resource)
289 {
290   if (xmlHasProp(member_descr, (const xmlChar*)test_hostname))
291   {
292     xmlChar* hostname = xmlGetProp(member_descr, (const xmlChar*)test_hostname);
293     resource.DataForSort._hostName = (const char*)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_user_name))
330   {
331     xmlChar* user_name= xmlGetProp(member_descr, (const xmlChar*)test_user_name);
332     resource.UserName = (const char*)user_name;
333     xmlFree(user_name);
334   }
335   else
336   {
337     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a user name" << std::endl;
338     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
339     return false;
340   }
341
342   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_nodes))
343   {
344     xmlChar* nb_of_nodes = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_nodes);
345     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
346     xmlFree(nb_of_nodes);
347   }
348   else
349   {
350     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfNodes" << std::endl;
351     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
352     return false;
353   }
354
355   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node))
356   {
357     xmlChar* nb_of_proc_per_node = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node);
358     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
359     xmlFree(nb_of_proc_per_node);
360   }
361   else
362   {
363     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfProcPerNode" << std::endl;
364     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
365     return false;
366   }
367
368   if (xmlHasProp(member_descr, (const xmlChar*)test_appli_path))
369   {
370     xmlChar* appli_path = xmlGetProp(member_descr, (const xmlChar*)test_appli_path);
371     resource.AppliPath = (const char*)appli_path;
372     xmlFree(appli_path);
373   }
374   else
375   {
376     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a AppliPath" << std::endl;
377     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
378     return false;
379   }
380 }
381
382 bool
383 SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, ParserResourcesType & resource)
384 {
385   if (xmlHasProp(machine_descr, (const xmlChar*)test_hostname))
386   {
387     xmlChar* hostname = xmlGetProp(machine_descr, (const xmlChar*)test_hostname);
388     resource.DataForSort._hostName = (const char*)hostname;
389     resource.HostName = (const char*)hostname;
390     xmlFree(hostname);
391   }
392   else
393   {
394     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning found a machine without a hostname" << std::endl;
395     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning this machine will not be added" << std::endl;
396     return false;
397   }
398
399   if (xmlHasProp(machine_descr, (const xmlChar*)test_alias))
400   {
401     xmlChar* alias = xmlGetProp(machine_descr, (const xmlChar*)test_alias);
402     resource.Alias = (const char*)alias;
403     xmlFree(alias);
404   }
405   else
406     resource.Alias = "";
407
408   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch_queue))
409   {
410     xmlChar* batch_queue = xmlGetProp(machine_descr, (const xmlChar*)test_batch_queue);
411     resource.batchQueue = (const char*)batch_queue;
412     xmlFree(batch_queue);
413   }
414   else
415     resource.batchQueue = "";
416
417   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_commands))
418   {
419     xmlChar* user_commands= xmlGetProp(machine_descr, (const xmlChar*)test_user_commands);
420     resource.userCommands = (const char*)user_commands;
421     xmlFree(user_commands);
422   }
423   else
424     resource.userCommands = "";
425
426   if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
427   {
428     xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
429     switch ( protocol[0])
430     {
431       case 'r':
432         resource.Protocol = rsh;
433         break;
434       case 's':
435         resource.Protocol = ssh;
436         break;
437       default:
438         // If it'not in all theses cases, the protocol is affected to rsh
439         resource.Protocol = rsh;
440         break;
441     }
442     xmlFree(protocol);
443   }
444   else
445     resource.Protocol = rsh;
446
447   if (xmlHasProp(machine_descr, (const xmlChar*)test_mode))
448   {
449     xmlChar* mode=xmlGetProp(machine_descr, (const xmlChar*)test_mode);
450     switch ( mode[0] )
451     {
452       case 'i':
453         resource.Mode = interactive;
454         break;
455       case 'b':
456         resource.Mode = batch;
457         break;
458       default:
459         // If it'not in all theses cases, the mode is affected to interactive
460         resource.Mode = interactive;
461         break;
462     }
463     xmlFree(mode);
464   }
465   else
466     resource.Mode = interactive;
467
468   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch))
469   {
470     xmlChar* batch = xmlGetProp(machine_descr, (const xmlChar*)test_batch);
471     std::string aBatch = (const char*)batch;
472     xmlFree(batch);
473     if (aBatch == "pbs")
474       resource.Batch = pbs;
475     else if  (aBatch == "lsf")
476       resource.Batch = lsf;
477     else if  (aBatch == "sge")
478       resource.Batch = sge;
479     else
480       resource.Batch = none;
481   }
482
483   if (xmlHasProp(machine_descr, (const xmlChar*)test_mpi))
484   {
485     xmlChar* mpi = xmlGetProp(machine_descr, (const xmlChar*)test_mpi);
486     std::string anMpi = (const char*)mpi;
487     xmlFree(mpi);
488     if (anMpi == "lam")
489       resource.mpi = lam;
490     else if (anMpi == "mpich1")
491       resource.mpi = mpich1;
492     else if (anMpi == "mpich2")
493       resource.mpi = mpich2;
494     else if (anMpi == "openmpi")
495       resource.mpi = openmpi;
496     else if  (anMpi == "slurm")
497       resource.mpi = slurm;
498     else if  (anMpi == "prun")
499       resource.mpi = prun;
500     else
501       resource.mpi = nompi;
502   }
503
504   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_name))
505   {
506     xmlChar* user_name= xmlGetProp(machine_descr, (const xmlChar*)test_user_name);
507     resource.UserName = (const char*)user_name;
508     xmlFree(user_name);
509   }
510
511   if (xmlHasProp(machine_descr, (const xmlChar*)test_appli_path))
512   {
513     xmlChar* appli_path = xmlGetProp(machine_descr, (const xmlChar*)test_appli_path);
514     resource.AppliPath = (const char*)appli_path;
515     xmlFree(appli_path);
516   }
517
518   if (xmlHasProp(machine_descr, (const xmlChar*)test_os))
519   {
520     xmlChar* os = xmlGetProp(machine_descr, (const xmlChar*)test_os);
521     resource.OS = (const char*)os;
522     xmlFree(os);
523   }
524
525   if (xmlHasProp(machine_descr, (const xmlChar*)test_mem_in_mb))
526   {
527     xmlChar* mem_in_mb = xmlGetProp(machine_descr, (const xmlChar*)test_mem_in_mb);
528     resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
529     xmlFree(mem_in_mb);
530   }
531
532   if (xmlHasProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz))
533   {
534     xmlChar* cpu_freq_mhz = xmlGetProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz);
535     resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
536     xmlFree(cpu_freq_mhz);
537   }
538
539   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_nodes))
540   {
541     xmlChar* nb_of_nodes = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_nodes);
542     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
543     xmlFree(nb_of_nodes);
544   }
545
546   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node))
547   {
548     xmlChar* nb_of_proc_per_node = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node);
549     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
550     xmlFree(nb_of_proc_per_node);
551   }
552
553   // Process children nodes
554   xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
555   while(aCurSubNode != NULL)
556   {
557     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
558     {
559       //If a component is given, it is in a module with the same name
560       //except if the module name is given
561       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
562       {
563         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
564         std::string aComponentName = (const char*)component_name;
565         _resource.ComponentsList.push_back(aComponentName);
566         if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
567         {
568           xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
569           std::string aModuleName = (const char*)module_name;
570           _resource.ModulesList.push_back(aModuleName);
571           xmlFree(module_name);
572         }
573         else
574           _resource.ModulesList.push_back(aComponentName);
575         xmlFree(component_name);
576       }
577     }
578     // Process modules
579     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
580     {
581       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
582       {
583         xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
584         std::string aModuleName = (const char*)module_name;
585         resource.ModulesList.push_back(aModuleName);
586         xmlFree(module_name);
587       }
588     }
589     aCurSubNode = aCurSubNode->next;
590   }
591   return true;
592 }
593
594 //=============================================================================
595 /*!
596  *  Fill the document tree in xml file, used to write in an xml file.
597  *  \param theDoc document to fill.
598  */ 
599 //=============================================================================
600
601 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
602 {
603   // Node pointers
604   xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
605   char string_buf[80];
606
607   root_node = xmlNewNode(NULL, BAD_CAST "resources");
608   xmlDocSetRootElement(theDoc, root_node);
609     
610   for (map<string, ParserResourcesType>::iterator iter =
611          _resources_list.begin();
612        iter != _resources_list.end();
613        iter++)
614     {
615       node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
616       xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
617       xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
618       xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
619       xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
620   
621       switch ((*iter).second.Protocol)
622         {
623         case rsh:
624           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
625           break;
626         case ssh:
627           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
628           break;
629         default:
630           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
631         }
632
633       switch ((*iter).second.Mode)
634         {
635         case interactive:
636           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
637           break;
638         case batch:
639           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
640           break;
641         default:
642           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
643         }
644
645       switch ((*iter).second.Batch)
646         {
647         case pbs:
648           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
649           break;
650         case lsf:
651           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
652           break;
653         case sge:
654           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
655           break;
656         default:
657           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
658         }
659
660       switch ((*iter).second.mpi)
661         {
662         case lam:
663           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
664           break;
665         case mpich1:
666           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
667           break;
668         case mpich2:
669           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
670           break;
671         case openmpi:
672           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
673           break;
674         case slurm:
675           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
676           break;
677         case prun:
678           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
679           break;
680         default:
681           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
682         }
683
684       xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
685
686      for (vector<string>::const_iterator iter2 =
687              (*iter).second.ComponentsList.begin();
688            iter2 != (*iter).second.ComponentsList.end();
689            iter2++)
690         {
691           node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
692           xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
693         }
694
695       xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
696       xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
697       xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
698       xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
699       xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
700     }
701   for (map<string, ParserResourcesType>::iterator iter =
702          _resources_batch_list.begin();
703        iter != _resources_batch_list.end();
704        iter++)
705     {
706       node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
707       xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
708       xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
709       
710       switch ((*iter).second.Protocol)
711         {
712         case rsh:
713           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
714           break;
715         case ssh:
716           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
717           break;
718         default:
719           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
720         }
721
722       switch ((*iter).second.Mode)
723         {
724         case interactive:
725           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
726           break;
727         case batch:
728           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
729           break;
730         default:
731           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
732         }
733
734       switch ((*iter).second.Batch)
735         {
736         case pbs:
737           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
738           break;
739         case lsf:
740           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
741           break;
742         case sge:
743           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
744           break;
745         default:
746           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
747         }
748
749       switch ((*iter).second.mpi)
750         {
751         case lam:
752           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
753           break;
754         case mpich1:
755           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
756           break;
757         case mpich2:
758           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
759           break;
760         case openmpi:
761           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
762           break;
763         case slurm:
764           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
765           break;
766         case prun:
767           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
768           break;
769         default:
770           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
771         }
772
773       xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
774
775      for (vector<string>::const_iterator iter2 =
776              (*iter).second.ComponentsList.begin();
777            iter2 != (*iter).second.ComponentsList.end();
778            iter2++)
779         {
780           node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
781           xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
782         }
783
784       xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
785       xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
786       xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
787       xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
788       xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
789     }
790 }