incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r833997 - /incubator/hama/trunk/src/test/org/apache/hama/Utils.java
Date Mon, 09 Nov 2009 08:48:50 GMT
Author: edwardyoon
Date: Mon Nov  9 08:48:48 2009
New Revision: 833997

URL: http://svn.apache.org/viewvc?rev=833997&view=rev
Log:
Add simple admin tool for manage the temporary tables.

Added:
    incubator/hama/trunk/src/test/org/apache/hama/Utils.java

Added: incubator/hama/trunk/src/test/org/apache/hama/Utils.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/Utils.java?rev=833997&view=auto
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/Utils.java (added)
+++ incubator/hama/trunk/src/test/org/apache/hama/Utils.java Mon Nov  9 08:48:48 2009
@@ -0,0 +1,52 @@
+package org.apache.hama;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+
+public class Utils {
+  private static HBaseConfiguration conf = new HBaseConfiguration();
+  private static HBaseAdmin admin;
+
+  public static void main(String[] args) throws Exception {
+    if (args.length < 1) {
+      System.out.println("Usage: org.apache.hama.Utils [list|delete-all]");
+      System.out.println(" - list : listing the tables, related with Hama");
+      System.out.println(" - delete-all : deleting the tables, related with Hama");
+      System.exit(-1);
+    }
+    admin = new HBaseAdmin(conf);
+
+    HTableDescriptor[] tables = admin.listTables();
+    for (int i = 0; i < tables.length; i++) {
+      if (isHamaTables(tables[i].getNameAsString())) {
+        if (args[0].equals("list")) {
+          System.out.println(tables[i].getNameAsString());
+        } else if (args[0].equals("delete-all")) {
+          deleteTable(tables[i]);
+        }
+      }
+    }
+  }
+
+  private static void deleteTable(HTableDescriptor tableDescriptor)
+      throws IOException {
+    byte[] tableName = tableDescriptor.getName();
+    while (admin.isTableEnabled(tableName)) {
+      admin.disableTable(tableName);
+    }
+
+    admin.deleteTable(tableName);
+  }
+
+  private static boolean isHamaTables(String name) {
+    if (name.equals(Constants.ADMINTABLE)
+        || name.startsWith("DenseMatrix_rand")
+        || name.startsWith("SparseMatrix_rand"))
+      return true;
+
+    return false;
+  }
+}



Mime
View raw message