You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by "Samunroyu (via GitHub)" <gi...@apache.org> on 2024/05/27 04:02:47 UTC
[PR] feat(shell): Add JSON format data output to the some backup_policy command [incubator-pegasus]
Samunroyu opened a new pull request, #2030:
URL: https://github.com/apache/incubator-pegasus/pull/2030
Add JSON output to some backup policy commands to facilitate the writing of automation scripts.
Backup policy commands including:
- ls_backup_policy
- query_backup_policy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org
Re: [PR] feat(shell): Add JSON format data output to some backup_policy commands [incubator-pegasus]
Posted by "acelyc111 (via GitHub)" <gi...@apache.org>.
acelyc111 commented on code in PR #2030:
URL: https://github.com/apache/incubator-pegasus/pull/2030#discussion_r1615662760
##########
src/client/replication_ddl_client.cpp:
##########
@@ -1217,23 +1219,34 @@ replication_ddl_client::query_backup_policy(const std::vector<std::string> &poli
configuration_query_backup_policy_response resp;
::dsn::unmarshall(resp_task->get_response(), resp);
+ std::streambuf *buf;
+ std::ofstream of;
+ buf = std::cout.rdbuf();
+ std::ostream out(buf);
+
if (resp.err != ERR_OK) {
return resp.err;
} else {
+ dsn::utils::multi_table_printer mtp;
for (int32_t idx = 0; idx < resp.policys.size(); idx++) {
if (idx != 0) {
std::cout << "************************" << std::endl;
}
const policy_entry &pentry = resp.policys[idx];
- std::cout << "policy_info:" << std::endl;
- print_policy_entry(pentry);
- std::cout << std::endl << "backup_infos:" << std::endl;
+ dsn::utils::table_printer tp_policy = print_policy_entry(pentry);
+ mtp.add(std::move(tp_policy));
const std::vector<backup_entry> &backup_infos = resp.backup_infos[idx];
+ dsn::utils::table_printer tp_backup("backup_infos");
Review Comment:
As cold_backup_constant::BACKUP_INFO is considered as the reserve key [1], so use cold_backup_constant::BACKUP_INFO instead of "backup_infos".
1. https://github.com/apache/incubator-pegasus/blob/master/src/meta/meta_backup_service.cpp#L1470
##########
src/shell/commands/cold_backup.cpp:
##########
@@ -143,31 +143,54 @@ bool add_backup_policy(command_executor *e, shell_context *sc, arguments args)
bool ls_backup_policy(command_executor *e, shell_context *sc, arguments args)
{
- ::dsn::error_code err = sc->ddl_client->ls_backup_policy();
+ static struct option long_options[] = {{"json", no_argument, 0, 'j'}, {0, 0, 0, 0}};
Review Comment:
It's recommend to use the modernize argh::parser instead of getopt_long.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org
Re: [PR] feat(shell): Add JSON format data output to some backup_policy commands [incubator-pegasus]
Posted by "empiredan (via GitHub)" <gi...@apache.org>.
empiredan merged PR #2030:
URL: https://github.com/apache/incubator-pegasus/pull/2030
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org
Re: [PR] feat(shell): Add JSON format data output to some backup_policy commands [incubator-pegasus]
Posted by "acelyc111 (via GitHub)" <gi...@apache.org>.
acelyc111 commented on code in PR #2030:
URL: https://github.com/apache/incubator-pegasus/pull/2030#discussion_r1616524588
##########
src/shell/commands/cold_backup.cpp:
##########
@@ -143,64 +145,51 @@ bool add_backup_policy(command_executor *e, shell_context *sc, arguments args)
bool ls_backup_policy(command_executor *e, shell_context *sc, arguments args)
{
- ::dsn::error_code err = sc->ddl_client->ls_backup_policy();
+ argh::parser cmd(args.argc, args.argv);
+ const bool json = cmd[{"-j", "--json"}];
+
+ ::dsn::error_code err = sc->ddl_client->ls_backup_policy(json);
if (err != ::dsn::ERR_OK) {
std::cout << "ls backup policy failed" << std::endl;
- } else {
- std::cout << std::endl << "ls backup policy succeed" << std::endl;
}
return true;
}
bool query_backup_policy(command_executor *e, shell_context *sc, arguments args)
{
- static struct option long_options[] = {{"policy_name", required_argument, 0, 'p'},
- {"backup_info_cnt", required_argument, 0, 'b'},
- {0, 0, 0, 0}};
- std::vector<std::string> policy_names;
- int backup_info_cnt = 3;
+ const std::string query_backup_policy_help = "<policy_name> [-b|--backup_info_cnt] [-j|--json]";
+ argh::parser cmd(args.argc, args.argv);
Review Comment:
Similar to https://github.com/apache/incubator-pegasus/pull/2027, it's needed to add a parameter `PREFER_PARAM_FOR_UNREG_OPTION`. @empiredan right?
##########
src/shell/commands/cold_backup.cpp:
##########
@@ -143,64 +145,51 @@ bool add_backup_policy(command_executor *e, shell_context *sc, arguments args)
bool ls_backup_policy(command_executor *e, shell_context *sc, arguments args)
{
- ::dsn::error_code err = sc->ddl_client->ls_backup_policy();
+ argh::parser cmd(args.argc, args.argv);
+ const bool json = cmd[{"-j", "--json"}];
+
+ ::dsn::error_code err = sc->ddl_client->ls_backup_policy(json);
if (err != ::dsn::ERR_OK) {
std::cout << "ls backup policy failed" << std::endl;
- } else {
- std::cout << std::endl << "ls backup policy succeed" << std::endl;
}
return true;
}
bool query_backup_policy(command_executor *e, shell_context *sc, arguments args)
{
- static struct option long_options[] = {{"policy_name", required_argument, 0, 'p'},
- {"backup_info_cnt", required_argument, 0, 'b'},
- {0, 0, 0, 0}};
- std::vector<std::string> policy_names;
- int backup_info_cnt = 3;
+ const std::string query_backup_policy_help = "<policy_name> [-b|--backup_info_cnt] [-j|--json]";
+ argh::parser cmd(args.argc, args.argv);
+ RETURN_FALSE_IF_NOT(cmd.pos_args().size() > 1,
+ "invalid command, should be in the form of '{}'",
+ query_backup_policy_help);
- optind = 0;
- while (true) {
- int option_index = 0;
- int c;
- c = getopt_long(args.argc, args.argv, "p:b:", long_options, &option_index);
- if (c == -1)
- break;
- switch (c) {
- case 'p': {
- std::vector<std::string> names;
- ::dsn::utils::split_args(optarg, names, ',');
- for (const auto &policy_name : names) {
- if (policy_name.empty()) {
- fprintf(stderr, "invalid, empty policy_name, just ignore\n");
- continue;
- } else {
- policy_names.emplace_back(policy_name);
- }
- }
- } break;
- case 'b':
- backup_info_cnt = atoi(optarg);
- if (backup_info_cnt <= 0) {
- fprintf(stderr, "invalid backup_info_cnt %s\n", optarg);
- return false;
- }
- break;
- default:
- return false;
+ std::vector<std::string> policy_names;
+ std::vector<std::string> names;
+ ::dsn::utils::split_args(cmd(1).str().c_str(), names, ',');
Review Comment:
I guess the `PARSE_STRS` macro can be used here, please check it.
##########
src/shell/commands/cold_backup.cpp:
##########
@@ -143,64 +145,51 @@ bool add_backup_policy(command_executor *e, shell_context *sc, arguments args)
bool ls_backup_policy(command_executor *e, shell_context *sc, arguments args)
{
- ::dsn::error_code err = sc->ddl_client->ls_backup_policy();
+ argh::parser cmd(args.argc, args.argv);
+ const bool json = cmd[{"-j", "--json"}];
+
+ ::dsn::error_code err = sc->ddl_client->ls_backup_policy(json);
if (err != ::dsn::ERR_OK) {
std::cout << "ls backup policy failed" << std::endl;
- } else {
- std::cout << std::endl << "ls backup policy succeed" << std::endl;
}
return true;
}
bool query_backup_policy(command_executor *e, shell_context *sc, arguments args)
{
- static struct option long_options[] = {{"policy_name", required_argument, 0, 'p'},
- {"backup_info_cnt", required_argument, 0, 'b'},
- {0, 0, 0, 0}};
- std::vector<std::string> policy_names;
- int backup_info_cnt = 3;
+ const std::string query_backup_policy_help = "<policy_name> [-b|--backup_info_cnt] [-j|--json]";
+ argh::parser cmd(args.argc, args.argv);
+ RETURN_FALSE_IF_NOT(cmd.pos_args().size() > 1,
+ "invalid command, should be in the form of '{}'",
+ query_backup_policy_help);
- optind = 0;
- while (true) {
- int option_index = 0;
- int c;
- c = getopt_long(args.argc, args.argv, "p:b:", long_options, &option_index);
- if (c == -1)
- break;
- switch (c) {
- case 'p': {
- std::vector<std::string> names;
- ::dsn::utils::split_args(optarg, names, ',');
- for (const auto &policy_name : names) {
- if (policy_name.empty()) {
- fprintf(stderr, "invalid, empty policy_name, just ignore\n");
- continue;
- } else {
- policy_names.emplace_back(policy_name);
- }
- }
- } break;
- case 'b':
- backup_info_cnt = atoi(optarg);
- if (backup_info_cnt <= 0) {
- fprintf(stderr, "invalid backup_info_cnt %s\n", optarg);
- return false;
- }
- break;
- default:
- return false;
+ std::vector<std::string> policy_names;
+ std::vector<std::string> names;
+ ::dsn::utils::split_args(cmd(1).str().c_str(), names, ',');
+ for (const auto &policy_name : names) {
+ if (policy_name.empty()) {
Review Comment:
Empty token will be ignored automatically, see
https://github.com/apache/incubator-pegasus/blob/master/src/utils/strings.h#L74
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org
Re: [PR] feat(shell): Add JSON format data output to some backup_policy commands [incubator-pegasus]
Posted by "acelyc111 (via GitHub)" <gi...@apache.org>.
acelyc111 commented on code in PR #2030:
URL: https://github.com/apache/incubator-pegasus/pull/2030#discussion_r1616953838
##########
src/meta/meta_backup_service.cpp:
##########
@@ -1469,7 +1469,7 @@ bool backup_service::is_valid_policy_name_unlocked(const std::string &policy_nam
// output when query the policy details, use different names to distinguish the respective
// contents.
static const std::set<std::string> kReservedNames = {cold_backup_constant::BACKUP_INFO};
Review Comment:
Now this line is useless, you can remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org