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