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> {
95 bool parents_required_authnetication =
false;
96 auto parent = get_parent_ptr();
99 parents_required_authnetication = parent->required_authentication();
102 return parents_required_authnetication ||
103 does_this_node_require_authentication();
107 auto parent = get_parent_ptr();
109 return (parent ? parent->get_url_path() : std::string()) +
110 get_my_url_path_part();
114 auto parent = get_parent_ptr();
115 Uri uri{parent ? parent->get_url() :
Uri{}};
116 uri.
set_path(uri.get_path() + get_my_url_part());
147 auto parent = get_parent_ptr();
151 auto this_enabled_level = get_this_node_enabled_level();
156 auto parent_enabled_level = parent->get_enabled_level();
159 return parent_enabled_level;
163 : parent_enabled_level;
167 auto lock = std::unique_lock<std::shared_mutex>(endpoints_access_);
168 change_parent(parent);
173 auto parent_old = get_parent_ptr();
175 if (parent_old == parent_new)
return;
176 if (parent_old) parent_old->remove_child_endpoint(
get_id());
177 if (parent_new) parent_new->add_child_endpoint(shared_from_this());
179 parent_ = parent_new;
188 auto lock = std::unique_lock<std::shared_mutex>(endpoints_access_);
190 endpoints_.insert_or_assign(child_ptr->get_id(), child_ptr);
194 auto lock = std::unique_lock<std::shared_mutex>(endpoints_access_);
195 endpoints_.erase(child_id);
200 result.reserve(endpoints_.size());
201 for (
auto [
_, child] : endpoints_) {
222 assert(
false &&
"Missing 'enums' value inside the switch.");
226 auto current = get_enabled_level();
227 if (last_state_ != current) {
228 last_state_ = current;
230 log_info(
"Endpoint(id=%s, path='%s'%s) changed state to '%s'",
232 get_extra_update_data().c_str(), get_state_name(current));
240 switch (get_enabled_level()) {
254 auto it = endpoints_.find(
id);
255 if (it == endpoints_.end())
return {};
272 auto children = get_children();
274 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:185
std::optional< std::vector< std::string > > OptionalIndexNames
Definition: endpoint_base.h:68
virtual std::string get_extra_update_data()
Definition: endpoint_base.h:236
void changed()
Definition: endpoint_base.h:268
virtual void activate_private()
Definition: endpoint_base.h:135
virtual UniversalId get_parent_id() const =0
virtual OptionalIndexNames get_index_files()=0
const EndpointBasePtr get_parent_ptr() const
Definition: endpoint_base.h:184
std::optional< EnabledType > last_state_
Definition: endpoint_base.h:212
EndpointBasePtr get_child_by_id(const UniversalId &id) const
Definition: endpoint_base.h:253
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:182
virtual std::optional< std::string > get_options() const =0
virtual void update()
Definition: endpoint_base.h:238
virtual std::string get_my_url_path_part() const =0
void log_update()
Definition: endpoint_base.h:225
virtual std::string get_my_url_part() const =0
virtual void deactivate()
Definition: endpoint_base.h:144
void remove_child_endpoint(const UniversalId &child_id)
Definition: endpoint_base.h:193
std::weak_ptr< EndpointBase > parent_
Definition: endpoint_base.h:280
std::shared_mutex endpoints_access_
Definition: endpoint_base.h:278
std::map< UniversalId, EndpointBasePtr > endpoints_
Definition: endpoint_base.h:279
std::shared_ptr< EndpointBase > EndpointBasePtr
Definition: endpoint_base.h:60
void set_parent(EndpointBasePtr parent)
Definition: endpoint_base.h:166
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:146
static const char * get_state_name(EnabledType et)
Definition: endpoint_base.h:213
virtual std::string get_url_path() const
Definition: endpoint_base.h:106
mrs::database::entry::UniversalId UniversalId
Definition: endpoint_base.h:61
virtual void activate_public()
Definition: endpoint_base.h:127
virtual Uri get_url() const
Definition: endpoint_base.h:113
EndpointConfigurationPtr configuration_
Definition: endpoint_base.h:281
void change_parent(EndpointBasePtr parent_new)
Definition: endpoint_base.h:172
void add_child_endpoint(EndpointBasePtr child_ptr)
Definition: endpoint_base.h:187
virtual bool required_authentication() const
Definition: endpoint_base.h:94
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:198
Definition: endpoint_configuration.h:35
Definition: rest_handler.h:135
#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:323
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:48
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