Skip to content

Commit 74e33dc

Browse files
committed
Merge pull request apache#840 from bvbharatk/CLOUDSTACK-8852
CLOUDSTACK-8852 Database shows that management server is UP when it iDatabase shows that management server is UP when it is actually stopped. This was happening as the stop method in clusterMnanagerImpl was not getting callled. Added shutdown hooks to all spring sub contexts, this enables spring to call the stop mehtods of the beans when management server is shutting down. Conflicts: framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java * pr/840: CLOUDSTACK-8852 Database shows that management server is UP when it is actually stopped from the CCP GUI Signed-off-by: Remi Bergsma <[email protected]>
2 parents 1056f3c + 4849368 commit 74e33dc

7 files changed

Lines changed: 23 additions & 5 deletions

File tree

client/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-management.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fi
4444

4545
NAME="$(basename $0)"
4646
stop() {
47-
SHUTDOWN_WAIT="30"
47+
SHUTDOWN_WAIT="40"
4848
count="0"
4949
if [ -f /var/run/cloud-management.pid ]; then
5050
pid=`cat /var/run/cloud-management.pid`

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public void stopBeans() {
9999
with(new WithComponentLifeCycle() {
100100
@Override
101101
public void with(ComponentLifecycle lifecycle) {
102+
log.info("stopping bean " + lifecycle.getName());
102103
lifecycle.stop();
103104
}
104105
});

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.Collection;
2424
import java.util.List;
25+
import java.util.Map;
2526

2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
@@ -71,10 +72,14 @@ public void init() throws IOException {
7172
}
7273

7374
public void registerShutdownHook() {
74-
ApplicationContext base = moduleDefinitionSet.getApplicationContext(baseName);
75+
Map<String, ApplicationContext> contextMap= moduleDefinitionSet.getContextMap();
7576

76-
if (base instanceof ConfigurableApplicationContext) {
77-
((ConfigurableApplicationContext)base).registerShutdownHook();
77+
for (String appName : contextMap.keySet()) {
78+
ApplicationContext contex = contextMap.get(appName);
79+
if (contex instanceof ConfigurableApplicationContext) {
80+
log.trace("registering shutdown hook for bean "+ appName);
81+
((ConfigurableApplicationContext)contex).registerShutdownHook();
82+
}
7883
}
7984
}
8085

framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/ModuleDefinitionSet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
import org.springframework.context.ApplicationContext;
2222
import org.springframework.core.io.Resource;
2323

24+
import java.util.Map;
25+
2426
public interface ModuleDefinitionSet {
2527

2628
ModuleDefinition getModuleDefinition(String name);
2729

2830
ApplicationContext getApplicationContext(String name);
2931

32+
Map<String, ApplicationContext> getContextMap();
33+
3034
Resource[] getConfigResources(String name);
3135

3236
}

framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ public ApplicationContext getApplicationContext(String name) {
278278
return contexts.get(name);
279279
}
280280

281+
@Override
282+
public Map<String, ApplicationContext> getContextMap() {
283+
return contexts;
284+
}
285+
281286
@Override
282287
public Resource[] getConfigResources(String name) {
283288
Set<Resource> resources = new LinkedHashSet<Resource>();

framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected ApplicationContext loadParentContext(ServletContext servletContext) {
5050
public void contextInitialized(ServletContextEvent event) {
5151
try {
5252
cloudStackContext = new CloudStackSpringContext();
53+
cloudStackContext.registerShutdownHook();
5354
event.getServletContext().setAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY, cloudStackContext);
5455
} catch (IOException e) {
5556
log.error("Failed to start CloudStack", e);

plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailManagerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ public boolean start() {
181181

182182
@Override
183183
public boolean stop() {
184-
_dbSyncTimer.cancel();
184+
if (_dbSyncTimer != null) {
185+
_dbSyncTimer.cancel();
186+
}
185187
return true;
186188
}
187189

0 commit comments

Comments
 (0)