]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | #ifndef PY_MODULES_H_ | |
15 | #define PY_MODULES_H_ | |
16 | ||
17 | #include "MgrPyModule.h" | |
18 | ||
19 | #include "common/Finisher.h" | |
20 | #include "common/Mutex.h" | |
21 | #include "common/Thread.h" | |
22 | ||
23 | #include "osdc/Objecter.h" | |
24 | #include "client/Client.h" | |
224ce89b WB |
25 | #include "common/LogClient.h" |
26 | #include "mon/MgrMap.h" | |
c07f9fc5 | 27 | #include "mon/MonCommand.h" |
7c673cae FG |
28 | |
29 | #include "DaemonState.h" | |
30 | #include "ClusterState.h" | |
31 | ||
32 | class ServeThread; | |
c07f9fc5 | 33 | class health_check_map_t; |
7c673cae FG |
34 | |
35 | class PyModules | |
36 | { | |
37 | std::map<std::string, std::unique_ptr<MgrPyModule>> modules; | |
38 | std::map<std::string, std::unique_ptr<ServeThread>> serve_threads; | |
39 | DaemonStateIndex &daemon_state; | |
40 | ClusterState &cluster_state; | |
41 | MonClient &monc; | |
224ce89b | 42 | LogChannelRef clog; |
7c673cae FG |
43 | Objecter &objecter; |
44 | Client &client; | |
45 | Finisher &finisher; | |
46 | ||
c07f9fc5 | 47 | mutable Mutex lock{"PyModules::lock"}; |
7c673cae FG |
48 | |
49 | std::string get_site_packages(); | |
50 | ||
31f18b77 FG |
51 | PyThreadState *pMainThreadState = nullptr; |
52 | ||
7c673cae | 53 | public: |
31f18b77 | 54 | static std::string config_prefix; |
7c673cae FG |
55 | |
56 | PyModules(DaemonStateIndex &ds, ClusterState &cs, MonClient &mc, | |
224ce89b | 57 | LogChannelRef clog_, Objecter &objecter_, Client &client_, |
7c673cae FG |
58 | Finisher &f); |
59 | ||
60 | ~PyModules(); | |
61 | ||
62 | // FIXME: wrap for send_command? | |
63 | MonClient &get_monc() {return monc;} | |
64 | Objecter &get_objecter() {return objecter;} | |
65 | Client &get_client() {return client;} | |
66 | ||
67 | PyObject *get_python(const std::string &what); | |
68 | PyObject *get_server_python(const std::string &hostname); | |
69 | PyObject *list_servers_python(); | |
224ce89b WB |
70 | PyObject *get_metadata_python( |
71 | std::string const &handle, | |
72 | const std::string &svc_name, const std::string &svc_id); | |
73 | PyObject *get_daemon_status_python( | |
74 | std::string const &handle, | |
75 | const std::string &svc_name, const std::string &svc_id); | |
76 | PyObject *get_counter_python( | |
77 | std::string const &handle, | |
78 | const std::string &svc_name, | |
79 | const std::string &svc_id, | |
80 | const std::string &path); | |
c07f9fc5 FG |
81 | PyObject *get_perf_schema_python( |
82 | const std::string &handle, | |
83 | const std::string svc_type, | |
84 | const std::string &svc_id); | |
7c673cae FG |
85 | PyObject *get_context(); |
86 | ||
87 | std::map<std::string, std::string> config_cache; | |
88 | ||
c07f9fc5 FG |
89 | // Python command definitions, including callback |
90 | std::vector<ModuleCommand> get_py_commands() const; | |
91 | ||
92 | // Monitor command definitions, suitable for CLI | |
93 | std::vector<MonCommand> get_commands() const; | |
7c673cae FG |
94 | |
95 | void insert_config(const std::map<std::string, std::string> &new_config); | |
96 | ||
97 | // Public so that MonCommandCompletion can use it | |
98 | // FIXME: for send_command completion notifications, | |
99 | // send it to only the module that sent the command, not everyone | |
100 | void notify_all(const std::string ¬ify_type, | |
101 | const std::string ¬ify_id); | |
102 | void notify_all(const LogEntry &log_entry); | |
103 | ||
104 | int init(); | |
105 | void start(); | |
106 | void shutdown(); | |
107 | ||
108 | void dump_server(const std::string &hostname, | |
109 | const DaemonStateCollection &dmc, | |
110 | Formatter *f); | |
111 | ||
112 | bool get_config(const std::string &handle, | |
113 | const std::string &key, std::string *val) const; | |
31f18b77 FG |
114 | PyObject *get_config_prefix(const std::string &handle, |
115 | const std::string &prefix) const; | |
7c673cae | 116 | void set_config(const std::string &handle, |
d2e6a577 | 117 | const std::string &key, const boost::optional<std::string> &val); |
7c673cae | 118 | |
c07f9fc5 FG |
119 | void set_health_checks(const std::string& handle, |
120 | health_check_map_t&& checks); | |
121 | void get_health_checks(health_check_map_t *checks); | |
122 | ||
7c673cae FG |
123 | void log(const std::string &handle, |
124 | int level, const std::string &record); | |
224ce89b WB |
125 | |
126 | static void list_modules(std::set<std::string> *modules); | |
7c673cae FG |
127 | }; |
128 | ||
129 | #endif | |
130 |