/Users/deen/code/yugabyte-db/src/yb/tools/yb-admin_cli.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | #ifndef YB_TOOLS_YB_ADMIN_CLI_H |
33 | | #define YB_TOOLS_YB_ADMIN_CLI_H |
34 | | |
35 | | #include <functional> |
36 | | #include <map> |
37 | | #include <vector> |
38 | | #include <string> |
39 | | |
40 | | #include <rapidjson/document.h> |
41 | | |
42 | | #include "yb/util/status_fwd.h" |
43 | | #include "yb/tools/tools_fwd.h" |
44 | | |
45 | | namespace yb { |
46 | | namespace client { |
47 | | |
48 | | class YBTableName; |
49 | | |
50 | | } // namespace client |
51 | | |
52 | | namespace tools { |
53 | | |
54 | | typedef enterprise::ClusterAdminClient ClusterAdminClientClass; |
55 | | |
56 | | // Tool to administer a cluster from the CLI. |
57 | | class ClusterAdminCli { |
58 | | public: |
59 | | typedef std::vector<std::string> CLIArguments; |
60 | | |
61 | 77 | virtual ~ClusterAdminCli() = default; |
62 | | |
63 | | Status Run(int argc, char** argv); |
64 | | |
65 | | static const Status kInvalidArguments; |
66 | | |
67 | | protected: |
68 | | typedef std::function<Status(const CLIArguments&)> Action; |
69 | | typedef std::function<Result<rapidjson::Document>(const CLIArguments&)> JsonAction; |
70 | | |
71 | | struct Command { |
72 | | std::string name_; |
73 | | std::string usage_arguments_; |
74 | | Action action_; |
75 | | }; |
76 | | |
77 | | void Register(std::string&& cmd_name, std::string&& cmd_args, Action&& action); |
78 | | void RegisterJson(std::string&& cmd_name, std::string&& cmd_args, JsonAction&& action); |
79 | | void SetUsage(const std::string& prog_name); |
80 | | |
81 | | virtual void RegisterCommandHandlers(ClusterAdminClientClass* client); |
82 | | |
83 | | private: |
84 | | std::vector<Command> commands_; |
85 | | std::map<std::string, size_t> command_indexes_; |
86 | | }; |
87 | | |
88 | | using CLIArgumentsIterator = ClusterAdminCli::CLIArguments::const_iterator; |
89 | | using TailArgumentsProcessor = |
90 | | std::function<Status(CLIArgumentsIterator, const CLIArgumentsIterator&)>; |
91 | | |
92 | | Result<std::vector<client::YBTableName>> ResolveTableNames( |
93 | | ClusterAdminClientClass* client, |
94 | | CLIArgumentsIterator i, |
95 | | const CLIArgumentsIterator& end, |
96 | | const TailArgumentsProcessor& tail_processor = TailArgumentsProcessor(), |
97 | | bool allow_namespace_only = false); |
98 | | |
99 | | Result<client::YBTableName> ResolveSingleTableName( |
100 | | ClusterAdminClientClass* client, |
101 | | CLIArgumentsIterator i, |
102 | | const CLIArgumentsIterator& end, |
103 | | TailArgumentsProcessor tail_processor = TailArgumentsProcessor()); |
104 | | |
105 | | CHECKED_STATUS CheckArgumentsCount(size_t count, size_t min, size_t max); |
106 | | |
107 | | } // namespace tools |
108 | | } // namespace yb |
109 | | |
110 | | #endif // YB_TOOLS_YB_ADMIN_CLI_H |