~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to storage/ndb/src/mgmapi/test/mgmSrvApi.cpp

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *  Name: 
 
21
 *       mgmSrvApi.cpp
 
22
 *
 
23
 *  Description:
 
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
 
28
 *  
 
29
 *****************************************************/
 
30
#include <ndb_global.h>
 
31
#include "mgmapi.h"
 
32
#include "mgmapi_commands.h"
 
33
#include <NdbMain.h>
 
34
#include <NdbOut.hpp>
 
35
 
 
36
/**
 
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 
 
43
 * a proper way.
 
44
 * USE: mgmSrvApi -n -i 
 
45
 *
 
46
 * @param       n     Number of nodes to crash
 
47
 *
 
48
 **/
 
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){
 
50
 
 
51
  const char *Addr = 0;
 
52
  int i;
 
53
  int nodesNo = 0; // Number of nodes to crash
 
54
  int ndbID = 0;  // Node ID to be crashed 
 
55
 
 
56
  i = 1;
 
57
  while (argc > 1) {
 
58
    if (strcmp(argv[i], "-n") == 0) 
 
59
      nodesNo = atoi(argv[i+1]);
 
60
 
 
61
    if (strcmp(argv[i], "-i") == 0) 
 
62
      ndbID = atoi(argv[i+1]);
 
63
 
 
64
    if (strcmp(argv[i], "-p") == 0)
 
65
       Addr = argv[i+1];
 
66
    
 
67
    argc -= 1;
 
68
    i = i + 1; 
 
69
  }
 
70
 
 
71
  /*  
 
72
   * Create a handle
 
73
   */
 
74
  ndbout << "Creating handle..." << endl;
 
75
  NdbMgmHandle h = ndb_mgm_create_handle();   
 
76
 
 
77
  /*  
 
78
   * Perfom the connection
 
79
   */
 
80
  ndbout << "Connecting..." << endl;
 
81
  if (ndb_mgm_connect(h, Addr) == -1) {
 
82
    ndbout << "Connection to " << Addr << " failed" << endl;
 
83
    exit(-1);
 
84
  }
 
85
 
 
86
  /*  
 
87
   * Get status of a node
 
88
   */
 
89
  ndbout << "Getting status..." << endl;
 
90
  
 
91
  struct ndb_mgm_cluster_state * status;
 
92
  struct ndb_mgm_node_state * nodes;
 
93
 
 
94
  status = ndb_mgm_get_status(h);
 
95
  nodes = status->node_states;
 
96
  if (nodes->node_status == 1) {
 
97
    ndbout << "No contact established" << endl;
 
98
    //  exit(-1);
 
99
  }
 
100
    
 
101
  /*  
 
102
   * Stop the NDB nodes
 
103
   */
 
104
  ndbout << "Stopping the node(s)" << endl;
 
105
  const int * list;
 
106
 
 
107
  if (nodesNo == 0) // all nodes stopped by definition
 
108
    ndbID = 0;
 
109
 
 
110
  list = &ndbID;
 
111
  if (ndb_mgm_stop(h, nodesNo, list) != 1) {
 
112
    ndbout << nodesNo << " NDB node(s) not stopped " << endl;
 
113
  }
 
114
 
 
115
  /*  
 
116
   * Disconnect from the management server
 
117
   */
 
118
  ndbout << "Disconnecting..." << endl;
 
119
  ndb_mgm_disconnect(h);
 
120
 
 
121
  /*  
 
122
   * Destroy the handle
 
123
   */
 
124
  ndbout << "Destroying the handle..." << endl;
 
125
  ndb_mgm_destroy_handle(&h);
 
126
 
 
127
  return 0;
 
128
}