You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/10/03 00:48:25 UTC

[GitHub] reddycharan commented on a change in pull request #1726: Introduce lifecycle components for managing components in AutoRecovery

reddycharan commented on a change in pull request #1726: Introduce lifecycle components for managing components in AutoRecovery
URL: https://github.com/apache/bookkeeper/pull/1726#discussion_r222154664
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java
 ##########
 @@ -266,45 +302,93 @@ private static ServerConfiguration parseArgs(String[] args)
     }
 
     public static void main(String[] args) {
-        ServerConfiguration conf = null;
+        int retCode = doMain(args);
+        Runtime.getRuntime().exit(retCode);
+    }
+
+    static int doMain(String[] args) {
+
+        ServerConfiguration conf;
+
+        // 0. parse command line
         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);
+            return ExitCode.INVALID_CONF;
         }
 
+        // 1. building the component stack:
+        LifecycleComponent server;
         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());
+            server = buildAutoRecoveryServer(new BookieConfiguration(conf));
         } catch (Exception e) {
-            LOG.error("Exception running AutoRecoveryMain : ", e);
-            System.exit(ExitCode.SERVER_EXCEPTION);
+            LOG.error("Failed to build AutoRecovery Server", e);
+            return ExitCode.SERVER_EXCEPTION;
+        }
+
+        // 2. start the server
+        try {
+            ComponentStarter.startComponent(server).get();
+        } catch (InterruptedException ie) {
+            Thread.currentThread().interrupt();
+            // the server is interrupted
+            LOG.info("AutoRecovery server is interrupted. Exiting ...");
+        } catch (ExecutionException ee) {
+            LOG.error("Error in bookie shutdown", ee.getCause());
+            return ExitCode.SERVER_EXCEPTION;
+        }
+        return ExitCode.OK;
+    }
+
+    static LifecycleComponentStack buildAutoRecoveryServer(BookieConfiguration conf) throws Exception {
+        LifecycleComponentStack.Builder serverBuilder = LifecycleComponentStack.newBuilder()
+                .withName("autorecovery-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 AutoRecovery server
+        AutoRecoveryService autoRecoveryService = new AutoRecoveryService(conf, rootStatsLogger);
+
+        serverBuilder.addComponent(autoRecoveryService);
+        LOG.info("Load lifecycle component : {}", AutoRecoveryService.class.getName());
+
+        // 4. build http service
+        if (conf.getServerConf().isHttpServerEnabled()) {
+            BKHttpServiceProvider provider = new BKHttpServiceProvider.Builder()
+                    .setAutoRecovery(autoRecoveryService.getAutoRecoveryServer())
+                    .setServerConfiguration(conf.getServerConf())
+                    .setStatsProvider(statsProviderService.getStatsProvider()).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();
 
 Review comment:
   removed extraComponents

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services