bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jujj...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-983: BookieShell LedgerDelete Command
Date Wed, 21 Dec 2016 00:42:52 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 548634733 -> 9a506c261


BOOKKEEPER-983: BookieShell LedgerDelete Command

BookieShell Command for LedgerDelete

Author: Charan Reddy Guttapalem <cguttapalem@salesforce.com>

Reviewers: Sijie Guo <sijie@apache.org>

Closes #90 from reddycharan/ledgerdeletecommand


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/9a506c26
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/9a506c26
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/9a506c26

Branch: refs/heads/master
Commit: 9a506c261d3702ddd3f39556f4331b91da952a6e
Parents: 5486347
Author: Charan Reddy Guttapalem <cguttapalem@salesforce.com>
Authored: Tue Dec 20 16:42:33 2016 -0800
Committer: JV <vjujjuri@salesforce.com>
Committed: Tue Dec 20 16:42:33 2016 -0800

----------------------------------------------------------------------
 .../apache/bookkeeper/bookie/BookieShell.java   | 75 +++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/9a506c26/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
index 7d63b62..678788e 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
@@ -58,6 +58,7 @@ import org.apache.bookkeeper.net.BookieSocketAddress;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
 import org.apache.bookkeeper.replication.AuditorElector;
 import org.apache.bookkeeper.util.EntryFormatter;
+import org.apache.bookkeeper.util.IOUtils;
 import org.apache.bookkeeper.util.MathUtils;
 import org.apache.bookkeeper.util.Tool;
 import org.apache.bookkeeper.versioning.Version;
@@ -111,6 +112,7 @@ public class BookieShell implements Tool {
     static final String CMD_UPDATECOOKIE = "updatecookie";
     static final String CMD_EXPANDSTORAGE = "expandstorage";
     static final String CMD_UPDATELEDGER = "updateledgers";
+    static final String CMD_DELETELEDGER = "deleteledger";
     static final String CMD_HELP = "help";
 
     final ServerConfiguration bkConf = new ServerConfiguration();
@@ -1554,6 +1556,75 @@ public class BookieShell implements Tool {
     }
 
     /**
+     * Command to delete a given ledger.
+     */
+    class DeleteLedgerCmd extends MyCommand {
+        Options lOpts = new Options();
+
+        DeleteLedgerCmd() {
+            super(CMD_DELETELEDGER);
+            lOpts.addOption("l", "ledgerid", true, "Ledger ID");
+            lOpts.addOption("f", "force", false, "Whether to force delete the Ledger without
prompt..?");
+        }
+
+        @Override
+        public int runCmd(CommandLine cmdLine) throws Exception {
+            final String lidStr = cmdLine.getOptionValue("ledgerid");
+            if (StringUtils.isBlank(lidStr)) {
+                LOG.error("Invalid argument list!");
+                this.printUsage();
+                return -1;
+            }
+
+            final long lid;
+            try {
+                lid = Long.parseLong(lidStr);
+            } catch (NumberFormatException nfe) {
+                System.err.println("ERROR: invalid ledger id " + lidStr);
+                printUsage();
+                return -1;
+            }
+
+            boolean force = cmdLine.hasOption("f");
+            boolean confirm = false;
+            if (!force) {
+                confirm = IOUtils.confirmPrompt("Are you sure to delete Ledger : " + lid
+ "?");
+            }
+
+            BookKeeper bk = null;
+            try {
+                if (force || confirm) {
+                    ClientConfiguration conf = new ClientConfiguration();
+                    conf.addConfiguration(bkConf);
+                    bk = new BookKeeper(conf);
+                    bk.deleteLedger(lid);
+                }
+            } finally {
+                if (bk != null) {
+                    bk.close();
+                }
+            }
+
+            return 0;
+        }
+
+        @Override
+        String getDescription() {
+            return "Delete a ledger";
+        }
+
+        @Override
+        String getUsage() {
+            return "deleteledger -ledgerid <ledgerid> [-force]";
+        }
+
+        @Override
+        Options getOptions() {
+            return lOpts;
+        }
+    }
+
+    /**
      * A facility for reporting update ledger progress.
      */
     public interface UpdateLedgerNotifier {
@@ -1581,6 +1652,7 @@ public class BookieShell implements Tool {
         commands.put(CMD_UPDATECOOKIE, new UpdateCookieCmd());
         commands.put(CMD_EXPANDSTORAGE, new ExpandStorageCmd());
         commands.put(CMD_UPDATELEDGER, new UpdateLedgerCmd());
+        commands.put(CMD_DELETELEDGER, new DeleteLedgerCmd());
         commands.put(CMD_HELP, new HelpCmd());
     }
 
@@ -1601,7 +1673,8 @@ public class BookieShell implements Tool {
     }
 
     private void printShellUsage() {
-        System.err.println("Usage: BookieShell [-conf configuration] <command>");
+        System.err.println(
+                "Usage: BookieShell [-conf configuration] <command>");
         System.err.println();
         List<String> commandNames = new ArrayList<String>();
         for (MyCommand c : commands.values()) {


Mime
View raw message