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 2019/03/13 01:54:16 UTC
[GitHub] [bookkeeper] zymap commented on a change in pull request #1981:
Issue #1980: Migrate command `ledger` from shell to bkctl
zymap commented on a change in pull request #1981: Issue #1980: Migrate command `ledger` from shell to bkctl
URL: https://github.com/apache/bookkeeper/pull/1981#discussion_r264949841
##########
File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/LedgerCommand.java
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.bookie;
+
+import com.beust.jcommander.Parameter;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import java.io.IOException;
+import java.util.function.Function;
+
+import lombok.Setter;
+import lombok.experimental.Accessors;
+import org.apache.bookkeeper.bookie.Bookie;
+import org.apache.bookkeeper.bookie.InterleavedLedgerStorage;
+import org.apache.bookkeeper.bookie.LedgerCache;
+import org.apache.bookkeeper.bookie.LedgerEntryPage;
+import org.apache.bookkeeper.bookie.SortedLedgerStorage;
+import org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.tools.cli.helpers.BookieCommand;
+import org.apache.bookkeeper.tools.framework.CliFlags;
+import org.apache.bookkeeper.tools.framework.CliSpec;
+import org.apache.bookkeeper.util.LedgerIdFormatter;
+import org.apache.commons.lang.mutable.MutableLong;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Command to dump ledger index entries into readable format.
+ */
+public class LedgerCommand extends BookieCommand<LedgerCommand.LedgerFlags> {
+
+ static final Logger LOG = LoggerFactory.getLogger(LedgerCommand.class);
+
+ private static final String NAME = "ledger";
+ private static final String DESC = "Dump ledger index entries into readable format";
+
+ private LedgerIdFormatter ledgerIdFormatter;
+
+ private Function<String, Boolean> print = this::printInfoLine;
+
+ public void setPrint(Function<String, Boolean> print) {
+ this.print = print;
+ }
+
+ public LedgerCommand() {
+ this(new LedgerFlags());
+ }
+
+ public LedgerCommand(LedgerIdFormatter ledgerIdFormatter) {
+ this(new LedgerFlags());
+ this.ledgerIdFormatter = ledgerIdFormatter;
+ }
+
+ private LedgerCommand(LedgerFlags flags) {
+ super(CliSpec.<LedgerFlags>newBuilder().withName(NAME).withDescription(DESC).withFlags(flags).build());
+ }
+
+ /**
+ * Flags for ledger command.
+ */
+ @Accessors(fluent = true)
+ @Setter
+ public static class LedgerFlags extends CliFlags {
+
+ @Parameter(names = { "-id", "--ledgerId" }, description = "Specific ledger id", required = true)
+ private long ledgerId;
+
+ @Parameter(names = { "-m", "--meta" }, description = "Print meta information")
+ private boolean meta;
+
+ @Parameter(names = { "-l", "--ledgeridformatter" }, description = "Set ledger id formatter")
+ private String ledgerIdFormatter = "";
+ }
+
+ @Override
+ public boolean apply(ServerConfiguration conf, LedgerFlags cmdFlags) {
+ initLedgerIdFormatter(conf, cmdFlags);
+ long ledgerId = cmdFlags.ledgerId;
+ if (conf.getLedgerStorageClass().equals(DbLedgerStorage.class.getName())) {
+ // dump ledger info
+ if (!dumpLedgerInfo(ledgerId, conf)) {
+ return false;
+ }
+ } else if (conf.getLedgerStorageClass().equals(SortedLedgerStorage.class.getName()) || conf
Review comment:
That 's because style check. :) I will fix it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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