1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/****************************************************
* Name:
* mgmSrvApi.cpp
*
* Description:
* Test the bahaviour of the Management Server
* API based on the tests specified in the
* "Test Specification for the Management
* Server API" document
*
*****************************************************/
#include <ndb_global.h>
#include "mgmapi.h"
#include "mgmapi_commands.h"
#include <NdbMain.h>
#include <NdbOut.hpp>
/**
* The pupose of this test program is to
* verify that the Management Server
* API is functioning properly, i.e. a handle
* can be created/destroyed properly, the
* connection to the NDB nodes is established
* correctly, and all the errors are handled in
* a proper way.
* USE: mgmSrvApi -n -i
*
* @param n Number of nodes to crash
*
**/
NDB_COMMAND(mgmSrvApi, "mgmSrvApi", "mgmSrvApi -n <Number of nodes to crash> -i <Node ID to be crashed> -p <IP address:port number>", "Management Server API testing", 65535){
const char *Addr = 0;
int i;
int nodesNo = 0; // Number of nodes to crash
int ndbID = 0; // Node ID to be crashed
i = 1;
while (argc > 1) {
if (strcmp(argv[i], "-n") == 0)
nodesNo = atoi(argv[i+1]);
if (strcmp(argv[i], "-i") == 0)
ndbID = atoi(argv[i+1]);
if (strcmp(argv[i], "-p") == 0)
Addr = argv[i+1];
argc -= 1;
i = i + 1;
}
/*
* Create a handle
*/
ndbout << "Creating handle..." << endl;
NdbMgmHandle h = ndb_mgm_create_handle();
/*
* Perfom the connection
*/
ndbout << "Connecting..." << endl;
if (ndb_mgm_connect(h, Addr) == -1) {
ndbout << "Connection to " << Addr << " failed" << endl;
exit(-1);
}
/*
* Get status of a node
*/
ndbout << "Getting status..." << endl;
struct ndb_mgm_cluster_state * status;
struct ndb_mgm_node_state * nodes;
status = ndb_mgm_get_status(h);
nodes = status->node_states;
if (nodes->node_status == 1) {
ndbout << "No contact established" << endl;
// exit(-1);
}
/*
* Stop the NDB nodes
*/
ndbout << "Stopping the node(s)" << endl;
const int * list;
if (nodesNo == 0) // all nodes stopped by definition
ndbID = 0;
list = &ndbID;
if (ndb_mgm_stop(h, nodesNo, list) != 1) {
ndbout << nodesNo << " NDB node(s) not stopped " << endl;
}
/*
* Disconnect from the management server
*/
ndbout << "Disconnecting..." << endl;
ndb_mgm_disconnect(h);
/*
* Destroy the handle
*/
ndbout << "Destroying the handle..." << endl;
ndb_mgm_destroy_handle(&h);
return 0;
}
|