Merge pull request #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 <github@remi.nl>
This commit is contained in:
Remi Bergsma 2015-12-05 18:47:52 +01:00
commit 74e33dc5ae
7 changed files with 23 additions and 5 deletions

View File

@ -44,7 +44,7 @@ fi
NAME="$(basename $0)"
stop() {
SHUTDOWN_WAIT="30"
SHUTDOWN_WAIT="40"
count="0"
if [ -f /var/run/cloud-management.pid ]; then
pid=`cat /var/run/cloud-management.pid`

View File

@ -99,6 +99,7 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector {
with(new WithComponentLifeCycle() {
@Override
public void with(ComponentLifecycle lifecycle) {
log.info("stopping bean " + lifecycle.getName());
lifecycle.stop();
}
});

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -71,10 +72,14 @@ public class CloudStackSpringContext {
}
public void registerShutdownHook() {
ApplicationContext base = moduleDefinitionSet.getApplicationContext(baseName);
Map<String, ApplicationContext> contextMap= moduleDefinitionSet.getContextMap();
if (base instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext)base).registerShutdownHook();
for (String appName : contextMap.keySet()) {
ApplicationContext contex = contextMap.get(appName);
if (contex instanceof ConfigurableApplicationContext) {
log.trace("registering shutdown hook for bean "+ appName);
((ConfigurableApplicationContext)contex).registerShutdownHook();
}
}
}

View File

@ -21,12 +21,16 @@ package org.apache.cloudstack.spring.module.model;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import java.util.Map;
public interface ModuleDefinitionSet {
ModuleDefinition getModuleDefinition(String name);
ApplicationContext getApplicationContext(String name);
Map<String, ApplicationContext> getContextMap();
Resource[] getConfigResources(String name);
}

View File

@ -278,6 +278,11 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet {
return contexts.get(name);
}
@Override
public Map<String, ApplicationContext> getContextMap() {
return contexts;
}
@Override
public Resource[] getConfigResources(String name) {
Set<Resource> resources = new LinkedHashSet<Resource>();

View File

@ -50,6 +50,7 @@ public class CloudStackContextLoaderListener extends ContextLoaderListener {
public void contextInitialized(ServletContextEvent event) {
try {
cloudStackContext = new CloudStackSpringContext();
cloudStackContext.registerShutdownHook();
event.getServletContext().setAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY, cloudStackContext);
} catch (IOException e) {
log.error("Failed to start CloudStack", e);

View File

@ -181,7 +181,9 @@ public class ContrailManagerImpl extends ManagerBase implements ContrailManager
@Override
public boolean stop() {
_dbSyncTimer.cancel();
if (_dbSyncTimer != null) {
_dbSyncTimer.cancel();
}
return true;
}