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