You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2019/04/01 16:18:47 UTC
[bookkeeper] branch master updated: Migrate command `metadataformat`
This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 138a7ae Migrate command `metadataformat`
138a7ae is described below
commit 138a7ae8569fa36b70e03ba61c57104d6ab94f18
Author: Yong Zhang <zh...@gmail.com>
AuthorDate: Tue Apr 2 00:18:42 2019 +0800
Migrate command `metadataformat`
Descriptions of the changes in this PR:
#2031
Reviewers: Sijie Guo <si...@apache.org>
This closes #2032 from zymap/command-metaformat
---
.../org/apache/bookkeeper/bookie/BookieShell.java | 8 ++-
.../cli/commands/bookies/MetaFormatCommand.java | 74 ++++++++++++++++++++++
.../tools/cli/commands/BookiesCommandGroup.java | 2 +
.../commands/bookies/MetaFormatCommandTest.java | 60 ++++++++++++++++++
4 files changed, 142 insertions(+), 2 deletions(-)
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 9746356..487a5a3 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
@@ -111,6 +111,7 @@ import org.apache.bookkeeper.tools.cli.commands.bookie.ReadJournalCommand;
import org.apache.bookkeeper.tools.cli.commands.bookie.SanityTestCommand;
import org.apache.bookkeeper.tools.cli.commands.bookies.InfoCommand;
import org.apache.bookkeeper.tools.cli.commands.bookies.ListBookiesCommand;
+import org.apache.bookkeeper.tools.cli.commands.bookies.MetaFormatCommand;
import org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand;
import org.apache.bookkeeper.tools.cli.commands.cookie.CreateCookieCommand;
import org.apache.bookkeeper.tools.cli.commands.cookie.DeleteCookieCommand;
@@ -318,8 +319,11 @@ public class BookieShell implements Tool {
boolean interactive = (!cmdLine.hasOption("n"));
boolean force = cmdLine.hasOption("f");
- boolean result = BookKeeperAdmin.format(bkConf, interactive, force);
- return (result) ? 0 : 1;
+ MetaFormatCommand cmd = new MetaFormatCommand();
+ MetaFormatCommand.MetaFormatFlags flags = new MetaFormatCommand.MetaFormatFlags()
+ .interactive(interactive).force(force);
+ boolean result = cmd.apply(bkConf, flags);
+ return result ? 0 : 1;
}
}
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookies/MetaFormatCommand.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookies/MetaFormatCommand.java
new file mode 100644
index 0000000..8ec247b
--- /dev/null
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookies/MetaFormatCommand.java
@@ -0,0 +1,74 @@
+/*
+ * 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.bookies;
+
+import com.beust.jcommander.Parameter;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+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;
+
+/**
+ * Format the bookkeeper metadata present in zookeeper.
+ */
+public class MetaFormatCommand extends BookieCommand<MetaFormatCommand.MetaFormatFlags> {
+
+ private static final String NAME = "metaformat";
+ private static final String DESC = "Format bookkeeper metadata in zookeeper.";
+
+ public MetaFormatCommand() {
+ this(new MetaFormatFlags());
+ }
+
+ private MetaFormatCommand(MetaFormatFlags flags) {
+ super(CliSpec.<MetaFormatCommand.MetaFormatFlags>newBuilder()
+ .withName(NAME)
+ .withDescription(DESC)
+ .withFlags(flags)
+ .build());
+ }
+
+ /**
+ * Flags for command meta format.
+ */
+ @Accessors(fluent = true)
+ @Setter
+ public static class MetaFormatFlags extends CliFlags {
+
+ @Parameter(names = { "-n", "nonInteractive" }, description = "Whether to confirm old data exists..?")
+ private boolean interactive;
+
+ @Parameter(names = {"-f", "--force"},
+ description = "If [nonInteractive] is specified, then whether to force delete the old data without prompt.")
+ private boolean force;
+ }
+
+ @Override
+ public boolean apply(ServerConfiguration conf, MetaFormatFlags flags) {
+ try {
+ return BookKeeperAdmin.format(conf, flags.interactive, flags.force);
+ } catch (Exception e) {
+ throw new UncheckedExecutionException(e.getMessage(), e);
+ }
+ }
+}
diff --git a/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/BookiesCommandGroup.java b/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/BookiesCommandGroup.java
index b299b5c..a9e6fbb 100644
--- a/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/BookiesCommandGroup.java
+++ b/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/BookiesCommandGroup.java
@@ -23,6 +23,7 @@ import static org.apache.bookkeeper.tools.common.BKCommandCategories.CATEGORY_IN
import org.apache.bookkeeper.tools.cli.BKCtl;
import org.apache.bookkeeper.tools.cli.commands.bookies.InfoCommand;
import org.apache.bookkeeper.tools.cli.commands.bookies.ListBookiesCommand;
+import org.apache.bookkeeper.tools.cli.commands.bookies.MetaFormatCommand;
import org.apache.bookkeeper.tools.common.BKFlags;
import org.apache.bookkeeper.tools.framework.CliCommandGroup;
import org.apache.bookkeeper.tools.framework.CliSpec;
@@ -42,6 +43,7 @@ public class BookiesCommandGroup extends CliCommandGroup<BKFlags> {
.withCategory(CATEGORY_INFRA_SERVICE)
.addCommand(new ListBookiesCommand())
.addCommand(new InfoCommand())
+ .addCommand(new MetaFormatCommand())
.build();
public BookiesCommandGroup() {
diff --git a/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/bookies/MetaFormatCommandTest.java b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/bookies/MetaFormatCommandTest.java
new file mode 100644
index 0000000..f8075d6
--- /dev/null
+++ b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/bookies/MetaFormatCommandTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.bookies;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.tools.cli.helpers.BookieCommandTestBase;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ * Unit test for {@link MetaFormatCommand}.
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ MetaFormatCommand.class, BookKeeperAdmin.class })
+public class MetaFormatCommandTest extends BookieCommandTestBase {
+
+ public MetaFormatCommandTest() {
+ super(3, 0);
+ }
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+
+ PowerMockito.mockStatic(BookKeeperAdmin.class);
+ PowerMockito.when(BookKeeperAdmin.class, "format", any(ServerConfiguration.class), anyBoolean(), anyBoolean())
+ .thenReturn(true);
+
+ }
+
+ @Test
+ public void testCommand() {
+ MetaFormatCommand cmd = new MetaFormatCommand();
+ Assert.assertTrue(cmd.apply(bkFlags, new String[] { "" }));
+ }
+}