Search in sources :

Example 1 with LifecycleComponentStack

use of org.apache.bookkeeper.common.component.LifecycleComponentStack in project bookkeeper by apache.

the class TestMain method testBuildBookieServer.

@Test
public void testBuildBookieServer() throws Exception {
    ServerConfiguration serverConf = new ServerConfiguration().setAutoRecoveryDaemonEnabled(false).setHttpServerEnabled(false).setExtraServerComponents(new String[] { TestComponent.class.getName() });
    BookieConfiguration conf = new BookieConfiguration(serverConf);
    BookieServer mockServer = PowerMockito.mock(BookieServer.class);
    whenNew(BookieServer.class).withArguments(any(ServerConfiguration.class), any(StatsLogger.class)).thenReturn(mockServer);
    LifecycleComponentStack stack = buildBookieServer(conf);
    assertEquals(3, stack.getNumComponents());
    assertTrue(stack.getComponent(2) instanceof TestComponent);
    stack.start();
    verify(mockServer, times(1)).start();
    stack.stop();
    stack.close();
    verify(mockServer, times(1)).shutdown();
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) Main.buildBookieServer(org.apache.bookkeeper.server.Main.buildBookieServer) LifecycleComponentStack(org.apache.bookkeeper.common.component.LifecycleComponentStack) BookieConfiguration(org.apache.bookkeeper.server.conf.BookieConfiguration) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with LifecycleComponentStack

use of org.apache.bookkeeper.common.component.LifecycleComponentStack in project bookkeeper by apache.

the class Main method buildBookieServer.

/**
 * Build the bookie server.
 *
 * <p>The sequence of the components is:
 *
 * <pre>
 * - stats provider
 * - bookie server
 * - autorecovery daemon
 * - http service
 * </pre>
 *
 * @param conf bookie server configuration
 * @return lifecycle stack
 */
static LifecycleComponentStack buildBookieServer(BookieConfiguration conf) throws Exception {
    LifecycleComponentStack.Builder serverBuilder = LifecycleComponentStack.newBuilder().withName("bookie-server");
    // 1. build stats provider
    StatsProviderService statsProviderService = new StatsProviderService(conf);
    StatsLogger rootStatsLogger = statsProviderService.getStatsProvider().getStatsLogger("");
    serverBuilder.addComponent(statsProviderService);
    log.info("Load lifecycle component : {}", StatsProviderService.class.getName());
    // 2. build bookie server
    BookieService bookieService = new BookieService(conf, rootStatsLogger);
    serverBuilder.addComponent(bookieService);
    log.info("Load lifecycle component : {}", BookieService.class.getName());
    // 3. build auto recovery
    if (conf.getServerConf().isAutoRecoveryDaemonEnabled()) {
        AutoRecoveryService autoRecoveryService = new AutoRecoveryService(conf, rootStatsLogger.scope(REPLICATION_SCOPE));
        serverBuilder.addComponent(autoRecoveryService);
        log.info("Load lifecycle component : {}", AutoRecoveryService.class.getName());
    }
    // 4. build http service
    if (conf.getServerConf().isHttpServerEnabled()) {
        BKHttpServiceProvider provider = new BKHttpServiceProvider.Builder().setBookieServer(bookieService.getServer()).setServerConfiguration(conf.getServerConf()).build();
        HttpService httpService = new HttpService(provider, conf, rootStatsLogger);
        serverBuilder.addComponent(httpService);
        log.info("Load lifecycle component : {}", HttpService.class.getName());
    }
    // 5. build extra services
    String[] extraComponents = conf.getServerConf().getExtraServerComponents();
    if (null != extraComponents) {
        List<ServerLifecycleComponent> components = loadServerComponents(extraComponents, conf, rootStatsLogger);
        for (ServerLifecycleComponent component : components) {
            serverBuilder.addComponent(component);
            log.info("Load lifecycle component : {}", component.getClass().getName());
        }
    }
    return serverBuilder.build();
}
Also used : StatsLogger(org.apache.bookkeeper.stats.StatsLogger) BKHttpServiceProvider(org.apache.bookkeeper.server.http.BKHttpServiceProvider) HttpService(org.apache.bookkeeper.server.service.HttpService) ServerLifecycleComponent(org.apache.bookkeeper.server.component.ServerLifecycleComponent) AutoRecoveryService(org.apache.bookkeeper.server.service.AutoRecoveryService) LifecycleComponentStack(org.apache.bookkeeper.common.component.LifecycleComponentStack) StatsProviderService(org.apache.bookkeeper.server.service.StatsProviderService) BookieService(org.apache.bookkeeper.server.service.BookieService)

Aggregations

LifecycleComponentStack (org.apache.bookkeeper.common.component.LifecycleComponentStack)2 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 BookieServer (org.apache.bookkeeper.proto.BookieServer)1 Main.buildBookieServer (org.apache.bookkeeper.server.Main.buildBookieServer)1 ServerLifecycleComponent (org.apache.bookkeeper.server.component.ServerLifecycleComponent)1 BookieConfiguration (org.apache.bookkeeper.server.conf.BookieConfiguration)1 BKHttpServiceProvider (org.apache.bookkeeper.server.http.BKHttpServiceProvider)1 AutoRecoveryService (org.apache.bookkeeper.server.service.AutoRecoveryService)1 BookieService (org.apache.bookkeeper.server.service.BookieService)1 HttpService (org.apache.bookkeeper.server.service.HttpService)1 StatsProviderService (org.apache.bookkeeper.server.service.StatsProviderService)1 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1