- Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathadmin_cmd_handler.h
257 lines (222 loc) · 12 KB
/
admin_cmd_handler.h
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* Copyright (c) 2015, 2025, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0,
* as published by the Free Software Foundation.
*
* This program is designed to work with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an additional
* permission to link the program and your derivative works with the
* separately licensed software that they have either included with
* the program or referenced in the documentation.
*
* 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, version 2.0, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PLUGIN_X_SRC_ADMIN_CMD_HANDLER_H_
#definePLUGIN_X_SRC_ADMIN_CMD_HANDLER_H_
#include<initializer_list>
#include<map>
#include<string>
#include<vector>
#include"my_compiler.h"// NOLINT(build/include_subdir)
MY_COMPILER_DIAGNOSTIC_PUSH()
// Suppress warning C4251 'type' : class 'type1' needs to have dll-interface
// to be used by clients of class 'type2'
MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(4251)
#include<google/protobuf/repeated_field.h>// NOLINT(build/include_order)
MY_COMPILER_DIAGNOSTIC_POP()
#include"plugin/x/src/admin_cmd_collection_handler.h"
#include"plugin/x/src/interface/admin_command_arguments.h"
#include"plugin/x/src/interface/sql_session.h"
#include"plugin/x/src/ngs/error_code.h"
namespacexpl {
classAdmin_command_handler {
public:
using Command_arguments = iface::Admin_command_arguments;
explicitAdmin_command_handler(iface::Session *session);
ngs::Error_code execute(const std::string &command, Command_arguments *args);
staticconstchar *const k_mysqlx_namespace;
protected:
using Argument_list = Command_arguments::Argument_list;
using Value_list = Command_arguments::List;
using Argument_appearance = Command_arguments::Appearance_type;
ngs::Error_code ping(Command_arguments *args);
ngs::Error_code list_clients(Command_arguments *args);
ngs::Error_code kill_client(Command_arguments *args);
/**
Create a new collection.
Create a collection with a given name in the specified schema. If collection
already exists an error is returned. 'create_collection' command supports
additional options. Validation option consists of two fields - schema and
level. Validation level field is optional and can be used to change the
state of validation operations. Validation schema field is required (if
validation option is supplied) and can be used to create constraint on
a given validation schema for newly created collection. Update
Mysqlx_stmt_create_collection variable on each call.
@param[in] args list of arguments for create_collection command.
Allowed fields are:
- name (string, required) - name of created
collection.
- schema (string, required) - name of collection's
schema.
- options (object, optional) - additional options
that will be used for collection. Possible fields:
- validation (object, optional) - validation
details. Possible fields:
- schema (object, required) - validation schema
that may be used when operating on a
collection.
- level (string, optional) - enables or disables
validation, default value is "strict".
@return Result of creating a collection
@retval == ER_TABLE_EXISTS_ERROR - specified collection already exists.
@retval == ER_X_CMD_NUM_ARGUMENTS - required argument is missing.
@retval == ER_X_CMD_INVALID_ARGUMENT - unknown argument provided.
@retval == ER_X_BAD_SCHEMA - invalid schema name.
@retval == ER_X_BAD_TABLE - invalid table name.
@retval == ER_X_CMD_ARGUMENT_VALUE - invalid validation level value.
@retval == ER_X_COLLECTION_OPTION_DOESNT_EXISTS - invalid validation
option field.
*/
ngs::Error_code create_collection(Command_arguments *args);
/**
Drop existing collection.
Drop a collection with a given name in the specified schema. If collection
do not exist an error is returned. Update Mysqlx_stmt_drop_collection
variable on each call.
@param[in] args list of arguments for drop_collection command.
Allowed fields are:
- name (string, required) - name of dropped
collection.
- schema (string, required) - name of collection's
schema.
@return Result of dropping a collection
@retval == ER_X_BAD_TABLE_ERROR - collection do not exist.
@retval == ER_X_CMD_NUM_ARGUMENTS - required argument is missing.
@retval == ER_X_CMD_INVALID_ARGUMENT - unknown argument provided.
@retval == ER_X_BAD_SCHEMA - invalid schema name.
@retval == ER_X_BAD_TABLE - invalid table name.
*/
ngs::Error_code drop_collection(Command_arguments *args);
/**
Ensure that a collection exists.
Ensure that a collection with a given name in the specified schema exists.
If not then create a new collection. 'ensure_collection' command supports
additional options. Validation option consists of two fields - schema and
level. Validation level field is optional and can be used to change the
state of validation operations. Validation schema field is required (if
validation option is supplied) and can be used to create constraint on
a given validation schema for newly created collection. Update
Mysqlx_stmt_ensure_collection variable on each call.
@param[in] args list of arguments for ensure_collection command.
Allowed fields are:
- name (string, required) - name of created
collection.
- schema (string, required) - name of collection's
schema.
- options (object, optional) - additional options
that will be used for collection. Possible fields:
- validation (object, optional) - validation
details. Possible fields:
- schema (object, required) - validation schema
that may be used when operating on a
collection.
- level (string, optional) - enables or disables
validation, default value is "strict".
@return Result of creating a collection
@retval == ER_X_CMD_NUM_ARGUMENTS - required argument is missing.
@retval == ER_X_CMD_INVALID_ARGUMENT - unknown argument provided.
@retval == ER_X_BAD_SCHEMA - invalid schema name.
@retval == ER_X_BAD_TABLE - invalid table name.
@retval == ER_X_CMD_ARGUMENT_VALUE - invalid validation level value.
@retval == ER_X_COLLECTION_OPTION_DOESNT_EXISTS - invalid validation
option field.
*/
ngs::Error_code ensure_collection(Command_arguments *args);
/**
Modify options for a specified collection.
Command used to modify collection options. It can be used to modify
validation schema of a collection or enable/disable validation. Update
Mysqlx_stmt_modify_collection_options variable on each call.
@param[in] args list of arguments for modify_collection_options
command. Allowed fields are:
- name (string, required) - name of collection.
- schema (string, required) - name of collection's
schema.
- options (object, optional) - additional options
that will be used for collection. Possible fields:
- validation (object, optional) - validation
details. Possible fields:
- schema (object, optional) - validation schema
that may be used when operating on a
collection.
- level (string, optional) - state of validation
operations.
@return Result of modifying a collection options
@retval == ER_X_INVALID_NAMESPACE - statement used in an unsupported
namespace.
@retval == ER_X_CMD_NUM_ARGUMENTS - required argument is missing.
@retval == ER_X_CMD_INVALID_ARGUMENT - unknown argument provided.
@retval == ER_X_BAD_SCHEMA - invalid schema name.
@retval == ER_X_BAD_TABLE - invalid table name.
@retval == ER_X_CMD_ARGUMENT_VALUE - invalid validation field value.
@retval == ER_X_COLLECTION_OPTION_DOESNT_EXISTS - invalid validation
option field.
@retval == ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA - existing
collection data violates validation schema constraints.
*/
ngs::Error_code modify_collection_options(Command_arguments *args);
/**
Get options for a specified collection.
Return a JSON containing requested collection options. Update
Mysqlx_stmt_get_collection_options variable on each call.
@param[in] args list of arguments for get_collection_options command.
Allowed fields are:
- name (string, required) - name of collection.
- schema (string, required) - name of collection's
schema.
- options (array, required) - options that will be
fetched from a collection.
@return Result of fetching a collection options
@retval == ER_X_INVALID_NAMESPACE - statement used in an unsupported
namespace.
@retval == ER_X_CMD_NUM_ARGUMENTS - required argument is missing.
@retval == ER_X_CMD_INVALID_ARGUMENT - unknown argument provided.
@retval == ER_X_BAD_SCHEMA - invalid schema name.
@retval == ER_X_BAD_TABLE - invalid table name.
@retval == ER_TABLEACCESS_DENIED_ERROR - user has no access to collection.
@retval == ER_NO_SUCH_TABLE - collection do not exist.
@retval == ER_X_COLLECTION_OPTION_DOESNT_EXISTS - invalid collection
option field.
*/
ngs::Error_code get_collection_options(Command_arguments *args);
ngs::Error_code create_collection_index(Command_arguments *args);
ngs::Error_code drop_collection_index(Command_arguments *args);
ngs::Error_code list_objects(Command_arguments *args);
ngs::Error_code enable_notices(Command_arguments *args);
ngs::Error_code disable_notices(Command_arguments *args);
ngs::Error_code list_notices(Command_arguments *args);
using Method_ptr =
ngs::Error_code (Admin_command_handler::*)(Command_arguments *args);
staticconststructCommand_handler
: private std::map<std::string, Method_ptr> {
Command_handler();
ngs::Error_code execute(Admin_command_handler *admin,
const std::string &command,
Command_arguments *args) const;
} m_command_handler;
iface::Session *m_session;
Admin_command_collection_handler m_collection_handler;
};
} // namespace xpl
#endif// PLUGIN_X_SRC_ADMIN_CMD_HANDLER_H_