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 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
;
48 LogChannelRef clog
, audit_clog
;
53 Finisher cmd_finisher
;
56 PyModuleRegistry
&py_module_registry
;
58 map
<std::string
,ProgressEvent
> progress_events
;
60 mutable ceph::mutex lock
= ceph::make_mutex("ActivePyModules::lock");
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
);
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(
97 PerfCounterInstance
& counter_instance
,
98 PerfCounterType
& counter_type
,
100 const std::string
&svc_name
,
101 const std::string
&svc_id
,
102 const std::string
&path
) const;
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
);
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
);
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
);
122 PyObject
*get_typed_config(const std::string
&module_name
,
123 const std::string
&key
,
124 const std::string
&prefix
= "") const;
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
);
130 void update_progress_event(const std::string
& evid
,
131 const std::string
& desc
,
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
);
137 void register_client(std::string_view name
, std::string addrs
);
138 void unregister_client(std::string_view name
, std::string addrs
);
140 void config_notify();
142 void set_uri(const std::string
& module_name
, const std::string
&uri
);
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
);
152 std::map
<std::string
, std::string
> get_services() const;
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
¬ify_type
,
158 const std::string
¬ify_id
);
159 void notify_all(const LogEntry
&log_entry
);
161 bool module_exists(const std::string
&name
) const
163 return modules
.count(name
) > 0;
167 const std::string
&module_name
,
168 const std::string
&method_name
) const
170 return modules
.at(module_name
)->method_exists(method_name
);
173 PyObject
*dispatch_remote(
174 const std::string
&other_module
,
175 const std::string
&method
,
183 void start_one(PyModuleRef py_module
);
185 void dump_server(const std::string
&hostname
,
186 const DaemonStateCollection
&dmc
,
189 void cluster_log(const std::string
&channel
, clog_type prio
,
190 const std::string
&message
);