2
Copyright (C) 2003-2006 MySQL AB
3
All rights reserved. Use is subject to license terms.
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.
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.
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
19
/****************************************************
24
* Test the bahaviour of the Management Server
25
* API based on the tests specified in the
26
* "Test Specification for the Management
27
* Server API" document
29
*****************************************************/
30
#include <ndb_global.h>
32
#include "mgmapi_commands.h"
37
* The pupose of this test program is to
38
* verify that the Management Server
39
* API is functioning properly, i.e. a handle
40
* can be created/destroyed properly, the
41
* connection to the NDB nodes is established
42
* correctly, and all the errors are handled in
44
* USE: mgmSrvApi -n -i
46
* @param n Number of nodes to crash
49
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){
53
int nodesNo = 0; // Number of nodes to crash
54
int ndbID = 0; // Node ID to be crashed
58
if (strcmp(argv[i], "-n") == 0)
59
nodesNo = atoi(argv[i+1]);
61
if (strcmp(argv[i], "-i") == 0)
62
ndbID = atoi(argv[i+1]);
64
if (strcmp(argv[i], "-p") == 0)
74
ndbout << "Creating handle..." << endl;
75
NdbMgmHandle h = ndb_mgm_create_handle();
78
* Perfom the connection
80
ndbout << "Connecting..." << endl;
81
if (ndb_mgm_connect(h, Addr) == -1) {
82
ndbout << "Connection to " << Addr << " failed" << endl;
87
* Get status of a node
89
ndbout << "Getting status..." << endl;
91
struct ndb_mgm_cluster_state * status;
92
struct ndb_mgm_node_state * nodes;
94
status = ndb_mgm_get_status(h);
95
nodes = status->node_states;
96
if (nodes->node_status == 1) {
97
ndbout << "No contact established" << endl;
104
ndbout << "Stopping the node(s)" << endl;
107
if (nodesNo == 0) // all nodes stopped by definition
111
if (ndb_mgm_stop(h, nodesNo, list) != 1) {
112
ndbout << nodesNo << " NDB node(s) not stopped " << endl;
116
* Disconnect from the management server
118
ndbout << "Disconnecting..." << endl;
119
ndb_mgm_disconnect(h);
124
ndbout << "Destroying the handle..." << endl;
125
ndb_mgm_destroy_handle(&h);