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)" NAME="$(basename $0)"
stop() { stop() {
SHUTDOWN_WAIT="30" SHUTDOWN_WAIT="40"
count="0" count="0"
if [ -f /var/run/cloud-management.pid ]; then if [ -f /var/run/cloud-management.pid ]; then
pid=`cat /var/run/cloud-management.pid` pid=`cat /var/run/cloud-management.pid`

View File

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

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -71,10 +72,14 @@ public class CloudStackSpringContext {
} }
public void registerShutdownHook() { public void registerShutdownHook() {
ApplicationContext base = moduleDefinitionSet.getApplicationContext(baseName); Map<String, ApplicationContext> contextMap= moduleDefinitionSet.getContextMap();
if (base instanceof ConfigurableApplicationContext) { for (String appName : contextMap.keySet()) {
((ConfigurableApplicationContext)base).registerShutdownHook(); 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.context.ApplicationContext;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import java.util.Map;
public interface ModuleDefinitionSet { public interface ModuleDefinitionSet {
ModuleDefinition getModuleDefinition(String name); ModuleDefinition getModuleDefinition(String name);
ApplicationContext getApplicationContext(String name); ApplicationContext getApplicationContext(String name);
Map<String, ApplicationContext> getContextMap();
Resource[] getConfigResources(String name); Resource[] getConfigResources(String name);
} }

View File

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

View File

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

View File

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