1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 John Spray <john.spray@inktank.com>
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.
16 #include "ActivePyModule.h"
18 #include "common/Finisher.h"
19 #include "common/ceph_mutex.h"
21 #include "PyFormatter.h"
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 #include "mon/ConfigMap.h"
30 #include "mgr/TTLCache.h"
32 #include "DaemonState.h"
33 #include "ClusterState.h"
34 #include "OSDPerfMetricTypes.h"
36 class health_check_map_t
;
40 class PyModuleRegistry
;
44 // module class instances not yet created
45 std::set
<std::string
, std::less
<>> pending_modules
;
46 // module class instances already created
47 std::map
<std::string
, std::shared_ptr
<ActivePyModule
>> modules
;
48 PyModuleConfig
&module_config
;
49 bool have_local_config_map
= false;
50 std::map
<std::string
, std::string
> store_cache
;
51 ConfigMap config_map
; ///< derived from store_cache config/ keys
52 DaemonStateIndex
&daemon_state
;
53 ClusterState
&cluster_state
;
55 LogChannelRef clog
, audit_clog
;
59 TTLCache
<string
, PyObject
*> ttl_cache
;
61 Finisher cmd_finisher
;
64 PyModuleRegistry
&py_module_registry
;
66 map
<std::string
,ProgressEvent
> progress_events
;
68 mutable ceph::mutex lock
= ceph::make_mutex("ActivePyModules::lock");
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
);
81 // FIXME: wrap for send_command?
82 MonClient
&get_monc() {return monc
;}
83 Objecter
&get_objecter() {return objecter
;}
84 Client
&get_client() {return client
;}
85 PyObject
*cacheable_get_python(const std::string
&what
);
86 PyObject
*get_python(const std::string
&what
);
87 PyObject
*get_server_python(const std::string
&hostname
);
88 PyObject
*list_servers_python();
89 PyObject
*get_metadata_python(
90 const std::string
&svc_type
, const std::string
&svc_id
);
91 PyObject
*get_daemon_status_python(
92 const std::string
&svc_type
, const std::string
&svc_id
);
93 PyObject
*get_counter_python(
94 const std::string
&svc_type
,
95 const std::string
&svc_id
,
96 const std::string
&path
);
97 PyObject
*get_latest_counter_python(
98 const std::string
&svc_type
,
99 const std::string
&svc_id
,
100 const std::string
&path
);
101 PyObject
*get_perf_schema_python(
102 const std::string
&svc_type
,
103 const std::string
&svc_id
);
104 PyObject
*get_rocksdb_version();
105 PyObject
*get_context();
106 PyObject
*get_osdmap();
107 /// @note @c fct is not allowed to acquire locks when holding GIL
108 PyObject
*with_perf_counters(
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;
117 MetricQueryID
add_osd_perf_query(
118 const OSDPerfMetricQuery
&query
,
119 const std::optional
<OSDPerfMetricLimit
> &limit
);
120 void remove_osd_perf_query(MetricQueryID query_id
);
121 PyObject
*get_osd_perf_counters(MetricQueryID query_id
);
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
);
127 void reregister_mds_perf_queries();
128 PyObject
*get_mds_perf_counters(MetricQueryID query_id
);
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
,
135 const std::string
&key
, const std::optional
<std::string
> &val
);
137 bool get_config(const std::string
&module_name
,
138 const std::string
&key
, std::string
*val
) const;
139 std::pair
<int, std::string
> set_config(const std::string
&module_name
,
140 const std::string
&key
, const std::optional
<std::string
> &val
);
142 PyObject
*get_typed_config(const std::string
&module_name
,
143 const std::string
&key
,
144 const std::string
&prefix
= "") const;
145 PyObject
*get_foreign_config(
146 const std::string
& who
,
147 const std::string
& name
);
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
);
153 void update_progress_event(const std::string
& evid
,
154 const std::string
& desc
,
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
);
161 void register_client(std::string_view name
, std::string addrs
);
162 void unregister_client(std::string_view name
, std::string addrs
);
164 void config_notify();
166 void set_uri(const std::string
& module_name
, const std::string
&uri
);
167 void set_device_wear_level(const std::string
& devid
, float wear_level
);
170 const ModuleCommand
& module_command
,
171 const MgrSession
& session
,
172 const cmdmap_t
&cmdmap
,
173 const bufferlist
&inbuf
,
174 std::stringstream
*ds
,
175 std::stringstream
*ss
);
177 std::map
<std::string
, std::string
> get_services() const;
180 const std::string prefix
,
182 const map
<std::string
, std::optional
<bufferlist
>, std::less
<>>& data
);
183 void _refresh_config_map();
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
);
192 bool is_pending(std::string_view name
) const {
193 return pending_modules
.count(name
) > 0;
195 bool module_exists(const std::string
&name
) const
197 return modules
.count(name
) > 0;
201 const std::string
&module_name
,
202 const std::string
&method_name
) const
204 return modules
.at(module_name
)->method_exists(method_name
);
207 PyObject
*dispatch_remote(
208 const std::string
&other_module
,
209 const std::string
&method
,
217 void start_one(PyModuleRef py_module
);
219 void dump_server(const std::string
&hostname
,
220 const DaemonStateCollection
&dmc
,
223 void cluster_log(const std::string
&channel
, clog_type prio
,
224 const std::string
&message
);
226 bool inject_python_on() const;
227 void update_cache_metrics();