You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/02/14 18:51:45 UTC

[GitHub] yzang commented on a change in pull request #1094: BP-27: New BookKeeper CLI

yzang commented on a change in pull request #1094: BP-27: New BookKeeper CLI 
URL: https://github.com/apache/bookkeeper/pull/1094#discussion_r168268922
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/cluster/ListBookiesCommand.java
 ##########
 @@ -0,0 +1,75 @@
+/*
+ * 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.bookkeeper.tools.cli.commands.cluster;
+
+import static org.apache.bookkeeper.common.concurrent.FutureUtils.result;
+import static org.apache.bookkeeper.tools.cli.helpers.CommandHelpers.getBookieSocketAddrStringRepresentation;
+
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.Parameters;
+import com.google.common.collect.Lists;
+import java.util.List;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+import org.apache.bookkeeper.discover.RegistrationClient;
+import org.apache.bookkeeper.net.BookieSocketAddress;
+import org.apache.bookkeeper.tools.cli.helpers.DiscoveryCommand;
+
+/**
+ * Command to list available bookies.
+ */
+@Accessors(fluent = true)
+@Setter
+@Parameters(commandDescription = "List the bookies, which are running as either readwrite or readonly mode.")
+public class ListBookiesCommand extends DiscoveryCommand {
+
+    @Parameter(names = { "-rw", "--readwrite" }, description = "Print readwrite bookies")
+    private boolean readwrite = false;
+    @Parameter(names = { "-ro", "--readonly" }, description = "Print readonly bookies")
+    private boolean readonly = false;
+
+    @Override
+    protected void run(RegistrationClient regClient) throws Exception {
+        List<BookieSocketAddress> bookies = Lists.newArrayList();
+        if (readwrite) {
+            bookies.addAll(
+                result(
+                    regClient.getWritableBookies()
+                ).getValue()
+            );
+        } else if (readonly) {
+            bookies.addAll(
+                result(
+                    regClient.getReadOnlyBookies()
+                ).getValue()
+            );
+        }
 
 Review comment:
   Is there any command to list all bookies and their state? For example, by default, we list all bookies running in the cluster and their running mode if no args is given. If we specify -ro, we only list read only bookies?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services