]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2014 John Spray <john.spray@inktank.com> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | */ | |
13 | ||
3efd9988 | 14 | #pragma once |
7c673cae | 15 | |
3efd9988 | 16 | #include "ActivePyModule.h" |
7c673cae FG |
17 | |
18 | #include "common/Finisher.h" | |
9f95a23c | 19 | #include "common/ceph_mutex.h" |
7c673cae | 20 | |
11fdf7f2 TL |
21 | #include "PyFormatter.h" |
22 | ||
7c673cae FG |
23 | #include "osdc/Objecter.h" |
24 | #include "client/Client.h" | |
224ce89b WB |
25 | #include "common/LogClient.h" |
26 | #include "mon/MgrMap.h" | |
c07f9fc5 | 27 | #include "mon/MonCommand.h" |
11fdf7f2 | 28 | #include "mon/mon_types.h" |
f67539c2 | 29 | #include "mon/ConfigMap.h" |
20effc67 | 30 | #include "mgr/TTLCache.h" |
7c673cae FG |
31 | |
32 | #include "DaemonState.h" | |
33 | #include "ClusterState.h" | |
11fdf7f2 | 34 | #include "OSDPerfMetricTypes.h" |
7c673cae | 35 | |
c07f9fc5 | 36 | class health_check_map_t; |
11fdf7f2 | 37 | class DaemonServer; |
92f5a8d4 TL |
38 | class MgrSession; |
39 | class ModuleCommand; | |
11fdf7f2 | 40 | class PyModuleRegistry; |
3efd9988 FG |
41 | |
42 | class ActivePyModules | |
7c673cae | 43 | { |
f6b5b4d7 TL |
44 | // module class instances not yet created |
45 | std::set<std::string, std::less<>> pending_modules; | |
46 | // module class instances already created | |
9f95a23c | 47 | std::map<std::string, std::shared_ptr<ActivePyModule>> modules; |
11fdf7f2 | 48 | PyModuleConfig &module_config; |
f67539c2 | 49 | bool have_local_config_map = false; |
11fdf7f2 | 50 | std::map<std::string, std::string> store_cache; |
f67539c2 | 51 | ConfigMap config_map; ///< derived from store_cache config/ keys |
7c673cae FG |
52 | DaemonStateIndex &daemon_state; |
53 | ClusterState &cluster_state; | |
54 | MonClient &monc; | |
11fdf7f2 | 55 | LogChannelRef clog, audit_clog; |
7c673cae FG |
56 | Objecter &objecter; |
57 | Client &client; | |
58 | Finisher &finisher; | |
20effc67 | 59 | TTLCache<string, PyObject*> ttl_cache; |
81eedcae TL |
60 | public: |
61 | Finisher cmd_finisher; | |
62 | private: | |
11fdf7f2 TL |
63 | DaemonServer &server; |
64 | PyModuleRegistry &py_module_registry; | |
7c673cae | 65 | |
11fdf7f2 | 66 | map<std::string,ProgressEvent> progress_events; |
7c673cae | 67 | |
9f95a23c | 68 | mutable ceph::mutex lock = ceph::make_mutex("ActivePyModules::lock"); |
31f18b77 | 69 | |
7c673cae | 70 | public: |
f67539c2 TL |
71 | ActivePyModules( |
72 | PyModuleConfig &module_config, | |
73 | std::map<std::string, std::string> store_data, | |
74 | bool mon_provides_kv_sub, | |
75 | DaemonStateIndex &ds, ClusterState &cs, MonClient &mc, | |
76 | LogChannelRef clog_, LogChannelRef audit_clog_, Objecter &objecter_, Client &client_, | |
77 | Finisher &f, DaemonServer &server, PyModuleRegistry &pmr); | |
7c673cae | 78 | |
3efd9988 | 79 | ~ActivePyModules(); |
7c673cae FG |
80 | |
81 | // FIXME: wrap for send_command? | |
82 | MonClient &get_monc() {return monc;} | |
83 | Objecter &get_objecter() {return objecter;} | |
84 | Client &get_client() {return client;} | |
20effc67 | 85 | PyObject *cacheable_get_python(const std::string &what); |
7c673cae FG |
86 | PyObject *get_python(const std::string &what); |
87 | PyObject *get_server_python(const std::string &hostname); | |
88 | PyObject *list_servers_python(); | |
224ce89b | 89 | PyObject *get_metadata_python( |
3efd9988 | 90 | const std::string &svc_type, const std::string &svc_id); |
224ce89b | 91 | PyObject *get_daemon_status_python( |
3efd9988 | 92 | const std::string &svc_type, const std::string &svc_id); |
224ce89b | 93 | PyObject *get_counter_python( |
3efd9988 | 94 | const std::string &svc_type, |
224ce89b WB |
95 | const std::string &svc_id, |
96 | const std::string &path); | |
11fdf7f2 TL |
97 | PyObject *get_latest_counter_python( |
98 | const std::string &svc_type, | |
99 | const std::string &svc_id, | |
100 | const std::string &path); | |
c07f9fc5 | 101 | PyObject *get_perf_schema_python( |
11fdf7f2 | 102 | const std::string &svc_type, |
c07f9fc5 | 103 | const std::string &svc_id); |
20effc67 | 104 | PyObject *get_rocksdb_version(); |
7c673cae | 105 | PyObject *get_context(); |
3efd9988 | 106 | PyObject *get_osdmap(); |
f67539c2 | 107 | /// @note @c fct is not allowed to acquire locks when holding GIL |
11fdf7f2 TL |
108 | PyObject *with_perf_counters( |
109 | std::function<void( | |
110 | PerfCounterInstance& counter_instance, | |
111 | PerfCounterType& counter_type, | |
112 | PyFormatter& f)> fct, | |
113 | const std::string &svc_name, | |
114 | const std::string &svc_id, | |
115 | const std::string &path) const; | |
116 | ||
9f95a23c | 117 | MetricQueryID add_osd_perf_query( |
11fdf7f2 TL |
118 | const OSDPerfMetricQuery &query, |
119 | const std::optional<OSDPerfMetricLimit> &limit); | |
9f95a23c TL |
120 | void remove_osd_perf_query(MetricQueryID query_id); |
121 | PyObject *get_osd_perf_counters(MetricQueryID query_id); | |
11fdf7f2 | 122 | |
f67539c2 TL |
123 | MetricQueryID add_mds_perf_query( |
124 | const MDSPerfMetricQuery &query, | |
125 | const std::optional<MDSPerfMetricLimit> &limit); | |
126 | void remove_mds_perf_query(MetricQueryID query_id); | |
33c7a0ef | 127 | void reregister_mds_perf_queries(); |
f67539c2 TL |
128 | PyObject *get_mds_perf_counters(MetricQueryID query_id); |
129 | ||
11fdf7f2 TL |
130 | bool get_store(const std::string &module_name, |
131 | const std::string &key, std::string *val) const; | |
132 | PyObject *get_store_prefix(const std::string &module_name, | |
133 | const std::string &prefix) const; | |
134 | void set_store(const std::string &module_name, | |
20effc67 | 135 | const std::string &key, const std::optional<std::string> &val); |
3efd9988 FG |
136 | |
137 | bool get_config(const std::string &module_name, | |
138 | const std::string &key, std::string *val) const; | |
20effc67 TL |
139 | std::pair<int, std::string> set_config(const std::string &module_name, |
140 | const std::string &key, const std::optional<std::string> &val); | |
3efd9988 | 141 | |
11fdf7f2 TL |
142 | PyObject *get_typed_config(const std::string &module_name, |
143 | const std::string &key, | |
144 | const std::string &prefix = "") const; | |
f67539c2 TL |
145 | PyObject *get_foreign_config( |
146 | const std::string& who, | |
147 | const std::string& name); | |
11fdf7f2 | 148 | |
3efd9988 FG |
149 | void set_health_checks(const std::string& module_name, |
150 | health_check_map_t&& checks); | |
151 | void get_health_checks(health_check_map_t *checks); | |
7c673cae | 152 | |
11fdf7f2 TL |
153 | void update_progress_event(const std::string& evid, |
154 | const std::string& desc, | |
f67539c2 TL |
155 | float progress, |
156 | bool add_to_ceph_s); | |
11fdf7f2 TL |
157 | void complete_progress_event(const std::string& evid); |
158 | void clear_all_progress_events(); | |
159 | void get_progress_events(std::map<std::string,ProgressEvent>* events); | |
7c673cae | 160 | |
9f95a23c TL |
161 | void register_client(std::string_view name, std::string addrs); |
162 | void unregister_client(std::string_view name, std::string addrs); | |
163 | ||
11fdf7f2 | 164 | void config_notify(); |
c07f9fc5 | 165 | |
11fdf7f2 | 166 | void set_uri(const std::string& module_name, const std::string &uri); |
f67539c2 | 167 | void set_device_wear_level(const std::string& devid, float wear_level); |
11fdf7f2 TL |
168 | |
169 | int handle_command( | |
92f5a8d4 TL |
170 | const ModuleCommand& module_command, |
171 | const MgrSession& session, | |
11fdf7f2 TL |
172 | const cmdmap_t &cmdmap, |
173 | const bufferlist &inbuf, | |
174 | std::stringstream *ds, | |
175 | std::stringstream *ss); | |
7c673cae | 176 | |
3efd9988 | 177 | std::map<std::string, std::string> get_services() const; |
7c673cae | 178 | |
f67539c2 TL |
179 | void update_kv_data( |
180 | const std::string prefix, | |
181 | bool incremental, | |
20effc67 | 182 | const map<std::string, std::optional<bufferlist>, std::less<>>& data); |
f67539c2 TL |
183 | void _refresh_config_map(); |
184 | ||
7c673cae FG |
185 | // Public so that MonCommandCompletion can use it |
186 | // FIXME: for send_command completion notifications, | |
187 | // send it to only the module that sent the command, not everyone | |
188 | void notify_all(const std::string ¬ify_type, | |
189 | const std::string ¬ify_id); | |
190 | void notify_all(const LogEntry &log_entry); | |
191 | ||
f6b5b4d7 TL |
192 | bool is_pending(std::string_view name) const { |
193 | return pending_modules.count(name) > 0; | |
194 | } | |
11fdf7f2 TL |
195 | bool module_exists(const std::string &name) const |
196 | { | |
197 | return modules.count(name) > 0; | |
198 | } | |
199 | ||
200 | bool method_exists( | |
201 | const std::string &module_name, | |
202 | const std::string &method_name) const | |
203 | { | |
204 | return modules.at(module_name)->method_exists(method_name); | |
205 | } | |
206 | ||
207 | PyObject *dispatch_remote( | |
208 | const std::string &other_module, | |
209 | const std::string &method, | |
210 | PyObject *args, | |
211 | PyObject *kwargs, | |
212 | std::string *err); | |
213 | ||
7c673cae | 214 | int init(); |
7c673cae FG |
215 | void shutdown(); |
216 | ||
11fdf7f2 | 217 | void start_one(PyModuleRef py_module); |
3efd9988 | 218 | |
7c673cae FG |
219 | void dump_server(const std::string &hostname, |
220 | const DaemonStateCollection &dmc, | |
221 | Formatter *f); | |
7c673cae | 222 | |
11fdf7f2 TL |
223 | void cluster_log(const std::string &channel, clog_type prio, |
224 | const std::string &message); | |
20effc67 TL |
225 | |
226 | bool inject_python_on() const; | |
227 | void update_cache_metrics(); | |
11fdf7f2 | 228 | }; |
20effc67 | 229 |