Started the tables tab, not finished

Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/518d0ac7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/518d0ac7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/518d0ac7

Branch: refs/heads/blur-console-v2
Commit: 518d0ac71112b8b4dcc19b18141b79a1dcb1b4bf
Parents: 7ee35f9
Author: Chris Rohr <[email protected]>
Authored: Wed Nov 6 21:02:43 2013 -0500
Committer: Chris Rohr <[email protected]>
Committed: Wed Nov 6 21:02:43 2013 -0500

----------------------------------------------------------------------
 .../org/apache/blur/console/JettyServer.java    |  2 +
 .../blur/console/servlets/TablesServlet.java    | 98 ++++++++++++++++++++
 .../org/apache/blur/console/util/TableUtil.java | 45 +++++++++
 .../org/apache/blur/console/webapp/js/tables.js | 31 +++++++
 .../console/webapp/partials/tables.tpl.html     | 51 ++++++++++
 5 files changed, 227 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/518d0ac7/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
----------------------------------------------------------------------
diff --git 
a/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java 
b/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
index 1a103b8..c265a35 100644
--- 
a/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
+++ 
b/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
@@ -20,6 +20,7 @@ package org.apache.blur.console;
 import java.net.URL;
 
 import org.apache.blur.console.servlets.DashboardServlet;
+import org.apache.blur.console.servlets.TablesServlet;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.mortbay.jetty.Server;
@@ -63,6 +64,7 @@ public class JettyServer {
            // for localhost:port/service/dashboard, etc.
            final Context context = new Context(server, "/service", 
Context.SESSIONS);
            context.addServlet(new ServletHolder(new DashboardServlet()), 
"/dashboard/*");
+           context.addServlet(new ServletHolder(new TablesServlet()), 
"/tables/*");
              
            try {
                        server.start();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/518d0ac7/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java
----------------------------------------------------------------------
diff --git 
a/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java
 
b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java
new file mode 100644
index 0000000..7f27f1f
--- /dev/null
+++ 
b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java
@@ -0,0 +1,98 @@
+package org.apache.blur.console.servlets;
+
+/**
+ * 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.
+ */
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.blur.console.util.HttpUtil;
+import org.apache.blur.console.util.NodeUtil;
+import org.apache.blur.console.util.QueryUtil;
+import org.apache.blur.console.util.TableUtil;
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.commons.io.IOUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+
+public class TablesServlet extends HttpServlet {
+       private static final long serialVersionUID = -5725846390100596115L;
+       private static Pattern tableTermsPattern = 
Pattern.compile("/(.*)/(.*)/terms");
+
+       @Override
+       protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+               String path = request.getPathInfo();
+               Matcher m;
+               if ("/summaries".equalsIgnoreCase(path)) {
+                       sendSummaries(response);
+               } else if ((m = tableTermsPattern.matcher(path)).matches()) {
+//                     sendTerms(response, m.group(1), m.group(2));
+               } 
+//             else if ("/query/status".equalsIgnoreCase(path)) {
+//                     sendQueryStatus(response);
+//             } 
+               else {
+                       response.setStatus(404);
+                       IOUtils.write("Route [" + path + "] doesn't exist", 
response.getOutputStream());
+               }
+       }
+       
+       private void sendError(HttpServletResponse response, Exception e) 
throws IOException {
+               String body = e.getMessage();
+               response.setContentType("application/json");
+               response.setContentLength(body.getBytes().length);
+               response.setStatus(500);
+               IOUtils.write(body, response.getOutputStream());
+       }
+       
+       private void sendSummaries(HttpServletResponse response) throws 
IOException {
+               Map<String, Object> tableSummaries = new HashMap<String, 
Object>();
+               try {
+                       tableSummaries = TableUtil.getTableSummaries();
+               } catch (IOException e) {
+                       throw new IOException(e);
+               } catch (Exception e) {
+                       sendError(response, e);
+                       return;
+               }
+               
+               HttpUtil.sendResponse(response, new 
ObjectMapper().writeValueAsString(tableSummaries), HttpUtil.JSON);
+       }
+       
+//     private void sendTerms(HttpServletResponse response, String cluster, 
String table) {
+//             Map<String, List<Map<String, Object>>> tableSummaries = new 
HashMap<String, List<Map<String,Object>>>();
+//             try {
+//                     tableSummaries = TableUtil.getTableSummaries();
+//             } catch (IOException e) {
+//                     throw new IOException(e);
+//             } catch (Exception e) {
+//                     sendError(response, e);
+//                     return;
+//             }
+//             
+//             HttpUtil.sendResponse(response, new 
ObjectMapper().writeValueAsString(tableSummaries), HttpUtil.JSON);
+//     }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/518d0ac7/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java
----------------------------------------------------------------------
diff --git 
a/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java
 
b/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java
index 2e65ed5..2c7acce 100644
--- 
a/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java
+++ 
b/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java
@@ -27,6 +27,8 @@ import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.BlurClient;
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.TableDescriptor;
+import org.apache.blur.thrift.generated.TableStats;
 
 public class TableUtil {
        public static Map<String, Object> getTableStatus() throws IOException, 
BlurException, TException {
@@ -102,4 +104,47 @@ public class TableUtil {
                
                return data;
        }
+       
+       public static Map<String, Object> getTableSummaries() throws 
IOException, BlurException, TException {
+               Iface client = 
BlurClient.getClient(Config.getConnectionString());
+               
+               Map<String, List<Map<String, Object>>> tablesByCluster = new 
HashMap<String, List<Map<String,Object>>>();
+               
+               List<String> clusters = client.shardClusterList();
+               
+               for (String cluster : clusters) {
+                       List<String> tables = 
client.tableListByCluster(cluster);
+                       List<Map<String, Object>> tableList = new 
ArrayList<Map<String,Object>>();
+                       for (String table : tables) {
+                               Map<String, Object> tableInfo = new 
HashMap<String, Object>();
+                               
+                               TableDescriptor descriptor = 
client.describe(table);
+                               TableStats stats = client.tableStats(table);
+                               
+                               tableInfo.put("name", table);
+                               tableInfo.put("enabled", 
descriptor.isEnabled());
+                               
+                               if (descriptor.isEnabled()) {
+                                       tableInfo.put("rowCount", 
stats.getRowCount());
+                                       tableInfo.put("recordCount", 
stats.getRecordCount());
+                               }
+                               
+                               tableList.add(tableInfo);
+                       }
+                       tablesByCluster.put(cluster, tableList);
+               }
+               
+               Map<String, Object> data = new HashMap<String, Object>();
+               
+               data.put("clusters", clusters);
+               data.put("tables", tablesByCluster);
+               
+               return data;
+       }
+       
+//     public static Object getTerms(String cluster, String table) throws 
IOException {
+//             Iface client = 
BlurClient.getClient(Config.getConnectionString());
+//             
+//             client.terms(arg0, arg1, arg2, arg3, arg4)
+//     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/518d0ac7/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/tables.js
----------------------------------------------------------------------
diff --git 
a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/tables.js
 
b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/tables.js
new file mode 100644
index 0000000..e1451d4
--- /dev/null
+++ 
b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/tables.js
@@ -0,0 +1,31 @@
+/**
+ * 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.
+ */
+ 
+blurApp.controller('TableCtrl', function($scope, $http, $timeout) {
+       $scope.summaryData = {};
+       $scope.testMsg = 'This message';
+
+       (function table_summary_tick() {
+        $http.get('/service/tables/summaries').success(function (data) {
+            $scope.summaryData = data;
+            $timeout(table_summary_tick, 30000);
+        }).error(function(){
+            console.log("Unable to update tables");
+            $timeout(table_summary_tick, 30000);
+        });
+    })();
+})
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/518d0ac7/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/partials/tables.tpl.html
----------------------------------------------------------------------
diff --git 
a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/partials/tables.tpl.html
 
b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/partials/tables.tpl.html
new file mode 100644
index 0000000..ed42964
--- /dev/null
+++ 
b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/partials/tables.tpl.html
@@ -0,0 +1,51 @@
+<!--
+
+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.
+
+-->
+
+<div ng-controller="TableCtrl">
+       <div ng-if="summaryData.clusters.length == 0">
+               <div class="alert alert-warning">No clusters found</div>
+       </div>
+       <div ng-if="summaryData.clusters.length > 0">
+               <tabset>
+            <tab ng-repeat="cluster in summaryData.clusters" 
heading="{{cluster}}">
+               <table class="table table-hover table-striped table-bordered 
table-condensed">
+                                       <thead>
+                                               <tr>
+                                                       <th>Name</th>
+                                                       <th>Row Count</th>
+                                                       <th>Record Count</th>
+                                                       <th>Info</th>
+                                                       <th>Actions</th>
+                                               </tr>
+                                       </thead>
+                                       <tbody>
+                                               <tr ng-repeat="table in 
summaryData.tables[cluster]">
+                                                       <td>{{table.name}}</td>
+                                                       
<td>{{table.rowCount}}</td>
+                                                       
<td>{{table.recordCount</td>
+                                                       <td></td>
+                                                       <td></td>
+                                               </tr>
+                                       </tbody>
+                               </table>
+            </tab>
+               </tabset>
+       </div>
+</div>
\ No newline at end of file

Reply via email to