Skip to content

Commit

Permalink
feat(shell): support resolve IP address in some shell commands (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smityz authored and acelyc111 committed Dec 30, 2019
1 parent 694cbd5 commit 06d922f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rdsn
Submodule rdsn updated 36 files
+4 −20 include/dsn/dist/replication/replication_ddl_client.h
+2 −0 include/dsn/perf_counter/perf_counters.h
+37 −5 include/dsn/tool-api/http_server.h
+38 −0 include/dsn/utility/utils.h
+141 −7 src/core/core/utils.cpp
+10 −0 src/core/perf_counter/perf_counters.cpp
+86 −0 src/core/tests/hostname_test.cpp
+30 −0 src/core/tests/perf_counters_test.cpp
+8 −0 src/core/tools/common/shared_io_service.h
+24 −2 src/dist/http/http_server.cpp
+45 −0 src/dist/http/perf_counter_http_service.cpp
+28 −0 src/dist/http/perf_counter_http_service.h
+10 −14 src/dist/http/pprof_http_service.h
+17 −3 src/dist/http/root_http_service.h
+4 −4 src/dist/http/server_info_http_services.h
+22 −0 src/dist/http/test/http_server_test.cpp
+65 −0 src/dist/http/test/perf_counter_http_service_test.cpp
+78 −0 src/dist/http/test/uri_decoder_test.cpp
+69 −0 src/dist/http/uri_decoder.cpp
+18 −0 src/dist/http/uri_decoder.h
+32 −114 src/dist/replication/ddl_lib/replication_ddl_client.cpp
+1 −1 src/dist/replication/lib/replica_stub.cpp
+43 −43 src/dist/replication/meta_server/meta_backup_service.cpp
+11 −3 src/dist/replication/meta_server/meta_backup_service.h
+63 −2 src/dist/replication/meta_server/meta_http_service.cpp
+17 −10 src/dist/replication/meta_server/meta_http_service.h
+13 −13 src/dist/replication/meta_server/meta_service.cpp
+2 −1 src/dist/replication/meta_server/meta_service.h
+20 −9 src/dist/replication/meta_server/server_state.cpp
+4 −4 src/dist/replication/test/meta_test/unit_test/backup_test.cpp
+1 −0 src/dist/replication/test/meta_test/unit_test/config-test.ini
+106 −0 src/dist/replication/test/meta_test/unit_test/meta_http_service_test.cpp
+7 −0 src/dist/replication/test/meta_test/unit_test/meta_service_test_app.h
+24 −0 src/dist/replication/test/meta_test/unit_test/state_sync_test.cpp
+5 −3 src/dist/replication/test/replica_test/unit_test/CMakeLists.txt
+4 −2 src/tests/dsn/CMakeLists.txt
18 changes: 15 additions & 3 deletions src/shell/commands/node_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// can be found in the LICENSE file in the root directory of this source tree.

#include "shell/commands.h"
#include <dsn/utility/utils.h>

bool query_cluster_info(command_executor *e, shell_context *sc, arguments args)
{
Expand Down Expand Up @@ -132,7 +133,7 @@ bool ls_nodes(command_executor *e, shell_context *sc, arguments args)
std::string node_name = kv.first.to_std_string();
if (resolve_ip) {
// TODO: put hostname_from_ip_port into common utils
node_name = sc->ddl_client->hostname_from_ip_port(node_name.c_str());
dsn::utils::hostname_from_ip_port(node_name.c_str(), &node_name);
}
tmp_map.emplace(kv.first, list_nodes_helper(node_name, status_str));
}
Expand Down Expand Up @@ -401,15 +402,17 @@ bool remote_command(command_executor *e, shell_context *sc, arguments args)
{
static struct option long_options[] = {{"node_type", required_argument, 0, 't'},
{"node_list", required_argument, 0, 'l'},
{"resolve_ip", no_argument, 0, 'r'},
{0, 0, 0, 0}};

std::string type;
std::string nodes;
optind = 0;
bool resolve_ip = false;
while (true) {
int option_index = 0;
int c;
c = getopt_long(args.argc, args.argv, "t:l:", long_options, &option_index);
c = getopt_long(args.argc, args.argv, "t:l:r", long_options, &option_index);
if (c == -1)
break;
switch (c) {
Expand All @@ -419,6 +422,9 @@ bool remote_command(command_executor *e, shell_context *sc, arguments args)
case 'l':
nodes = optarg;
break;
case 'r':
resolve_ip = true;
break;
default:
return false;
}
Expand Down Expand Up @@ -487,7 +493,13 @@ bool remote_command(command_executor *e, shell_context *sc, arguments args)
// TODO (yingchun) output is hard to read, need do some refactor
for (int i = 0; i < node_list.size(); ++i) {
node_desc &n = node_list[i];
fprintf(stderr, "CALL [%s] [%s] ", n.desc.c_str(), n.address.to_string());
std::string hostname;
if (resolve_ip) {
dsn::utils::hostname_from_ip_port(n.address.to_string(), &hostname);
} else {
hostname = n.address.to_string();
}
fprintf(stderr, "CALL [%s] [%s] ", n.desc.c_str(), hostname.c_str());
if (results[i].first) {
fprintf(stderr, "succeed: %s\n", results[i].second.c_str());
succeed++;
Expand Down
28 changes: 23 additions & 5 deletions src/shell/commands/table_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
if (args.argc <= 1)
return false;

static struct option long_options[] = {{"detailed", no_argument, 0, 'd'},
static struct option long_options[] = {{"resolve_ip", no_argument, 0, 'r'},
{"detailed", no_argument, 0, 'd'},
{"json", no_argument, 0, 'j'},
{"output", required_argument, 0, 'o'},
{0, 0, 0, 0}};
Expand All @@ -130,18 +131,22 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
std::string out_file;
bool detailed = false;
bool json = false;
bool resolve_ip = false;

optind = 0;
while (true) {
int option_index = 0;
int c;
c = getopt_long(args.argc, args.argv, "djo:", long_options, &option_index);
c = getopt_long(args.argc, args.argv, "drjo:", long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'd':
detailed = true;
break;
case 'r':
resolve_ip = true;
break;
case 'j':
json = true;
break;
Expand All @@ -152,7 +157,6 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
return false;
}
}

if (app_name.empty()) {
std::cout << "ERROR: null app name" << std::endl;
return false;
Expand Down Expand Up @@ -184,6 +188,7 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
int32_t partition_count = 0;
int32_t max_replica_count = 0;
std::vector<dsn::partition_configuration> partitions;

dsn::error_code err = sc->ddl_client->list_app(app_name, app_id, partition_count, partitions);
if (err != ::dsn::ERR_OK) {
std::cout << "ERROR: list app " << app_name << " failed, error=" << err.to_string()
Expand Down Expand Up @@ -304,7 +309,13 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
}
}
std::stringstream oss;
oss << p.primary.to_string() << "(";
std::string hostname;
std::string ip = p.primary.to_string();
if (resolve_ip && dsn::utils::hostname_from_ip_port(ip.c_str(), &hostname)) {
oss << hostname << "(";
} else {
oss << p.primary.to_string() << "(";
};
if (disk_found)
oss << disk_value;
else
Expand Down Expand Up @@ -348,7 +359,14 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
count_value = f3->second;
}
}
oss << p.secondaries[j].to_string() << "(";

std::string hostname;
std::string ip = p.secondaries[j].to_string();
if (resolve_ip && dsn::utils::hostname_from_ip_port(ip.c_str(), &hostname)) {
oss << hostname << "(";
} else {
oss << p.secondaries[j].to_string() << "(";
};
if (found)
oss << value;
else
Expand Down
10 changes: 5 additions & 5 deletions src/shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static command_executor commands[] = {
{
"app_disk",
"get the disk usage information for some specific app",
"<app_name> [-d|--detailed] [-j|--json] [-o|--output file_name]",
"<app_name> [-d|--detailed] [-r|--resolve_ip] [-j|--json] [-o|--output file_name]",
app_disk,
},
{
Expand Down Expand Up @@ -293,20 +293,20 @@ static command_executor commands[] = {
{
"remote_command",
"send remote command to servers",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...] "
"[-t all|meta-server|replica-server] [-r|--resolve_ip] [-l ip:port,ip:port...]"
"<command> [arguments...]",
remote_command,
},
{
"server_info",
"get info of servers",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...]",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...] [-r|--resolve_ip]",
server_info,
},
{
"server_stat",
"get stat of servers",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...]",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...] [-r|--resolve_ip]",
server_stat,
},
{
Expand All @@ -319,7 +319,7 @@ static command_executor commands[] = {
{
"flush_log",
"flush log of servers",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...]",
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...][-r|--resolve_ip]",
flush_log,
},
{
Expand Down

0 comments on commit 06d922f

Please sign in to comment.