MySQL 9.0.0
Source Code Documentation
section_config_exposer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, 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 MYSQL_HARNESS_SESSION_CONFIG_EXPOSER_INCLUDED
27#define MYSQL_HARNESS_SESSION_CONFIG_EXPOSER_INCLUDED
28
29#include <map>
30#include <string>
31#include <string_view>
32#include <variant>
33
34#include "harness_export.h"
37
38namespace mysql_harness {
39
40/** @class SectionConfigExposer
41 *
42 * @brief Base class for a plugin specific specializations. Lets the plugin
43 * expose their initial and default configuration to the DynamicConfig object.
44 */
45class HARNESS_EXPORT SectionConfigExposer {
46 public:
48
50
51 enum class Mode { ExposeInitialConfig, ExposeDefaultConfig };
52
53 /**
54 * Constructor.
55 *
56 * @param initial flag indicating if the initial or default configuration is
57 * being shared.
58 * @param default_section default section of the current configuration
59 * @param section_id identifier of the plugin configuration in the Dynamic
60 * config object.
61 */
63 const mysql_harness::ConfigSection &default_section,
64 const DC::SectionId &section_id)
65 : mode_(initial ? Mode::ExposeInitialConfig : Mode::ExposeDefaultConfig),
66 default_section_(default_section),
67 section_id_(section_id) {}
68
69 virtual ~SectionConfigExposer() = default;
70
72
73 protected:
74 /**
75 * Exposes plugin instance configuration.
76 */
77 virtual void expose() = 0;
78
79 const Mode mode_;
81
83 const DC::SectionId common_section_id_{"common", ""};
84
85 /**
86 * Exposes single option configuration.
87 *
88 * @param option option name
89 * @param value configured (initial) value of the option
90 * @param default_value default value for both Cluster and ClusterSet
91 * configuration
92 * @param is_common indicates whether the options is supposed to also be
93 * shared in the "common" section of the configuration
94 */
95 void expose_option(std::string_view option, const OptionValue &value,
96 const OptionValue &default_value, bool is_common = false);
97
98 /**
99 * Exposes single option configuration (overload for options that have
100 * different defaults for Cluster and for ClusterSet configuration).
101 *
102 * @param option option name
103 * @param value configured (initial) value of the option
104 * @param default_value_cluster default value for Cluster configuration
105 * @param default_value_clusterset default value for ClusterSet configuration
106 * @param is_common indicates whether the options is supposed to also be
107 * shared in the "common" section of the configuration
108 */
109 void expose_option(std::string_view option, const OptionValue &value,
110 const OptionValue &default_value_cluster,
111 const OptionValue &default_value_clusterset,
112 bool is_common);
113
114 private:
115 void expose_str_option(std::string_view option, const OptionValue &value,
116 const OptionValue &default_value_cluster,
117 const OptionValue &default_value_clusterset,
118 bool is_common = false);
119
120 void expose_int_option(std::string_view option, const OptionValue &value,
121 const OptionValue &default_value_cluster,
122 const OptionValue &default_value_clusterset,
123 bool is_common = false);
124
125 void expose_double_option(std::string_view option, const OptionValue &value,
126 const OptionValue &default_value_cluster,
127 const OptionValue &default_value_clusterset,
128 bool is_common = false);
129
130 void expose_bool_option(std::string_view option, const OptionValue &value,
131 const OptionValue &default_value_cluster,
132 const OptionValue &default_value_clusterset,
133 bool is_common = false);
134
135 void expose_default(std::string_view option,
136 const auto &default_value_cluster,
137 const auto &default_value_clusterset, bool is_common) {
138 DC::instance().set_option_default(
139 section_id_, option, default_value_cluster, default_value_clusterset);
140 if (is_common) {
141 DC::instance().set_option_default(common_section_id_, option,
142 default_value_cluster,
143 default_value_clusterset);
144 }
145 }
146};
147
148} // namespace mysql_harness
149
150#endif // MYSQL_HARNESS_SESSION_CONFIG_EXPOSER_INCLUDED
Configuration section.
Definition: config_parser.h:141
Respresents the current Router configuration.
Definition: dynamic_config.h:48
std::variant< std::monostate, int64_t, bool, double, std::string > OptionValue
Definition: dynamic_config.h:53
std::pair< std::string, std::string > SectionId
Definition: dynamic_config.h:62
Base class for a plugin specific specializations.
Definition: section_config_exposer.h:45
const mysql_harness::ConfigSection & default_section_
Definition: section_config_exposer.h:80
SectionConfigExposer(const SectionConfigExposer &)=delete
const DC::SectionId section_id_
Definition: section_config_exposer.h:82
const Mode mode_
Definition: section_config_exposer.h:79
SectionConfigExposer(bool initial, const mysql_harness::ConfigSection &default_section, const DC::SectionId &section_id)
Constructor.
Definition: section_config_exposer.h:62
virtual void expose()=0
Exposes plugin instance configuration.
Mode
Definition: section_config_exposer.h:51
virtual ~SectionConfigExposer()=default
void expose_default(std::string_view option, const auto &default_value_cluster, const auto &default_value_clusterset, bool is_common)
Definition: section_config_exposer.h:135
DC::OptionValue OptionValue
Definition: section_config_exposer.h:49
Definition: common.h:42