Finished the copy table command, added it to the console, and fixed shell usage for copy and create table
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/52ef04c6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/52ef04c6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/52ef04c6 Branch: refs/heads/master Commit: 52ef04c60c02ac92a662f5844c25ff9ecdf7fa37 Parents: dc96edb Author: Chris Rohr <[email protected]> Authored: Sun Aug 24 23:33:09 2014 -0400 Committer: Chris Rohr <[email protected]> Committed: Sun Aug 24 23:33:09 2014 -0400 ---------------------------------------------------------------------- .../blur/console/servlets/TablesServlet.java | 26 +++++----- .../blur/console/util/CachingBlurClient.java | 11 +++++ .../org/apache/blur/console/util/TableUtil.java | 25 ++++++++-- blur-console/src/main/webapp/Gruntfile.js | 6 +-- .../src/main/webapp/js/blurconsole.data.js | 14 ++++++ .../src/main/webapp/js/blurconsole.fake.js | 5 ++ .../src/main/webapp/js/blurconsole.model.js | 19 +++++++- .../src/main/webapp/js/blurconsole.tables.js | 50 +++++++++++++++++--- blur-console/src/main/webapp/public/index.html | 2 +- ...rconsole.79e31ef1502d0a9a2b09a9f003068074.js | 27 +++++++++++ ...rconsole.a8f3746a0720a51832c01a94032c39ec.js | 27 ----------- ...rconsole.c0b013833cf4610ee6480569d8ea841b.js | 27 +++++++++++ ...rconsole.dafc5660ee546fc3f9427794e4e541f5.js | 27 ----------- .../src/main/webapp/public/js/blurconsole.js | 6 +-- ...sole.js.048af85f6ba8bfea2f94f056e1095f81.map | 1 + ...sole.js.435b285e3a48f6da71fd4aa79ce0185c.map | 1 - .../main/webapp/public/js/blurconsole.js.map | 2 +- .../org/apache/blur/shell/CopyTableCommand.java | 13 ++++- .../apache/blur/shell/CreateTableCommand.java | 2 +- 19 files changed, 204 insertions(+), 87 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java ---------------------------------------------------------------------- diff --git a/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java b/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java index 856d6c0..6f3ea1f 100644 --- a/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java +++ b/blur-console/src/main/java/org/apache/blur/console/servlets/TablesServlet.java @@ -40,6 +40,7 @@ public class TablesServlet extends BaseConsoleServlet { private static Pattern tableDisablePattern = Pattern.compile("/(.*)/disable"); private static Pattern tableDeletePattern = Pattern.compile("/(.*)/delete"); private static Pattern tableTermsPattern = Pattern.compile("/(.*)/(.*)/(.*)/terms"); + private static Pattern tableCopyPattern = Pattern.compile("/(.*)/copy"); @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { @@ -57,6 +58,8 @@ public class TablesServlet extends BaseConsoleServlet { disable(req, res, m.group(1)); } else if ((m = tableDeletePattern.matcher(path)).matches()) { delete(req, res, m.group(1), req.getParameter("includeFiles")); + } else if ((m = tableCopyPattern.matcher(path)).matches()) { + copy(req, res, m.group(1), req.getParameter("newName"), req.getParameter("newLocation"), req.getParameter("cluster")); } else { sendNotFound(res, req.getRequestURI()); } @@ -67,8 +70,6 @@ public class TablesServlet extends BaseConsoleServlet { Map<String, List> tableSummaries = new HashMap<String, List>(); try { tableSummaries = TableUtil.getTableSummaries(); - } catch (IOException e) { - throw new IOException(e); } catch (Exception e) { sendError(response, e); return; @@ -81,8 +82,6 @@ public class TablesServlet extends BaseConsoleServlet { Object schema; try { schema = TableUtil.getSchema(table); - } catch (IOException e) { - throw new IOException(e); } catch (Exception e) { sendError(response, e); return; @@ -96,8 +95,6 @@ public class TablesServlet extends BaseConsoleServlet { List<String> terms = new ArrayList<String>(); try { terms = TableUtil.getTerms(table, family, column, startsWith); - } catch (IOException e) { - throw new IOException(e); } catch (Exception e) { sendError(res, e); return; @@ -110,8 +107,6 @@ public class TablesServlet extends BaseConsoleServlet { authorize(request, User.MANAGER_ROLE); try { TableUtil.enableTable(table); - } catch (IOException e) { - throw new IOException(e); } catch (Exception e) { sendError(response, e); return; @@ -123,8 +118,6 @@ public class TablesServlet extends BaseConsoleServlet { authorize(request, User.MANAGER_ROLE); try { TableUtil.disableTable(table); - } catch (IOException e) { - throw new IOException(e); } catch (Exception e) { sendError(response, e); return; @@ -136,8 +129,17 @@ public class TablesServlet extends BaseConsoleServlet { authorize(request, User.MANAGER_ROLE); try { TableUtil.deleteTable(table, Boolean.parseBoolean(includeFiles)); - } catch (IOException e) { - throw new IOException(e); + } catch (Exception e) { + sendError(response, e); + return; + } + sendGenericOk(response); + } + + private void copy(HttpServletRequest request, HttpServletResponse response, String srcTable, String destTable, String destLocation, String cluster) throws IOException { + authorize(request, User.MANAGER_ROLE); + try { + TableUtil.copyTable(srcTable, destTable, destLocation, cluster); } catch (Exception e) { sendError(response, e); return; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/java/org/apache/blur/console/util/CachingBlurClient.java ---------------------------------------------------------------------- diff --git a/blur-console/src/main/java/org/apache/blur/console/util/CachingBlurClient.java b/blur-console/src/main/java/org/apache/blur/console/util/CachingBlurClient.java index c2a9d63..3d1aca6 100644 --- a/blur-console/src/main/java/org/apache/blur/console/util/CachingBlurClient.java +++ b/blur-console/src/main/java/org/apache/blur/console/util/CachingBlurClient.java @@ -20,7 +20,9 @@ package org.apache.blur.console.util; 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.BlurQueryStatus; +import org.apache.blur.thrift.generated.ColumnDefinition; import org.apache.blur.thrift.generated.Schema; import org.apache.blur.thrift.generated.TableDescriptor; import org.apache.blur.thrift.generated.TableStats; @@ -128,6 +130,15 @@ public class CachingBlurClient { invalidateQuery(table, uuid); } + public void createTable(TableDescriptor td) throws TException { + getClient().createTable(td); + cleanup(tableListCache); + } + + public void addColumnDefinition(String table, ColumnDefinition def) throws BlurException, TException { + getClient().addColumnDefinition(table, def); + } + private void invalidateQuery(String table, String uuid) { synchronized (queryListCache) { Item item = queryListCache.get(null); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java ---------------------------------------------------------------------- diff --git a/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java b/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java index 50be7eb..40fd612 100644 --- a/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java +++ b/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java @@ -29,7 +29,7 @@ import java.util.*; public class TableUtil { @SuppressWarnings("rawtypes") - public static Map<String, List> getTableSummaries() throws IOException, TException { + public static Map<String, List> getTableSummaries() throws TException { CachingBlurClient client = Config.getCachingBlurClient(); List<Map<String, Object>> summaries = new ArrayList<Map<String, Object>>(); @@ -70,7 +70,7 @@ public class TableUtil { return data; } - public static Map<String, Map<String, Map<String, Object>>> getSchema(String table) throws IOException, TException { + public static Map<String, Map<String, Map<String, Object>>> getSchema(String table) throws TException { CachingBlurClient client = Config.getCachingBlurClient(); Schema schema = client.schema(table); @@ -92,7 +92,7 @@ public class TableUtil { return schemaInfo; } - public static List<String> getTerms(String table, String family, String column, String startWith) throws IOException, TException { + public static List<String> getTerms(String table, String family, String column, String startWith) throws TException { CachingBlurClient client = Config.getCachingBlurClient(); return client.terms(table, family, column, startWith, (short) 10); @@ -109,4 +109,23 @@ public class TableUtil { public static void deleteTable(String table, boolean includeFiles) throws TException, IOException { Config.getCachingBlurClient().removeTable(table, includeFiles); } + + public static void copyTable(String srcTable, String destTable, String destLocation, String cluster) throws TException { + TableDescriptor td = Config.getCachingBlurClient().describe(srcTable); + + td.setTableUri(destLocation); + td.setCluster(cluster); + td.setName(destTable); + + CachingBlurClient client = Config.getCachingBlurClient(); + client.createTable(td); + + Schema schema = client.schema(srcTable); + + for(Map<String, ColumnDefinition> column : schema.getFamilies().values()) { + for (ColumnDefinition def : column.values()) { + client.addColumnDefinition(destTable, def); + } + } + } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/webapp/Gruntfile.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/Gruntfile.js b/blur-console/src/main/webapp/Gruntfile.js index 5280cb0..bc46261 100644 --- a/blur-console/src/main/webapp/Gruntfile.js +++ b/blur-console/src/main/webapp/Gruntfile.js @@ -84,9 +84,9 @@ module.exports = function (grunt) { sourceMap: true, sourceMapIncludeSources: true, banner:'/*\n<%= banner %>\n*/', - compress: { - drop_console: true - } +// compress: { +// drop_console: true +// } }, files: { 'public/js/blurconsole.js': all_js_files http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/webapp/js/blurconsole.data.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/js/blurconsole.data.js b/blur-console/src/main/webapp/js/blurconsole.data.js index 6b5a7dd..cc3485a 100644 --- a/blur-console/src/main/webapp/js/blurconsole.data.js +++ b/blur-console/src/main/webapp/js/blurconsole.data.js @@ -108,6 +108,19 @@ blurconsole.data = (function() { }); } + function copyTable(srcTable, destTable, destLocation, cluster) { + $.ajax('/service/tables/' + srcTable + '/copy', { + data: { + newName: destTable, + cluster: cluster, + newLocation: destLocation + }, + error: function(xhr) { + _handleError(xhr, 'tables'); + } + }); + } + function sendSearch(query, table, args, callback) { var params = $.extend({table:table, query:query}, args); $.ajax('/service/search', { @@ -131,6 +144,7 @@ blurconsole.data = (function() { deleteTable : deleteTable, getSchema : getSchema, findTerms : findTerms, + copyTable : copyTable, sendSearch : sendSearch }; }()); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/webapp/js/blurconsole.fake.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/js/blurconsole.fake.js b/blur-console/src/main/webapp/js/blurconsole.fake.js index 6c8e11e..f591ec3 100644 --- a/blur-console/src/main/webapp/js/blurconsole.fake.js +++ b/blur-console/src/main/webapp/js/blurconsole.fake.js @@ -211,6 +211,10 @@ blurconsole.fake = (function() { _sendCallback(callback, terms); } + function copyTable(srcTable, destTable, destLocation, cluster) { + console.log('Fake sending request to copy table [' + srcTable + '] to [' + destTable + '] on cluster [' + cluster + '] stored in location [' + destLocation + ']'); + } + function sendSearch(query, table, args, callback) { console.log('sending fake search [' + query + '] on table [' + table + ']'); @@ -286,6 +290,7 @@ blurconsole.fake = (function() { deleteTable : deleteTable, getSchema : getSchema, findTerms : findTerms, + copyTable : copyTable, sendSearch : sendSearch }; }()); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/webapp/js/blurconsole.model.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/js/blurconsole.model.js b/blur-console/src/main/webapp/js/blurconsole.model.js index 7998ac6..0190098 100644 --- a/blur-console/src/main/webapp/js/blurconsole.model.js +++ b/blur-console/src/main/webapp/js/blurconsole.model.js @@ -85,6 +85,17 @@ blurconsole.model = (function() { return tableMap; } + function getTableNamesForCluster(cluster) { + var list = []; + $.each(stateMap.currentTables, function(idx, table) { + if (table.cluster === cluster) { + list.push(table.name); + } + }); + + return list; + } + function isDataLoaded() { return stateMap.currentTables !== null; } @@ -136,6 +147,10 @@ blurconsole.model = (function() { configMap.poller.findTerms(table, family, column, startsWith, callback); } + function copyTable(srcTable, destTable, destLocation, cluster) { + configMap.poller.copyTable(srcTable, destTable, destLocation, cluster); + } + return { getClusters : getClusters, getEnabledTables : getEnabledTables, @@ -147,7 +162,9 @@ blurconsole.model = (function() { getSchema : getSchema, findTerms : findTerms, getAllEnabledTables : getAllEnabledTables, - getFamilies : getFamilies + getFamilies : getFamilies, + copyTable : copyTable, + getTableNamesForCluster : getTableNamesForCluster }; }()); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/webapp/js/blurconsole.tables.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/js/blurconsole.tables.js b/blur-console/src/main/webapp/js/blurconsole.tables.js index ff1a06e..21606bc 100644 --- a/blur-console/src/main/webapp/js/blurconsole.tables.js +++ b/blur-console/src/main/webapp/js/blurconsole.tables.js @@ -18,10 +18,10 @@ specific language governing permissions and limitations under the License. */ -/*global blurconsole:false */ +/*global blurconsole:false, alert:false */ blurconsole.tables = (function () { 'use strict'; - + //------------------------ Configuration and State ---------------------- var configMap = { view : 'views/tables.tpl.html', @@ -35,6 +35,7 @@ blurconsole.tables = (function () { var actions = '', table = row.name; actions += '<a href="#" class="schemaTrigger btn btn-default" data-name="' + table + '"><i class="glyphicon glyphicon-list-alt"></i> Schema</a> '; if(blurconsole.auth.hasRole('manager')) { + actions += '<a href="#" class="copyTrigger btn btn-default" data-name="' + table + '"><i class="glyphicon glyphicon-export"></i> Copy</a> '; actions += '<a href="#" class="disableTrigger btn btn-danger" data-name="' + table + '"><i class="glyphicon glyphicon-cloud-download"></i> Disable</a> '; } return actions; @@ -72,7 +73,7 @@ blurconsole.tables = (function () { setTimeout(_waitForData, 100); } } - + function _registerPageEvents() { // Tab control jqueryMap.$tableInfoHolder.on('click', 'ul.nav a', function(e) { @@ -120,6 +121,43 @@ blurconsole.tables = (function () { }); return false; }); + + // Copy Table + jqueryMap.$tableInfoHolder.on('click', 'a.copyTrigger', function() { + var tableName = $(this).data('name'); + + var modalBody = '<form><div class="form-group"><label for="clusters">Destination Cluster:</label><select id="clusters" class="form-control">'; + $.each(blurconsole.model.tables.getClusters(), function(i, cluster) { + modalBody += '<option value="' + cluster + '">' + cluster + '</option>'; + }); + modalBody += '</select></div><div class="form-group"><label for="newName">New Table Name:</label><input type="text" class="form-control" id="newName"/></div>'; + modalBody += '<div class="form-group"><label for="newName">New Table Location:</label><input type="text" class="form-control" id="newLocation"/></div></form>'; + + var modalContent = blurconsole.browserUtils.modal('copyInfo', 'Where do you want to copy table ' + tableName, modalBody, [ + {classes: 'btn-primary copyTable', label: 'Copy'}, + {classes: 'btn-default cancel', label: 'Cancel', data: {dismiss:'modal'}} + ], 'medium'); + + var modal = $(modalContent).modal().on('shown.bs.modal', function(e) { + $(e.currentTarget).on('click', '.copyTable', function() { + var newTableName = $('#newName').val(); + var newCluster = $('#clusters').val(); + var newLocation = $('#newLocation').val(); + + if (newTableName === '' || newLocation === '') { + alert('New Table Name and New Table Location are required'); + } else if (blurconsole.model.tables.getTableNamesForCluster(newCluster).indexOf(newTableName) >= 0) { + alert('Table ' + newTableName + ' already exists in cluster ' + newCluster); + } else { + blurconsole.model.tables.copyTable(tableName, newTableName, newLocation, newCluster); + modal.modal('hide'); + } + }); + }).on('hidden.bs.modal', function(e) { + $(e.currentTarget).remove(); + }); + return false; + }); } function _unregisterPageEvents() { @@ -127,7 +165,7 @@ blurconsole.tables = (function () { jqueryMap.$tableInfoHolder.off(); } } - + //------------------------- Event Handling and DOM Methods --------------------------- function _buildTabs() { var clusters = blurconsole.model.tables.getClusters(); @@ -178,7 +216,7 @@ blurconsole.tables = (function () { } }); } - + function _updateActivityIndicators() { var clusters = blurconsole.model.tables.getClusters(); @@ -202,7 +240,7 @@ blurconsole.tables = (function () { } }); } - + //-------------------------- Public API ------------------------------ function unloadModule() { $.gevent.unsubscribe(jqueryMap.$container, 'tables-updated'); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/52ef04c6/blur-console/src/main/webapp/public/index.html ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/public/index.html b/blur-console/src/main/webapp/public/index.html index ffd74f4..e4276a1 100644 --- a/blur-console/src/main/webapp/public/index.html +++ b/blur-console/src/main/webapp/public/index.html @@ -64,7 +64,7 @@ under the License. </ul> </nav> <div id="blurconsole"></div> - <script src="js/blurconsole.dafc5660ee546fc3f9427794e4e541f5.js"></script> + <script src="js/blurconsole.79e31ef1502d0a9a2b09a9f003068074.js"></script> <script src="/service/config.js"></script> <script type="text/javascript"> $(function () { blurconsole.initModule( $('#blurconsole') ); });
