Search in sources :

Example 1 with CliFlags

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;
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) CommandHelpers(org.apache.bookkeeper.tools.cli.helpers.CommandHelpers) BookieCommand(org.apache.bookkeeper.tools.cli.helpers.BookieCommand) Logger(org.slf4j.Logger) DecimalFormat(java.text.DecimalFormat) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) BookieInfo(org.apache.bookkeeper.client.BookieInfoReader.BookieInfo) CliSpec(org.apache.bookkeeper.tools.framework.CliSpec) BookKeeper(org.apache.bookkeeper.client.BookKeeper) CliFlags(org.apache.bookkeeper.tools.framework.CliFlags) Collectors(java.util.stream.Collectors) BKException(org.apache.bookkeeper.client.BKException) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) Map(java.util.Map) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) BookieId(org.apache.bookkeeper.net.BookieId) RoundingMode(java.math.RoundingMode) BookieInfo(org.apache.bookkeeper.client.BookieInfoReader.BookieInfo) BookKeeper(org.apache.bookkeeper.client.BookKeeper) IOException(java.io.IOException) BKException(org.apache.bookkeeper.client.BKException) Map(java.util.Map) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration)

Example 2 with CliFlags

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));
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) CliFlags(org.apache.bookkeeper.tools.framework.CliFlags) Test(org.junit.Test)

Example 3 with CliFlags

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();
}
Also used : CliFlags(org.apache.bookkeeper.tools.framework.CliFlags) Test(org.junit.Test)

Example 4 with CliFlags

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();
    }
}
Also used : MetadataDrivers(org.apache.bookkeeper.meta.MetadataDrivers) Executors(java.util.concurrent.Executors) URI(java.net.URI) CliFlags(org.apache.bookkeeper.tools.framework.CliFlags) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Aggregations

CliFlags (org.apache.bookkeeper.tools.framework.CliFlags)4 Test (org.junit.Test)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)2 IOException (java.io.IOException)1 RoundingMode (java.math.RoundingMode)1 URI (java.net.URI)1 DecimalFormat (java.text.DecimalFormat)1 Map (java.util.Map)1 Executors (java.util.concurrent.Executors)1 Collectors (java.util.stream.Collectors)1 BKException (org.apache.bookkeeper.client.BKException)1 BookKeeper (org.apache.bookkeeper.client.BookKeeper)1 BookieInfo (org.apache.bookkeeper.client.BookieInfoReader.BookieInfo)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 MetadataDrivers (org.apache.bookkeeper.meta.MetadataDrivers)1 BookieId (org.apache.bookkeeper.net.BookieId)1 BookieCommand (org.apache.bookkeeper.tools.cli.helpers.BookieCommand)1 CommandHelpers (org.apache.bookkeeper.tools.cli.helpers.CommandHelpers)1 CliSpec (org.apache.bookkeeper.tools.framework.CliSpec)1 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)1