MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Services.hpp
1 /*
2  Copyright (C) 2003-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc.
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 #ifndef MGMAPI_SERVICE_HPP
20 #define MGMAPI_SERVICE_HPP
21 
22 #include <SocketServer.hpp>
23 #include <NdbSleep.h>
24 #include <Parser.hpp>
25 #include <OutputStream.hpp>
26 #include <InputStream.hpp>
27 
28 #include "MgmtSrvr.hpp"
29 
31 {
32  static void stop_session_if_timed_out(SocketServer::Session *_s, void *data);
33  static void stop_session_if_not_connected(SocketServer::Session *_s, void *data);
34  static void list_session(SocketServer::Session *_s, void *data);
35  static void get_session(SocketServer::Session *_s, void *data);
36 private:
38 
39  class MgmtSrvr & m_mgmsrv;
40  InputStream *m_input;
41  OutputStream *m_output;
42  Parser_t *m_parser;
43  MgmtSrvr::Allocated_resources *m_allocated_resources;
44  char m_err_str[1024];
45  int m_stopSelf; // -1 is restart, 0 do nothing, 1 stop
46  NdbMutex *m_mutex;
47 
48  // for listing sessions and other fun:
49  Parser_t::Context *m_ctx;
50  Uint64 m_session_id;
51 
52  int m_errorInsert;
53 
54  BaseString m_name;
55  const char* name() { return m_name.c_str(); }
56 
57  const char *get_error_text(int err_no)
58  { return m_mgmsrv.getErrorText(err_no, m_err_str, sizeof(m_err_str)); }
59 
60 public:
61  MgmApiSession(class MgmtSrvr & mgm, NDB_SOCKET_TYPE sock, Uint64 session_id);
62  virtual ~MgmApiSession();
63  void runSession();
64 
65  static const unsigned SOCKET_TIMEOUT = 30000;
66 
67  void getConfig(Parser_t::Context &ctx, const class Properties &args);
68  void setConfig(Parser_t::Context &ctx, const class Properties &args);
69  void showConfig(Parser_t::Context &ctx, const class Properties &args);
70  void reloadConfig(Parser_t::Context &ctx, const class Properties &args);
71 
72  void get_nodeid(Parser_t::Context &ctx, const class Properties &args);
73  void getVersion(Parser_t::Context &ctx, const class Properties &args);
74  void getStatus(Parser_t::Context &ctx, const class Properties &args);
75  void getInfoClusterLog(Parser_t::Context &ctx, const class Properties &args);
76  void restart(const class Properties &args, int version);
77  void restart_v1(Parser_t::Context &ctx, const class Properties &args);
78  void restart_v2(Parser_t::Context &ctx, const class Properties &args);
79  void restartAll(Parser_t::Context &ctx, const class Properties &args);
80  void insertError(Parser_t::Context &ctx, const class Properties &args);
81  void setTrace(Parser_t::Context &ctx, const class Properties &args);
82  void logSignals(Parser_t::Context &ctx, const class Properties &args);
83  void startSignalLog(Parser_t::Context &ctx, const class Properties &args);
84  void stopSignalLog(Parser_t::Context &ctx, const class Properties &args);
85  void dumpState(Parser_t::Context &ctx, const class Properties &args);
86  void startBackup(Parser_t::Context &ctx, const class Properties &args);
87  void abortBackup(Parser_t::Context &ctx, const class Properties &args);
88  void enterSingleUser(Parser_t::Context &ctx, const class Properties &args);
89  void exitSingleUser(Parser_t::Context &ctx, const class Properties &args);
90  void stop_v1(Parser_t::Context &ctx, const class Properties &args);
91  void stop_v2(Parser_t::Context &ctx, const class Properties &args);
92  void stop(const class Properties &args, int version);
93  void stopAll(Parser_t::Context &ctx, const class Properties &args);
94  void start(Parser_t::Context &ctx, const class Properties &args);
95  void startAll(Parser_t::Context &ctx, const class Properties &args);
96  void bye(Parser_t::Context &ctx, const class Properties &args);
97  void endSession(Parser_t::Context &ctx, const class Properties &args);
98  void setLogLevel(Parser_t::Context &ctx, const class Properties &args);
99  void getClusterLogLevel(Parser_t::Context &ctx,
100  const class Properties &args);
101  void setClusterLogLevel(Parser_t::Context &ctx,
102  const class Properties &args);
103  void setLogFilter(Parser_t::Context &ctx, const class Properties &args);
104 
105  void setParameter(Parser_t::Context &ctx, const class Properties &args);
106  void setConnectionParameter(Parser_t::Context &ctx,
107  const class Properties &args);
108  void getConnectionParameter(Parser_t::Context &ctx,
109  Properties const &args);
110 
111  void listen_event(Parser_t::Context &ctx, const class Properties &args);
112 
113  void purge_stale_sessions(Parser_t::Context &ctx, const class Properties &args);
114  void check_connection(Parser_t::Context &ctx, const class Properties &args);
115 
116  void transporter_connect(Parser_t::Context &ctx, Properties const &args);
117 
118  void get_mgmd_nodeid(Parser_t::Context &ctx, Properties const &args);
119 
120  void report_event(Parser_t::Context &ctx, Properties const &args);
121 
122  void listSessions(Parser_t::Context &ctx, Properties const &args);
123 
124  void getSessionId(Parser_t::Context &ctx, Properties const &args);
125  void getSession(Parser_t::Context &ctx, Properties const &args);
126 
127  void create_nodegroup(Parser_t::Context &ctx, Properties const &args);
128  void drop_nodegroup(Parser_t::Context &ctx, Properties const &args);
129 
130  void show_variables(Parser_t::Context &ctx, Properties const &args);
131 
132  void dump_events(Parser_t::Context &ctx, Properties const &args);
133 };
134 
136  MgmtSrvr& m_mgmsrv;
137  Uint64 m_next_session_id; // Protected by m_sessions mutex it SocketServer
138 public:
139  MgmApiService(MgmtSrvr& mgm):
140  m_mgmsrv(mgm),
141  m_next_session_id(1) {}
142 
143  SocketServer::Session * newSession(NDB_SOCKET_TYPE socket){
144  return new MgmApiSession(m_mgmsrv, socket, m_next_session_id++);
145  }
146 };
147 
148 static const char* str_null(const char* str)
149 {
150  return (str ? str : "(null)");
151 }
152 
153 static const char* yes_no(bool value)
154 {
155  return (value ? "yes" : "no");
156 }
157 
158 
159 #endif