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";
62 test_user_name = "userName";
63 test_appli_path = "appliPath";
64 test_modules = "modules";
65 test_module_name = "moduleName";
66 test_module_path = "modulePath";
67 test_pre_req_file_path = "preReqFilePath";
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) )
121 if (xmlHasProp(aCurNode, (const xmlChar*)test_hostname))
122 _resource.DataForSort._hostName = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_hostname);
126 if (xmlHasProp(aCurNode, (const xmlChar*)test_alias))
127 _resource.Alias = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_alias);
129 _resource.Alias = "";
131 switch ( ((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_protocol))[0] )
134 _resource.Protocol = rsh;
137 _resource.Protocol = ssh;
140 // If it'not in all theses cases, the protocol is affected to rsh
141 _resource.Protocol = rsh;
145 switch ( ((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_mode))[0] )
148 _resource.Mode = interactive;
151 _resource.Mode = batch;
154 // If it'not in all theses cases, the mode is affected to interactive
155 _resource.Mode = interactive;
159 if (xmlHasProp(aCurNode, (const xmlChar*)test_user_name))
160 _resource.UserName = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_user_name);
162 if (xmlHasProp(aCurNode, (const xmlChar*)test_appli_path))
163 _resource.AppliPath = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_appli_path);
165 if (xmlHasProp(aCurNode, (const xmlChar*)test_pre_req_file_path))
166 _resource.PreReqFilePath = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_pre_req_file_path);
168 if (xmlHasProp(aCurNode, (const xmlChar*)test_os))
169 _resource.OS = (const char*)xmlGetProp(aCurNode, (const xmlChar*)test_os);
171 if (xmlHasProp(aCurNode, (const xmlChar*)test_mem_in_mb))
172 _resource.DataForSort._memInMB = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_mem_in_mb));
174 if (xmlHasProp(aCurNode, (const xmlChar*)test_cpu_freq_mhz))
175 _resource.DataForSort._CPUFreqMHz = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_cpu_freq_mhz));
177 if (xmlHasProp(aCurNode, (const xmlChar*)test_nb_of_nodes))
178 _resource.DataForSort._nbOfNodes = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_nb_of_nodes));
180 if (xmlHasProp(aCurNode, (const xmlChar*)test_nb_of_proc_per_node))
181 _resource.DataForSort._nbOfProcPerNode = atoi((const char*)xmlGetProp(aCurNode, (const xmlChar*)test_nb_of_proc_per_node));
184 xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
185 while(aCurSubNode != NULL)
187 if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
189 if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name) &&
190 xmlHasProp(aCurSubNode, (const xmlChar*)test_module_path))
192 std::string aModuleName = (const char*)xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
193 std::string aModulePath = (const char*)xmlGetProp(aCurSubNode, (const xmlChar*)test_module_path);
194 _resource.ModulesPath[aModuleName] = aModulePath;
197 aCurSubNode = aCurSubNode->next;
200 int aNbNodes = _resource.DataForSort._nbOfNodes;
202 string clusterNode = _resource.DataForSort._hostName ;
203 for( int i=0; i < aNbNodes; i++ ){
206 sprintf(inode,"%s%d",clusterNode.c_str(),i+1);
207 std::string nodeName(inode);
208 _resource.DataForSort._hostName = nodeName ;
209 _resources_list[nodeName] = _resource;
213 _resources_list[_resource.DataForSort._hostName] = _resource;
216 aCurNode = aCurNode->next;
222 for (map<string, ParserResourcesType>::const_iterator iter =
223 _resources_list.begin();
224 iter != _resources_list.end();
227 SCRUTE((*iter).second.Alias);
228 SCRUTE((*iter).second.UserName);
229 SCRUTE((*iter).second.AppliPath);
230 SCRUTE((*iter).second.PreReqFilePath);
231 SCRUTE((*iter).second.OS);
232 SCRUTE((*iter).second.Protocol);
233 SCRUTE((*iter).second.Mode);
236 MESSAGE("This is the end of document");
241 //=============================================================================
243 * Fill the document tree in xml file, used to write in an xml file.
244 * \param theDoc document to fill.
246 //=============================================================================
248 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
251 xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
254 root_node = xmlNewNode(NULL, BAD_CAST "resources");
255 xmlDocSetRootElement(theDoc, root_node);
257 for (map<string, ParserResourcesType>::iterator iter =
258 _resources_list.begin();
259 iter != _resources_list.end();
262 node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
263 xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).first.c_str());
264 xmlNewProp(node, BAD_CAST test_alias, BAD_CAST (*iter).second.Alias.c_str());
266 switch ((*iter).second.Protocol)
269 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
272 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
275 xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
278 switch ((*iter).second.Mode)
281 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
284 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
287 xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
290 xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
292 for (map<string, string>::const_iterator iter2 =
293 (*iter).second.ModulesPath.begin();
294 iter2 != (*iter).second.ModulesPath.end();
297 node1 = xmlNewChild(node, NULL, BAD_CAST test_modules, NULL);
298 xmlNewProp(node1, BAD_CAST test_module_name, BAD_CAST (*iter2).first.c_str());
299 xmlNewProp(node1, BAD_CAST test_module_path, BAD_CAST (*iter2).second.c_str());
302 xmlNewProp(node, BAD_CAST test_pre_req_file_path, BAD_CAST (*iter).second.PreReqFilePath.c_str());
303 xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
304 xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
305 xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
306 xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
307 xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));