From f6ef41a05ee87f59b9cd33ab3c7acc1b98724713 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 5 Feb 2019 10:15:58 -0600 Subject: [PATCH] mgr: allow progress events to be reported from modules Signed-off-by: Sage Weil --- src/mgr/ActivePyModules.cc | 29 ++++++++++++++++++++ src/mgr/ActivePyModules.h | 9 ++++++ src/mgr/BaseMgrModule.cc | 53 ++++++++++++++++++++++++++++++++++++ src/mon/mon_types.h | 24 ++++++++++++++++ src/pybind/mgr/mgr_module.py | 9 ++++++ 5 files changed, 124 insertions(+) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 1f185714972c1..42f28a0caadf1 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -911,6 +911,35 @@ void ActivePyModules::get_health_checks(health_check_map_t *checks) } } +void ActivePyModules::update_progress_event( + const std::string& evid, + const std::string& desc, + float progress) +{ + std::lock_guard l(lock); + auto& pe = progress_events[evid]; + pe.message = desc; + pe.progress = progress; +} + +void ActivePyModules::complete_progress_event(const std::string& evid) +{ + std::lock_guard l(lock); + progress_events.erase(evid); +} + +void ActivePyModules::clear_all_progress_events() +{ + std::lock_guard l(lock); + progress_events.clear(); +} + +void ActivePyModules::get_progress_events(std::map *events) +{ + std::lock_guard l(lock); + *events = progress_events; +} + void ActivePyModules::config_notify() { std::lock_guard l(lock); diff --git a/src/mgr/ActivePyModules.h b/src/mgr/ActivePyModules.h index d1761283334e1..bd3aee07d3c29 100644 --- a/src/mgr/ActivePyModules.h +++ b/src/mgr/ActivePyModules.h @@ -25,6 +25,7 @@ #include "common/LogClient.h" #include "mon/MgrMap.h" #include "mon/MonCommand.h" +#include "mon/mon_types.h" #include "DaemonState.h" #include "ClusterState.h" @@ -49,6 +50,7 @@ class ActivePyModules DaemonServer &server; PyModuleRegistry &py_module_registry; + map progress_events; mutable Mutex lock{"ActivePyModules::lock"}; @@ -119,6 +121,13 @@ public: health_check_map_t&& checks); void get_health_checks(health_check_map_t *checks); + void update_progress_event(const std::string& evid, + const std::string& desc, + float progress); + void complete_progress_event(const std::string& evid); + void clear_all_progress_events(); + void get_progress_events(std::map* events); + void config_notify(); void set_uri(const std::string& module_name, const std::string &uri); diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 15a250cf112b4..e4e0a1c388bbb 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -658,6 +658,52 @@ ceph_have_mon_connection(BaseMgrModule *self, PyObject *args) } } +static PyObject* +ceph_update_progress_event(BaseMgrModule *self, PyObject *args) +{ + char *evid = nullptr; + char *desc = nullptr; + float progress = 0.0; + if (!PyArg_ParseTuple(args, "ssf:ceph_update_progress_event", + &evid, &desc, &progress)) { + return nullptr; + } + + PyThreadState *tstate = PyEval_SaveThread(); + self->py_modules->update_progress_event(evid, desc, progress); + PyEval_RestoreThread(tstate); + + Py_RETURN_NONE; +} + +static PyObject* +ceph_complete_progress_event(BaseMgrModule *self, PyObject *args) +{ + char *evid = nullptr; + if (!PyArg_ParseTuple(args, "s:ceph_complete_progress_event", + &evid)) { + return nullptr; + } + + PyThreadState *tstate = PyEval_SaveThread(); + self->py_modules->complete_progress_event(evid); + PyEval_RestoreThread(tstate); + + Py_RETURN_NONE; +} + +static PyObject* +ceph_clear_all_progress_events(BaseMgrModule *self, PyObject *args) +{ + PyThreadState *tstate = PyEval_SaveThread(); + self->py_modules->clear_all_progress_events(); + PyEval_RestoreThread(tstate); + + Py_RETURN_NONE; +} + + + static PyObject * ceph_dispatch_remote(BaseMgrModule *self, PyObject *args) { @@ -1047,6 +1093,13 @@ PyMethodDef BaseMgrModule_methods[] = { METH_NOARGS, "Find out whether this mgr daemon currently has " "a connection to a monitor"}, + {"_ceph_update_progress_event", (PyCFunction)ceph_update_progress_event, + METH_VARARGS, "Update status of a progress event"}, + {"_ceph_complete_progress_event", (PyCFunction)ceph_complete_progress_event, + METH_VARARGS, "Complete a progress event"}, + {"_ceph_clear_all_progress_events", (PyCFunction)ceph_clear_all_progress_events, + METH_NOARGS, "Clear all progress events"}, + {"_ceph_dispatch_remote", (PyCFunction)ceph_dispatch_remote, METH_VARARGS, "Dispatch a call to another module"}, diff --git a/src/mon/mon_types.h b/src/mon/mon_types.h index bf0b99b73d300..ad54cd44549eb 100644 --- a/src/mon/mon_types.h +++ b/src/mon/mon_types.h @@ -591,4 +591,28 @@ inline ostream& operator<<(ostream& out, const mon_feature_t& f) { return out; } + +struct ProgressEvent { + string message; ///< event description + float progress; ///< [0..1] + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + encode(message, bl); + encode(progress, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::const_iterator& p) { + DECODE_START(1, p); + decode(message, p); + decode(progress, p); + DECODE_FINISH(p); + } + void dump(Formatter *f) const { + f->dump_string("message", message); + f->dump_float("progress", progress); + } +}; +WRITE_CLASS_ENCODER(ProgressEvent) + #endif diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 50477f7f46261..1733ffd8d607c 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -1122,6 +1122,15 @@ class MgrModule(ceph_module.BaseMgrModule): return self._ceph_have_mon_connection() + def update_progress_event(self, evid, desc, progress): + return self._ceph_update_progress_event(str(evid), str(desc), float(progress)) + + def complete_progress_event(self, evid): + return self._ceph_complete_progress_event(str(evid)) + + def clear_all_progress_events(self): + return self._ceph_clear_all_progress_events() + @property def rados(self): """ -- 2.39.5