Skip to content

Commit

Permalink
refactor(FQDN): update some logs in cpp-shell CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Jul 15, 2024
1 parent a4279ec commit 3542864
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
20 changes: 11 additions & 9 deletions src/shell/command_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,32 @@
#include "utils/error_code.h"

bool validate_ip(shell_context *sc,
const std::string &ip_str,
const std::string &target_hp_str,
dsn::host_port &target_hp,
std::string &err_info)
{
target_hp = dsn::host_port::from_string(ip_str);
target_hp = dsn::host_port::from_string(target_hp_str);
if (!target_hp) {
err_info = fmt::format("invalid ip:port={}, can't transform it into host_port", ip_str);
err_info =
fmt::format("invalid host:port '{}', can't transform it into host_port", target_hp_str);
return false;
}

std::map<dsn::host_port, dsn::replication::node_status::type> nodes;
auto error = sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, nodes);
std::map<dsn::host_port, dsn::replication::node_status::type> ns_by_nodes;
const auto error =
sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, ns_by_nodes);
if (error != dsn::ERR_OK) {
err_info = fmt::format("list nodes failed, error={}", error.to_string());
err_info = fmt::format("list nodes failed, error={}", error);
return false;
}

for (const auto &node : nodes) {
if (target_hp == node.first) {
for (const auto &[node, _] : ns_by_nodes) {
if (target_hp == node) {
return true;
}
}

err_info = fmt::format("invalid ip:port={}, can't find it in the cluster", ip_str);
err_info = fmt::format("invalid host:port '{}', can't find it in the cluster", target_hp_str);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/shell/command_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ inline bool validate_cmd(const argh::parser &cmd,
}

bool validate_ip(shell_context *sc,
const std::string &ip_str,
const std::string &host_port_str,
/*out*/ dsn::host_port &target_hp,
/*out*/ std::string &err_info);

Expand Down
6 changes: 3 additions & 3 deletions src/shell/commands/detect_hotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ bool detect_hotkey(command_executor *e, shell_context *sc, arguments args)

dsn::host_port target_hp;
std::string err_info;
std::string ip_str = cmd({"-d", "--address"}).str();
if (!validate_ip(sc, ip_str, target_hp, err_info)) {
const auto &target_hp_str = cmd({"-d", "--address"}).str();
if (!validate_ip(sc, target_hp_str, target_hp, err_info)) {
fmt::print(stderr, "{}\n", err_info);
return false;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ bool detect_hotkey(command_executor *e, shell_context *sc, arguments args)
app_id,
partition_index,
hotkey_type,
ip_str);
target_hp_str);
break;
case dsn::replication::detect_action::STOP:
fmt::print("Hotkey detection is stopped now\n");
Expand Down
2 changes: 1 addition & 1 deletion src/shell/commands/node_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ bool remote_command(command_executor *e, shell_context *sc, arguments args)
for (std::string &token : tokens) {
const auto node = dsn::host_port::from_string(token);
if (!node) {
fprintf(stderr, "parse %s as a ip:port node failed\n", token.c_str());
fprintf(stderr, "parse %s as a host:port node failed\n", token.c_str());
return true;
}
node_list.emplace_back("user-specified", node);
Expand Down
4 changes: 2 additions & 2 deletions src/shell/commands/recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool recover(command_executor *e, shell_context *sc, arguments args)
for (std::string &token : tokens) {
const auto node = dsn::host_port::from_string(token);
if (!node) {
fprintf(stderr, "parse %s as a ip:port node failed\n", token.c_str());
fprintf(stderr, "parse %s as a host:port node failed\n", token.c_str());
return true;
}
node_list.push_back(node);
Expand All @@ -140,7 +140,7 @@ bool recover(command_executor *e, shell_context *sc, arguments args)
const auto node = dsn::host_port::from_string(str);
if (!node) {
fprintf(stderr,
"parse %s at file %s line %d as ip:port failed\n",
"parse %s at file %s line %d as host:port failed\n",
str.c_str(),
node_list_file.c_str(),
lineno);
Expand Down
8 changes: 4 additions & 4 deletions src/shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,20 +372,20 @@ static command_executor commands[] = {
{
"remote_command",
"send remote command to servers",
"[-t all|meta-server|replica-server] [-r|--resolve_ip] [-l ip:port,ip:port...]"
"[-t all|meta-server|replica-server] [-r|--resolve_ip] [-l host:port,host:port...]"
" <command> [arguments...]",
remote_command,
},
{
"server_info",
"get info of servers",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...] [-r|--resolve_ip]",
"[-t all|meta-server|replica-server] [-l host:port,host:port...] [-r|--resolve_ip]",
server_info,
},
{
"server_stat",
"get stat of servers",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...] [-r|--resolve_ip]",
"[-t all|meta-server|replica-server] [-l host:port,host:port...] [-r|--resolve_ip]",
server_stat,
},
{
Expand All @@ -398,7 +398,7 @@ static command_executor commands[] = {
{
"flush_log",
"flush log of servers",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...][-r|--resolve_ip]",
"[-t all|meta-server|replica-server] [-l host:port,host:port...][-r|--resolve_ip]",
flush_log,
},
{
Expand Down

0 comments on commit 3542864

Please sign in to comment.