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