X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fmgr%2FMgrClient.h;fp=src%2Fceph%2Fsrc%2Fmgr%2FMgrClient.h;h=08ff24c23849428219570c0446a88813f927b8a2;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/mgr/MgrClient.h b/src/ceph/src/mgr/MgrClient.h new file mode 100644 index 0000000..08ff24c --- /dev/null +++ b/src/ceph/src/mgr/MgrClient.h @@ -0,0 +1,125 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2016 John Spray + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#ifndef MGR_CLIENT_H_ +#define MGR_CLIENT_H_ + +#include "msg/Dispatcher.h" +#include "mon/MgrMap.h" + +#include "msg/Connection.h" + +#include "common/perf_counters.h" +#include "common/Timer.h" +#include "common/CommandTable.h" + +class MMgrMap; +class MMgrConfigure; +class Messenger; +class MCommandReply; +class MPGStats; + +class MgrSessionState +{ + public: + // Which performance counters have we already transmitted schema for? + std::set declared; + + // Our connection to the mgr + ConnectionRef con; +}; + +class MgrCommand : public CommandOp +{ + public: + + MgrCommand(ceph_tid_t t) : CommandOp(t) {} + MgrCommand() : CommandOp() {} +}; + +class MgrClient : public Dispatcher +{ +protected: + CephContext *cct; + MgrMap map; + Messenger *msgr; + + unique_ptr session; + + Mutex lock = {"MgrClient::lock"}; + + uint32_t stats_period = 0; + uint32_t stats_threshold = 0; + SafeTimer timer; + + CommandTable command_table; + + utime_t last_connect_attempt; + + Context *report_callback = nullptr; + Context *connect_retry_callback = nullptr; + + // If provided, use this to compose an MPGStats to send with + // our reports (hook for use by OSD) + std::function pgstats_cb; + + // for service registration and beacon + bool service_daemon = false; + bool daemon_dirty_status = false; + std::string service_name, daemon_name; + std::map daemon_metadata; + std::map daemon_status; + + void reconnect(); + void _send_open(); + +public: + MgrClient(CephContext *cct_, Messenger *msgr_); + + void set_messenger(Messenger *msgr_) { msgr = msgr_; } + + void init(); + void shutdown(); + + bool ms_dispatch(Message *m) override; + bool ms_handle_reset(Connection *con) override; + void ms_handle_remote_reset(Connection *con) override {} + bool ms_handle_refused(Connection *con) override; + + bool handle_mgr_map(MMgrMap *m); + bool handle_mgr_configure(MMgrConfigure *m); + bool handle_command_reply(MCommandReply *m); + + void send_report(); + void send_pgstats(); + + void set_pgstats_cb(std::function cb_) + { + Mutex::Locker l(lock); + pgstats_cb = cb_; + } + + int start_command(const vector& cmd, const bufferlist& inbl, + bufferlist *outbl, string *outs, + Context *onfinish); + + int service_daemon_register( + const std::string& service, + const std::string& name, + const std::map& metadata); + int service_daemon_update_status( + const std::map& status); +}; + +#endif +