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) 2016 John Spray <john.spray@redhat.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.
17 #include "msg/Dispatcher.h"
18 #include "mon/MgrMap.h"
20 #include "msg/Connection.h"
22 #include "common/perf_counters.h"
23 #include "common/Timer.h"
24 #include "common/CommandTable.h"
35 // Which performance counters have we already transmitted schema for?
36 std::set
<std::string
> declared
;
38 // Our connection to the mgr
42 class MgrCommand
: public CommandOp
46 MgrCommand(ceph_tid_t t
) : CommandOp(t
) {}
47 MgrCommand() : CommandOp() {}
50 class MgrClient
: public Dispatcher
57 unique_ptr
<MgrSessionState
> session
;
59 Mutex lock
= {"MgrClient::lock"};
61 uint32_t stats_period
= 0;
64 CommandTable
<MgrCommand
> command_table
;
66 utime_t last_connect_attempt
;
68 Context
*report_callback
= nullptr;
69 Context
*connect_retry_callback
= nullptr;
71 // If provided, use this to compose an MPGStats to send with
72 // our reports (hook for use by OSD)
73 std::function
<MPGStats
*()> pgstats_cb
;
75 // for service registration and beacon
76 bool service_daemon
= false;
77 bool daemon_dirty_status
= false;
78 std::string service_name
, daemon_name
;
79 std::map
<std::string
,std::string
> daemon_metadata
;
80 std::map
<std::string
,std::string
> daemon_status
;
86 MgrClient(CephContext
*cct_
, Messenger
*msgr_
);
88 void set_messenger(Messenger
*msgr_
) { msgr
= msgr_
; }
93 bool ms_dispatch(Message
*m
) override
;
94 bool ms_handle_reset(Connection
*con
) override
;
95 void ms_handle_remote_reset(Connection
*con
) override
{}
96 bool ms_handle_refused(Connection
*con
) override
;
98 bool handle_mgr_map(MMgrMap
*m
);
99 bool handle_mgr_configure(MMgrConfigure
*m
);
100 bool handle_command_reply(MCommandReply
*m
);
105 void set_pgstats_cb(std::function
<MPGStats
*()> cb_
)
107 Mutex::Locker
l(lock
);
111 int start_command(const vector
<string
>& cmd
, const bufferlist
& inbl
,
112 bufferlist
*outbl
, string
*outs
,
115 int service_daemon_register(
116 const std::string
& service
,
117 const std::string
& name
,
118 const std::map
<std::string
,std::string
>& metadata
);
119 int service_daemon_update_status(
120 const std::map
<std::string
,std::string
>& status
);