MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
router_conf.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_MYSQL_ROUTER_CONF_INCLUDED
27#define ROUTER_MYSQL_ROUTER_CONF_INCLUDED
28
30
31/** @file
32 * @brief Defining the main class MySQLRouter
33 *
34 * This file defines the main class `MySQLRouter`.
35 *
36 */
37
38#include "config_generator.h"
39#include "dim.h"
45
46#include <cstdint>
47#include <iostream>
48#include <memory>
49#include <stdexcept>
50#include <vector>
51
53 public:
55 std::ostream &out_stream = std::cout,
56 std::ostream &err_stream = std::cerr)
57 : keyring_info_(keyring_info),
58 out_stream_(out_stream),
59 err_stream_(err_stream) {}
60
61 virtual ~MySQLRouterConf() = default;
62
63 virtual void prepare_command_options(
64 CmdArgHandler &arg_handler,
65 const std::string &bootstrap_uri = "") noexcept;
66
67 bool is_bootstrap() const { return !bootstrap_uri_.empty(); }
68 virtual bool is_legacy() const { return true; }
69
70 bool skipped() const { return skipped_; }
71
72 void add_option(const std::string &key, const std::string &value) {
74 }
75
76 const std::map<std::string, std::string> &bootstrap_options() const {
77 return bootstrap_options_;
78 }
79
80 public:
81 void connect();
82
83 mysqlrouter::MySQLSession *session() const { return mysql_.get(); }
84
85 std::string bootstrap(
86 const std::string &program_name, const mysql_harness::Path &origin,
87 bool allow_standalone, const std::string &plugin_folder
88#ifndef _WIN32
89 ,
90 mysqlrouter::SysUserOperationsBase *sys_user_operations = nullptr
91#endif
92 );
93
94 std::map<std::string, std::string> get_config_cmdln_options() const;
95
96 protected:
97 friend class MySQLRouter;
98
99#ifdef FRIEND_TEST
100 FRIEND_TEST(ConfigGeneratorTest, ssl_stage1_cmdline_arg_parse);
101 FRIEND_TEST(ConfigGeneratorTest, ssl_stage2_bootstrap_connection);
102 FRIEND_TEST(ConfigGeneratorTest, ssl_stage3_create_config);
103#endif
104
105 /**
106 * @brief Value of the argument passed to the -B or --bootstrap
107 * command line option for bootstrapping.
108 */
109 std::string bootstrap_uri_;
110 /**
111 * @brief Valueof the argument passed to the --directory command line option
112 */
114 /**
115 * @brief key/value map of additional configuration options for bootstrap
116 */
117 std::map<std::string, std::string> bootstrap_options_;
118
119 /**
120 * @brief key/list-of-values map of additional configuration options for
121 * bootstrap
122 */
123 std::map<std::string, std::vector<std::string>> bootstrap_multivalue_options_;
124
126 std::unique_ptr<mysqlrouter::MySQLSession> mysql_;
127
129
130 bool skipped_ = false;
131
132 std::ostream &out_stream_;
133 std::ostream &err_stream_;
134
135 std::string plugin_folder_;
136
137 /** @brief Saves the selected command line option in the internal options
138 * array after verifying it's value not empty and the router is doing
139 * bootstrap.
140 *
141 * Throws: std::runtime_error
142 */
143 void save_bootstrap_option_not_empty(const std::string &option_name,
144 const std::string &save_name,
145 const std::string &option_value);
146
147 /**
148 * @brief verify that bootstrap option (--bootstrap or -B) was given by user.
149 *
150 * @throw std::runtime_error if called in non-bootstrap mode.
151 */
152 void assert_bootstrap_mode(const std::string &option_name) const;
153
154 int get_connect_timeout() const;
155 int get_read_timeout() const;
156 std::string get_bootstrap_socket() const;
157};
158
159class silent_exception : public std::exception {
160 public:
161 silent_exception() : std::exception() {}
162};
163
164#endif // ROUTER_MYSQL_ROUTER_CONF_INCLUDED
Defining the commandline argument handler class CmdArgHandler.
Handles command line arguments.
Definition: arg_handler.h:141
KeyringInfo class encapsulates loading and storing master key using master-key-reader and master-key-...
Definition: keyring_info.h:76
Definition: router_conf.h:52
virtual void prepare_command_options(CmdArgHandler &arg_handler, const std::string &bootstrap_uri="") noexcept
Definition: router_conf.cc:212
bool skipped() const
Definition: router_conf.h:70
bool is_bootstrap() const
Definition: router_conf.h:67
MySQLRouterConf(KeyringInfo &keyring_info, std::ostream &out_stream=std::cout, std::ostream &err_stream=std::cerr)
Definition: router_conf.h:54
bool skipped_
Definition: router_conf.h:130
std::string get_bootstrap_socket() const
Definition: router_conf.cc:1101
int get_read_timeout() const
Definition: router_conf.cc:1091
virtual bool is_legacy() const
Definition: router_conf.h:68
KeyringInfo & keyring_info_
Definition: router_conf.h:128
std::ostream & err_stream_
Definition: router_conf.h:133
std::string bootstrap_directory_
Valueof the argument passed to the –directory command line option.
Definition: router_conf.h:113
void assert_bootstrap_mode(const std::string &option_name) const
verify that bootstrap option (–bootstrap or -B) was given by user.
Definition: router_conf.cc:1074
mysqlrouter::MySQLSession * session() const
Definition: router_conf.h:83
std::map< std::string, std::vector< std::string > > bootstrap_multivalue_options_
key/list-of-values map of additional configuration options for bootstrap
Definition: router_conf.h:123
mysqlrouter::URI target_uri_
Definition: router_conf.h:125
void connect()
Definition: router_conf.cc:1106
std::map< std::string, std::string > get_config_cmdln_options() const
Definition: router_conf.cc:1163
std::map< std::string, std::string > bootstrap_options_
key/value map of additional configuration options for bootstrap
Definition: router_conf.h:117
std::string bootstrap_uri_
Value of the argument passed to the -B or –bootstrap command line option for bootstrapping.
Definition: router_conf.h:109
void save_bootstrap_option_not_empty(const std::string &option_name, const std::string &save_name, const std::string &option_value)
Saves the selected command line option in the internal options array after verifying it's value not e...
Definition: router_conf.cc:1064
int get_connect_timeout() const
Definition: router_conf.cc:1081
std::unique_ptr< mysqlrouter::MySQLSession > mysql_
Definition: router_conf.h:126
std::ostream & out_stream_
Definition: router_conf.h:132
const std::map< std::string, std::string > & bootstrap_options() const
Definition: router_conf.h:76
void add_option(const std::string &key, const std::string &value)
Definition: router_conf.h:72
virtual ~MySQLRouterConf()=default
std::string bootstrap(const std::string &program_name, const mysql_harness::Path &origin, bool allow_standalone, const std::string &plugin_folder, mysqlrouter::SysUserOperationsBase *sys_user_operations=nullptr)
Definition: router_conf.cc:1240
std::string plugin_folder_
Definition: router_conf.h:135
Manage the MySQL Router application.
Definition: router_app.h:81
Class representing a path in a file system.
Definition: filesystem.h:63
Definition: mysql_session.h:157
Base class to allow multiple SysUserOperations implementations.
Definition: sys_user_operations.h:45
Parse and create URIs according to RFC3986.
Definition: uri.h:66
Definition: router_conf.h:159
silent_exception()
Definition: router_conf.h:161
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: gcs_xcom_synode.h:64
required string key
Definition: replication_asynchronous_connection_failover.proto:60