Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mon / OldHealthMonitor.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2013 Inktank, Inc
7  *
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.
12  *
13  */
14
15 #include <sstream>
16 #include <stdlib.h>
17 #include <limits.h>
18
19 // #include <boost/intrusive_ptr.hpp>
20 // Because intusive_ptr clobbers our assert...
21 #include "include/assert.h"
22
23 #include "mon/Monitor.h"
24 #include "mon/HealthService.h"
25 #include "mon/OldHealthMonitor.h"
26 #include "mon/DataHealthService.h"
27
28 #include "messages/MMonHealth.h"
29 #include "common/Formatter.h"
30 // #include "common/config.h"
31
32 #define dout_subsys ceph_subsys_mon
33 #undef dout_prefix
34 #define dout_prefix _prefix(_dout, mon, this)
35 static ostream& _prefix(std::ostream *_dout, const Monitor *mon,
36                         const OldHealthMonitor *hmon) {
37   return *_dout << "mon." << mon->name << "@" << mon->rank
38                 << "(" << mon->get_state_name() << ")." << hmon->get_name()
39                 << "(" << hmon->get_epoch() << ") ";
40 }
41
42 void OldHealthMonitor::init()
43 {
44   dout(10) << __func__ << dendl;
45   assert(services.empty());
46   services[HealthService::SERVICE_HEALTH_DATA] = new DataHealthService(mon);
47
48   for (map<int,HealthService*>::iterator it = services.begin();
49        it != services.end();
50        ++it) {
51     it->second->init();
52   }
53 }
54
55 bool OldHealthMonitor::service_dispatch(MonOpRequestRef op)
56 {
57   assert(op->get_req()->get_type() == MSG_MON_HEALTH);
58   MMonHealth *hm = static_cast<MMonHealth*>(op->get_req());
59   int service_type = hm->get_service_type();
60   if (services.count(service_type) == 0) {
61     dout(1) << __func__ << " service type " << service_type
62             << " not registered -- drop message!" << dendl;
63     return false;
64   }
65   return services[service_type]->service_dispatch(op);
66 }
67
68 void OldHealthMonitor::start_epoch() {
69   epoch_t epoch = get_epoch();
70   for (map<int,HealthService*>::iterator it = services.begin();
71        it != services.end(); ++it) {
72     it->second->start(epoch);
73   }
74 }
75
76 void OldHealthMonitor::finish_epoch() {
77   generic_dout(20) << "OldHealthMonitor::finish_epoch()" << dendl;
78   for (map<int,HealthService*>::iterator it = services.begin();
79        it != services.end(); ++it) {
80     assert(it->second != NULL);
81     it->second->finish();
82   }
83 }
84
85 void OldHealthMonitor::service_shutdown()
86 {
87   dout(0) << "OldHealthMonitor::service_shutdown "
88           << services.size() << " services" << dendl;
89   for (map<int,HealthService*>::iterator it = services.begin();
90       it != services.end();
91        ++it) {
92     it->second->shutdown();
93     delete it->second;
94   }
95   services.clear();
96 }
97
98 void OldHealthMonitor::get_health(
99   list<pair<health_status_t,string> >& summary,
100   list<pair<health_status_t,string> > *detail)
101 {
102   for (map<int,HealthService*>::iterator it = services.begin();
103        it != services.end();
104        ++it) {
105     it->second->get_health(summary, detail);
106   }
107 }