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/Mutex.h"
21 #include "osdc/Objecter.h"
22 #include "client/Client.h"
23 #include "common/LogClient.h"
24 #include "mon/MgrMap.h"
25 #include "mon/MonCommand.h"
27 #include "DaemonState.h"
28 #include "ClusterState.h"
30 class health_check_map_t;
32 typedef std::map<std::string, std::string> PyModuleConfig;
37 std::map<std::string, std::unique_ptr<ActivePyModule>> modules;
38 PyModuleConfig config_cache;
39 DaemonStateIndex &daemon_state;
40 ClusterState &cluster_state;
48 mutable Mutex lock{"ActivePyModules::lock"};
51 ActivePyModules(PyModuleConfig const &config_,
52 DaemonStateIndex &ds, ClusterState &cs, MonClient &mc,
53 LogChannelRef clog_, Objecter &objecter_, Client &client_,
58 // FIXME: wrap for send_command?
59 MonClient &get_monc() {return monc;}
60 Objecter &get_objecter() {return objecter;}
61 Client &get_client() {return client;}
63 PyObject *get_python(const std::string &what);
64 PyObject *get_server_python(const std::string &hostname);
65 PyObject *list_servers_python();
66 PyObject *get_metadata_python(
67 const std::string &svc_type, const std::string &svc_id);
68 PyObject *get_daemon_status_python(
69 const std::string &svc_type, const std::string &svc_id);
70 PyObject *get_counter_python(
71 const std::string &svc_type,
72 const std::string &svc_id,
73 const std::string &path);
74 PyObject *get_perf_schema_python(
75 const std::string svc_type,
76 const std::string &svc_id);
77 PyObject *get_context();
78 PyObject *get_osdmap();
80 bool get_config(const std::string &module_name,
81 const std::string &key, std::string *val) const;
82 PyObject *get_config_prefix(const std::string &module_name,
83 const std::string &prefix) const;
84 void set_config(const std::string &module_name,
85 const std::string &key, const boost::optional<std::string> &val);
87 void set_health_checks(const std::string& module_name,
88 health_check_map_t&& checks);
89 void get_health_checks(health_check_map_t *checks);
91 void set_uri(const std::string& module_name, const std::string &uri);
93 // Python command definitions, including callback
94 std::vector<ModuleCommand> get_py_commands() const;
96 // Monitor command definitions, suitable for CLI
97 std::vector<MonCommand> get_commands() const;
99 std::map<std::string, std::string> get_services() const;
101 // Public so that MonCommandCompletion can use it
102 // FIXME: for send_command completion notifications,
103 // send it to only the module that sent the command, not everyone
104 void notify_all(const std::string ¬ify_type,
105 const std::string ¬ify_id);
106 void notify_all(const LogEntry &log_entry);
111 int start_one(std::string const &module_name,
113 const SafeThreadState &pMyThreadState);
115 void dump_server(const std::string &hostname,
116 const DaemonStateCollection &dmc,