26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_INTERFACE_ENDPOINT_BASE_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_INTERFACE_ENDPOINT_BASE_H_
32#include <shared_mutex>
57class EndpointBase :
public std::enable_shared_from_this<EndpointBase> {
96 bool parents_required_authnetication =
false;
97 auto parent = get_parent_ptr();
100 parents_required_authnetication = parent->required_authentication();
103 return parents_required_authnetication ||
104 does_this_node_require_authentication();
108 auto parent = get_parent_ptr();
110 return (parent ? parent->get_url_path() : std::string()) +
111 get_my_url_path_part();
115 auto parent = get_parent_ptr();
116 Uri uri{parent ? parent->get_url() :
Uri{}};
117 uri.
set_path(uri.get_path() + get_my_url_part());
148 auto parent = get_parent_ptr();
152 auto this_enabled_level = get_this_node_enabled_level();
157 auto parent_enabled_level = parent->get_enabled_level();
160 return parent_enabled_level;
164 : parent_enabled_level;
168 auto lock = std::unique_lock<std::shared_mutex>(endpoints_access_);
169 change_parent(parent);
174 auto parent_old = get_parent_ptr();
176 if (parent_old == parent_new)
return;
177 if (parent_old) parent_old->remove_child_endpoint(
get_id());
178 if (parent_new) parent_new->add_child_endpoint(shared_from_this());
180 parent_ = parent_new;
189 auto lock = std::unique_lock<std::shared_mutex>(endpoints_access_);
191 endpoints_.insert_or_assign(child_ptr->get_id(), child_ptr);
195 auto lock = std::unique_lock<std::shared_mutex>(endpoints_access_);
196 endpoints_.erase(child_id);
201 result.reserve(endpoints_.size());
202 for (
auto [
_, child] : endpoints_) {
223 assert(
false &&
"Missing 'enums' value inside the switch.");
227 auto current = get_enabled_level();
228 if (last_state_ != current) {
229 last_state_ = current;
231 log_info(
"Endpoint(id=%s, path='%s'%s) changed state to '%s'",
233 get_extra_update_data().c_str(), get_state_name(current));
241 switch (get_enabled_level()) {
255 auto it = endpoints_.find(
id);
256 if (it == endpoints_.end())
return {};
273 auto children = get_children();
275 for (
auto &child : children) child->changed();
virtual void set_path(const std::string &path)
Definition: uri.cc:162
Definition: endpoint_base.h:57
EndpointBasePtr get_parent_ptr()
Definition: endpoint_base.h:186
std::optional< std::vector< std::string > > OptionalIndexNames
Definition: endpoint_base.h:68
virtual std::string get_extra_update_data()
Definition: endpoint_base.h:237
void changed()
Definition: endpoint_base.h:269
virtual void activate_private()
Definition: endpoint_base.h:136
virtual UniversalId get_parent_id() const =0
virtual OptionalIndexNames get_index_files()=0
const EndpointBasePtr get_parent_ptr() const
Definition: endpoint_base.h:185
std::optional< EnabledType > last_state_
Definition: endpoint_base.h:213
EndpointBasePtr get_child_by_id(const UniversalId &id) const
Definition: endpoint_base.h:254
virtual UniversalId get_id() const =0
std::vector< EndpointBasePtr > Children
Definition: endpoint_base.h:62
mrs::database::entry::EnabledType EnabledType
Definition: endpoint_base.h:59
EndpointConfigurationPtr get_configuration() const
Definition: endpoint_base.h:183
virtual std::optional< std::string > get_options() const =0
virtual void update()
Definition: endpoint_base.h:239
virtual std::string get_my_url_path_part() const =0
void log_update()
Definition: endpoint_base.h:226
virtual std::string get_my_url_part() const =0
virtual void deactivate()
Definition: endpoint_base.h:145
void remove_child_endpoint(const UniversalId &child_id)
Definition: endpoint_base.h:194
std::weak_ptr< EndpointBase > parent_
Definition: endpoint_base.h:281
std::shared_mutex endpoints_access_
Definition: endpoint_base.h:279
std::map< UniversalId, EndpointBasePtr > endpoints_
Definition: endpoint_base.h:280
std::shared_ptr< EndpointBase > EndpointBasePtr
Definition: endpoint_base.h:60
void set_parent(EndpointBasePtr parent)
Definition: endpoint_base.h:167
EndpointBase(EndpointConfigurationPtr configuration)
Definition: endpoint_base.h:71
virtual bool does_this_node_require_authentication() const =0
virtual EnabledType get_enabled_level() const
Definition: endpoint_base.h:147
static const char * get_state_name(EnabledType et)
Definition: endpoint_base.h:214
virtual std::string get_url_path() const
Definition: endpoint_base.h:107
mrs::database::entry::UniversalId UniversalId
Definition: endpoint_base.h:61
virtual void activate_public()
Definition: endpoint_base.h:128
virtual Uri get_url() const
Definition: endpoint_base.h:114
EndpointConfigurationPtr configuration_
Definition: endpoint_base.h:282
void change_parent(EndpointBasePtr parent_new)
Definition: endpoint_base.h:173
void add_child_endpoint(EndpointBasePtr child_ptr)
Definition: endpoint_base.h:188
virtual bool required_authentication() const
Definition: endpoint_base.h:95
std::shared_ptr< Handler > HandlerPtr
Definition: endpoint_base.h:66
virtual ~EndpointBase()=default
std::shared_ptr< EndpointConfiguration > EndpointConfigurationPtr
Definition: endpoint_base.h:64
virtual EnabledType get_this_node_enabled_level() const =0
Children get_children()
Definition: endpoint_base.h:199
Definition: endpoint_configuration.h:35
Definition: rest_handler.h:141
#define log_info(...)
Definition: log_client.h:153
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
Logging interface for using and extending the logging subsystem.
#define IMPORT_LOG_FUNCTIONS()
convenience macro to avoid common boilerplate
Definition: logging.h:331
static uint update
Definition: myisamlog.cc:94
Request::Uri Uri
Definition: request.cc:36
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
EnabledType
Definition: entry.h:56
@ EnabledType_private
Definition: entry.h:59
@ EnabledType_none
Definition: entry.h:57
@ EnabledType_public
Definition: entry.h:58
DbServiceEndpoint::EndpointConfiguration EndpointConfiguration
Definition: db_service_endpoint.cc:49
Definition: authorize_manager.h:48
mrs::database::entry::UniversalId UniversalId
Definition: universal_id.h:33
std::string join(const detail::range auto &rng, std::string_view delim)
join elements of a range into a string separated by a delimiter.
Definition: string.h:74
pid_type get_id()
Definition: process.h:48
struct result result
Definition: result.h:34
required string configuration
Definition: replication_asynchronous_connection_failover.proto:49
static task_env * deactivate(task_env *t)
Definition: task.cc:564
#define _(str)
Definition: win_i18n.h:33