Skip to content

Commit c159471

Browse files
Shutdown expunged resources cleanup executor properly, and allow other components to configure/start/stop on error (#9723)
1 parent 04c428c commit c159471

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private void onSendingClusterPdu() {
294294
}
295295
}
296296
} catch (final Throwable e) {
297-
logger.error("Unexcpeted exception: ", e);
297+
logger.error("Unexpected exception: ", e);
298298
}
299299
}
300300
}
@@ -346,7 +346,7 @@ protected void runInContext() {
346346
}
347347
});
348348
} catch (final Throwable e) {
349-
logger.error("Unexcpeted exception: ", e);
349+
logger.error("Unexpected exception: ", e);
350350
}
351351
}
352352
}
@@ -384,7 +384,7 @@ public void broadcast(final long agentId, final String cmds) {
384384
}
385385
executeAsync(peerName, agentId, cmds, true);
386386
} catch (final Exception e) {
387-
logger.warn("Caught exception while talkign to " + peer.getMsid());
387+
logger.warn("Caught exception while talking to " + peer.getMsid());
388388
}
389389
}
390390
}

framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ public void startBeans() {
6969
with(new WithComponentLifeCycle() {
7070
@Override
7171
public void with(ComponentLifecycle lifecycle) {
72-
lifecycle.start();
72+
logger.info("starting bean {}.", lifecycle.getName());
73+
try {
74+
lifecycle.start();
75+
} catch (Exception e) {
76+
logger.error("Error on starting bean {} - {}", lifecycle.getName(), e.getMessage(), e);
77+
}
7378

7479
if (lifecycle instanceof ManagementBean) {
7580
ManagementBean mbean = (ManagementBean)lifecycle;
@@ -93,13 +98,21 @@ public void with(ComponentLifecycle lifecycle) {
9398
}
9499

95100
public void stopBeans() {
101+
logger.info("Stopping CloudStack Components");
102+
96103
with(new WithComponentLifeCycle() {
97104
@Override
98105
public void with(ComponentLifecycle lifecycle) {
99-
logger.info("stopping bean " + lifecycle.getName());
100-
lifecycle.stop();
106+
logger.info("stopping bean {}.", lifecycle.getName());
107+
try {
108+
lifecycle.stop();
109+
} catch (Exception e) {
110+
logger.error("Error on stopping bean {} - {}", lifecycle.getName(), e.getMessage(), e);
111+
}
101112
}
102113
});
114+
115+
logger.info("Done Stopping CloudStack Components");
103116
}
104117

105118
private void configure() {
@@ -109,10 +122,13 @@ private void configure() {
109122
@Override
110123
public void with(ComponentLifecycle lifecycle) {
111124
try {
125+
logger.info("configuring bean {}.", lifecycle.getName());
112126
lifecycle.configure(lifecycle.getName(), lifecycle.getConfigParams());
113127
} catch (ConfigurationException e) {
114128
logger.error("Failed to configure " + lifecycle.getName(), e);
115129
throw new CloudRuntimeException(e);
130+
} catch (Exception e) {
131+
logger.error("Error on configuring bean {} - {}", lifecycle.getName(), e.getMessage(), e);
116132
}
117133
}
118134
});

framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java

-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ public void setLifeCycle(CloudStackExtendedLifeCycle lifeCycle) {
4545
public void run() {
4646
lifeCycle.startBeans();
4747
}
48-
4948
}

framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ public void registerShutdownHook() {
7777
for (String appName : contextMap.keySet()) {
7878
ApplicationContext contex = contextMap.get(appName);
7979
if (contex instanceof ConfigurableApplicationContext) {
80-
logger.trace("registering shutdown hook for bean "+ appName);
80+
logger.trace("Registering shutdown hook for bean {}.", appName);
8181
((ConfigurableApplicationContext)contex).registerShutdownHook();
82+
} else {
83+
logger.warn("Shutdown hook not registered for bean {}.", appName);
8284
}
8385
}
8486
}

server/src/main/java/org/apache/cloudstack/resource/ResourceCleanupServiceImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ public boolean start() {
579579
@Override
580580
public boolean stop() {
581581
purgeExpungedResourcesJobExecutor.shutdown();
582-
expungedResourcesCleanupExecutor.shutdownNow();
582+
if (expungedResourcesCleanupExecutor != null) {
583+
expungedResourcesCleanupExecutor.shutdownNow();
584+
}
583585
return true;
584586
}
585587

0 commit comments

Comments
 (0)