MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
printConfig.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 
20 #include <ndb_global.h>
21 
22 #include <NdbMain.h>
23 #include <mgmapi.h>
24 #include <ConfigRetriever.hpp>
25 #include <Properties.hpp>
26 #include <NdbOut.hpp>
27 
28 void usage(const char * prg){
29  ndbout << "Usage " << prg
30  << " host <mgm host> <mgm port> <node id> [<ver id>]" << endl;
31 
32  char buf[255];
33  for(unsigned i = 0; i<strlen(prg); i++)
34  buf[i] = ' ';
35  buf[strlen(prg)] = 0;
36  ndbout << " " << buf << " file <filename> <node id> [<ver id>]"
37  << endl;
38 }
39 
40 NDB_COMMAND(printConfig,
41  "printConfig", "printConfig", "Prints configuration", 16384){
42  if(argc < 4){
43  usage(argv[0]);
44  return 0;
45  }
46  if(strcmp("file", argv[1]) != 0 && strcmp("host", argv[1]) != 0){
47  usage(argv[0]);
48  return 0;
49  }
50 
51  if(strcmp("host", argv[1]) == 0 && argc < 5){
52  usage(argv[0]);
53  return 0;
54  }
55 
56  ConfigRetriever c;
57  struct ndb_mgm_configuration * p = 0;
58 
59  if(strcmp("host", argv[1]) == 0){
60  int verId = 0;
61  if(argc > 5)
62  verId = atoi(argv[5]);
63 
64  ndbout << "Getting config from: " << argv[2] << ":" << atoi(argv[3])
65  << " NodeId =" << atoi(argv[4])
66  << " VersionId = " << verId << endl;
67 
68  p = c.getConfig(argv[2],
69  atoi(argv[3]),
70  verId);
71  } else if (strcmp("file", argv[1]) == 0){
72  int verId = 0;
73  if(argc > 4)
74  verId = atoi(argv[4]);
75 
76  ndbout << "Getting config from: " << argv[2]
77  << " NodeId =" << atoi(argv[3])
78  << " VersionId = " << verId << endl;
79 
80  p = c.getConfig(argv[2], atoi(argv[3]), verId);
81  }
82 
83  if(p != 0){
84  //
85  free(p);
86  } else {
87  ndbout << "Configuration not found: " << c.getErrorString() << endl;
88  }
89 
90  return 0;
91 }