Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 =
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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 {
Expand All @@ -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();
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down