Skip to content

Commit

Permalink
mon,mgr: improve 'mgr module disable/enable' cmds
Browse files Browse the repository at this point in the history
when running those cmds, check if the module do exist
or is disabled already.
also check if the module is enabled already.

Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
  • Loading branch information
guzhongyan committed Apr 23, 2018
1 parent 4f73c60 commit a7677c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/mon/MgrMap.h
Expand Up @@ -193,6 +193,23 @@ class MgrMap
throw std::logic_error(oss.str());
}

bool module_enabled(const std::string& module_name) const
{
return modules.find(module_name) != modules.end();
}

bool any_supports_module(const std::string& module) const {
if (have_module(module)) {
return true;
}
for (auto& p : standbys) {
if (p.second.have_module(module)) {
return true;
}
}
return false;
}

bool have_name(const string& name) const {
if (active_name == name) {
return true;
Expand Down
13 changes: 13 additions & 0 deletions src/mon/MgrMonitor.cc
Expand Up @@ -897,6 +897,11 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op)
goto out;
}

if (pending_map.module_enabled(module)) {
ss << "module '" << module << "' is already enabled";
r = 0;
goto out;
}
pending_map.modules.insert(module);
} else if (prefix == "mgr module disable") {
string module;
Expand All @@ -905,6 +910,14 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op)
r = -EINVAL;
goto out;
}
if (!pending_map.module_enabled(module)) {
ss << "module '" << module << "' is already disabled";
r = 0;
goto out;
}
if (!pending_map.any_supports_module(module)) {
ss << "module '" << module << "' does not exist";
}
pending_map.modules.erase(module);
} else {
ss << "Command '" << prefix << "' not implemented!";
Expand Down

0 comments on commit a7677c7

Please sign in to comment.