mirror of
https://github.com/ceph/ceph
synced 2025-04-01 23:02:17 +00:00
Merge pull request #36937 from tchaikov/wip-mgr-cleanup
mgr: use range-based loop and cleanups Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
This commit is contained in:
commit
7b23ddf13b
@ -111,11 +111,9 @@ PyObject *ActivePyModules::list_servers_python()
|
||||
(const std::map<std::string, DaemonStateCollection> &all) {
|
||||
PyEval_RestoreThread(tstate);
|
||||
|
||||
for (const auto &i : all) {
|
||||
const auto &hostname = i.first;
|
||||
|
||||
for (const auto &[hostname, daemon_state] : all) {
|
||||
f.open_object_section("server");
|
||||
dump_server(hostname, i.second, &f);
|
||||
dump_server(hostname, daemon_state, &f);
|
||||
f.close_section();
|
||||
}
|
||||
});
|
||||
@ -136,8 +134,8 @@ PyObject *ActivePyModules::get_metadata_python(
|
||||
std::lock_guard l(metadata->lock);
|
||||
PyFormatter f;
|
||||
f.dump_string("hostname", metadata->hostname);
|
||||
for (const auto &i : metadata->metadata) {
|
||||
f.dump_string(i.first.c_str(), i.second);
|
||||
for (const auto &[key, val] : metadata->metadata) {
|
||||
f.dump_string(key, val);
|
||||
}
|
||||
|
||||
return f.get();
|
||||
@ -155,8 +153,8 @@ PyObject *ActivePyModules::get_daemon_status_python(
|
||||
|
||||
std::lock_guard l(metadata->lock);
|
||||
PyFormatter f;
|
||||
for (const auto &i : metadata->service_status) {
|
||||
f.dump_string(i.first.c_str(), i.second);
|
||||
for (const auto &[daemon, status] : metadata->service_status) {
|
||||
f.dump_string(daemon, status);
|
||||
}
|
||||
return f.get();
|
||||
}
|
||||
|
@ -216,8 +216,8 @@ DaemonStateCollection DaemonStateIndex::get_by_server(
|
||||
{
|
||||
std::shared_lock l{lock};
|
||||
|
||||
if (by_server.count(hostname)) {
|
||||
return by_server.at(hostname);
|
||||
if (auto found = by_server.find(hostname); found != by_server.end()) {
|
||||
return found->second;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
@ -100,9 +100,8 @@ void MetadataUpdate::finish(int r)
|
||||
}
|
||||
}
|
||||
|
||||
DaemonStatePtr state;
|
||||
if (daemon_state.exists(key)) {
|
||||
state = daemon_state.get(key);
|
||||
DaemonStatePtr state = daemon_state.get(key);
|
||||
state->hostname = daemon_meta.at("hostname").get_str();
|
||||
|
||||
if (key.type == "mds" || key.type == "mgr" || key.type == "mon") {
|
||||
@ -112,13 +111,12 @@ void MetadataUpdate::finish(int r)
|
||||
}
|
||||
daemon_meta.erase("hostname");
|
||||
map<string,string> m;
|
||||
for (const auto &i : daemon_meta) {
|
||||
m[i.first] = i.second.get_str();
|
||||
for (const auto &[key, val] : daemon_meta) {
|
||||
m.emplace(key, val.get_str());
|
||||
}
|
||||
|
||||
daemon_state.update_metadata(state, m);
|
||||
} else {
|
||||
state = std::make_shared<DaemonState>(daemon_state.types);
|
||||
auto state = std::make_shared<DaemonState>(daemon_state.types);
|
||||
state->key = key;
|
||||
state->hostname = daemon_meta.at("hostname").get_str();
|
||||
|
||||
@ -130,8 +128,8 @@ void MetadataUpdate::finish(int r)
|
||||
daemon_meta.erase("hostname");
|
||||
|
||||
map<string,string> m;
|
||||
for (const auto &i : daemon_meta) {
|
||||
m[i.first] = i.second.get_str();
|
||||
for (const auto &[key, val] : daemon_meta) {
|
||||
m.emplace(key, val.get_str());
|
||||
}
|
||||
state->set_metadata(m);
|
||||
|
||||
@ -371,8 +369,8 @@ void Mgr::load_all_metadata()
|
||||
daemon_meta.erase("name");
|
||||
daemon_meta.erase("hostname");
|
||||
|
||||
for (const auto &i : daemon_meta) {
|
||||
dm->metadata[i.first] = i.second.get_str();
|
||||
for (const auto &[key, val] : daemon_meta) {
|
||||
dm->metadata.emplace(key, val.get_str());
|
||||
}
|
||||
|
||||
daemon_state.insert(dm);
|
||||
@ -394,8 +392,8 @@ void Mgr::load_all_metadata()
|
||||
daemon_meta.erase("hostname");
|
||||
|
||||
map<string,string> m;
|
||||
for (const auto &i : daemon_meta) {
|
||||
m[i.first] = i.second.get_str();
|
||||
for (const auto &[key, val] : daemon_meta) {
|
||||
m.emplace(key, val.get_str());
|
||||
}
|
||||
dm->set_metadata(m);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user