Search in sources :

Example 1 with BKHttpServiceProvider

use of org.apache.bookkeeper.server.http.BKHttpServiceProvider in project bookkeeper by apache.

the class AutoRecoveryMain method main.

public static void main(String[] args) {
    ServerConfiguration conf = null;
    try {
        conf = parseArgs(args);
    } catch (IllegalArgumentException iae) {
        LOG.error("Error parsing command line arguments : ", iae);
        System.err.println(iae.getMessage());
        printUsage();
        System.exit(ExitCode.INVALID_CONF);
    }
    try {
        final AutoRecoveryMain autoRecoveryMain = new AutoRecoveryMain(conf);
        autoRecoveryMain.start();
        HttpServerLoader.loadHttpServer(conf);
        final HttpServer httpServer = HttpServerLoader.get();
        if (conf.isHttpServerEnabled() && httpServer != null) {
            BKHttpServiceProvider serviceProvider = new BKHttpServiceProvider.Builder().setAutoRecovery(autoRecoveryMain).setServerConfiguration(conf).build();
            httpServer.initialize(serviceProvider);
            httpServer.startServer(conf.getHttpServerPort());
        }
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                autoRecoveryMain.shutdown();
                if (httpServer != null && httpServer.isRunning()) {
                    httpServer.stopServer();
                }
                LOG.info("Shutdown AutoRecoveryMain successfully");
            }
        });
        LOG.info("Register shutdown hook successfully");
        autoRecoveryMain.join();
        System.exit(autoRecoveryMain.getExitCode());
    } catch (Exception e) {
        LOG.error("Exception running AutoRecoveryMain : ", e);
        System.exit(ExitCode.SERVER_EXCEPTION);
    }
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) HttpServer(org.apache.bookkeeper.http.HttpServer) CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) BKHttpServiceProvider(org.apache.bookkeeper.server.http.BKHttpServiceProvider) BookieCriticalThread(org.apache.bookkeeper.bookie.BookieCriticalThread)

Example 2 with BKHttpServiceProvider

use of org.apache.bookkeeper.server.http.BKHttpServiceProvider 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

BKHttpServiceProvider (org.apache.bookkeeper.server.http.BKHttpServiceProvider)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 BookieCriticalThread (org.apache.bookkeeper.bookie.BookieCriticalThread)1 LifecycleComponentStack (org.apache.bookkeeper.common.component.LifecycleComponentStack)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 HttpServer (org.apache.bookkeeper.http.HttpServer)1 CompatibilityException (org.apache.bookkeeper.replication.ReplicationException.CompatibilityException)1 UnavailableException (org.apache.bookkeeper.replication.ReplicationException.UnavailableException)1 ServerLifecycleComponent (org.apache.bookkeeper.server.component.ServerLifecycleComponent)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 ParseException (org.apache.commons.cli.ParseException)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 KeeperException (org.apache.zookeeper.KeeperException)1