hycdong commented on a change in pull request #605: URL: https://github.com/apache/incubator-pegasus/pull/605#discussion_r495788931
########## File path: src/shell/validate_utils.cpp ########## @@ -0,0 +1,75 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "shell/validate_utils.h" + +bool validate_cmd(const argh::parser &cmd, + const std::set<std::string> ¶ms, + const std::set<std::string> &flags) +{ + if (cmd.size() > 1) { + fmt::print(stderr, "too many params!\n"); + return false; + } + + for (const auto ¶m : cmd.params()) { + if (params.find(param.first) == params.end()) { + fmt::print(stderr, "unknown param {} = {}\n", param.first, param.second); + return false; + } + } + + for (const auto &flag : cmd.flags()) { + if (params.find(flag) != params.end()) { + fmt::print(stderr, "missing value of {}\n", flag); + return false; + } + + if (flags.find(flag) == flags.end()) { + fmt::print(stderr, "unknown flag {}\n", flag); + return false; + } + } + + return true; +} + +bool validate_ip(shell_context *sc, Review comment: In my view, it needn't to check whether the validate ip address of replica server, only basic validation needed, you can reference: https://github.com/apache/incubator-pegasus/blob/5d969e89cb42934800e326a2771844bffb2d3f40/src/shell/commands/node_management.cpp#L529-L533 ########## File path: src/shell/commands/detect_hotkey.cpp ########## @@ -0,0 +1,136 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "shell/commands.h" +#include "shell/validate_utils.h" +#include <dsn/dist/replication/replication_types.h> + +bool generate_hotkey_request(dsn::replication::detect_hotkey_request &req, + const std::string &hotkey_action, + const std::string &hotkey_type, + int app_id, + int partition_index, + std::string &err_info) +{ + std::string hotkey_action_check = hotkey_action; + std::string hotkey_type_check = hotkey_type; + std::transform( + hotkey_type_check.begin(), hotkey_type_check.end(), hotkey_type_check.begin(), tolower); + std::transform(hotkey_action_check.begin(), + hotkey_action_check.end(), + hotkey_action_check.begin(), + tolower); + if (hotkey_type_check == "read") { + req.type = dsn::replication::hotkey_type::type::READ; + } else if (hotkey_type_check == "write") { + req.type = dsn::replication::hotkey_type::type::WRITE; + } else { + err_info = fmt::format("\"{}\" is an invalid hotkey type (should be 'read' or 'write')\n", + hotkey_type); + return false; + } + if (hotkey_action_check == "start") { + req.action = dsn::replication::detect_action::START; + } else if (hotkey_action_check == "stop") { + req.action = dsn::replication::detect_action::STOP; + } else { + err_info = + fmt::format("\"{}\" is an invalid hotkey detect action (should be 'start' or 'stop')\n", + hotkey_action); + return false; + } + req.pid = dsn::gpid(app_id, partition_index); + return true; +} + +// TODO: (Tangyanzhao) merge hotspot_partition_calculator::send_detect_hotkey_request +bool detect_hotkey(command_executor *e, shell_context *sc, arguments args) +{ + // detect_hotkey [-a|--app_id] [-p|--partition_index][-c|--hotkey_action][-t|--hotkey_type] Review comment: detect_hotkey [-a|--app_id] [-p|--partition_index][-c|--hotkey_action][-t|--hotkey_type][-d|--address] ########## File path: src/shell/validate_utils.h ########## @@ -0,0 +1,29 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "shell/argh.h" +#include <dsn/dist/fmt_logging.h> +#include "command_executor.h" + +bool validate_cmd(const argh::parser &cmd, + const std::set<std::string> ¶ms, + const std::set<std::string> &flags); Review comment: `validate_cmd` can be implemented in `command_utis.h`, besides, add comments for this function. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
