This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 9b1ff304ca5f9f2e1ea08646c7307fcbe0486015 Author: Alexey Serbin <[email protected]> AuthorDate: Thu Nov 14 19:45:30 2019 -0800 [mini_cluster] SetDaemonFlag for test minicluster Added control knobs to call SetFlag() RPC on masters and tablet servers via mini_cluster test interface. Also, added a test to cover the new functionality. Change-Id: Ie05aa87bba1b709cbbab953b6b220cae0fc958bb Reviewed-on: http://gerrit.cloudera.org:8080/14712 Tested-by: Kudu Jenkins Reviewed-by: Adar Dembo <[email protected]> --- .../apache/kudu/test/cluster/MiniKuduCluster.java | 39 +++++++++++++ src/kudu/tools/kudu-tool-test.cc | 64 ++++++++++++++++++++++ src/kudu/tools/tool.proto | 10 ++++ src/kudu/tools/tool_action_test.cc | 17 ++++++ 4 files changed, 130 insertions(+) diff --git a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/MiniKuduCluster.java b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/MiniKuduCluster.java index 2d40df6..ff5a15a 100644 --- a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/MiniKuduCluster.java +++ b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/MiniKuduCluster.java @@ -52,6 +52,7 @@ import org.apache.kudu.tools.Tool.GetMastersRequestPB; import org.apache.kudu.tools.Tool.GetTServersRequestPB; import org.apache.kudu.tools.Tool.KdestroyRequestPB; import org.apache.kudu.tools.Tool.KinitRequestPB; +import org.apache.kudu.tools.Tool.SetDaemonFlagRequestPB; import org.apache.kudu.tools.Tool.StartClusterRequestPB; import org.apache.kudu.tools.Tool.StartDaemonRequestPB; import org.apache.kudu.tools.Tool.StopDaemonRequestPB; @@ -421,6 +422,44 @@ public class MiniKuduCluster implements AutoCloseable { } /** + * Set flag for the specified master. + * + * @param hp unique host and port identifying the target master + * @throws IOException if something went wrong in transit + */ + public void setMasterFlag(HostAndPort hp, String flag, String value) + throws IOException { + DaemonInfo d = getMasterServer(hp); + LOG.info("Setting flag for master at {}", hp); + sendRequestToCluster(ControlShellRequestPB.newBuilder() + .setSetDaemonFlag(SetDaemonFlagRequestPB.newBuilder() + .setId(d.id) + .setFlag(flag) + .setValue(value) + .build()) + .build()); + } + + /** + * Set flag for the specified tablet server. + * + * @param hp unique host and port identifying the target tablet server + * @throws IOException if something went wrong in transit + */ + public void setTServerFlag(HostAndPort hp, String flag, String value) + throws IOException { + DaemonInfo d = getTabletServer(hp); + LOG.info("Setting flag for tserver at {}", hp); + sendRequestToCluster(ControlShellRequestPB.newBuilder() + .setSetDaemonFlag(SetDaemonFlagRequestPB.newBuilder() + .setId(d.id) + .setFlag(flag) + .setValue(value) + .build()) + .build()); + } + + /** * Removes all credentials for all principals from the Kerberos credential cache. */ public void kdestroy() throws IOException { diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc index d5fb05c..bd4ec0b 100644 --- a/src/kudu/tools/kudu-tool-test.cc +++ b/src/kudu/tools/kudu-tool-test.cc @@ -4733,6 +4733,70 @@ TEST_P(ControlShellToolTest, TestControlShell) { ASSERT_OK(SendReceive(req, &resp)); } + // Set flag. + { + ControlShellRequestPB req; + ControlShellResponsePB resp; + auto* r = req.mutable_set_daemon_flag(); + *r->mutable_id() = tservers[0].id(); + r->set_flag("rpc_negotiation_timeout_ms"); + r->set_value("5000"); + ASSERT_OK(SendReceive(req, &resp)); + } + + // Try to set a non-existent flag: this should fail. + { + ControlShellRequestPB req; + ControlShellResponsePB resp; + auto* r = req.mutable_set_daemon_flag(); + *r->mutable_id() = masters[0].id(); + r->set_flag("__foo_bar_flag__"); + r->set_value("__value__"); + ASSERT_OK(proto_->SendMessage(req)); + ASSERT_OK(proto_->ReceiveMessage(&resp)); + ASSERT_TRUE(resp.has_error()); + auto s = StatusFromPB(resp.error()); + ASSERT_TRUE(s.IsRemoteError()) << s.ToString(); + ASSERT_STR_CONTAINS(s.ToString(), + "failed to set flag: result: NO_SUCH_FLAG"); + } + + // Try to set a flag on a non-existent daemon: this should fail. + { + ControlShellRequestPB req; + ControlShellResponsePB resp; + auto* r = req.mutable_set_daemon_flag(); + r->mutable_id()->set_index(1000); + r->mutable_id()->set_type(MASTER); + r->set_flag("flag"); + r->set_value("value"); + ASSERT_OK(proto_->SendMessage(req)); + ASSERT_OK(proto_->ReceiveMessage(&resp)); + ASSERT_TRUE(resp.has_error()); + auto s = StatusFromPB(resp.error()); + ASSERT_TRUE(s.IsNotFound()) << s.ToString(); + ASSERT_STR_CONTAINS(s.ToString(), "no master with index 1000"); + } + + // Try to set a flag on a KDC: this should fail since mini-KDC doesn't support + // SetFlag() call. + { + ControlShellRequestPB req; + ControlShellResponsePB resp; + auto* r = req.mutable_set_daemon_flag(); + r->mutable_id()->set_index(0); + r->mutable_id()->set_type(KDC); + r->set_flag("flag"); + r->set_value("value"); + ASSERT_OK(proto_->SendMessage(req)); + ASSERT_OK(proto_->ReceiveMessage(&resp)); + ASSERT_TRUE(resp.has_error()); + auto s = StatusFromPB(resp.error()); + ASSERT_TRUE(s.IsInvalidArgument()) << s.ToString(); + ASSERT_STR_CONTAINS(s.ToString(), + "mini-KDC doesn't support SetFlag()"); + } + if (enable_kerberos()) { // Restart the KDC. { diff --git a/src/kudu/tools/tool.proto b/src/kudu/tools/tool.proto index da11ea2..1754417 100644 --- a/src/kudu/tools/tool.proto +++ b/src/kudu/tools/tool.proto @@ -159,6 +159,15 @@ message KinitRequestPB { optional string username = 1 [ default = "test-admin" ]; }; +// Call SetFlag() on the specific daemon. +message SetDaemonFlagRequestPB { + // The identifier for the daemon to sent the request to. + optional DaemonIdentifierPB id = 1; + // The name of the flag to set. + optional string flag = 2; + // Value to set. + optional string value = 3; +} // Sent by the control shell in response to a control shell command request. message ControlShellResponsePB { @@ -194,6 +203,7 @@ message ControlShellRequestPB { GetKDCEnvVarsRequestPB get_kdc_env_vars = 9; KdestroyRequestPB kdestroy = 10; KinitRequestPB kinit = 11; + SetDaemonFlagRequestPB set_daemon_flag = 12; } } diff --git a/src/kudu/tools/tool_action_test.cc b/src/kudu/tools/tool_action_test.cc index af65dad..da0de8d 100644 --- a/src/kudu/tools/tool_action_test.cc +++ b/src/kudu/tools/tool_action_test.cc @@ -286,6 +286,23 @@ Status ProcessRequest(const ControlShellRequestPB& req, RETURN_NOT_OK((*cluster)->kdc()->Kinit(req.kinit().username())); break; } + case ControlShellRequestPB::kSetDaemonFlag: + { + const auto& r = req.set_daemon_flag(); + if (!r.has_id()) { + RETURN_NOT_OK(Status::InvalidArgument("missing process id")); + } + const auto& id = r.id(); + if (id.type() == DaemonType::KDC) { + return Status::InvalidArgument("mini-KDC doesn't support SetFlag()"); + } + ExternalDaemon* daemon; + MiniKdc* kdc; + RETURN_NOT_OK(FindDaemon(*cluster, id, &daemon, &kdc)); + DCHECK(daemon); + RETURN_NOT_OK((*cluster)->SetFlag(daemon, r.flag(), r.value())); + break; + } default: RETURN_NOT_OK(Status::InvalidArgument("unknown cluster control request")); }
