You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by zh...@apache.org on 2019/04/17 06:32:29 UTC
[bookkeeper] branch master updated: Migrate command `triggeraudit`
This is an automated email from the ASF dual-hosted git repository.
zhaijia 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 6f33968 Migrate command `triggeraudit`
6f33968 is described below
commit 6f33968019c3452cefc2d78e0258bb3206d78e8a
Author: Yong Zhang <zh...@gmail.com>
AuthorDate: Wed Apr 17 14:32:24 2019 +0800
Migrate command `triggeraudit`
Descriptions of the changes in this PR:
- Using `bkctl` run command `triggeraudit`
### Motivation
#2011
Reviewers: Sijie Guo <si...@apache.org>, Jia Zhai <zh...@apache.org>
This closes #2012 from zymap/command-triggeraudit and squashes the following commits:
5a4b496ec [Yong Zhang] Fix conflict ---
236b7d6e5 [Yong Zhang] Fix validation
b039b637e [Yong Zhang] Rename file
8bea52522 [Yong Zhang] Remove unused imports
d39d1e886 [Yong Zhang] Migrate command `triggeraudit`
60d993edf [Yong Zhang] Migrate command `autorecovery`
ed008f278 [Yong Zhang] Migrate command `whoisauditor`
5b8e0971a [Yong Zhang] Migrate command `Whatisinstanceid`
90c79444d [Yong Zhang] Migrate command `rebuild-db-ledger-locations-index`
848f8527f [Nicolas Michael] ISSUE #2053: Bugfix for Percentile Calculation in FastCodahale Timer Implementation
06f2b6f50 [Yong Zhang] Migrate command `updateledgers`
7ad5849b1 [Yong Zhang] Migrate command `regenerate-interleaved-storage-index-file`
d4dbb6bfb [Dongfa,Huang] Avoid useless verify if LedgerEntryRequest completed
5c150f283 [Enrico Olivelli] Release notes for 4.9.1
1246826ba [Yong Zhang] Migrate command `recover`
1d4cc71fd [Yong Zhang] Migrate command `localconsistencycheck`
67f83620e [Yong Zhang] Migrate command `readledger`
bfbd6b023 [Yong Zhang] Migrate command `decommission`
d40b8b69f [Yong Zhang] Migrate command `readlog`
95d145a15 [Yong Zhang] Migrate command `nukeexistingcluster`
e2b1dc7f3 [Yong Zhang] Migrate command `listunderreplicated`
0988e12c7 [bd2019us] ISSUE #2023: change cached thread pool to fixed thread pool
6a6d7bbd9 [Yong Zhang] Migrate command `initnewcluster`
c391fe58d [Yong Zhang] Migrate command `readlogmetadata`
120d67737 [Yong Zhang] Migrate command `lostbookierecoverydelay`
bf66235e5 [Yong Zhang] Migrate command `deleteledger`
751e55fa4 [Arvin] ISSUE #2020: close db properly to avoid open RocksDB failure at the second time
138a7ae85 [Yong Zhang] Migrate command `metadataformat`
b043d1694 [Yong Zhang] Migrate command `listledgers`
4573285db [Ivan Kelly] Docker autobuild hook
e3d807a32 [Like] Fix IDE complain as there are multi choices for error code
9524a9f4a [Yong Zhang] Migrate command `readjournal`
6c3f33f55 [Yong Zhang] Fix when met unexpect entry id crashed
e35a108c7 [Like] Fix error message for unrecognized number-of-bookies
5902ee27b [Boyang Jerry Peng] fix potential NPE when releasing entry that is null
6aa73ce05 [Ivan Kelly] [RELEASE] Update website to include documentation for 4.8.2
1448d12aa [Yong Zhang] Migrate command `listfilesondisk`
4de598379 [Yong Zhang] Issue #1987: Migrate command `convert-to-interleaved-storage`
468743e7e [Matteo Merli] In DbLedgerStorage use default values when config key is present but empty
f26a4cae0 [Ivan Kelly] Release notes for v4.8.2
ec2636cd2 [Yong Zhang] Issue #1985: Migrate command `convert-to-db-storage`
8cc7239ac [Yong Zhang] Issue #1982: Migrate command `bookiesanity`
fa90f0185 [Yong Zhang] Issue #1980: Migrate command `ledger` from shell to bkctl
---
.../org/apache/bookkeeper/bookie/BookieShell.java | 14 +---
.../commands/autorecovery/TriggerAuditCommand.java | 68 ++++++++++++++++++
.../cli/commands/autorecovery/package-info.java | 19 ++---
.../cli/commands/AutoRecoveryCommandGroup.java | 7 ++
.../autorecovery/TriggerAuditCommandTest.java | 81 ++++++++++++++++++++++
5 files changed, 166 insertions(+), 23 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 eff70ed..700ce11 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
@@ -47,11 +47,9 @@ import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.bookkeeper.bookie.BookieException.CookieNotFoundException;
import org.apache.bookkeeper.bookie.BookieException.InvalidCookieException;
-import org.apache.bookkeeper.client.BookKeeperAdmin;
import org.apache.bookkeeper.client.LedgerEntry;
import org.apache.bookkeeper.client.api.LedgerMetadata;
import org.apache.bookkeeper.common.annotation.InterfaceAudience.Private;
-import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.conf.ServerConfiguration;
import org.apache.bookkeeper.meta.LedgerManager;
import org.apache.bookkeeper.meta.LedgerMetadataSerDe;
@@ -59,6 +57,7 @@ import org.apache.bookkeeper.net.BookieSocketAddress;
import org.apache.bookkeeper.tools.cli.commands.autorecovery.ListUnderReplicatedCommand;
import org.apache.bookkeeper.tools.cli.commands.autorecovery.LostBookieRecoveryDelayCommand;
import org.apache.bookkeeper.tools.cli.commands.autorecovery.ToggleCommand;
+import org.apache.bookkeeper.tools.cli.commands.autorecovery.TriggerAuditCommand;
import org.apache.bookkeeper.tools.cli.commands.autorecovery.WhoIsAuditorCommand;
import org.apache.bookkeeper.tools.cli.commands.bookie.ConvertToDBStorageCommand;
import org.apache.bookkeeper.tools.cli.commands.bookie.ConvertToInterleavedStorageCommand;
@@ -1861,15 +1860,8 @@ public class BookieShell implements Tool {
@Override
public int runCmd(CommandLine cmdLine) throws Exception {
- ClientConfiguration adminConf = new ClientConfiguration(bkConf);
- BookKeeperAdmin admin = new BookKeeperAdmin(adminConf);
- try {
- admin.triggerAudit();
- } finally {
- if (admin != null) {
- admin.close();
- }
- }
+ TriggerAuditCommand cmd = new TriggerAuditCommand();
+ cmd.apply(bkConf, new CliFlags());
return 0;
}
}
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/TriggerAuditCommand.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/TriggerAuditCommand.java
new file mode 100644
index 0000000..c645a5c
--- /dev/null
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/TriggerAuditCommand.java
@@ -0,0 +1,68 @@
+/*
+ * 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.autorecovery;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+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;
+
+/**
+ * Command to trigger AuditTask by resetting lostBookieRecoveryDelay to its current value.
+ */
+public class TriggerAuditCommand extends BookieCommand<CliFlags> {
+
+ private static final String NAME = "triggeraudit";
+ private static final String DESC = "Force trigger the Audit by resetting the lostBookieRecoveryDelay.";
+
+ public TriggerAuditCommand() {
+ super(CliSpec.newBuilder()
+ .withName(NAME)
+ .withDescription(DESC)
+ .withFlags(new CliFlags())
+ .build());
+ }
+
+ @Override
+ public boolean apply(ServerConfiguration conf, CliFlags cmdFlags) {
+ try {
+ return handler(conf);
+ } catch (Exception e) {
+ throw new UncheckedExecutionException(e.getMessage(), e);
+ }
+ }
+
+ public boolean handler(ServerConfiguration configuration) throws Exception {
+ ClientConfiguration adminConf = new ClientConfiguration(configuration);
+ BookKeeperAdmin admin = new BookKeeperAdmin(adminConf);
+
+ try {
+ admin.triggerAudit();
+ } finally {
+ if (admin != null) {
+ admin.close();
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/package-info.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/package-info.java
index 9294bf9..acfe982 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/package-info.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/package-info.java
@@ -1,4 +1,4 @@
-/*
+/**
* 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
@@ -7,17 +7,12 @@
* "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
+ * 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.
- */
-
-/**
- * This package provides all autorecovery commands.
+ * 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.autorecovery;
\ No newline at end of file
diff --git a/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/AutoRecoveryCommandGroup.java b/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/AutoRecoveryCommandGroup.java
index aa4d7f4..7cc88ea 100644
--- a/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/AutoRecoveryCommandGroup.java
+++ b/tools/ledger/src/main/java/org/apache/bookkeeper/tools/cli/commands/AutoRecoveryCommandGroup.java
@@ -20,7 +20,10 @@ package org.apache.bookkeeper.tools.cli.commands;
import static org.apache.bookkeeper.tools.common.BKCommandCategories.CATEGORY_INFRA_SERVICE;
+import org.apache.bookkeeper.tools.cli.commands.autorecovery.ListUnderReplicatedCommand;
+import org.apache.bookkeeper.tools.cli.commands.autorecovery.LostBookieRecoveryDelayCommand;
import org.apache.bookkeeper.tools.cli.commands.autorecovery.ToggleCommand;
+import org.apache.bookkeeper.tools.cli.commands.autorecovery.TriggerAuditCommand;
import org.apache.bookkeeper.tools.cli.commands.autorecovery.WhoIsAuditorCommand;
import org.apache.bookkeeper.tools.common.BKFlags;
import org.apache.bookkeeper.tools.framework.CliCommandGroup;
@@ -39,7 +42,11 @@ public class AutoRecoveryCommandGroup extends CliCommandGroup<BKFlags> {
.withDescription(DESC)
.withCategory(CATEGORY_INFRA_SERVICE)
.addCommand(new WhoIsAuditorCommand())
+ .addCommand(new TriggerAuditCommand())
.addCommand(new ToggleCommand())
+ .addCommand(new TriggerAuditCommand())
+ .addCommand(new ListUnderReplicatedCommand())
+ .addCommand(new LostBookieRecoveryDelayCommand())
.build();
public AutoRecoveryCommandGroup() {
diff --git a/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/TriggerAuditCommandTest.java b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/TriggerAuditCommandTest.java
new file mode 100644
index 0000000..b60eaf6
--- /dev/null
+++ b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/TriggerAuditCommandTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.autorecovery;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.doNothing;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.verifyNew;
+
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.conf.AbstractConfiguration;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+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 TriggerAuditCommand}.
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TriggerAuditCommand.class})
+public class TriggerAuditCommandTest extends BookieCommandTestBase {
+
+ private ClientConfiguration clientConfiguration;
+ private BookKeeperAdmin admin;
+
+ public TriggerAuditCommandTest() {
+ super(3, 0);
+ }
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+
+ PowerMockito.whenNew(ServerConfiguration.class).withNoArguments().thenReturn(conf);
+
+ clientConfiguration = mock(ClientConfiguration.class);
+ PowerMockito.whenNew(ClientConfiguration.class).withParameterTypes(AbstractConfiguration.class)
+ .withArguments(eq(conf)).thenReturn(clientConfiguration);
+
+ admin = mock(BookKeeperAdmin.class);
+ PowerMockito.whenNew(BookKeeperAdmin.class).withParameterTypes(ClientConfiguration.class)
+ .withArguments(eq(clientConfiguration)).thenReturn(admin);
+
+ doNothing().when(admin).triggerAudit();
+ }
+
+ @Test
+ public void testCommand() throws Exception {
+ TriggerAuditCommand cmd = new TriggerAuditCommand();
+ Assert.assertTrue(cmd.apply(bkFlags, new String[] { "" }));
+
+ verifyNew(ClientConfiguration.class, times(1)).withArguments(conf);
+ verifyNew(BookKeeperAdmin.class, times(1)).withArguments(clientConfiguration);
+
+ verify(admin, times(1)).triggerAudit();
+ }
+}