Repository: kudu Updated Branches: refs/heads/master 098a1e581 -> a09450465
Add list of tablet servers to /dump-entities This adds the list of tablet servers to the output of /dump-entities endpoint of master server to facilitate the development of external tools and scripts. Change-Id: Ia8ef52a6d2c0c193f5f5db359e144dc1a403a8ab Reviewed-on: http://gerrit.cloudera.org:8080/5977 Reviewed-by: Todd Lipcon <[email protected]> Tested-by: Kudu Jenkins Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/186ac44c Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/186ac44c Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/186ac44c Branch: refs/heads/master Commit: 186ac44c24bd074606d3cbbbabbd054570640377 Parents: 098a1e5 Author: Junegunn Choi <[email protected]> Authored: Tue Feb 14 14:52:16 2017 +0900 Committer: Todd Lipcon <[email protected]> Committed: Tue Feb 14 08:50:01 2017 +0000 ---------------------------------------------------------------------- src/kudu/integration-tests/delete_table-test.cc | 6 ++- src/kudu/master/master-path-handlers.cc | 40 ++++++++++++++++++++ src/kudu/master/master-test.cc | 26 +++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/186ac44c/src/kudu/integration-tests/delete_table-test.cc ---------------------------------------------------------------------- diff --git a/src/kudu/integration-tests/delete_table-test.cc b/src/kudu/integration-tests/delete_table-test.cc index eae3eac..abe52c7 100644 --- a/src/kudu/integration-tests/delete_table-test.cc +++ b/src/kudu/integration-tests/delete_table-test.cc @@ -23,6 +23,7 @@ #include <boost/optional.hpp> #include <glog/stl_logging.h> #include <gtest/gtest.h> +#include <rapidjson/document.h> #include "kudu/client/client-test-util.h" #include "kudu/client/shared_ptr.h" @@ -283,7 +284,10 @@ TEST_F(DeleteTableTest, TestDeleteEmptyTable) { ASSERT_OK(c.FetchURL(Substitute("http://$0/dump-entities", cluster_->master()->bound_http_hostport().ToString()), &entities_buf)); - ASSERT_EQ("{\"tables\":[],\"tablets\":[]}", entities_buf.ToString()); + rapidjson::Document doc; + doc.Parse<0>(entities_buf.ToString().c_str()); + ASSERT_EQ(0, doc["tables"].Size()); + ASSERT_EQ(0, doc["tablets"].Size()); } // Test that a DeleteTablet RPC is rejected without a matching destination UUID. http://git-wip-us.apache.org/repos/asf/kudu/blob/186ac44c/src/kudu/master/master-path-handlers.cc ---------------------------------------------------------------------- diff --git a/src/kudu/master/master-path-handlers.cc b/src/kudu/master/master-path-handlers.cc index efd5183..113b85d 100644 --- a/src/kudu/master/master-path-handlers.cc +++ b/src/kudu/master/master-path-handlers.cc @@ -516,6 +516,46 @@ void MasterPathHandlers::HandleDumpEntities(const Webserver::WebRequest& req, } jw.EndArray(); + jw.String("tablet_servers"); + jw.StartArray(); + vector<std::shared_ptr<TSDescriptor> > descs; + master_->ts_manager()->GetAllDescriptors(&descs); + for (const std::shared_ptr<TSDescriptor>& desc : descs) { + jw.StartObject(); + + jw.String("uuid"); + jw.String(desc->permanent_uuid()); + + ServerRegistrationPB reg; + desc->GetRegistration(®); + + jw.String("rpc_addrs"); + jw.StartArray(); + for (const HostPortPB& host_port : reg.rpc_addresses()) { + jw.String(Substitute("$0:$1", host_port.host(), host_port.port())); + } + jw.EndArray(); + + jw.String("http_addrs"); + jw.StartArray(); + for (const HostPortPB& host_port : reg.http_addresses()) { + jw.String(Substitute("http://$0:$1", host_port.host(), host_port.port())); + } + jw.EndArray(); + + jw.String("live"); + jw.Bool(!desc->PresumedDead()); + + jw.String("millis_since_heartbeat"); + jw.Int64(desc->TimeSinceHeartbeat().ToMilliseconds()); + + jw.String("version"); + jw.String(reg.software_version()); + + jw.EndObject(); + } + jw.EndArray(); + jw.EndObject(); } http://git-wip-us.apache.org/repos/asf/kudu/blob/186ac44c/src/kudu/master/master-test.cc ---------------------------------------------------------------------- diff --git a/src/kudu/master/master-test.cc b/src/kudu/master/master-test.cc index 8e6c8ee..7c6a046 100644 --- a/src/kudu/master/master-test.cc +++ b/src/kudu/master/master-test.cc @@ -16,6 +16,7 @@ // under the License. #include <gtest/gtest.h> +#include <rapidjson/document.h> #include <algorithm> #include <memory> @@ -36,9 +37,11 @@ #include "kudu/master/ts_manager.h" #include "kudu/rpc/messenger.h" #include "kudu/server/rpc_server.h" +#include "kudu/util/curl_util.h" #include "kudu/util/pb_util.h" #include "kudu/util/status.h" #include "kudu/util/test_util.h" +#include "kudu/util/version_info.h" using kudu::rpc::Messenger; using kudu::rpc::MessengerBuilder; @@ -149,6 +152,7 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) { ServerRegistrationPB fake_reg; MakeHostPortPB("localhost", 1000, fake_reg.add_rpc_addresses()); MakeHostPortPB("localhost", 2000, fake_reg.add_http_addresses()); + fake_reg.set_software_version(VersionInfo::GetShortVersionString()); { TSHeartbeatRequestPB req; @@ -280,6 +284,28 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) { ASSERT_EQ(1, resp.servers(0).instance_id().instance_seqno()); } + // Ensure that /dump-entities endpoint also shows the faked server. + { + EasyCurl c; + faststring buf; + string addr = mini_master_->bound_http_addr().ToString(); + ASSERT_OK(c.FetchURL(Substitute("http://$0/dump-entities", addr), &buf)) + rapidjson::Document doc; + doc.Parse<0>(buf.ToString().c_str()); + const rapidjson::Value& tablet_servers = doc["tablet_servers"]; + ASSERT_EQ(tablet_servers.Size(), 1); + const rapidjson::Value& tablet_server = tablet_servers[rapidjson::SizeType(0)]; + ASSERT_STREQ("localhost:1000", + tablet_server["rpc_addrs"][rapidjson::SizeType(0)].GetString()); + ASSERT_STREQ("http://localhost:2000", + tablet_server["http_addrs"][rapidjson::SizeType(0)].GetString()); + ASSERT_STREQ("my-ts-uuid", tablet_server["uuid"].GetString()); + ASSERT_TRUE(tablet_server["millis_since_heartbeat"].GetInt64() >= 0); + ASSERT_EQ(true, tablet_server["live"].GetBool()); + ASSERT_STREQ(VersionInfo::GetShortVersionString().c_str(), + tablet_server["version"].GetString()); + } + // Ensure that trying to re-register with a different version is OK. { TSHeartbeatRequestPB req;
