Salome HOME
Merge from V5_1_3_BR 07/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,
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         if(_resource.HostName == "localhost")
148           {
149             _resource.HostName = Kernel_Utils::GetHostname();
150             _resource.DataForSort._hostName = Kernel_Utils::GetHostname();
151             _resources_list[Kernel_Utils::GetHostname()] = _resource;
152           }
153         else
154           _resources_list[_resource.HostName] = _resource;
155           }
156         }
157         else
158           // Adding a batch machine/cluster
159           _resources_batch_list[_resource.HostName] = _resource;
160       }
161     }
162     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_cluster) )
163     {
164       // Cas de la déclaration d'un cluster
165       _resource.Clear();
166       if(ProcessCluster(aCurNode, _resource))
167         _resources_list[_resource.HostName] = _resource;
168     }
169     aCurNode = aCurNode->next;
170   }
171
172 #ifdef _DEBUG_
173   for (map<string, ParserResourcesType>::const_iterator iter = _resources_list.begin();
174        iter != _resources_list.end();
175        iter++)
176   {
177     std::cerr << (*iter).first << std::endl;
178     std::cerr << (*iter).second.HostName << std::endl;
179     std::cerr << (*iter).second.Alias << std::endl;
180     std::cerr << (*iter).second.UserName << std::endl;
181     std::cerr << (*iter).second.AppliPath << std::endl;
182     std::cerr << (*iter).second.OS << std::endl;
183     std::cerr << (*iter).second.Protocol << std::endl;
184     std::cerr << (*iter).second.Mode << std::endl;
185   }
186 #endif
187
188 }
189
190 bool
191 SALOME_ResourcesCatalog_Handler::ProcessCluster(xmlNodePtr cluster_descr, ParserResourcesType & resource)
192 {
193   // Ajout d'un cluster
194   // hostname, use et nbOfProc sont obligatoires
195   if (xmlHasProp(cluster_descr, (const xmlChar*)test_hostname))
196   {
197     xmlChar* hostname = xmlGetProp(cluster_descr, (const xmlChar*)test_hostname);
198     resource.DataForSort._hostName = (const char*)hostname;
199     resource.HostName = (const char*)hostname;
200     xmlFree(hostname);
201   }
202   else
203   {
204     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a hostname" << std::endl;
205     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
206     return false;
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.DataForSort._hostName = (const char*)hostname;
295     resource.HostName = (const char*)hostname;
296     xmlFree(hostname);
297   }
298   else
299   {
300     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a hostname" << std::endl;
301     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
302     return false;
303   }
304
305   if (xmlHasProp(member_descr, (const xmlChar*)test_protocol))
306   {
307     xmlChar* protocol= xmlGetProp(member_descr, (const xmlChar*)test_protocol);
308     switch (protocol[0])
309     {
310       case 'r':
311         resource.Protocol = rsh;
312         break;
313       case 's':
314         resource.Protocol = ssh;
315         break;
316       default:
317         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
318         std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
319         return false;
320     }
321     xmlFree(protocol);
322   }
323   else
324   {
325     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
326     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
327     return false;
328   }
329
330   if (xmlHasProp(member_descr, (const xmlChar*)test_user_name))
331   {
332     xmlChar* user_name= xmlGetProp(member_descr, (const xmlChar*)test_user_name);
333     resource.UserName = (const char*)user_name;
334     xmlFree(user_name);
335   }
336   else
337   {
338     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a user name" << std::endl;
339     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
340     return false;
341   }
342
343   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_nodes))
344   {
345     xmlChar* nb_of_nodes = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_nodes);
346     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
347     xmlFree(nb_of_nodes);
348   }
349   else
350   {
351     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfNodes" << std::endl;
352     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
353     return false;
354   }
355
356   if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node))
357   {
358     xmlChar* nb_of_proc_per_node = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node);
359     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
360     xmlFree(nb_of_proc_per_node);
361   }
362   else
363   {
364     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfProcPerNode" << std::endl;
365     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
366     return false;
367   }
368
369   if (xmlHasProp(member_descr, (const xmlChar*)test_appli_path))
370   {
371     xmlChar* appli_path = xmlGetProp(member_descr, (const xmlChar*)test_appli_path);
372     resource.AppliPath = (const char*)appli_path;
373     xmlFree(appli_path);
374   }
375   else
376   {
377     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a AppliPath" << std::endl;
378     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
379     return false;
380   }
381   return true;
382 }
383
384 bool
385 SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, ParserResourcesType & resource)
386 {
387   if (xmlHasProp(machine_descr, (const xmlChar*)test_hostname))
388   {
389     xmlChar* hostname = xmlGetProp(machine_descr, (const xmlChar*)test_hostname);
390     resource.DataForSort._hostName = (const char*)hostname;
391     resource.HostName = (const char*)hostname;
392     xmlFree(hostname);
393   }
394   else
395   {
396     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning found a machine without a hostname" << std::endl;
397     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning this machine will not be added" << std::endl;
398     return false;
399   }
400
401   if (xmlHasProp(machine_descr, (const xmlChar*)test_alias))
402   {
403     xmlChar* alias = xmlGetProp(machine_descr, (const xmlChar*)test_alias);
404     resource.Alias = (const char*)alias;
405     xmlFree(alias);
406   }
407   else
408     resource.Alias = "";
409
410   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch_queue))
411   {
412     xmlChar* batch_queue = xmlGetProp(machine_descr, (const xmlChar*)test_batch_queue);
413     resource.batchQueue = (const char*)batch_queue;
414     xmlFree(batch_queue);
415   }
416   else
417     resource.batchQueue = "";
418
419   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_commands))
420   {
421     xmlChar* user_commands= xmlGetProp(machine_descr, (const xmlChar*)test_user_commands);
422     resource.userCommands = (const char*)user_commands;
423     xmlFree(user_commands);
424   }
425   else
426     resource.userCommands = "";
427
428   if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
429   {
430     xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
431     switch ( protocol[0])
432     {
433       case 'r':
434         resource.Protocol = rsh;
435         break;
436       case 's':
437         resource.Protocol = ssh;
438         break;
439       default:
440         // If it'not in all theses cases, the protocol is affected to rsh
441         resource.Protocol = rsh;
442         break;
443     }
444     xmlFree(protocol);
445   }
446   else
447     resource.Protocol = rsh;
448
449   if (xmlHasProp(machine_descr, (const xmlChar*)test_mode))
450   {
451     xmlChar* mode=xmlGetProp(machine_descr, (const xmlChar*)test_mode);
452     switch ( mode[0] )
453     {
454       case 'i':
455         resource.Mode = interactive;
456         break;
457       case 'b':
458         resource.Mode = batch;
459         break;
460       default:
461         // If it'not in all theses cases, the mode is affected to interactive
462         resource.Mode = interactive;
463         break;
464     }
465     xmlFree(mode);
466   }
467   else
468     resource.Mode = interactive;
469
470   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch))
471   {
472     xmlChar* batch = xmlGetProp(machine_descr, (const xmlChar*)test_batch);
473     std::string aBatch = (const char*)batch;
474     xmlFree(batch);
475     if (aBatch == "pbs")
476       resource.Batch = pbs;
477     else if  (aBatch == "lsf")
478       resource.Batch = lsf;
479     else if  (aBatch == "sge")
480       resource.Batch = sge;
481     else
482       resource.Batch = none;
483   }
484
485   if (xmlHasProp(machine_descr, (const xmlChar*)test_mpi))
486   {
487     xmlChar* mpi = xmlGetProp(machine_descr, (const xmlChar*)test_mpi);
488     std::string anMpi = (const char*)mpi;
489     xmlFree(mpi);
490     if (anMpi == "lam")
491       resource.mpi = lam;
492     else if (anMpi == "mpich1")
493       resource.mpi = mpich1;
494     else if (anMpi == "mpich2")
495       resource.mpi = mpich2;
496     else if (anMpi == "openmpi")
497       resource.mpi = openmpi;
498     else if  (anMpi == "slurm")
499       resource.mpi = slurm;
500     else if  (anMpi == "prun")
501       resource.mpi = prun;
502     else
503       resource.mpi = nompi;
504   }
505
506   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_name))
507   {
508     xmlChar* user_name= xmlGetProp(machine_descr, (const xmlChar*)test_user_name);
509     resource.UserName = (const char*)user_name;
510     xmlFree(user_name);
511   }
512
513   if (xmlHasProp(machine_descr, (const xmlChar*)test_appli_path))
514   {
515     xmlChar* appli_path = xmlGetProp(machine_descr, (const xmlChar*)test_appli_path);
516     resource.AppliPath = (const char*)appli_path;
517     xmlFree(appli_path);
518   }
519
520   if (xmlHasProp(machine_descr, (const xmlChar*)test_os))
521   {
522     xmlChar* os = xmlGetProp(machine_descr, (const xmlChar*)test_os);
523     resource.OS = (const char*)os;
524     xmlFree(os);
525   }
526
527   if (xmlHasProp(machine_descr, (const xmlChar*)test_mem_in_mb))
528   {
529     xmlChar* mem_in_mb = xmlGetProp(machine_descr, (const xmlChar*)test_mem_in_mb);
530     resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
531     xmlFree(mem_in_mb);
532   }
533
534   if (xmlHasProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz))
535   {
536     xmlChar* cpu_freq_mhz = xmlGetProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz);
537     resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
538     xmlFree(cpu_freq_mhz);
539   }
540
541   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_nodes))
542   {
543     xmlChar* nb_of_nodes = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_nodes);
544     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
545     xmlFree(nb_of_nodes);
546   }
547
548   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node))
549   {
550     xmlChar* nb_of_proc_per_node = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node);
551     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
552     xmlFree(nb_of_proc_per_node);
553   }
554
555   // Process children nodes
556   xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
557   while(aCurSubNode != NULL)
558   {
559     // Process components
560     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
561     {
562       //If a component is given, it is in a module with the same name
563       //except if the module name is given
564       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
565       {
566         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
567         std::string aComponentName = (const char*)component_name;
568         _resource.ComponentsList.push_back(aComponentName);
569         if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
570         {
571           xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
572           std::string aModuleName = (const char*)module_name;
573           _resource.ModulesList.push_back(aModuleName);
574           xmlFree(module_name);
575         }
576         else
577           _resource.ModulesList.push_back(aComponentName);
578         xmlFree(component_name);
579       }
580     }
581     // Process modules
582     else if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
583     {
584       // If a module is given, we create an entry in componentsList and modulesList
585       // with the same name (module == component)
586       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
587       {
588         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
589         std::string aComponentName = (const char*)component_name;
590         _resource.ComponentsList.push_back(aComponentName);
591         _resource.ModulesList.push_back(aComponentName);
592         xmlFree(component_name);
593       }
594     }
595     aCurSubNode = aCurSubNode->next;
596   }
597   return true;
598 }
599
600 //=============================================================================
601 /*!
602  *  Fill the document tree in xml file, used to write in an xml file.
603  *  \param theDoc document to fill.
604  */ 
605 //=============================================================================
606
607 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
608 {
609   // Node pointers
610   xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
611   char string_buf[80];
612
613   root_node = xmlNewNode(NULL, BAD_CAST "resources");
614   xmlDocSetRootElement(theDoc, root_node);
615     
616   for (map<string, ParserResourcesType>::iterator iter =
617          _resources_list.begin();
618        iter != _resources_list.end();
619        iter++)
620     {
621       node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
622       xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
623       xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
624       xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
625       xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
626   
627       switch ((*iter).second.Protocol)
628         {
629         case rsh:
630           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
631           break;
632         case ssh:
633           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
634           break;
635         default:
636           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
637         }
638
639       switch ((*iter).second.Mode)
640         {
641         case interactive:
642           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
643           break;
644         case batch:
645           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
646           break;
647         default:
648           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
649         }
650
651       switch ((*iter).second.Batch)
652         {
653         case pbs:
654           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
655           break;
656         case lsf:
657           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
658           break;
659         case sge:
660           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
661           break;
662         default:
663           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
664         }
665
666       switch ((*iter).second.mpi)
667         {
668         case lam:
669           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
670           break;
671         case mpich1:
672           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
673           break;
674         case mpich2:
675           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
676           break;
677         case openmpi:
678           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
679           break;
680         case slurm:
681           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
682           break;
683         case prun:
684           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
685           break;
686         default:
687           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
688         }
689
690       xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
691
692      for (vector<string>::const_iterator iter2 =
693              (*iter).second.ComponentsList.begin();
694            iter2 != (*iter).second.ComponentsList.end();
695            iter2++)
696         {
697           node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
698           xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
699         }
700
701       xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
702       xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
703       xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
704       xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
705       xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
706     }
707   for (map<string, ParserResourcesType>::iterator iter =
708          _resources_batch_list.begin();
709        iter != _resources_batch_list.end();
710        iter++)
711     {
712       node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
713       xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
714       xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
715       
716       switch ((*iter).second.Protocol)
717         {
718         case rsh:
719           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
720           break;
721         case ssh:
722           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
723           break;
724         default:
725           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
726         }
727
728       switch ((*iter).second.Mode)
729         {
730         case interactive:
731           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
732           break;
733         case batch:
734           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
735           break;
736         default:
737           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
738         }
739
740       switch ((*iter).second.Batch)
741         {
742         case pbs:
743           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
744           break;
745         case lsf:
746           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
747           break;
748         case sge:
749           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
750           break;
751         default:
752           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
753         }
754
755       switch ((*iter).second.mpi)
756         {
757         case lam:
758           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
759           break;
760         case mpich1:
761           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
762           break;
763         case mpich2:
764           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
765           break;
766         case openmpi:
767           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
768           break;
769         case slurm:
770           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
771           break;
772         case prun:
773           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
774           break;
775         default:
776           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
777         }
778
779       xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
780
781      for (vector<string>::const_iterator iter2 =
782              (*iter).second.ComponentsList.begin();
783            iter2 != (*iter).second.ComponentsList.end();
784            iter2++)
785         {
786           node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
787           xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
788         }
789
790       xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
791       xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
792       xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
793       xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
794       xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
795     }
796 }