use of org.apache.bookkeeper.tools.framework.CliFlags in project bookkeeper by apache.
the class InfoCommand method apply.
@Override
public boolean apply(ServerConfiguration conf, CliFlags cmdFlags) {
ClientConfiguration clientConf = new ClientConfiguration(conf);
clientConf.setDiskWeightBasedPlacementEnabled(true);
try (BookKeeper bk = new BookKeeper(clientConf)) {
Map<BookieId, BookieInfo> map = bk.getBookieInfo();
if (map.size() == 0) {
LOG.info("Failed to retrieve bookie information from any of the bookies");
bk.close();
return true;
}
LOG.info("Free disk space info:");
long totalFree = 0, total = 0;
for (Map.Entry<BookieId, BookieInfo> e : map.entrySet()) {
BookieInfo bInfo = e.getValue();
BookieId bookieId = e.getKey();
LOG.info("{}: \tFree: {}\tTotal: {}", CommandHelpers.getBookieSocketAddrStringRepresentation(bookieId, bk.getBookieAddressResolver()), bInfo.getFreeDiskSpace() + getReadable(bInfo.getFreeDiskSpace()), bInfo.getTotalDiskSpace() + getReadable(bInfo.getTotalDiskSpace()));
}
// group by hostname
Map<String, BookieInfo> dedupedMap = map.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().toString(), entry -> entry.getValue(), (key1, key2) -> key2));
for (BookieInfo bookieInfo : dedupedMap.values()) {
totalFree += bookieInfo.getFreeDiskSpace();
total += bookieInfo.getTotalDiskSpace();
}
LOG.info("Total free disk space in the cluster:\t{}", totalFree + getReadable(totalFree));
LOG.info("Total disk capacity in the cluster:\t{}", total + getReadable(total));
bk.close();
return true;
} catch (IOException | InterruptedException | BKException e) {
e.printStackTrace();
}
return true;
}
use of org.apache.bookkeeper.tools.framework.CliFlags in project bookkeeper by apache.
the class BookieShellCommandTest method testShellCommand.
@SuppressWarnings("unchecked")
@Test
public void testShellCommand() throws Exception {
BKCommand<CliFlags> command = mock(BKCommand.class);
String shellCommandName = "test-shell-command";
CompositeConfiguration conf = new CompositeConfiguration();
BookieShellCommand<CliFlags> shellCommand = new BookieShellCommand<>(shellCommandName, command, conf);
// test `description`
assertEquals(shellCommandName + " [options]", shellCommand.description());
// test `printUsage`
shellCommand.printUsage();
verify(command, times(1)).usage();
// test `runCmd`
String[] args = new String[] { "arg-1", "arg-2" };
shellCommand.runCmd(args);
verify(command, times(1)).apply(same(shellCommandName), same(conf), same(args));
}
use of org.apache.bookkeeper.tools.framework.CliFlags in project bookkeeper by apache.
the class ClientCommandTest method testRun.
@Test
public void testRun() throws Exception {
CliFlags flags = new CliFlags();
assertTrue(cmd.apply(serverConf, flags));
verify(cmd, times(1)).run(eq(bk), same(flags));
verify(bkBuilder, times(1)).build();
}
use of org.apache.bookkeeper.tools.framework.CliFlags in project bookkeeper by apache.
the class DiscoveryCommandTest method testRun.
@Test
public void testRun() throws Exception {
try (final MockedStatic<Executors> executorsMockedStatic = Mockito.mockStatic(Executors.class);
final MockedStatic<MetadataDrivers> mdriversMockedStatic = Mockito.mockStatic(MetadataDrivers.class)) {
executorsMockedStatic.when(() -> Executors.newSingleThreadScheduledExecutor()).thenReturn(executor);
mdriversMockedStatic.when(() -> MetadataDrivers.getClientDriver(any(URI.class))).thenReturn(clientDriver);
CliFlags cliFlags = new CliFlags();
assertTrue(cmd.apply(serverConf, cliFlags));
verify(cmd, times(1)).run(eq(regClient), same(cliFlags));
verify(clientDriver, times(1)).initialize(any(ClientConfiguration.class), eq(executor), eq(NullStatsLogger.INSTANCE), eq(Optional.empty()));
verify(clientDriver, times(1)).getRegistrationClient();
verify(clientDriver, times(1)).close();
verify(executor, times(1)).shutdown();
}
}
Aggregations