diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java index 418b60a076..4d418d7f52 100644 --- a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java +++ b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java @@ -126,15 +126,16 @@ public static void main(String[] args) { service.dispose(); LOG.info("AMS service has been shut down"); })); + service.startRestServices(); while (true) { try { service.waitLeaderShip(); - service.startService(); + service.startOptimizingService(); service.waitFollowerShip(); } catch (Exception e) { LOG.error("AMS start error", e); } finally { - service.dispose(); + service.disposeOptimizingService(); } } } catch (Throwable t) { @@ -151,14 +152,21 @@ public void waitFollowerShip() throws Exception { haContainer.waitFollowerShip(); } - public void startService() throws Exception { + public void startRestServices() throws Exception { EventsManager.getInstance(); MetricManager.getInstance(); catalogManager = new DefaultCatalogManager(serviceConfig); tableManager = new DefaultTableManager(serviceConfig, catalogManager); optimizerManager = new DefaultOptimizerManager(serviceConfig, catalogManager); + terminalManager = new TerminalManager(serviceConfig, catalogManager); + + initHttpService(); + startHttpService(); + registerAmsServiceMetric(); + } + public void startOptimizingService() throws Exception { tableService = new DefaultTableService(serviceConfig, catalogManager); optimizingService = @@ -180,14 +188,9 @@ public void startService() throws Exception { tableService.initialize(); LOG.info("AMS table service have been initialized"); tableManager.setTableService(tableService); - terminalManager = new TerminalManager(serviceConfig, catalogManager); initThriftService(); startThriftService(); - - initHttpService(); - startHttpService(); - registerAmsServiceMetric(); } private void addHandlerChain(RuntimeHandlerChain chain) { @@ -196,7 +199,7 @@ private void addHandlerChain(RuntimeHandlerChain chain) { } } - public void dispose() { + public void disposeOptimizingService() { if (tableManagementServer != null && tableManagementServer.isServing()) { LOG.info("Stopping table management server..."); tableManagementServer.stop(); @@ -205,6 +208,19 @@ public void dispose() { LOG.info("Stopping optimizing server..."); optimizingServiceServer.stop(); } + if (tableService != null) { + LOG.info("Stopping table service..."); + tableService.dispose(); + tableService = null; + } + if (optimizingService != null) { + LOG.info("Stopping optimizing service..."); + optimizingService.dispose(); + optimizingService = null; + } + } + + public void disposeRestService() { if (httpServer != null) { LOG.info("Stopping http server..."); try { @@ -213,22 +229,11 @@ public void dispose() { LOG.error("Error stopping http server", e); } } - if (tableService != null) { - LOG.info("Stopping table service..."); - tableService.dispose(); - tableService = null; - } if (terminalManager != null) { LOG.info("Stopping terminal manager..."); terminalManager.dispose(); terminalManager = null; } - if (optimizingService != null) { - LOG.info("Stopping optimizing service..."); - optimizingService.dispose(); - optimizingService = null; - } - if (amsServiceMetrics != null) { amsServiceMetrics.unregister(); } @@ -237,6 +242,11 @@ public void dispose() { MetricManager.dispose(); } + public void dispose() { + disposeOptimizingService(); + disposeRestService(); + } + private void initConfig() throws Exception { LOG.info("initializing configurations..."); new ConfigurationHelper().init(); diff --git a/amoro-ams/src/test/java/org/apache/amoro/server/AmsEnvironment.java b/amoro-ams/src/test/java/org/apache/amoro/server/AmsEnvironment.java index 39384c68c2..827135da42 100644 --- a/amoro-ams/src/test/java/org/apache/amoro/server/AmsEnvironment.java +++ b/amoro-ams/src/test/java/org/apache/amoro/server/AmsEnvironment.java @@ -315,7 +315,8 @@ private void startAms() throws Exception { AmoroManagementConf.OPTIMIZING_SERVICE_THRIFT_BIND_PORT, optimizingServiceBindPort); serviceConfig.set( AmoroManagementConf.REFRESH_EXTERNAL_CATALOGS_INTERVAL, Duration.ofMillis(1000L)); - serviceContainer.startService(); + serviceContainer.startRestServices(); + serviceContainer.startOptimizingService(); LOG.info("Started test AMS."); break; } catch (TTransportException e) {