zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umamah...@apache.org
Subject svn commit: r1450005 - in /zookeeper/bookkeeper/trunk: ./ bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ bookkeeper-server/src/main/java/org/apache/bookkeeper/client/
Date Tue, 26 Feb 2013 03:12:24 GMT
Author: umamahesh
Date: Tue Feb 26 03:12:24 2013
New Revision: 1450005

URL: http://svn.apache.org/r1450005
Log:
BOOKKEEPER-574: Extend the bookkeeper shell to get a list of available bookies. Contributed
by Ivan Kelly


Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookieWatcher.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1450005&r1=1450004&r2=1450005&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Tue Feb 26 03:12:24 2013
@@ -37,6 +37,8 @@ Trunk (unreleased changes)
 
       BOOKKEEPER-556: BookieServerMXBean#getServerState makes no sense (ivank via sijie)
 
+      BOOKKEEPER-574: Extend the bookkeeper shell to get a list of available bookies (ivank
via umamahesh)
+
 Release 4.2.0 - 2013-01-14
 
   Non-backward compatible changes:

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java?rev=1450005&r1=1450004&r2=1450005&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
Tue Feb 26 03:12:24 2013
@@ -42,6 +42,7 @@ import org.apache.bookkeeper.conf.Server
 import org.apache.bookkeeper.util.EntryFormatter;
 import org.apache.bookkeeper.util.Tool;
 import org.apache.bookkeeper.util.ZkUtils;
+import org.apache.bookkeeper.util.StringUtils;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.CompositeConfiguration;
@@ -73,6 +74,7 @@ public class BookieShell implements Tool
     static final String CMD_READJOURNAL = "readjournal";
     static final String CMD_LASTMARK = "lastmark";
     static final String CMD_AUTORECOVERY = "autorecovery";
+    static final String CMD_LISTBOOKIES = "listbookies";
     static final String CMD_HELP = "help";
 
     final ServerConfiguration bkConf = new ServerConfiguration();
@@ -474,6 +476,55 @@ public class BookieShell implements Tool
     }
 
     /**
+     * List available bookies
+     */
+    class ListBookiesCmd extends MyCommand {
+        Options opts = new Options();
+
+        ListBookiesCmd() {
+            super(CMD_LISTBOOKIES);
+            opts.addOption("h", "hostnames", false, "Also print hostnames");
+        }
+
+        @Override
+        public int runCmd(CommandLine cmdLine) throws Exception {
+            ClientConfiguration clientconf = new ClientConfiguration(bkConf)
+                .setZkServers(bkConf.getZkServers());
+            BookKeeperAdmin bka = new BookKeeperAdmin(clientconf);
+
+            int count = 0;
+            for (InetSocketAddress b : bka.getAvailableBookies()) {
+                System.out.print(StringUtils.addrToString(b));
+                if (cmdLine.hasOption("h")) {
+                    System.out.print("\t" + b.getHostName());
+                }
+                System.out.println("");
+                count++;
+            }
+            if (count == 0) {
+                System.err.println("No bookies available");
+                return 1;
+            }
+            return 0;
+        }
+
+        @Override
+        String getDescription() {
+            return "List all available bookies.";
+        }
+
+        @Override
+        String getUsage() {
+            return "listbookies [-hostnames]";
+        }
+
+        @Override
+        Options getOptions() {
+            return opts;
+        }
+    }
+
+    /**
      * Command to print help message
      */
     class HelpCmd implements Command {
@@ -583,6 +634,7 @@ public class BookieShell implements Tool
         commands.put(CMD_READJOURNAL, new ReadJournalCmd());
         commands.put(CMD_LASTMARK, new LastMarkCmd());
         commands.put(CMD_AUTORECOVERY, new AutoRecoveryCmd());
+        commands.put(CMD_LISTBOOKIES, new ListBookiesCmd());
         commands.put(CMD_HELP, new HelpCmd());
     }
 
@@ -592,7 +644,7 @@ public class BookieShell implements Tool
         journalDirectory = Bookie.getCurrentDirectory(bkConf.getJournalDir());
         ledgerDirectories = Bookie.getCurrentDirectories(bkConf.getLedgerDirs());
         formatter = EntryFormatter.newEntryFormatter(bkConf, ENTRY_FORMATTER_CLASS);
-        LOG.info("Using entry formatter " + formatter.getClass().getName());
+        LOG.debug("Using entry formatter {}", formatter.getClass().getName());
         pageSize = bkConf.getPageSize();
         entriesPerPage = pageSize / 8;
     }
@@ -607,6 +659,7 @@ public class BookieShell implements Tool
         System.err.println("       readlog      [-msg] <entry_log_id|entry_log_file_name>");
         System.err.println("       readjournal  [-msg] <journal_id|journal_file_name>");
         System.err.println("       autorecovery [-enable|-disable]");
+        System.err.println("       listbookies  [-hostnames]");
         System.err.println("       lastmark");
         System.err.println("       help");
     }

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java?rev=1450005&r1=1450004&r2=1450005&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
Tue Feb 26 03:12:24 2013
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Random;
 import java.util.UUID;
+import java.util.Collection;
 
 import org.apache.bookkeeper.client.AsyncCallback.OpenCallback;
 import org.apache.bookkeeper.client.AsyncCallback.RecoverCallback;
@@ -154,6 +155,17 @@ public class BookKeeperAdmin {
     }
 
     /**
+     * Get a list of the available bookies.
+     *
+     * @return the collection of available bookies
+     */
+    public Collection<InetSocketAddress> getAvailableBookies()
+            throws InterruptedException, KeeperException {
+        bkc.bookieWatcher.readBookiesBlocking();
+        return bkc.bookieWatcher.getBookies();
+    }
+
+    /**
      * Open a ledger as an administrator. This means that no digest password
      * checks are done. Otherwise, the call is identical to BookKeeper#asyncOpenLedger
      *

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookieWatcher.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookieWatcher.java?rev=1450005&r1=1450004&r2=1450005&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookieWatcher.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookieWatcher.java
Tue Feb 26 03:12:24 2013
@@ -21,6 +21,7 @@ package org.apache.bookkeeper.client;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -84,6 +85,10 @@ class BookieWatcher implements Watcher, 
         readOnlyBookieWatcher = new ReadOnlyBookieWatcher(conf, bk);
     }
 
+    public synchronized Collection<InetSocketAddress> getBookies() {
+        return new HashSet<InetSocketAddress>(knownBookies);
+    }
+
     public void readBookies() {
         readBookies(this);
     }



Mime
View raw message