]> git.proxmox.com Git - ceph.git/blame - ceph/src/mgr/ServiceMap.h
import ceph quincy 17.2.4
[ceph.git] / ceph / src / mgr / ServiceMap.h
CommitLineData
224ce89b
WB
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#pragma once
5
6#include <string>
7#include <map>
8#include <list>
9#include <sstream>
10
11#include "include/utime.h"
12#include "include/buffer.h"
13#include "msg/msg_types.h"
14
15namespace ceph {
16 class Formatter;
17}
18
19struct ServiceMap {
20 struct Daemon {
21 uint64_t gid = 0;
22 entity_addr_t addr;
23 epoch_t start_epoch = 0; ///< epoch first registered
24 utime_t start_stamp; ///< timestamp daemon started/registered
25 std::map<std::string,std::string> metadata; ///< static metadata
9f95a23c 26 std::map<std::string,std::string> task_status; ///< running task status
224ce89b 27
9f95a23c
TL
28 void encode(ceph::buffer::list& bl, uint64_t features) const;
29 void decode(ceph::buffer::list::const_iterator& p);
30 void dump(ceph::Formatter *f) const;
224ce89b
WB
31 static void generate_test_instances(std::list<Daemon*>& ls);
32 };
33
34 struct Service {
9f95a23c
TL
35 std::map<std::string,Daemon> daemons;
36 std::string summary; ///< summary status std::string for 'ceph -s'
224ce89b 37
9f95a23c
TL
38 void encode(ceph::buffer::list& bl, uint64_t features) const;
39 void decode(ceph::buffer::list::const_iterator& p);
40 void dump(ceph::Formatter *f) const;
224ce89b
WB
41 static void generate_test_instances(std::list<Service*>& ls);
42
f67539c2
TL
43 std::string get_summary() const;
44 bool has_running_tasks() const;
45 std::string get_task_summary(const std::string_view task_prefix) const;
9f95a23c 46 void count_metadata(const std::string& field,
f67539c2 47 std::map<std::string,int> *out) const;
224ce89b
WB
48 };
49
50 epoch_t epoch = 0;
51 utime_t modified;
9f95a23c 52 std::map<std::string,Service> services;
224ce89b 53
9f95a23c
TL
54 void encode(ceph::buffer::list& bl, uint64_t features) const;
55 void decode(ceph::buffer::list::const_iterator& p);
56 void dump(ceph::Formatter *f) const;
224ce89b
WB
57 static void generate_test_instances(std::list<ServiceMap*>& ls);
58
9f95a23c
TL
59 std::pair<Daemon*,bool> get_daemon(const std::string& service,
60 const std::string& daemon) {
61 auto& s = services[service];
62 auto [d, added] = s.daemons.try_emplace(daemon);
63 return {&d->second, added};
224ce89b
WB
64 }
65
66 bool rm_daemon(const std::string& service,
67 const std::string& daemon) {
68 auto p = services.find(service);
69 if (p == services.end()) {
70 return false;
71 }
72 auto q = p->second.daemons.find(daemon);
73 if (q == p->second.daemons.end()) {
74 return false;
75 }
76 p->second.daemons.erase(q);
77 if (p->second.daemons.empty()) {
78 services.erase(p);
79 }
80 return true;
81 }
9f95a23c
TL
82
83 static inline bool is_normal_ceph_entity(std::string_view type) {
84 if (type == "osd" ||
85 type == "client" ||
86 type == "mon" ||
87 type == "mds" ||
88 type == "mgr") {
89 return true;
90 }
91
92 return false;
93 }
224ce89b
WB
94};
95WRITE_CLASS_ENCODER_FEATURES(ServiceMap)
96WRITE_CLASS_ENCODER_FEATURES(ServiceMap::Service)
97WRITE_CLASS_ENCODER_FEATURES(ServiceMap::Daemon)