Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F2025200CE0 for ; Wed, 26 Jul 2017 21:08:15 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id F0C881696D2; Wed, 26 Jul 2017 19:08:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 23B051696D3 for ; Wed, 26 Jul 2017 21:08:14 +0200 (CEST) Received: (qmail 52122 invoked by uid 500); 26 Jul 2017 19:08:14 -0000 Mailing-List: contact commits-help@kudu.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@kudu.apache.org Delivered-To: mailing list commits@kudu.apache.org Received: (qmail 52106 invoked by uid 99); 26 Jul 2017 19:08:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Jul 2017 19:08:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3AE5AE5E44; Wed, 26 Jul 2017 19:08:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: danburkert@apache.org To: commits@kudu.apache.org Date: Wed, 26 Jul 2017 19:08:15 -0000 Message-Id: <611836d37bcf4f1a94db3720993084bb@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] kudu git commit: Switch tables page to template archived-at: Wed, 26 Jul 2017 19:08:16 -0000 Switch tables page to template Converts the /tables page of the master web UI to use a mustache template. Change-Id: I2750448bb5c96b8837bc045dca41d4a4113b0c6b Reviewed-on: http://gerrit.cloudera.org:8080/7506 Reviewed-by: Dan Burkert Tested-by: Dan Burkert Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/9285f2b4 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/9285f2b4 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/9285f2b4 Branch: refs/heads/master Commit: 9285f2b44edb23a906cc3a697d9289ee3b3c5673 Parents: 634e1cc Author: Sam Okrent Authored: Tue Jul 25 14:28:58 2017 -0700 Committer: Dan Burkert Committed: Wed Jul 26 19:07:55 2017 +0000 ---------------------------------------------------------------------- src/kudu/master/master-path-handlers.cc | 34 +++++++--------------- src/kudu/master/master-path-handlers.h | 3 +- www/tables.mustache | 43 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/9285f2b4/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 d1855f7..80668b1 100644 --- a/src/kudu/master/master-path-handlers.cc +++ b/src/kudu/master/master-path-handlers.cc @@ -44,6 +44,7 @@ #include "kudu/master/sys_catalog.h" #include "kudu/master/ts_descriptor.h" #include "kudu/master/ts_manager.h" +#include "kudu/util/easy_json.h" #include "kudu/util/pb_util.h" #include "kudu/util/string_case.h" #include "kudu/util/url-coding.h" @@ -126,24 +127,18 @@ void MasterPathHandlers::HandleTabletServers(const Webserver::WebRequest& req, } void MasterPathHandlers::HandleCatalogManager(const Webserver::WebRequest& req, - ostringstream* output) { + EasyJson* output) { CatalogManager::ScopedLeaderSharedLock l(master_->catalog_manager()); if (!l.first_failed_status().ok()) { - *output << "Master is not ready: " << l.first_failed_status().ToString(); + (*output)["error"] = Substitute("Master is not ready: $0", l.first_failed_status().ToString()); return; } - *output << "

Tables

\n"; - std::vector> tables; master_->catalog_manager()->GetAllTables(&tables); + (*output).Set("num_tables", tables.size()); - *output << Substitute("There are $0 tables\n", tables.size()); - *output << "\n"; - *output << " " << - "\n"; - typedef std::map StringMap; - StringMap ordered_tables; + EasyJson tables_json = output->Set("tables", EasyJson::kArray); for (const scoped_refptr& table : tables) { TableMetadataLock l(table.get(), TableMetadataLock::READ); if (!l.data().is_running()) { @@ -151,19 +146,12 @@ void MasterPathHandlers::HandleCatalogManager(const Webserver::WebRequest& req, } string state = SysTablesEntryPB_State_Name(l.data().pb.state()); Capitalize(&state); - ordered_tables[l.data().name()] = Substitute( - "" - "\n", - EscapeForHtmlToString(l.data().name()), - EscapeForHtmlToString(table->id()), - state, - EscapeForHtmlToString(l.data().pb.state_msg())); + EasyJson table_json = tables_json.PushBack(EasyJson::kObject); + table_json["name"] = EscapeForHtmlToString(l.data().name()); + table_json["id"] = EscapeForHtmlToString(table->id()); + table_json["state"] = state; + table_json["message"] = EscapeForHtmlToString(l.data().pb.state_msg()); } - *output << "\n"; - for (const StringMap::value_type& table : ordered_tables) { - *output << table.second; - } - *output << "
Table NameTable IdStateState Message
$0$1$2$3
\n"; } namespace { @@ -593,7 +581,7 @@ Status MasterPathHandlers::Register(Webserver* server) { "/tablet-servers", "Tablet Servers", boost::bind(&MasterPathHandlers::HandleTabletServers, this, _1, _2), is_styled, is_on_nav_bar); - server->RegisterPrerenderedPathHandler( + server->RegisterPathHandler( "/tables", "Tables", boost::bind(&MasterPathHandlers::HandleCatalogManager, this, _1, _2), is_styled, is_on_nav_bar); http://git-wip-us.apache.org/repos/asf/kudu/blob/9285f2b4/src/kudu/master/master-path-handlers.h ---------------------------------------------------------------------- diff --git a/src/kudu/master/master-path-handlers.h b/src/kudu/master/master-path-handlers.h index 0850edb..73a7a8e 100644 --- a/src/kudu/master/master-path-handlers.h +++ b/src/kudu/master/master-path-handlers.h @@ -23,6 +23,7 @@ #include "kudu/gutil/macros.h" #include "kudu/server/webserver.h" +#include "kudu/util/easy_json.h" namespace kudu { class Schema; @@ -49,7 +50,7 @@ class MasterPathHandlers { void HandleTabletServers(const Webserver::WebRequest& req, std::ostringstream* output); void HandleCatalogManager(const Webserver::WebRequest& req, - std::ostringstream* output); + EasyJson* output); void HandleTablePage(const Webserver::WebRequest& req, std::ostringstream *output); void HandleMasters(const Webserver::WebRequest& req, http://git-wip-us.apache.org/repos/asf/kudu/blob/9285f2b4/www/tables.mustache ---------------------------------------------------------------------- diff --git a/www/tables.mustache b/www/tables.mustache new file mode 100644 index 0000000..6abe133 --- /dev/null +++ b/www/tables.mustache @@ -0,0 +1,43 @@ +{{! +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. +}} +

Tables

+{{#error}} +
{{{.}}}
+{{/error}} +{{^error}} +There are {{num_tables}} tables + + + + + + + + + {{#tables}} + + + + + + + {{/tables}} + +
Table NameTable IdStateState Message
{{name}}{{id}}{{state}}{{message}}
+{{/error}}