summaryrefslogtreecommitdiffstats
path: root/src/mgr/Mgr.h
blob: 28a7da93de08312fc3ece50de516af6791e37050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// -*- 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) 2014 John Spray <john.spray@inktank.com>
 *
 * 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 CEPH_MGR_H_
#define CEPH_MGR_H_

// Python.h comes first because otherwise it clobbers ceph's assert
#include <Python.h>

#include "mds/FSMap.h"
#include "messages/MFSMap.h"
#include "msg/Messenger.h"
#include "auth/Auth.h"
#include "common/Finisher.h"
#include "mon/MgrMap.h"

#include "DaemonServer.h"
#include "PyModuleRegistry.h"

#include "DaemonState.h"
#include "ClusterState.h"

class MCommand;
class MMgrDigest;
class MLog;
class MServiceMap;
class Objecter;
class Client;

class Mgr : public AdminSocketHook {
protected:
  MonClient *monc;
  Objecter  *objecter;
  Client    *client;
  Messenger *client_messenger;

  mutable ceph::mutex lock = ceph::make_mutex("Mgr::lock");
  Finisher finisher;

  // Track receipt of initial data during startup
  ceph::condition_variable fs_map_cond;
  bool digest_received;
  ceph::condition_variable digest_cond;

  PyModuleRegistry *py_module_registry;
  DaemonStateIndex daemon_state;
  ClusterState cluster_state;

  DaemonServer server;

  LogChannelRef clog;
  LogChannelRef audit_clog;

  std::map<std::string, std::string> pre_init_store;

  void load_all_metadata();
  std::map<std::string, std::string> load_store();
  void init();

  bool initialized;
  bool initializing;

public:
  Mgr(MonClient *monc_, const MgrMap& mgrmap,
      PyModuleRegistry *py_module_registry_,
      Messenger *clientm_, Objecter *objecter_,
      Client *client_, LogChannelRef clog_, LogChannelRef audit_clog_);
  ~Mgr();

  bool is_initialized() const {return initialized;}
  entity_addrvec_t get_server_addrs() const {
    return server.get_myaddrs();
  }

  void handle_mgr_digest(ceph::ref_t<MMgrDigest> m);
  void handle_fs_map(ceph::ref_t<MFSMap> m);
  void handle_osd_map();
  void handle_log(ceph::ref_t<MLog> m);
  void handle_service_map(ceph::ref_t<MServiceMap> m);
  void handle_mon_map();

  bool got_mgr_map(const MgrMap& m);

  bool ms_dispatch2(const ceph::ref_t<Message>& m);

  void background_init(Context *completion);
  void shutdown();

  void handle_signal(int signum);

  std::map<std::string, std::string> get_services() const;

  int call(
    std::string_view command,
    const cmdmap_t& cmdmap,
    Formatter *f,
    std::ostream& errss,
    ceph::buffer::list& out) override;
};

/**
 * Context for completion of metadata mon commands: take
 * the result and stash it in DaemonStateIndex
 */
class MetadataUpdate : public Context
{

private:
  DaemonStateIndex &daemon_state;
  DaemonKey key;

  std::map<std::string, std::string> defaults;

public:
  bufferlist outbl;
  std::string outs;

  MetadataUpdate(DaemonStateIndex &daemon_state_, const DaemonKey &key_)
    : daemon_state(daemon_state_), key(key_)
  {
      daemon_state.notify_updating(key);
  }

  void set_default(const std::string &k, const std::string &v)
  {
    defaults[k] = v;
  }

  void finish(int r) override;
};


#endif