kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danburk...@apache.org
Subject [2/2] kudu git commit: Switch tables page to template
Date Wed, 26 Jul 2017 19:08:15 GMT
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 <danburkert@apache.org>
Tested-by: Dan Burkert <danburkert@apache.org>


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 <samuel.okrent@cloudera.com>
Authored: Tue Jul 25 14:28:58 2017 -0700
Committer: Dan Burkert <danburkert@apache.org>
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 << "<h1>Tables</h1>\n";
-
   std::vector<scoped_refptr<TableInfo>> tables;
   master_->catalog_manager()->GetAllTables(&tables);
+  (*output).Set<int64_t>("num_tables", tables.size());
 
-  *output << Substitute("There are $0 tables\n", tables.size());
-  *output << "<table class='table table-striped'>\n";
-  *output << "  <thead><tr><th>Table Name</th><th>Table
Id</th>" <<
-      "<th>State</th><th>State Message</th></tr></thead>\n";
-  typedef std::map<string, string> StringMap;
-  StringMap ordered_tables;
+  EasyJson tables_json = output->Set("tables", EasyJson::kArray);
   for (const scoped_refptr<TableInfo>& 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(
-        "<tr><th>$0</th><td><a href=\"/table?id=$1\">$1</a></td>"
-            "<td>$2</td><td>$3</td></tr>\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 << "<tbody>\n";
-  for (const StringMap::value_type& table : ordered_tables) {
-    *output << table.second;
-  }
-  *output << "</tbody></table>\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.
+}}
+<h1>Tables</h1>
+{{#error}}
+  <div class="text-error">{{{.}}}</div>
+{{/error}}
+{{^error}}
+There are {{num_tables}} tables
+<table class="table table-striped">
+  <thead><tr>
+    <th>Table Name</th>
+    <th>Table Id</th>
+    <th>State</th>
+    <th>State Message</th>
+  </tr></thead>
+  <tbody>
+   {{#tables}}
+    <tr>
+      <th>{{name}}</th>
+      <td><a href="/table?id={{id}}">{{id}}</a></td>
+      <td>{{state}}</td>
+      <td>{{message}}</td>
+    </tr>
+   {{/tables}}
+  </tbody>
+</table>
+{{/error}}


Mime
View raw message