Salome HOME
4234cda85e3162dacf7a25ce2f6c9518aac7d22f
[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   return true;
381 }
382
383 bool
384 SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, ParserResourcesType & resource)
385 {
386   if (xmlHasProp(machine_descr, (const xmlChar*)test_hostname))
387   {
388     xmlChar* hostname = xmlGetProp(machine_descr, (const xmlChar*)test_hostname);
389     resource.DataForSort._hostName = (const char*)hostname;
390     resource.HostName = (const char*)hostname;
391     xmlFree(hostname);
392   }
393   else
394   {
395     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning found a machine without a hostname" << std::endl;
396     std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning this machine will not be added" << std::endl;
397     return false;
398   }
399
400   if (xmlHasProp(machine_descr, (const xmlChar*)test_alias))
401   {
402     xmlChar* alias = xmlGetProp(machine_descr, (const xmlChar*)test_alias);
403     resource.Alias = (const char*)alias;
404     xmlFree(alias);
405   }
406   else
407     resource.Alias = "";
408
409   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch_queue))
410   {
411     xmlChar* batch_queue = xmlGetProp(machine_descr, (const xmlChar*)test_batch_queue);
412     resource.batchQueue = (const char*)batch_queue;
413     xmlFree(batch_queue);
414   }
415   else
416     resource.batchQueue = "";
417
418   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_commands))
419   {
420     xmlChar* user_commands= xmlGetProp(machine_descr, (const xmlChar*)test_user_commands);
421     resource.userCommands = (const char*)user_commands;
422     xmlFree(user_commands);
423   }
424   else
425     resource.userCommands = "";
426
427   if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
428   {
429     xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
430     switch ( protocol[0])
431     {
432       case 'r':
433         resource.Protocol = rsh;
434         break;
435       case 's':
436         resource.Protocol = ssh;
437         break;
438       default:
439         // If it'not in all theses cases, the protocol is affected to rsh
440         resource.Protocol = rsh;
441         break;
442     }
443     xmlFree(protocol);
444   }
445   else
446     resource.Protocol = rsh;
447
448   if (xmlHasProp(machine_descr, (const xmlChar*)test_mode))
449   {
450     xmlChar* mode=xmlGetProp(machine_descr, (const xmlChar*)test_mode);
451     switch ( mode[0] )
452     {
453       case 'i':
454         resource.Mode = interactive;
455         break;
456       case 'b':
457         resource.Mode = batch;
458         break;
459       default:
460         // If it'not in all theses cases, the mode is affected to interactive
461         resource.Mode = interactive;
462         break;
463     }
464     xmlFree(mode);
465   }
466   else
467     resource.Mode = interactive;
468
469   if (xmlHasProp(machine_descr, (const xmlChar*)test_batch))
470   {
471     xmlChar* batch = xmlGetProp(machine_descr, (const xmlChar*)test_batch);
472     std::string aBatch = (const char*)batch;
473     xmlFree(batch);
474     if (aBatch == "pbs")
475       resource.Batch = pbs;
476     else if  (aBatch == "lsf")
477       resource.Batch = lsf;
478     else if  (aBatch == "sge")
479       resource.Batch = sge;
480     else
481       resource.Batch = none;
482   }
483
484   if (xmlHasProp(machine_descr, (const xmlChar*)test_mpi))
485   {
486     xmlChar* mpi = xmlGetProp(machine_descr, (const xmlChar*)test_mpi);
487     std::string anMpi = (const char*)mpi;
488     xmlFree(mpi);
489     if (anMpi == "lam")
490       resource.mpi = lam;
491     else if (anMpi == "mpich1")
492       resource.mpi = mpich1;
493     else if (anMpi == "mpich2")
494       resource.mpi = mpich2;
495     else if (anMpi == "openmpi")
496       resource.mpi = openmpi;
497     else if  (anMpi == "slurm")
498       resource.mpi = slurm;
499     else if  (anMpi == "prun")
500       resource.mpi = prun;
501     else
502       resource.mpi = nompi;
503   }
504
505   if (xmlHasProp(machine_descr, (const xmlChar*)test_user_name))
506   {
507     xmlChar* user_name= xmlGetProp(machine_descr, (const xmlChar*)test_user_name);
508     resource.UserName = (const char*)user_name;
509     xmlFree(user_name);
510   }
511
512   if (xmlHasProp(machine_descr, (const xmlChar*)test_appli_path))
513   {
514     xmlChar* appli_path = xmlGetProp(machine_descr, (const xmlChar*)test_appli_path);
515     resource.AppliPath = (const char*)appli_path;
516     xmlFree(appli_path);
517   }
518
519   if (xmlHasProp(machine_descr, (const xmlChar*)test_os))
520   {
521     xmlChar* os = xmlGetProp(machine_descr, (const xmlChar*)test_os);
522     resource.OS = (const char*)os;
523     xmlFree(os);
524   }
525
526   if (xmlHasProp(machine_descr, (const xmlChar*)test_mem_in_mb))
527   {
528     xmlChar* mem_in_mb = xmlGetProp(machine_descr, (const xmlChar*)test_mem_in_mb);
529     resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
530     xmlFree(mem_in_mb);
531   }
532
533   if (xmlHasProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz))
534   {
535     xmlChar* cpu_freq_mhz = xmlGetProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz);
536     resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
537     xmlFree(cpu_freq_mhz);
538   }
539
540   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_nodes))
541   {
542     xmlChar* nb_of_nodes = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_nodes);
543     resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
544     xmlFree(nb_of_nodes);
545   }
546
547   if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node))
548   {
549     xmlChar* nb_of_proc_per_node = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node);
550     resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
551     xmlFree(nb_of_proc_per_node);
552   }
553
554   // Process children nodes
555   xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
556   while(aCurSubNode != NULL)
557   {
558     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
559     {
560       //If a component is given, it is in a module with the same name
561       //except if the module name is given
562       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
563       {
564         xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
565         std::string aComponentName = (const char*)component_name;
566         _resource.ComponentsList.push_back(aComponentName);
567         if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
568         {
569           xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
570           std::string aModuleName = (const char*)module_name;
571           _resource.ModulesList.push_back(aModuleName);
572           xmlFree(module_name);
573         }
574         else
575           _resource.ModulesList.push_back(aComponentName);
576         xmlFree(component_name);
577       }
578     }
579     // Process modules
580     if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
581     {
582       if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
583       {
584         xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
585         std::string aModuleName = (const char*)module_name;
586         resource.ModulesList.push_back(aModuleName);
587         xmlFree(module_name);
588       }
589     }
590     aCurSubNode = aCurSubNode->next;
591   }
592   return true;
593 }
594
595 //=============================================================================
596 /*!
597  *  Fill the document tree in xml file, used to write in an xml file.
598  *  \param theDoc document to fill.
599  */ 
600 //=============================================================================
601
602 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
603 {
604   // Node pointers
605   xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
606   char string_buf[80];
607
608   root_node = xmlNewNode(NULL, BAD_CAST "resources");
609   xmlDocSetRootElement(theDoc, root_node);
610     
611   for (map<string, ParserResourcesType>::iterator iter =
612          _resources_list.begin();
613        iter != _resources_list.end();
614        iter++)
615     {
616       node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
617       xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
618       xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
619       xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
620       xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
621   
622       switch ((*iter).second.Protocol)
623         {
624         case rsh:
625           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
626           break;
627         case ssh:
628           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
629           break;
630         default:
631           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
632         }
633
634       switch ((*iter).second.Mode)
635         {
636         case interactive:
637           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
638           break;
639         case batch:
640           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
641           break;
642         default:
643           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
644         }
645
646       switch ((*iter).second.Batch)
647         {
648         case pbs:
649           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
650           break;
651         case lsf:
652           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
653           break;
654         case sge:
655           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
656           break;
657         default:
658           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
659         }
660
661       switch ((*iter).second.mpi)
662         {
663         case lam:
664           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
665           break;
666         case mpich1:
667           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
668           break;
669         case mpich2:
670           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
671           break;
672         case openmpi:
673           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
674           break;
675         case slurm:
676           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
677           break;
678         case prun:
679           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
680           break;
681         default:
682           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
683         }
684
685       xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
686
687      for (vector<string>::const_iterator iter2 =
688              (*iter).second.ComponentsList.begin();
689            iter2 != (*iter).second.ComponentsList.end();
690            iter2++)
691         {
692           node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
693           xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
694         }
695
696       xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
697       xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
698       xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
699       xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
700       xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
701     }
702   for (map<string, ParserResourcesType>::iterator iter =
703          _resources_batch_list.begin();
704        iter != _resources_batch_list.end();
705        iter++)
706     {
707       node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
708       xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
709       xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
710       
711       switch ((*iter).second.Protocol)
712         {
713         case rsh:
714           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
715           break;
716         case ssh:
717           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
718           break;
719         default:
720           xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
721         }
722
723       switch ((*iter).second.Mode)
724         {
725         case interactive:
726           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
727           break;
728         case batch:
729           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
730           break;
731         default:
732           xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
733         }
734
735       switch ((*iter).second.Batch)
736         {
737         case pbs:
738           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
739           break;
740         case lsf:
741           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
742           break;
743         case sge:
744           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
745           break;
746         default:
747           xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
748         }
749
750       switch ((*iter).second.mpi)
751         {
752         case lam:
753           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
754           break;
755         case mpich1:
756           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
757           break;
758         case mpich2:
759           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
760           break;
761         case openmpi:
762           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
763           break;
764         case slurm:
765           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
766           break;
767         case prun:
768           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
769           break;
770         default:
771           xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
772         }
773
774       xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
775
776      for (vector<string>::const_iterator iter2 =
777              (*iter).second.ComponentsList.begin();
778            iter2 != (*iter).second.ComponentsList.end();
779            iter2++)
780         {
781           node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
782           xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
783         }
784
785       xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
786       xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
787       xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
788       xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
789       xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
790     }
791 }