Shutdown expunged resources cleanup executor properly, and allow other components to configure/start/stop on error (#9723)

This commit is contained in:
Suresh Kumar Anaparti 2024-09-30 14:39:45 +05:30 committed by GitHub
parent 04c428cb2f
commit c159471434
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 9 deletions

View File

@ -294,7 +294,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C
} }
} }
} catch (final Throwable e) { } catch (final Throwable e) {
logger.error("Unexcpeted exception: ", e); logger.error("Unexpected exception: ", e);
} }
} }
} }
@ -346,7 +346,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C
} }
}); });
} catch (final Throwable e) { } catch (final Throwable e) {
logger.error("Unexcpeted exception: ", e); logger.error("Unexpected exception: ", e);
} }
} }
} }
@ -384,7 +384,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C
} }
executeAsync(peerName, agentId, cmds, true); executeAsync(peerName, agentId, cmds, true);
} catch (final Exception e) { } catch (final Exception e) {
logger.warn("Caught exception while talkign to " + peer.getMsid()); logger.warn("Caught exception while talking to " + peer.getMsid());
} }
} }
} }

View File

@ -69,7 +69,12 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector {
with(new WithComponentLifeCycle() { with(new WithComponentLifeCycle() {
@Override @Override
public void with(ComponentLifecycle lifecycle) { public void with(ComponentLifecycle lifecycle) {
lifecycle.start(); logger.info("starting bean {}.", lifecycle.getName());
try {
lifecycle.start();
} catch (Exception e) {
logger.error("Error on starting bean {} - {}", lifecycle.getName(), e.getMessage(), e);
}
if (lifecycle instanceof ManagementBean) { if (lifecycle instanceof ManagementBean) {
ManagementBean mbean = (ManagementBean)lifecycle; ManagementBean mbean = (ManagementBean)lifecycle;
@ -93,13 +98,21 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector {
} }
public void stopBeans() { public void stopBeans() {
logger.info("Stopping CloudStack Components");
with(new WithComponentLifeCycle() { with(new WithComponentLifeCycle() {
@Override @Override
public void with(ComponentLifecycle lifecycle) { public void with(ComponentLifecycle lifecycle) {
logger.info("stopping bean " + lifecycle.getName()); logger.info("stopping bean {}.", lifecycle.getName());
lifecycle.stop(); try {
lifecycle.stop();
} catch (Exception e) {
logger.error("Error on stopping bean {} - {}", lifecycle.getName(), e.getMessage(), e);
}
} }
}); });
logger.info("Done Stopping CloudStack Components");
} }
private void configure() { private void configure() {
@ -109,10 +122,13 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector {
@Override @Override
public void with(ComponentLifecycle lifecycle) { public void with(ComponentLifecycle lifecycle) {
try { try {
logger.info("configuring bean {}.", lifecycle.getName());
lifecycle.configure(lifecycle.getName(), lifecycle.getConfigParams()); lifecycle.configure(lifecycle.getName(), lifecycle.getConfigParams());
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
logger.error("Failed to configure " + lifecycle.getName(), e); logger.error("Failed to configure " + lifecycle.getName(), e);
throw new CloudRuntimeException(e); throw new CloudRuntimeException(e);
} catch (Exception e) {
logger.error("Error on configuring bean {} - {}", lifecycle.getName(), e.getMessage(), e);
} }
} }
}); });

View File

@ -45,5 +45,4 @@ public class CloudStackExtendedLifeCycleStart extends AbstractSmartLifeCycle imp
public void run() { public void run() {
lifeCycle.startBeans(); lifeCycle.startBeans();
} }
} }

View File

@ -77,8 +77,10 @@ public class CloudStackSpringContext {
for (String appName : contextMap.keySet()) { for (String appName : contextMap.keySet()) {
ApplicationContext contex = contextMap.get(appName); ApplicationContext contex = contextMap.get(appName);
if (contex instanceof ConfigurableApplicationContext) { if (contex instanceof ConfigurableApplicationContext) {
logger.trace("registering shutdown hook for bean "+ appName); logger.trace("Registering shutdown hook for bean {}.", appName);
((ConfigurableApplicationContext)contex).registerShutdownHook(); ((ConfigurableApplicationContext)contex).registerShutdownHook();
} else {
logger.warn("Shutdown hook not registered for bean {}.", appName);
} }
} }
} }

View File

@ -579,7 +579,9 @@ public class ResourceCleanupServiceImpl extends ManagerBase implements ResourceC
@Override @Override
public boolean stop() { public boolean stop() {
purgeExpungedResourcesJobExecutor.shutdown(); purgeExpungedResourcesJobExecutor.shutdown();
expungedResourcesCleanupExecutor.shutdownNow(); if (expungedResourcesCleanupExecutor != null) {
expungedResourcesCleanupExecutor.shutdownNow();
}
return true; return true;
} }