]>
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" | |
19 | #include "common/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" |
7c673cae FG |
29 | |
30 | #include "DaemonState.h" | |
31 | #include "ClusterState.h" | |
11fdf7f2 | 32 | #include "OSDPerfMetricTypes.h" |
7c673cae | 33 | |
c07f9fc5 | 34 | class health_check_map_t; |
11fdf7f2 TL |
35 | class DaemonServer; |
36 | class PyModuleRegistry; | |
3efd9988 FG |
37 | |
38 | class ActivePyModules | |
7c673cae | 39 | { |
3efd9988 | 40 | std::map<std::string, std::unique_ptr<ActivePyModule>> modules; |
11fdf7f2 TL |
41 | PyModuleConfig &module_config; |
42 | std::map<std::string, std::string> store_cache; | |
7c673cae FG |
43 | DaemonStateIndex &daemon_state; |
44 | ClusterState &cluster_state; | |
45 | MonClient &monc; | |
11fdf7f2 | 46 | LogChannelRef clog, audit_clog; |
7c673cae FG |
47 | Objecter &objecter; |
48 | Client &client; | |
49 | Finisher &finisher; | |
11fdf7f2 TL |
50 | DaemonServer &server; |
51 | PyModuleRegistry &py_module_registry; | |
7c673cae | 52 | |
11fdf7f2 | 53 | map<std::string,ProgressEvent> progress_events; |
7c673cae | 54 | |
3efd9988 | 55 | mutable Mutex lock{"ActivePyModules::lock"}; |
31f18b77 | 56 | |
7c673cae | 57 | public: |
11fdf7f2 TL |
58 | ActivePyModules(PyModuleConfig &module_config, |
59 | std::map<std::string, std::string> store_data, | |
3efd9988 | 60 | DaemonStateIndex &ds, ClusterState &cs, MonClient &mc, |
11fdf7f2 TL |
61 | LogChannelRef clog_, LogChannelRef audit_clog_, Objecter &objecter_, Client &client_, |
62 | Finisher &f, DaemonServer &server, PyModuleRegistry &pmr); | |
7c673cae | 63 | |
3efd9988 | 64 | ~ActivePyModules(); |
7c673cae FG |
65 | |
66 | // FIXME: wrap for send_command? | |
67 | MonClient &get_monc() {return monc;} | |
68 | Objecter &get_objecter() {return objecter;} | |
69 | Client &get_client() {return client;} | |
7c673cae FG |
70 | PyObject *get_python(const std::string &what); |
71 | PyObject *get_server_python(const std::string &hostname); | |
72 | PyObject *list_servers_python(); | |
224ce89b | 73 | PyObject *get_metadata_python( |
3efd9988 | 74 | const std::string &svc_type, const std::string &svc_id); |
224ce89b | 75 | PyObject *get_daemon_status_python( |
3efd9988 | 76 | const std::string &svc_type, const std::string &svc_id); |
224ce89b | 77 | PyObject *get_counter_python( |
3efd9988 | 78 | const std::string &svc_type, |
224ce89b WB |
79 | const std::string &svc_id, |
80 | const std::string &path); | |
11fdf7f2 TL |
81 | PyObject *get_latest_counter_python( |
82 | const std::string &svc_type, | |
83 | const std::string &svc_id, | |
84 | const std::string &path); | |
c07f9fc5 | 85 | PyObject *get_perf_schema_python( |
11fdf7f2 | 86 | const std::string &svc_type, |
c07f9fc5 | 87 | const std::string &svc_id); |
7c673cae | 88 | PyObject *get_context(); |
3efd9988 | 89 | PyObject *get_osdmap(); |
11fdf7f2 TL |
90 | PyObject *with_perf_counters( |
91 | std::function<void( | |
92 | PerfCounterInstance& counter_instance, | |
93 | PerfCounterType& counter_type, | |
94 | PyFormatter& f)> fct, | |
95 | const std::string &svc_name, | |
96 | const std::string &svc_id, | |
97 | const std::string &path) const; | |
98 | ||
99 | OSDPerfMetricQueryID add_osd_perf_query( | |
100 | const OSDPerfMetricQuery &query, | |
101 | const std::optional<OSDPerfMetricLimit> &limit); | |
102 | void remove_osd_perf_query(OSDPerfMetricQueryID query_id); | |
103 | PyObject *get_osd_perf_counters(OSDPerfMetricQueryID query_id); | |
104 | ||
105 | bool get_store(const std::string &module_name, | |
106 | const std::string &key, std::string *val) const; | |
107 | PyObject *get_store_prefix(const std::string &module_name, | |
108 | const std::string &prefix) const; | |
109 | void set_store(const std::string &module_name, | |
110 | const std::string &key, const boost::optional<std::string> &val); | |
3efd9988 FG |
111 | |
112 | bool get_config(const std::string &module_name, | |
113 | const std::string &key, std::string *val) const; | |
3efd9988 FG |
114 | void set_config(const std::string &module_name, |
115 | const std::string &key, const boost::optional<std::string> &val); | |
116 | ||
11fdf7f2 TL |
117 | PyObject *get_typed_config(const std::string &module_name, |
118 | const std::string &key, | |
119 | const std::string &prefix = "") const; | |
120 | ||
3efd9988 FG |
121 | void set_health_checks(const std::string& module_name, |
122 | health_check_map_t&& checks); | |
123 | void get_health_checks(health_check_map_t *checks); | |
7c673cae | 124 | |
11fdf7f2 TL |
125 | void update_progress_event(const std::string& evid, |
126 | const std::string& desc, | |
127 | float progress); | |
128 | void complete_progress_event(const std::string& evid); | |
129 | void clear_all_progress_events(); | |
130 | void get_progress_events(std::map<std::string,ProgressEvent>* events); | |
7c673cae | 131 | |
11fdf7f2 | 132 | void config_notify(); |
c07f9fc5 | 133 | |
11fdf7f2 TL |
134 | void set_uri(const std::string& module_name, const std::string &uri); |
135 | ||
136 | int handle_command( | |
137 | const std::string &module_name, | |
138 | const cmdmap_t &cmdmap, | |
139 | const bufferlist &inbuf, | |
140 | std::stringstream *ds, | |
141 | std::stringstream *ss); | |
7c673cae | 142 | |
3efd9988 | 143 | std::map<std::string, std::string> get_services() const; |
7c673cae FG |
144 | |
145 | // Public so that MonCommandCompletion can use it | |
146 | // FIXME: for send_command completion notifications, | |
147 | // send it to only the module that sent the command, not everyone | |
148 | void notify_all(const std::string ¬ify_type, | |
149 | const std::string ¬ify_id); | |
150 | void notify_all(const LogEntry &log_entry); | |
151 | ||
11fdf7f2 TL |
152 | bool module_exists(const std::string &name) const |
153 | { | |
154 | return modules.count(name) > 0; | |
155 | } | |
156 | ||
157 | bool method_exists( | |
158 | const std::string &module_name, | |
159 | const std::string &method_name) const | |
160 | { | |
161 | return modules.at(module_name)->method_exists(method_name); | |
162 | } | |
163 | ||
164 | PyObject *dispatch_remote( | |
165 | const std::string &other_module, | |
166 | const std::string &method, | |
167 | PyObject *args, | |
168 | PyObject *kwargs, | |
169 | std::string *err); | |
170 | ||
7c673cae | 171 | int init(); |
7c673cae FG |
172 | void shutdown(); |
173 | ||
11fdf7f2 | 174 | void start_one(PyModuleRef py_module); |
3efd9988 | 175 | |
7c673cae FG |
176 | void dump_server(const std::string &hostname, |
177 | const DaemonStateCollection &dmc, | |
178 | Formatter *f); | |
7c673cae | 179 | |
11fdf7f2 TL |
180 | void cluster_log(const std::string &channel, clog_type prio, |
181 | const std::string &message); | |
182 | }; |