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"
30 #include "DaemonState.h"
31 #include "ClusterState.h"
32 #include "OSDPerfMetricTypes.h"
34 class health_check_map_t
;
38 class PyModuleRegistry
;
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
;
51 LogChannelRef clog
, audit_clog
;
56 Finisher cmd_finisher
;
59 PyModuleRegistry
&py_module_registry
;
61 map
<std::string
,ProgressEvent
> progress_events
;
63 mutable ceph::mutex lock
= ceph::make_mutex("ActivePyModules::lock");
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
);
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(
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;
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
);
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
);
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
);
125 PyObject
*get_typed_config(const std::string
&module_name
,
126 const std::string
&key
,
127 const std::string
&prefix
= "") const;
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
);
133 void update_progress_event(const std::string
& evid
,
134 const std::string
& desc
,
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
);
140 void register_client(std::string_view name
, std::string addrs
);
141 void unregister_client(std::string_view name
, std::string addrs
);
143 void config_notify();
145 void set_uri(const std::string
& module_name
, const std::string
&uri
);
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
);
155 std::map
<std::string
, std::string
> get_services() const;
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
¬ify_type
,
161 const std::string
¬ify_id
);
162 void notify_all(const LogEntry
&log_entry
);
164 bool is_pending(std::string_view name
) const {
165 return pending_modules
.count(name
) > 0;
167 bool module_exists(const std::string
&name
) const
169 return modules
.count(name
) > 0;
173 const std::string
&module_name
,
174 const std::string
&method_name
) const
176 return modules
.at(module_name
)->method_exists(method_name
);
179 PyObject
*dispatch_remote(
180 const std::string
&other_module
,
181 const std::string
&method
,
189 void start_one(PyModuleRef py_module
);
191 void dump_server(const std::string
&hostname
,
192 const DaemonStateCollection
&dmc
,
195 void cluster_log(const std::string
&channel
, clog_type prio
,
196 const std::string
&message
);