]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: allow progress events to be reported from modules
authorSage Weil <sage@redhat.com>
Tue, 5 Feb 2019 16:15:58 +0000 (10:15 -0600)
committerSage Weil <sage@redhat.com>
Tue, 5 Feb 2019 16:15:58 +0000 (10:15 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/ActivePyModules.cc
src/mgr/ActivePyModules.h
src/mgr/BaseMgrModule.cc
src/mon/mon_types.h
src/pybind/mgr/mgr_module.py

index 1f185714972c14f636d8c51e6b16f8dbb302b026..42f28a0caadf1b3eef53a5b06aaee0ed4422e307 100644 (file)
@@ -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<std::string,ProgressEvent> *events)
+{
+  std::lock_guard l(lock);
+  *events = progress_events;
+}
+
 void ActivePyModules::config_notify()
 {
   std::lock_guard l(lock);
index d1761283334e10447da0d976c663a88f5f7c1131..bd3aee07d3c29f715a772d3a9431746bf436d9bd 100644 (file)
@@ -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<std::string,ProgressEvent> 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<std::string,ProgressEvent>* events);
+
   void config_notify();
 
   void set_uri(const std::string& module_name, const std::string &uri);
index 15a250cf112b43d52c84b5b6f58b0cbd2882bafc..e4e0a1c388bbba756ea03cac1c7cc2a3824e97cd 100644 (file)
@@ -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"},
 
index bf0b99b73d3000743bd762093c156b3da2a3fbdc..ad54cd44549eb152f2fd9c89d96b2466c3de81eb 100644 (file)
@@ -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
index 50477f7f46261065e91aa0d98aaa1439c8ed5817..1733ffd8d607c6d1b69da1c1628b5b1f4194e113 100644 (file)
@@ -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):
         """