bool DaemonServer::handle_open(MMgrOpen *m)
{
uint32_t type = m->get_connection()->get_peer_type();
- DaemonKey key(type, m->daemon_name);
+ DaemonKey key(ceph_entity_type_name(type), m->daemon_name);
dout(4) << "from " << m->get_connection() << " name "
<< ceph_entity_type_name(type) << "." << m->daemon_name << dendl;
bool DaemonServer::handle_report(MMgrReport *m)
{
uint32_t type = m->get_connection()->get_peer_type();
- DaemonKey key(type, m->daemon_name);
+ DaemonKey key(ceph_entity_type_name(type), m->daemon_name);
dout(4) << "from " << m->get_connection() << " name "
<< ceph_entity_type_name(type) << "." << m->daemon_name << dendl;
all.erase(to_erase);
}
-DaemonStateCollection DaemonStateIndex::get_by_type(uint8_t type) const
+DaemonStateCollection DaemonStateIndex::get_by_service(
+ const std::string& svc) const
{
Mutex::Locker l(lock);
DaemonStateCollection result;
for (const auto &i : all) {
- if (i.first.first == type) {
+ if (i.first.first == svc) {
result[i.first] = i.second;
}
}
return all.at(key);
}
-void DaemonStateIndex::cull(entity_type_t daemon_type,
+void DaemonStateIndex::cull(const std::string& svc_name,
const std::set<std::string>& names_exist)
{
std::vector<string> victims;
Mutex::Locker l(lock);
- auto begin = all.lower_bound({daemon_type, ""});
+ auto begin = all.lower_bound({svc_name, ""});
auto end = all.end();
for (auto &i = begin; i != end; ++i) {
const auto& daemon_key = i->first;
- if (daemon_key.first != daemon_type)
+ if (daemon_key.first != svc_name)
break;
if (names_exist.count(daemon_key.second) == 0) {
victims.push_back(daemon_key.second);
for (auto &i : victims) {
dout(4) << "Removing data for " << i << dendl;
- _erase({daemon_type, i});
+ _erase({svc_name, i});
}
}
// Unique reference to a daemon within a cluster
-typedef std::pair<entity_type_t, std::string> DaemonKey;
+typedef std::pair<std::string, std::string> DaemonKey;
// An instance of a performance counter type, within
// a particular daemon.
bool exists(const DaemonKey &key) const;
DaemonStatePtr get(const DaemonKey &key);
DaemonStateCollection get_by_server(const std::string &hostname) const;
- DaemonStateCollection get_by_type(uint8_t type) const;
+ DaemonStateCollection get_by_service(const std::string &svc_name) const;
const DaemonStateCollection &get_all() const {return all;}
const std::map<std::string, DaemonStateCollection> &get_all_servers() const
* a cluster map and want to ensure that anything absent in the map
* is also absent in this class.
*/
- void cull(entity_type_t daemon_type, const std::set<std::string>& names_exist);
+ void cull(const std::string& svc_name,
+ const std::set<std::string>& names_exist);
};
#endif
{
daemon_state.clear_updating(key);
if (r == 0) {
- if (key.first == CEPH_ENTITY_TYPE_MDS) {
+ if (key.first == "mds") {
json_spirit::mValue json_result;
bool read_ok = json_spirit::read(
outbl.to_str(), json_result);
if (!read_ok) {
dout(1) << "mon returned invalid JSON for "
- << ceph_entity_type_name(key.first)
- << "." << key.second << dendl;
+ << key.first << "." << key.second << dendl;
return;
}
daemon_state.insert(state);
}
- } else if (key.first == CEPH_ENTITY_TYPE_OSD) {
+ } else if (key.first == "osd") {
} else {
ceph_abort();
}
} else {
dout(1) << "mon failed to return metadata for "
- << ceph_entity_type_name(key.first)
- << "." << key.second << ": " << cpp_strerror(r) << dendl;
+ << key.first << "." << key.second << ": "
+ << cpp_strerror(r) << dendl;
}
}
};
}
DaemonStatePtr dm = std::make_shared<DaemonState>(daemon_state.types);
- dm->key = DaemonKey(CEPH_ENTITY_TYPE_MDS,
+ dm->key = DaemonKey("mds",
daemon_meta.at("name").get_str());
dm->hostname = daemon_meta.at("hostname").get_str();
}
DaemonStatePtr dm = std::make_shared<DaemonState>(daemon_state.types);
- dm->key = DaemonKey(CEPH_ENTITY_TYPE_MON,
+ dm->key = DaemonKey("mon",
daemon_meta.at("name").get_str());
dm->hostname = daemon_meta.at("hostname").get_str();
dout(4) << osd_metadata.at("hostname").get_str() << dendl;
DaemonStatePtr dm = std::make_shared<DaemonState>(daemon_state.types);
- dm->key = DaemonKey(CEPH_ENTITY_TYPE_OSD,
+ dm->key = DaemonKey("osd",
stringify(osd_metadata.at("id").get_int()));
dm->hostname = osd_metadata.at("hostname").get_str();
// Consider whether to update the daemon metadata (new/restarted daemon)
bool update_meta = false;
- const auto k = DaemonKey(CEPH_ENTITY_TYPE_OSD, stringify(osd_id));
+ const auto k = DaemonKey("osd", stringify(osd_id));
if (daemon_state.is_updating(k)) {
continue;
}
});
// TODO: same culling for MonMap
- daemon_state.cull(CEPH_ENTITY_TYPE_OSD, names_exist);
+ daemon_state.cull("osd", names_exist);
}
void Mgr::handle_log(MLog *m)
// Remember which MDS exists so that we can cull any that don't
names_exist.insert(info.name);
- const auto k = DaemonKey(CEPH_ENTITY_TYPE_MDS, info.name);
+ const auto k = DaemonKey("mds", info.name);
if (daemon_state.is_updating(k)) {
continue;
}
{}, &c->outbl, &c->outs, c);
}
}
- daemon_state.cull(CEPH_ENTITY_TYPE_MDS, names_exist);
+ daemon_state.cull("mds", names_exist);
}
bool Mgr::got_mgr_map(const MgrMap& m)
for (const auto &i : dmc) {
const auto &key = i.first;
- const std::string str_type = ceph_entity_type_name(key.first);
+ const std::string &str_type = key.first;
const std::string &svc_name = key.second;
// TODO: pick the highest version, and make sure that
return f.get();
}
-PyObject *PyModules::get_metadata_python(std::string const &handle,
- entity_type_t svc_type, const std::string &svc_id)
+PyObject *PyModules::get_metadata_python(
+ std::string const &handle,
+ const std::string &svc_name,
+ const std::string &svc_id)
{
- auto metadata = daemon_state.get(DaemonKey(svc_type, svc_id));
+ auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id));
PyFormatter f;
f.dump_string("hostname", metadata->hostname);
for (const auto &i : metadata->metadata) {
return f.get();
} else if (what == "osd_metadata") {
PyFormatter f;
- auto dmc = daemon_state.get_by_type(CEPH_ENTITY_TYPE_OSD);
+ auto dmc = daemon_state.get_by_service("osd");
for (const auto &i : dmc) {
f.open_object_section(i.first.second.c_str());
f.dump_string("hostname", i.second->hostname);
PyObject* PyModules::get_counter_python(
const std::string &handle,
- entity_type_t svc_type,
+ const std::string &svc_name,
const std::string &svc_id,
const std::string &path)
{
PyFormatter f;
f.open_array_section(path.c_str());
- auto metadata = daemon_state.get(DaemonKey(svc_type, svc_id));
+ auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id));
// FIXME: this is unsafe, I need to either be inside DaemonStateIndex's
// lock or put a lock on individual DaemonStates
}
} else {
dout(4) << "Missing counter: '" << path << "' ("
- << ceph_entity_type_name(svc_type) << "."
- << svc_id << ")" << dendl;
+ << svc_name << "." << svc_id << ")" << dendl;
dout(20) << "Paths are:" << dendl;
for (const auto &i : metadata->perf_counters.instances) {
dout(20) << i.first << dendl;
}
} else {
dout(4) << "No daemon state for "
- << ceph_entity_type_name(svc_type) << "."
- << svc_id << ")" << dendl;
+ << svc_name << "." << svc_id << ")" << dendl;
}
f.close_section();
return f.get();
PyObject *get_python(const std::string &what);
PyObject *get_server_python(const std::string &hostname);
PyObject *list_servers_python();
- PyObject *get_metadata_python(std::string const &handle,
- entity_type_t svc_type, const std::string &svc_id);
- PyObject *get_counter_python(std::string const &handle,
- entity_type_t svc_type, const std::string &svc_id,
- const std::string &path);
+ PyObject *get_metadata_python(
+ std::string const &handle,
+ const std::string &svc_name, const std::string &svc_id);
+ PyObject *get_counter_python(
+ std::string const &handle,
+ const std::string &svc_name,
+ const std::string &svc_id,
+ const std::string &path);
PyObject *get_context();
std::map<std::string, std::string> config_cache;
Py_RETURN_NONE;
}
-static entity_type_t svc_type_from_str(const std::string &type_str)
-{
- if (type_str == std::string("mds")) {
- return CEPH_ENTITY_TYPE_MDS;
- } else if (type_str == std::string("osd")) {
- return CEPH_ENTITY_TYPE_OSD;
- } else if (type_str == std::string("mon")) {
- return CEPH_ENTITY_TYPE_MON;
- } else {
- return CEPH_ENTITY_TYPE_ANY;
- }
-}
-
static PyObject*
get_metadata(PyObject *self, PyObject *args)
{
char *handle = nullptr;
- char *type_str = NULL;
+ char *svc_name = NULL;
char *svc_id = NULL;
- if (!PyArg_ParseTuple(args, "sss:get_metadata", &handle, &type_str, &svc_id)) {
- return nullptr;
- }
-
- entity_type_t svc_type = svc_type_from_str(type_str);
- if (svc_type == CEPH_ENTITY_TYPE_ANY) {
- // FIXME: form a proper exception
+ if (!PyArg_ParseTuple(args, "sss:get_metadata", &handle, &svc_name, &svc_id)) {
return nullptr;
}
-
-
- return global_handle->get_metadata_python(handle, svc_type, svc_id);
+ return global_handle->get_metadata_python(handle, svc_name, svc_id);
}
static PyObject*
get_counter(PyObject *self, PyObject *args)
{
char *handle = nullptr;
- char *type_str = nullptr;
+ char *svc_name = nullptr;
char *svc_id = nullptr;
char *counter_path = nullptr;
- if (!PyArg_ParseTuple(args, "ssss:get_counter", &handle, &type_str,
+ if (!PyArg_ParseTuple(args, "ssss:get_counter", &handle, &svc_name,
&svc_id, &counter_path)) {
return nullptr;
}
-
- entity_type_t svc_type = svc_type_from_str(type_str);
- if (svc_type == CEPH_ENTITY_TYPE_ANY) {
- // FIXME: form a proper exception
- return nullptr;
- }
-
return global_handle->get_counter_python(
- handle, svc_type, svc_id, counter_path);
+ handle, svc_name, svc_id, counter_path);
}
PyMethodDef CephStateMethods[] = {
"""
Fetch the metadata for a particular service.
- :param svc_type: one of 'mds', 'osd', 'mon'
+ :param svc_type: string (e.g., 'mds', 'osd', 'mon')
:param svc_id: string
:return: dict
"""