]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/ActivePyModules.h
4892f2705fcda596095f2a527395c5e516f76fc8
[ceph.git] / ceph / src / mgr / ActivePyModules.h
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
14 #pragma once
15
16 #include "ActivePyModule.h"
17
18 #include "common/Finisher.h"
19 #include "common/ceph_mutex.h"
20
21 #include "PyFormatter.h"
22
23 #include "osdc/Objecter.h"
24 #include "client/Client.h"
25 #include "common/LogClient.h"
26 #include "mon/MgrMap.h"
27 #include "mon/MonCommand.h"
28 #include "mon/mon_types.h"
29
30 #include "DaemonState.h"
31 #include "ClusterState.h"
32 #include "OSDPerfMetricTypes.h"
33
34 class health_check_map_t;
35 class DaemonServer;
36 class MgrSession;
37 class ModuleCommand;
38 class PyModuleRegistry;
39
40 class ActivePyModules
41 {
42 // module class instances not yet created
43 std::set<std::string, std::less<>> pending_modules;
44 // module class instances already created
45 std::map<std::string, std::shared_ptr<ActivePyModule>> modules;
46 PyModuleConfig &module_config;
47 std::map<std::string, std::string> store_cache;
48 DaemonStateIndex &daemon_state;
49 ClusterState &cluster_state;
50 MonClient &monc;
51 LogChannelRef clog, audit_clog;
52 Objecter &objecter;
53 Client &client;
54 Finisher &finisher;
55 public:
56 Finisher cmd_finisher;
57 private:
58 DaemonServer &server;
59 PyModuleRegistry &py_module_registry;
60
61 map<std::string,ProgressEvent> progress_events;
62
63 mutable ceph::mutex lock = ceph::make_mutex("ActivePyModules::lock");
64
65 public:
66 ActivePyModules(PyModuleConfig &module_config,
67 std::map<std::string, std::string> store_data,
68 DaemonStateIndex &ds, ClusterState &cs, MonClient &mc,
69 LogChannelRef clog_, LogChannelRef audit_clog_, Objecter &objecter_, Client &client_,
70 Finisher &f, DaemonServer &server, PyModuleRegistry &pmr);
71
72 ~ActivePyModules();
73
74 // FIXME: wrap for send_command?
75 MonClient &get_monc() {return monc;}
76 Objecter &get_objecter() {return objecter;}
77 Client &get_client() {return client;}
78 PyObject *get_python(const std::string &what);
79 PyObject *get_server_python(const std::string &hostname);
80 PyObject *list_servers_python();
81 PyObject *get_metadata_python(
82 const std::string &svc_type, const std::string &svc_id);
83 PyObject *get_daemon_status_python(
84 const std::string &svc_type, const std::string &svc_id);
85 PyObject *get_counter_python(
86 const std::string &svc_type,
87 const std::string &svc_id,
88 const std::string &path);
89 PyObject *get_latest_counter_python(
90 const std::string &svc_type,
91 const std::string &svc_id,
92 const std::string &path);
93 PyObject *get_perf_schema_python(
94 const std::string &svc_type,
95 const std::string &svc_id);
96 PyObject *get_context();
97 PyObject *get_osdmap();
98 PyObject *with_perf_counters(
99 std::function<void(
100 PerfCounterInstance& counter_instance,
101 PerfCounterType& counter_type,
102 PyFormatter& f)> fct,
103 const std::string &svc_name,
104 const std::string &svc_id,
105 const std::string &path) const;
106
107 MetricQueryID add_osd_perf_query(
108 const OSDPerfMetricQuery &query,
109 const std::optional<OSDPerfMetricLimit> &limit);
110 void remove_osd_perf_query(MetricQueryID query_id);
111 PyObject *get_osd_perf_counters(MetricQueryID query_id);
112
113 bool get_store(const std::string &module_name,
114 const std::string &key, std::string *val) const;
115 PyObject *get_store_prefix(const std::string &module_name,
116 const std::string &prefix) const;
117 void set_store(const std::string &module_name,
118 const std::string &key, const boost::optional<std::string> &val);
119
120 bool get_config(const std::string &module_name,
121 const std::string &key, std::string *val) const;
122 void set_config(const std::string &module_name,
123 const std::string &key, const boost::optional<std::string> &val);
124
125 PyObject *get_typed_config(const std::string &module_name,
126 const std::string &key,
127 const std::string &prefix = "") const;
128
129 void set_health_checks(const std::string& module_name,
130 health_check_map_t&& checks);
131 void get_health_checks(health_check_map_t *checks);
132
133 void update_progress_event(const std::string& evid,
134 const std::string& desc,
135 float progress);
136 void complete_progress_event(const std::string& evid);
137 void clear_all_progress_events();
138 void get_progress_events(std::map<std::string,ProgressEvent>* events);
139
140 void register_client(std::string_view name, std::string addrs);
141 void unregister_client(std::string_view name, std::string addrs);
142
143 void config_notify();
144
145 void set_uri(const std::string& module_name, const std::string &uri);
146
147 int handle_command(
148 const ModuleCommand& module_command,
149 const MgrSession& session,
150 const cmdmap_t &cmdmap,
151 const bufferlist &inbuf,
152 std::stringstream *ds,
153 std::stringstream *ss);
154
155 std::map<std::string, std::string> get_services() const;
156
157 // Public so that MonCommandCompletion can use it
158 // FIXME: for send_command completion notifications,
159 // send it to only the module that sent the command, not everyone
160 void notify_all(const std::string &notify_type,
161 const std::string &notify_id);
162 void notify_all(const LogEntry &log_entry);
163
164 bool is_pending(std::string_view name) const {
165 return pending_modules.count(name) > 0;
166 }
167 bool module_exists(const std::string &name) const
168 {
169 return modules.count(name) > 0;
170 }
171
172 bool method_exists(
173 const std::string &module_name,
174 const std::string &method_name) const
175 {
176 return modules.at(module_name)->method_exists(method_name);
177 }
178
179 PyObject *dispatch_remote(
180 const std::string &other_module,
181 const std::string &method,
182 PyObject *args,
183 PyObject *kwargs,
184 std::string *err);
185
186 int init();
187 void shutdown();
188
189 void start_one(PyModuleRef py_module);
190
191 void dump_server(const std::string &hostname,
192 const DaemonStateCollection &dmc,
193 Formatter *f);
194
195 void cluster_log(const std::string &channel, clog_type prio,
196 const std::string &message);
197 };