incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Adding a truncate command to the shell.
Date Wed, 19 Jun 2013 20:19:31 GMT
Updated Branches:
  refs/heads/master 2ee0c17ed -> 6dd9aa3f7


Adding a truncate command to the shell.


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

Branch: refs/heads/master
Commit: 6dd9aa3f729c45c9dacd98822961f9722d15c0ae
Parents: 2ee0c17
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Wed Jun 19 16:19:09 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Wed Jun 19 16:19:09 2013 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/blur/shell/Main.java   | 11 ++--
 .../apache/blur/shell/TruncateTableCommand.java | 59 ++++++++++++++++++++
 2 files changed, 65 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6dd9aa3f/blur-shell/src/main/java/org/apache/blur/shell/Main.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Main.java b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
index 8598f10..fb7be21 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/Main.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
@@ -99,7 +99,7 @@ public class Main {
     }
 
   }
-  
+
   private static class HighlightCommand extends Command {
 
     @Override
@@ -130,8 +130,8 @@ public class Main {
 
       int bufferLength = getMaxCommandLength(cmds.keySet()) + 2;
       out.println(" - Table commands - ");
-      String[] tableCommands = { "create", "enable", "disable", "remove", "describe", "list",
"schema", "stats",
-          "layout" };
+      String[] tableCommands = { "create", "enable", "disable", "remove", "truncate", "describe",
"list", "schema",
+          "stats", "layout" };
       printCommandAndHelp(out, cmds, tableCommands, bufferLength);
 
       out.println();
@@ -234,13 +234,14 @@ public class Main {
     builder.put("layout", new ShardServerLayoutCommand());
     builder.put("controllers", new ControllersEchoCommand());
     builder.put("shards", new ShardsEchoCommand());
+    builder.put("truncate", new TruncateTableCommand());
     commands = builder.build();
 
     try {
       ConsoleReader reader = new ConsoleReader();
-      
+
       setConsoleReader(commands, reader);
-      
+
       reader.setPrompt("blur> ");
 
       String controllerConnectionString = null;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6dd9aa3f/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java
new file mode 100644
index 0000000..9490314
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/TruncateTableCommand.java
@@ -0,0 +1,59 @@
+/**
+ * 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.
+ */
+
+package org.apache.blur.shell;
+
+import java.io.PrintWriter;
+import java.util.List;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.Blur;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.TableDescriptor;
+
+public class TruncateTableCommand extends Command {
+  @Override
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
+    if (args.length != 2) {
+      throw new CommandException("Invalid args: " + help());
+    }
+    String tablename = args[1];
+    List<String> tableList = client.tableList();
+    if (tableList.contains(tablename)) {
+      out.println("Table does not exist.");
+    }
+    TableDescriptor tableDescriptor = client.describe(tablename);
+    if (tableDescriptor.isIsEnabled()) {
+      out.println("Disabling table.");
+      out.flush();
+      client.disableTable(tablename);
+    }
+    out.println("Removing table.");
+    out.flush();
+    client.removeTable(tablename, true);
+    out.println("Creating table.");
+    out.flush();
+    client.createTable(tableDescriptor);
+  }
+
+  @Override
+  public String help() {
+    return "truncate the named table, args; tablename";
+  }
+}


Mime
View raw message