Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bin/bookkeeper-cli → bin/bkctl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BK_HOME=`cd ${BINDIR}/..;pwd`
source ${BK_HOME}/bin/common.sh
source ${BK_HOME}/conf/bk_cli_env.sh

CLI_MODULE_PATH=bookkeeper-tools
CLI_MODULE_PATH=tools/all
CLI_MODULE_NAME="(org.apache.bookkeeper-)?bookkeeper-tools"
CLI_MODULE_HOME=${BK_HOME}/${CLI_MODULE_PATH}

Expand All @@ -46,21 +46,21 @@ if [ -z "${CLI_LOG_CONF}" ]; then
CLI_LOG_CONF=${DEFAULT_LOG_CONF}
fi
CLI_LOG_DIR=${CLI_LOG_DIR:-"$BK_HOME/logs"}
CLI_LOG_FILE=${CLI_LOG_FILE:-"bookkeeper-cli.log"}
CLI_ROOT_LOGGER=${CLI_ROOT_LOGGER:-"INFO,CONSOLE"}
CLI_LOG_FILE=${CLI_LOG_FILE:-"bkctl.log"}
CLI_ROOT_LOGGER=${CLI_ROOT_LOGGER:-"INFO,ROLLINGFILE"}

# Configure the classpath
CLI_CLASSPATH="$CLI_JAR:$CLI_CLASSPATH:$CLI_EXTRA_CLASSPATH"
CLI_CLASSPATH="`dirname $CLI_LOG_CONF`:$CLI_CLASSPATH"

# Build the OPTs
BOOKIE_OPTS=$(build_bookie_opts)
GC_OPTS=$(build_cli_jvm_opts ${CLI_LOG_DIR} "bookkeeper-cli-gc.log")
GC_OPTS=$(build_cli_jvm_opts ${CLI_LOG_DIR} "bkctl-gc.log")
NETTY_OPTS=$(build_netty_opts)
LOGGING_OPTS=$(build_logging_opts ${CLI_LOG_CONF} ${CLI_LOG_DIR} ${CLI_LOG_FILE} ${CLI_ROOT_LOGGER})
LOGGING_OPTS=$(build_cli_logging_opts ${CLI_LOG_CONF} ${CLI_LOG_DIR} ${CLI_LOG_FILE} ${CLI_ROOT_LOGGER})

OPTS="${OPTS} -cp ${CLI_CLASSPATH} ${BOOKIE_OPTS} ${GC_OPTS} ${NETTY_OPTS} ${LOGGING_OPTS} ${CLI_EXTRA_OPTS}"

#Change to BK_HOME to support relative paths
cd "$BK_HOME"
exec ${JAVA} ${OPTS} org.apache.bookkeeper.tools.cli.BookKeeperCLI --conf ${CLI_CONF} $@
exec ${JAVA} ${OPTS} org.apache.bookkeeper.tools.cli.BKCtl --conf ${CLI_CONF} $@
5 changes: 5 additions & 0 deletions bookkeeper-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<artifactId>bookkeeper-proto</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-tools-framework</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@
import org.apache.bookkeeper.replication.ReplicationException.UnavailableException;
import org.apache.bookkeeper.stats.NullStatsLogger;
import org.apache.bookkeeper.tools.cli.commands.bookie.LastMarkCommand;
import org.apache.bookkeeper.tools.cli.commands.bookies.ListBookiesCommand;
import org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand;
import org.apache.bookkeeper.tools.cli.commands.cluster.ListBookiesCommand;
import org.apache.bookkeeper.tools.framework.CliFlags;
import org.apache.bookkeeper.util.BookKeeperConstants;
import org.apache.bookkeeper.util.DiskChecker;
import org.apache.bookkeeper.util.EntryFormatter;
Expand Down Expand Up @@ -1128,13 +1129,15 @@ public int runCmd(CommandLine cmdLine) throws Exception {
int ackQuorum = getOptionIntValue(cmdLine, "ackQuorum", 2);
int numEntries = getOptionIntValue(cmdLine, "numEntries", 1000);

SimpleTestCommand command = new SimpleTestCommand()
SimpleTestCommand.Flags flags = new SimpleTestCommand.Flags()
.ensembleSize(ensemble)
.writeQuorumSize(writeQuorum)
.ackQuorumSize(ackQuorum)
.numEntries(numEntries);

command.run(bkConf);
SimpleTestCommand command = new SimpleTestCommand(flags);

command.apply(bkConf, flags);
return 0;
}

Expand Down Expand Up @@ -1482,7 +1485,7 @@ class LastMarkCmd extends MyCommand {
@Override
public int runCmd(CommandLine c) throws Exception {
LastMarkCommand command = new LastMarkCommand();
command.run(bkConf);
command.apply(bkConf, new CliFlags());
return 0;
}

Expand Down Expand Up @@ -1527,10 +1530,13 @@ public int runCmd(CommandLine cmdLine) throws Exception {
return 1;
}

ListBookiesCommand command = new ListBookiesCommand()
ListBookiesCommand.Flags flags = new ListBookiesCommand.Flags()
.readwrite(readwrite)
.readonly(readonly);
command.run(bkConf);

ListBookiesCommand command = new ListBookiesCommand(flags);

command.apply(bkConf, flags);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,35 @@
*/
package org.apache.bookkeeper.tools.cli.commands.bookie;

import com.beust.jcommander.Parameters;

import java.io.File;

import org.apache.bookkeeper.bookie.Journal;
import org.apache.bookkeeper.bookie.LedgerDirsManager;
import org.apache.bookkeeper.bookie.LogMark;
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.DiskChecker;

/**
* A bookie command to print the last log marker.
*/
@Parameters(commandDescription = "Print last log marker")
public class LastMarkCommand extends BookieCommand {
public class LastMarkCommand extends BookieCommand<CliFlags> {

@Override
public String name() {
return "lastmark";
private static final String NAME = "lastmark";
private static final String DESC = "Print last log marker";

public LastMarkCommand() {
super(CliSpec.newBuilder()
.withName(NAME)
.withFlags(new CliFlags())
.withDescription(DESC)
.build());
}

@Override
public void run(ServerConfiguration conf) throws Exception {
public boolean apply(ServerConfiguration conf, CliFlags flags) {
LedgerDirsManager dirsManager = new LedgerDirsManager(
conf, conf.getJournalDirs(),
new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
Expand All @@ -54,5 +59,6 @@ public void run(ServerConfiguration conf) throws Exception {
+ Long.toHexString(lastLogMark.getLogFileId()) + ".txn), Pos - "
+ lastLogMark.getLogFileOffset());
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,67 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bookkeeper.tools.cli.commands.cluster;
package org.apache.bookkeeper.tools.cli.commands.bookies;

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 java.util.Collection;
import java.util.Set;
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.commands.bookies.ListBookiesCommand.Flags;
import org.apache.bookkeeper.tools.cli.helpers.DiscoveryCommand;
import org.apache.bookkeeper.tools.framework.CliFlags;
import org.apache.bookkeeper.tools.framework.CliSpec;

/**
* 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 {
public class ListBookiesCommand extends DiscoveryCommand<Flags> {

@Parameter(names = { "-rw", "--readwrite" }, description = "Print readwrite bookies")
private boolean readwrite = false;
@Parameter(names = { "-ro", "--readonly" }, description = "Print readonly bookies")
private boolean readonly = false;
private static final String NAME = "list";
private static final String DESC = "List the bookies, which are running as either readwrite or readonly mode.";

public ListBookiesCommand() {
this(new Flags());
}

public ListBookiesCommand(Flags flags) {
super(CliSpec.<Flags>newBuilder()
.withName(NAME)
.withDescription(DESC)
.withFlags(flags)
.build());
}

/**
* Flags for list bookies command.
*/
@Accessors(fluent = true)
@Setter
public static class Flags extends CliFlags {

@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 {
if (!readwrite && !readonly) {
protected void run(RegistrationClient regClient, Flags flags) throws Exception {
if (!flags.readwrite && !flags.readonly) {
// case: no args is provided. list all the bookies by default.
readwrite = true;
readonly = true;
flags.readwrite = true;
flags.readonly = true;
}

boolean hasBookies = false;
if (readwrite) {
if (flags.readwrite) {
Set<BookieSocketAddress> bookies = result(
regClient.getWritableBookies()
).getValue();
Expand All @@ -63,7 +86,7 @@ protected void run(RegistrationClient regClient) throws Exception {
hasBookies = true;
}
}
if (readonly) {
if (flags.readonly) {
Set<BookieSocketAddress> bookies = result(
regClient.getReadOnlyBookies()
).getValue();
Expand All @@ -84,8 +107,4 @@ private static void printBookies(Collection<BookieSocketAddress> bookies) {
}
}

@Override
public String name() {
return "listbookies";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*/

/**
* Commands on operating a cluster.
* Commands on operating a cluster of bookies.
*/
package org.apache.bookkeeper.tools.cli.commands.cluster;
package org.apache.bookkeeper.tools.cli.commands.bookies;
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,77 @@
import static org.apache.bookkeeper.common.concurrent.FutureUtils.result;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import java.util.concurrent.TimeUnit;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.bookkeeper.client.api.BookKeeper;
import org.apache.bookkeeper.client.api.DigestType;
import org.apache.bookkeeper.client.api.WriteHandle;
import org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand.Flags;
import org.apache.bookkeeper.tools.cli.helpers.ClientCommand;
import org.apache.bookkeeper.tools.framework.CliFlags;
import org.apache.bookkeeper.tools.framework.CliSpec;

/**
* A client command that simply tests if a cluster is healthy.
*/
@Accessors(fluent = true)
@Setter
@Parameters(commandDescription = "Simple test to create a ledger and write entries to it.")
public class SimpleTestCommand extends ClientCommand {
public class SimpleTestCommand extends ClientCommand<Flags> {

@Parameter(names = { "-e", "--ensemble-size" }, description = "Ensemble size (default 3)")
private int ensembleSize = 3;
@Parameter(names = { "-w", "--write-quorum-size" }, description = "Write quorum size (default 2)")
private int writeQuorumSize = 2;
@Parameter(names = { "-a", "--ack-quorum-size" }, description = "Ack quorum size (default 2)")
private int ackQuorumSize = 2;
@Parameter(names = { "-n", "--num-entries" }, description = "Entries to write (default 100)")
private int numEntries = 100;
private static final String NAME = "simpletest";
private static final String DESC = "Simple test to create a ledger and write entries to it.";

@Override
public String name() {
return "simpletest";
/**
* Flags for simple test command.
*/
@Accessors(fluent = true)
@Setter
public static class Flags extends CliFlags {

@Parameter(names = { "-e", "--ensemble-size" }, description = "Ensemble size (default 3)")
private int ensembleSize = 3;
@Parameter(names = { "-w", "--write-quorum-size" }, description = "Write quorum size (default 2)")
private int writeQuorumSize = 2;
@Parameter(names = { "-a", "--ack-quorum-size" }, description = "Ack quorum size (default 2)")
private int ackQuorumSize = 2;
@Parameter(names = { "-n", "--num-entries" }, description = "Entries to write (default 100)")
private int numEntries = 100;

}
public SimpleTestCommand() {
this(new Flags());
}

public SimpleTestCommand(Flags flags) {
super(CliSpec.<Flags>newBuilder()
.withName(NAME)
.withDescription(DESC)
.withFlags(flags)
.build());
}

@Override
protected void run(BookKeeper bk) throws Exception {
protected void run(BookKeeper bk, Flags flags) throws Exception {
byte[] data = new byte[100]; // test data

try (WriteHandle wh = result(bk.newCreateLedgerOp()
.withEnsembleSize(ensembleSize)
.withWriteQuorumSize(writeQuorumSize)
.withAckQuorumSize(ackQuorumSize)
.withEnsembleSize(flags.ensembleSize)
.withWriteQuorumSize(flags.writeQuorumSize)
.withAckQuorumSize(flags.ackQuorumSize)
.withDigestType(DigestType.CRC32C)
.withPassword(new byte[0])
.execute())) {

System.out.println("Ledger ID: " + wh.getId());
long lastReport = System.nanoTime();
for (int i = 0; i < numEntries; i++) {
for (int i = 0; i < flags.numEntries; i++) {
wh.append(data);
if (TimeUnit.SECONDS.convert(System.nanoTime() - lastReport,
TimeUnit.NANOSECONDS) > 1) {
System.out.println(i + " entries written");
lastReport = System.nanoTime();
}
}
System.out.println(numEntries + " entries written to ledger " + wh.getId());
System.out.println(flags.numEntries + " entries written to ledger " + wh.getId());
}
}
}
Loading