You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by GitBox <gi...@apache.org> on 2020/09/29 11:34:27 UTC

[GitHub] [incubator-pegasus] Smityz opened a new pull request #611: feat(shell): add a util to validate the input ip string with list_nodes

Smityz opened a new pull request #611:
URL: https://github.com/apache/incubator-pegasus/pull/611


   This util can help us if the input IP string is sent to the right replicas belongs to metas.


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


[GitHub] [incubator-pegasus] levy5307 commented on a change in pull request #611: feat(shell): add a util to validate the input ip string with list_nodes

Posted by GitBox <gi...@apache.org>.
levy5307 commented on a change in pull request #611:
URL: https://github.com/apache/incubator-pegasus/pull/611#discussion_r497230637



##########
File path: src/shell/command_utils.h
##########
@@ -9,6 +9,7 @@
 #include <set>
 
 #include "shell/argh.h"
+#include "command_executor.h"

Review comment:
       remove `#include "command_executor.h"`
   using forward declaration is ok




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


[GitHub] [incubator-pegasus] levy5307 commented on a change in pull request #611: feat(shell): add a util to validate the input ip string with list_nodes

Posted by GitBox <gi...@apache.org>.
levy5307 commented on a change in pull request #611:
URL: https://github.com/apache/incubator-pegasus/pull/611#discussion_r497231185



##########
File path: src/shell/commands/detect_hotkey.cpp
##########
@@ -85,13 +85,13 @@ bool detect_hotkey(command_executor *e, shell_context *sc, arguments args)
     }
 
     dsn::rpc_address target_address;
+    std::string err_info;
     std::string ip_str = cmd({"-d", "--address"}).str();
-    if (!target_address.from_string_ipv4(ip_str.c_str())) {
-        fmt::print("invalid ip, error={}\n", ip_str);
+    if (!validate_ip(sc, ip_str, target_address, err_info)) {
+        fmt::print("{}\n", err_info);

Review comment:
       `fmt::print(stderr, "{}\n", err_info)`




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


[GitHub] [incubator-pegasus] levy5307 commented on a change in pull request #611: feat(shell): add a util to validate the input ip string with list_nodes

Posted by GitBox <gi...@apache.org>.
levy5307 commented on a change in pull request #611:
URL: https://github.com/apache/incubator-pegasus/pull/611#discussion_r497315140



##########
File path: src/shell/command_utils.cpp
##########
@@ -0,0 +1,47 @@
+// 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 "command_utils.h"
+
+#include "command_executor.h"
+
+bool validate_ip(shell_context *sc,
+                 const std::string &ip_str,
+                 dsn::rpc_address &target_address,
+                 std::string &err_info)
+{
+    if (!target_address.from_string_ipv4(ip_str.c_str())) {
+        err_info = fmt::format("invalid ip:port={}, can't transform it into rpc_address", ip_str);
+        return false;
+    }
+
+    std::map<dsn::rpc_address, dsn::replication::node_status::type> nodes;
+    auto error = sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, nodes);
+    if (error != dsn::ERR_OK) {
+        err_info = fmt::format("list nodes failed, error={}", error.to_string());
+        return false;
+    }
+
+    for (const auto &node : nodes) {
+        if (target_address == node.first) {
+            return true;
+        }
+    }
+
+    err_info = fmt::format("invalid ip:port={}, can't find it in metas", ip_str);

Review comment:
       can't find it in cluster




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


[GitHub] [incubator-pegasus] acelyc111 merged pull request #611: feat(shell): add a util to validate the input ip string with list_nodes

Posted by GitBox <gi...@apache.org>.
acelyc111 merged pull request #611:
URL: https://github.com/apache/incubator-pegasus/pull/611


   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


[GitHub] [incubator-pegasus] acelyc111 commented on a change in pull request #611: feat(shell): add a util to validate the input ip string with list_nodes

Posted by GitBox <gi...@apache.org>.
acelyc111 commented on a change in pull request #611:
URL: https://github.com/apache/incubator-pegasus/pull/611#discussion_r496700732



##########
File path: src/shell/command_utils.cpp
##########
@@ -0,0 +1,33 @@
+#include "command_utils.h"

Review comment:
       License

##########
File path: src/shell/command_utils.cpp
##########
@@ -0,0 +1,33 @@
+#include "command_utils.h"
+
+bool validate_ip(shell_context *sc,
+                 const std::string &ip_str,
+                 /*out*/ dsn::rpc_address &target_address,
+                 /*out*/ std::string &err_info)
+{
+    std::map<dsn::rpc_address, dsn::replication::node_status::type> nodes;
+    auto error = sc->ddl_client->list_nodes(::dsn::replication::node_status::NS_INVALID, nodes);
+    if (error != dsn::ERR_OK) {
+        err_info = fmt::format("list nodes failed, error={} \n", error.to_string());
+        return false;
+    }
+
+    if (!target_address.from_string_ipv4(ip_str.c_str())) {
+        err_info = fmt::format("invalid ip:port:{}, can't transform it into rpc_address\n", ip_str);
+        return false;
+    }
+
+    bool not_find_ip = true;
+    for (const auto &node : nodes) {
+        if (target_address == node.first) {
+            not_find_ip = false;
+        }
+    }
+
+    if (not_find_ip) {
+        err_info = fmt::format("invalid ip:port:{}, can't find it in metas \n", ip_str);
+        return false;
+    }
+
+    return true;

Review comment:
       ```suggestion
       if (!target_address.from_string_ipv4(ip_str.c_str())) {
           err_info = fmt::format("invalid ip:port={}, can't transform it into rpc_address", ip_str);
           return false;
       }
   
       std::map<dsn::rpc_address, dsn::replication::node_status::type> nodes;
       auto error = sc->ddl_client->list_nodes(::dsn::replication::node_status::NS_INVALID, nodes);
       if (error != dsn::ERR_OK) {
           err_info = fmt::format("list nodes failed, error={}", error.to_string());
           return false;
       }
   
       for (const auto &node : nodes) {
           if (target_address == node.first) {
               return true;
           }
       }
   
       err_info = fmt::format("invalid ip:port={}, can't find it in metas", ip_str);
       return false;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


[GitHub] [incubator-pegasus] levy5307 commented on a change in pull request #611: feat(shell): add a util to validate the input ip string with list_nodes

Posted by GitBox <gi...@apache.org>.
levy5307 commented on a change in pull request #611:
URL: https://github.com/apache/incubator-pegasus/pull/611#discussion_r497230144



##########
File path: src/shell/command_utils.cpp
##########
@@ -0,0 +1,45 @@
+// 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 "command_utils.h"
+
+bool validate_ip(shell_context *sc,
+                 const std::string &ip_str,
+                 /*out*/ dsn::rpc_address &target_address,
+                 /*out*/ std::string &err_info)
+{
+    if (!target_address.from_string_ipv4(ip_str.c_str())) {
+        err_info = fmt::format("invalid ip:port={}, can't transform it into rpc_address", ip_str);
+        return false;
+    }
+
+    std::map<dsn::rpc_address, dsn::replication::node_status::type> nodes;
+    auto error = sc->ddl_client->list_nodes(::dsn::replication::node_status::NS_INVALID, nodes);

Review comment:
       remove the prefix `::`




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org