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))
123 _resource.DataForSort._hostName = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_hostname);
127 if (xmlHasProp(aCurNode, (const xmlChar*)test_alias))
128 _resource.Alias = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_alias);
130 _resource.Alias = "";
132 switch ( ((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_protocol))[0] )
135 _resource.Protocol = rsh;
138 _resource.Protocol = ssh;
141 // If it'not in all theses cases, the protocol is affected to rsh
142 _resource.Protocol = rsh;
146 switch ( ((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_mode))[0] )
149 _resource.Mode = interactive;
152 _resource.Mode = batch;
155 // If it'not in all theses cases, the mode is affected to interactive
156 _resource.Mode = interactive;
160 if (xmlHasProp(aCurNode, (const xmlChar*)test_batch))
162 std::string aBatch = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_batch);
164 _resource.Batch = pbs;
165 else if (aBatch == "lsf")
166 _resource.Batch = lsf;
167 else if (aBatch == "slurm")
168 _resource.Batch = slurm;
170 _resource.Batch = none;
173 if (xmlHasProp(aCurNode, (const xmlChar*)test_mpi))
175 std::string anMpi = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_mpi);
178 else if (anMpi == "mpich1")
179 _resource.mpi = mpich1;
180 else if (anMpi == "mpich2")
181 _resource.mpi = mpich2;
182 else if (anMpi == "openmpi")
183 _resource.mpi = openmpi;
185 _resource.mpi = indif;
188 if (xmlHasProp(aCurNode, (const xmlChar*)test_user_name))
189 _resource.UserName = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_user_name);
191 if (xmlHasProp(aCurNode, (const xmlChar*)test_appli_path))
192 _resource.AppliPath = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_appli_path);
194 if (xmlHasProp(aCurNode, (const xmlChar*)test_os))
195 _resource.OS = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_os);
197 if (xmlHasProp(aCurNode, (const xmlChar*)test_mem_in_mb))
198 _resource.DataForSort._memInMB = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_mem_in_mb));
200 if (xmlHasProp(aCurNode, (const xmlChar*)test_cpu_freq_mhz))
201 _resource.DataForSort._CPUFreqMHz = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_cpu_freq_mhz));
203 if (xmlHasProp(aCurNode, (const xmlChar*)test_nb_of_nodes))
204 _resource.DataForSort._nbOfNodes = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_nb_of_nodes));
206 if (xmlHasProp(aCurNode, (const xmlChar*)test_nb_of_proc_per_node))
207 _resource.DataForSort._nbOfProcPerNode = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_nb_of_proc_per_node));
210 xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
211 while(aCurSubNode != NULL)
213 if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
215 if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name))
217 std::string aModuleName = (const char*)xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
218 _resource.ModulesList.push_back(aModuleName);
221 aCurSubNode = aCurSubNode->next;
224 int aNbNodes = _resource.DataForSort._nbOfNodes;
226 string clusterNode = _resource.DataForSort._hostName ;
227 for( int i=0; i < aNbNodes; i++ ){
230 sprintf(inode,"%s%d",clusterNode.c_str(),i+1);
231 std::string nodeName(inode);
232 _resource.DataForSort._hostName = nodeName ;
233 _resources_list[nodeName] = _resource;
237 _resources_list[_resource.DataForSort._hostName] = _resource;
240 aCurNode = aCurNode->next;
246 for (map<string, ParserResourcesType>::const_iterator iter =
247 _resources_list.begin();
248 iter != _resources_list.end();
251 SCRUTE((*iter).second.Alias);
252 SCRUTE((*iter).second.UserName);
253 SCRUTE((*iter).second.AppliPath);
254 SCRUTE((*iter).second.OS);
255 SCRUTE((*iter).second.Protocol);
256 SCRUTE((*iter).second.Mode);
259 MESSAGE("This is the end of document");
264 //=============================================================================
266 * Fill the document tree in xml file, used to write in an xml file.
267 * \param theDoc document to fill.
269 //=============================================================================
271 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
274 xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
277 root_node = xmlNewNode(NULL, BAD_CAST "resources");
278 xmlDocSetRootElement(theDoc, root_node);
280 for (map<string, ParserResourcesType>::iterator iter =
281 _resources_list.begin();
282 iter != _resources_list.end();
285 node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
286 xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).first.c_str());
287 xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
289 switch ((*iter).second.Protocol)
292 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
295 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
298 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
301 switch ((*iter).second.Mode)
304 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
307 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
310 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
313 switch ((*iter).second.Batch)
316 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
319 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
322 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "slurm");
325 xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
328 switch ((*iter).second.mpi)
331 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
334 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
337 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
340 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
343 xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
346 xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
348 for (vector<string>::const_iterator iter2 =
349 (*iter).second.ModulesList.begin();
350 iter2 != (*iter).second.ModulesList.end();
353 node1 = xmlNewChild(node, NULL, BAD_CAST test_modules, NULL);
354 xmlNewProp(node1, BAD_CAST test_module_name, BAD_CAST (*iter2).c_str());
357 xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
358 xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
359 xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
360 xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
361 xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));