MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbConfig.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "NdbConfig.hpp"
20 #include <NdbOut.hpp>
21 #include <NDBT_Output.hpp>
22 #include <assert.h>
23 #include <NdbConfig.h>
24 #include <ConfigRetriever.hpp>
25 #include <ndb_version.h>
26 #include <mgmapi.h>
27 #include <mgmapi_config_parameters.h>
28 #include <mgmapi_configuration.hpp>
29 
30 bool
31 NdbConfig::getHostName(unsigned int node_id, const char ** hostname) {
32 
33  ndb_mgm_configuration * p = getConfig();
34  if(p == 0){
35  return false;
36  }
37 
41  ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
42  if (iter.find(CFG_NODE_ID, node_id)){
43  ndbout << "Invalid configuration fetched, DB missing" << endl;
44  return false;
45  }
46 
47  if (iter.get(CFG_NODE_HOST, hostname)){
48  ndbout << "Host not found" << endl;
49  return false;
50  }
51 
52  return true;
53 }
54 
55 bool
56 NdbConfig::getProperty(unsigned nodeid,
57  unsigned type, unsigned key, Uint32 * val){
58  ndb_mgm_configuration * p = getConfig();
59  if(p == 0){
60  return false;
61  }
62 
66  ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
67  if (iter.find(CFG_NODE_ID, nodeid)){
68  ndbout << "Invalid configuration fetched, DB missing" << endl;
69  return false;
70  }
71 
72  unsigned _type;
73  if (iter.get(CFG_TYPE_OF_SECTION, &_type) || type != _type){
74  ndbout << "No such node in configuration" << endl;
75  return false;
76  }
77 
78  if (iter.get(key, val)){
79  ndbout << "No such key: " << key << " in configuration" << endl;
80  return false;
81  }
82 
83  return true;
84 }
85