1 // SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SALOME_ResourcesCatalog_Handler.cxx
25 // Author : Estelle Deville
29 #include "SALOME_ResourcesCatalog_Handler.hxx"
32 #include "utilities.h"
37 static int MYDEBUG = 1;
39 static int MYDEBUG = 0;
42 //=============================================================================
45 * \param listOfResources: map of ParserResourcesType to fill when parsing
47 //=============================================================================
49 SALOME_ResourcesCatalog_Handler::
50 SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
51 _resources_list(listOfResources)
53 MESSAGE("SALOME_ResourcesCatalog_Handler creation");
54 //XML tags initialisation
55 test_machine = "machine";
56 test_resources = "resources";
58 test_hostname = "hostname";
60 test_protocol = "protocol";
64 test_user_name = "userName";
65 test_appli_path = "appliPath";
66 test_modules = "modules";
67 test_module_name = "moduleName";
69 test_mem_in_mb = "memInMB";
70 test_cpu_freq_mhz = "CPUFreqMHz";
71 test_nb_of_nodes = "nbOfNodes";
72 test_nb_of_proc_per_node = "nbOfProcPerNode";
75 //=============================================================================
79 //=============================================================================
81 SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
83 // MESSAGE("SALOME_ResourcesCatalog_Handler destruction");
86 //=============================================================================
88 * Retrieves DS after the file parse.
90 //=============================================================================
92 const MapOfParserResourcesType&
93 SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
95 return _resources_list;
98 //=============================================================================
100 * Processes XML document and fills the list of resources
102 //=============================================================================
104 void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
106 if (MYDEBUG) MESSAGE("Begin parse document");
108 // Empty private elements
109 _resources_list.clear();
111 // Get the document root node
112 xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
114 aCurNode = aCurNode->xmlChildrenNode;
116 // Processing the document nodes
117 while(aCurNode != NULL)
119 if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_machine) )
122 if (xmlHasProp(aCurNode, (const xmlChar*)test_hostname))
124 xmlChar* hostname = xmlGetProp(aCurNode, (const xmlChar*)test_hostname);
125 _resource.DataForSort._hostName = (const char*)hostname;
131 if (xmlHasProp(aCurNode, (const xmlChar*)test_alias))
133 xmlChar* alias = xmlGetProp(aCurNode, (const xmlChar*)test_alias);
134 _resource.Alias = (const char*)alias;
138 _resource.Alias = "";
140 if (xmlHasProp(aCurNode, (const xmlChar*)test_protocol))
142 xmlChar* protocol= xmlGetProp(aCurNode, (const xmlChar*)test_protocol);
143 switch ( protocol[0])
146 _resource.Protocol = rsh;
149 _resource.Protocol = ssh;
152 // If it'not in all theses cases, the protocol is affected to rsh
153 _resource.Protocol = rsh;
159 _resource.Protocol = rsh;
161 if (xmlHasProp(aCurNode, (const xmlChar*)test_mode))
163 xmlChar* mode=xmlGetProp(aCurNode, (const xmlChar*)test_mode);
167 _resource.Mode = interactive;
170 _resource.Mode = batch;
173 // If it'not in all theses cases, the mode is affected to interactive
174 _resource.Mode = interactive;
180 _resource.Mode = interactive;
182 if (xmlHasProp(aCurNode, (const xmlChar*)test_batch))
184 xmlChar* batch = xmlGetProp(aCurNode, (const xmlChar*)test_batch);
185 std::string aBatch = (const char*)batch;
188 _resource.Batch = pbs;
189 else if (aBatch == "lsf")
190 _resource.Batch = lsf;
191 else if (aBatch == "slurm")
192 _resource.Batch = slurm;
194 _resource.Batch = none;
197 if (xmlHasProp(aCurNode, (const xmlChar*)test_mpi))
199 xmlChar* mpi = xmlGetProp(aCurNode, (const xmlChar*)test_mpi);
200 std::string anMpi = (const char*)mpi;
204 else if (anMpi == "mpich1")
205 _resource.mpi = mpich1;
206 else if (anMpi == "mpich2")
207 _resource.mpi = mpich2;
208 else if (anMpi == "openmpi")
209 _resource.mpi = openmpi;
211 _resource.mpi = indif;
214 if (xmlHasProp(aCurNode, (const xmlChar*)test_user_name))
216 xmlChar* user_name= xmlGetProp(aCurNode, (const xmlChar*)test_user_name);
217 _resource.UserName = (const char*)user_name;
221 if (xmlHasProp(aCurNode, (const xmlChar*)test_appli_path))
223 xmlChar* appli_path = xmlGetProp(aCurNode, (const xmlChar*)test_appli_path);
224 _resource.AppliPath = (const char*)appli_path;
228 if (xmlHasProp(aCurNode, (const xmlChar*)test_os))
230 xmlChar* os = xmlGetProp(aCurNode, (const xmlChar*)test_os);
231 _resource.OS = (const char*)os;
235 if (xmlHasProp(aCurNode, (const xmlChar*)test_mem_in_mb))
237 xmlChar* mem_in_mb = xmlGetProp(aCurNode, (const xmlChar*)test_mem_in_mb);
238 _resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
242 if (xmlHasProp(aCurNode, (const xmlChar*)test_cpu_freq_mhz))
244 xmlChar* cpu_freq_mhz = xmlGetProp(aCurNode, (const xmlChar*)test_cpu_freq_mhz);
245 _resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
246 xmlFree(cpu_freq_mhz);
249 if (xmlHasProp(aCurNode, (const xmlChar*)test_nb_of_nodes))
251 xmlChar* nb_of_nodes = xmlGetProp(aCurNode, (const xmlChar*)test_nb_of_nodes);
252 _resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
253 xmlFree(nb_of_nodes);
256 if (xmlHasProp(aCurNode, (const xmlChar*)test_nb_of_proc_per_node))
258 xmlChar* nb_of_proc_per_node = xmlGetProp(aCurNode, (const xmlChar*)test_nb_of_proc_per_node);
259 _resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
260 xmlFree(nb_of_proc_per_node);
264 xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
265 while(aCurSubNode != NULL)
267 if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
269 if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name))
271 xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
272 std::string aModuleName = (const char*)module_name;
273 _resource.ModulesList.push_back(aModuleName);
274 xmlFree(module_name);
277 aCurSubNode = aCurSubNode->next;
280 int aNbNodes = _resource.DataForSort._nbOfNodes;
282 string clusterNode = _resource.DataForSort._hostName ;
283 for( int i=0; i < aNbNodes; i++ ){
286 sprintf(inode,"%s%d",clusterNode.c_str(),i+1);
287 std::string nodeName(inode);
288 _resource.DataForSort._hostName = nodeName ;
289 _resources_list[nodeName] = _resource;
293 _resources_list[_resource.DataForSort._hostName] = _resource;
296 aCurNode = aCurNode->next;
302 for (map<string, ParserResourcesType>::const_iterator iter =
303 _resources_list.begin();
304 iter != _resources_list.end();
307 SCRUTE((*iter).second.Alias);
308 SCRUTE((*iter).second.UserName);
309 SCRUTE((*iter).second.AppliPath);
310 SCRUTE((*iter).second.OS);
311 SCRUTE((*iter).second.Protocol);
312 SCRUTE((*iter).second.Mode);
315 MESSAGE("This is the end of document");
320 //=============================================================================
322 * Fill the document tree in xml file, used to write in an xml file.
323 * \param theDoc document to fill.
325 //=============================================================================
327 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
330 xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
333 root_node = xmlNewNode(NULL, BAD_CAST "resources");
334 xmlDocSetRootElement(theDoc, root_node);
336 for (map<string, ParserResourcesType>::iterator iter =
337 _resources_list.begin();
338 iter != _resources_list.end();
341 node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
342 xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).first.c_str());
343 xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
345 switch ((*iter).second.Protocol)
348 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
351 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
354 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
357 switch ((*iter).second.Mode)
360 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
363 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
366 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
369 switch ((*iter).second.Batch)
372 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
375 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
378 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "slurm");
381 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
384 switch ((*iter).second.mpi)
387 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
390 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
393 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
396 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
399 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
402 xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
404 for (vector<string>::const_iterator iter2 =
405 (*iter).second.ModulesList.begin();
406 iter2 != (*iter).second.ModulesList.end();
409 node1 = xmlNewChild(node, NULL, BAD_CAST test_modules, NULL);
410 xmlNewProp(node1, BAD_CAST test_module_name, BAD_CAST (*iter2).c_str());
413 xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
414 xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
415 xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
416 xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
417 xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));