Bug 10860 - PremiumUpgrade is not run when upgrading to 2.2.8

Use a new target "system-integrity-checker" in components.xml/components-premium.xml.
All checkers must be explicitly specified in XML file, they will execute before any components load

status 10860: resolved fixed
This commit is contained in:
frank 2011-07-27 17:32:12 -07:00
parent 9a5304911b
commit 1381c58fa1
11 changed files with 55 additions and 93 deletions

View File

@ -30,12 +30,6 @@ import com.cloud.utils.db.GenericDao;
public class AgentComponentLibraryBase extends ComponentLibraryBase { public class AgentComponentLibraryBase extends ComponentLibraryBase {
@Override
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
return null;
}
@Override @Override
public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() { public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() {
return null; return null;

View File

@ -23,6 +23,11 @@
documented, please contact the author. documented, please contact the author.
--> -->
<components.xml> <components.xml>
<system-integrity-checker class="com.cloud.upgrade.DatabaseUpgradeChecker">
<checker name="ManagementServerNode" class="com.cloud.cluster.ManagementServerNode"/>
<checker name="DatabaseUpgradeChecker" class="com.cloud.upgrade.DatabaseUpgradeChecker"/>
</system-integrity-checker>
<interceptor library="com.cloud.configuration.DefaultInterceptorLibrary"/> <interceptor library="com.cloud.configuration.DefaultInterceptorLibrary"/>
<management-server class="com.cloud.server.ManagementServerImpl" library="com.cloud.configuration.DefaultComponentLibrary"> <management-server class="com.cloud.server.ManagementServerImpl" library="com.cloud.configuration.DefaultComponentLibrary">
<adapters key="com.cloud.agent.manager.allocator.HostAllocator"> <adapters key="com.cloud.agent.manager.allocator.HostAllocator">
@ -99,7 +104,7 @@
</management-server> </management-server>
<configuration-server class="com.cloud.server.ConfigurationServerImpl" library="com.cloud.configuration.ConfigurationCompoentLibrary"> <configuration-server class="com.cloud.server.ConfigurationServerImpl">
<dao name="Configuration configuration server" class="com.cloud.configuration.dao.ConfigurationDaoImpl" singleton="false"> <dao name="Configuration configuration server" class="com.cloud.configuration.dao.ConfigurationDaoImpl" singleton="false">
<param name="premium">false</param> <param name="premium">false</param>
</dao> </dao>

3
server/src/com/cloud/cluster/ManagementServerNode.java Normal file → Executable file
View File

@ -17,10 +17,13 @@
*/ */
package com.cloud.cluster; package com.cloud.cluster;
import javax.ejb.Local;
import com.cloud.utils.component.SystemIntegrityChecker; import com.cloud.utils.component.SystemIntegrityChecker;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.MacAddress; import com.cloud.utils.net.MacAddress;
@Local(value = {SystemIntegrityChecker.class})
public class ManagementServerNode implements SystemIntegrityChecker { public class ManagementServerNode implements SystemIntegrityChecker {
private static final long s_nodeId = MacAddress.getMacAddress().toLong(); private static final long s_nodeId = MacAddress.getMacAddress().toLong();

View File

@ -1,47 +0,0 @@
package com.cloud.configuration;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.cloud.upgrade.DatabaseUpgradeChecker;
import com.cloud.utils.component.Adapter;
import com.cloud.utils.component.ComponentLibraryBase;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.SystemIntegrityChecker;
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
import com.cloud.utils.db.GenericDao;
public class ConfigurationCompoentLibrary extends ComponentLibraryBase {
@Override
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
ArrayList<SystemIntegrityChecker> checkers = new ArrayList<SystemIntegrityChecker>();
checkers.add(new DatabaseUpgradeChecker());
return checkers;
}
@Override
public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() {
return new LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>>(0);
}
@Override
public Map<String, ComponentInfo<Manager>> getManagers() {
return new LinkedHashMap<String, ComponentInfo<Manager>>(0);
}
@Override
public Map<String, List<ComponentInfo<Adapter>>> getAdapters() {
return new LinkedHashMap<String, List<ComponentInfo<Adapter>>>(0);
}
@Override
public Map<Class<?>, Class<?>> getFactories() {
return new HashMap<Class<?>, Class<?>>(0);
}
}

View File

@ -157,15 +157,6 @@ import com.cloud.vm.dao.UserVmDetailsDaoImpl;
import com.cloud.vm.dao.VMInstanceDaoImpl; import com.cloud.vm.dao.VMInstanceDaoImpl;
public class DefaultComponentLibrary extends ComponentLibraryBase implements ComponentLibrary { public class DefaultComponentLibrary extends ComponentLibraryBase implements ComponentLibrary {
@Override
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
ArrayList<SystemIntegrityChecker> checkers = new ArrayList<SystemIntegrityChecker>();
checkers.add(new ManagementServerNode());
checkers.add(new DatabaseUpgradeChecker());
return checkers;
}
protected void populateDaos() { protected void populateDaos() {
addDao("StackMaidDao", StackMaidDaoImpl.class); addDao("StackMaidDao", StackMaidDaoImpl.class);
addDao("VMTemplateZoneDao", VMTemplateZoneDaoImpl.class); addDao("VMTemplateZoneDao", VMTemplateZoneDaoImpl.class);

10
server/src/com/cloud/servlet/CloudStartupServlet.java Normal file → Executable file
View File

@ -29,6 +29,8 @@ import com.cloud.server.ConfigurationServer;
import com.cloud.server.ManagementServer; import com.cloud.server.ManagementServer;
import com.cloud.utils.SerialVersionUID; import com.cloud.utils.SerialVersionUID;
import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.SystemIntegrityChecker;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
@ -40,9 +42,11 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
protected static ComponentLocator s_locator; protected static ComponentLocator s_locator;
@Override @Override
public void init() throws ServletException { public void init() throws ServletException {
// Save Configuration Values /* System Integrity checker will run before all components really loaded */
//ComponentLocator loc = ComponentLocator.getLocator(ConfigurationServer.Name); ComponentLocator.getComponent(SystemIntegrityChecker.Name);
// Save Configuration Values
//ComponentLocator loc = ComponentLocator.getLocator(ConfigurationServer.Name);
ConfigurationServer c = (ConfigurationServer)ComponentLocator.getComponent(ConfigurationServer.Name); ConfigurationServer c = (ConfigurationServer)ComponentLocator.getComponent(ConfigurationServer.Name);
//ConfigurationServer c = new ConfigurationServerImpl(); //ConfigurationServer c = new ConfigurationServerImpl();
try { try {

View File

@ -31,6 +31,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import javax.ejb.Local;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.cluster.ClusterManagerImpl; import com.cloud.cluster.ClusterManagerImpl;
@ -58,6 +60,7 @@ import com.cloud.utils.db.ScriptRunner;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
@Local(value = {SystemIntegrityChecker.class})
public class DatabaseUpgradeChecker implements SystemIntegrityChecker { public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
private final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class); private final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class);

View File

@ -33,14 +33,7 @@ import com.cloud.utils.db.GenericDao;
* within the components.xml overrides the one within ComponentLibrary. * within the components.xml overrides the one within ComponentLibrary.
* *
*/ */
public interface ComponentLibrary { public interface ComponentLibrary {
/**
* @return a list of SytemIntegrityCheckers which is run before other
* components are started to check if the system are fit to check
* the system.
*/
List<SystemIntegrityChecker> getSystemIntegrityCheckers();
/** /**
* @return all of the daos * @return all of the daos
*/ */

View File

@ -94,6 +94,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
protected HashMap<String, Adapters<? extends Adapter>> _adapterMap; protected HashMap<String, Adapters<? extends Adapter>> _adapterMap;
protected HashMap<String, ComponentInfo<Manager>> _managerMap; protected HashMap<String, ComponentInfo<Manager>> _managerMap;
protected HashMap<String, ComponentInfo<SystemIntegrityChecker>> _checkerMap;
protected LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>> _daoMap; protected LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>> _daoMap;
protected String _serverName; protected String _serverName;
protected Object _component; protected Object _component;
@ -123,12 +124,13 @@ public class ComponentLocator implements ComponentLocatorMBean {
return getLocatorName(); return getLocatorName();
} }
protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>> parse2(String filename) { protected Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>> parse2(String filename) {
try { try {
SAXParserFactory spfactory = SAXParserFactory.newInstance(); SAXParserFactory spfactory = SAXParserFactory.newInstance();
SAXParser saxParser = spfactory.newSAXParser(); SAXParser saxParser = spfactory.newSAXParser();
_daoMap = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>>(); _daoMap = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>>();
_managerMap = new LinkedHashMap<String, ComponentInfo<Manager>>(); _managerMap = new LinkedHashMap<String, ComponentInfo<Manager>>();
_checkerMap = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
_adapterMap = new HashMap<String, Adapters<? extends Adapter>>(); _adapterMap = new HashMap<String, Adapters<? extends Adapter>>();
_factories = new HashMap<Class<?>, Class<?>>(); _factories = new HashMap<Class<?>, Class<?>>();
File file = PropertiesUtil.findConfigFile(filename); File file = PropertiesUtil.findConfigFile(filename);
@ -157,7 +159,6 @@ public class ComponentLocator implements ComponentLocatorMBean {
} }
ComponentLibrary library = null; ComponentLibrary library = null;
List<SystemIntegrityChecker> checkers = null;
if (handler.library != null) { if (handler.library != null) {
Class<?> clazz = Class.forName(handler.library); Class<?> clazz = Class.forName(handler.library);
library = (ComponentLibrary)clazz.newInstance(); library = (ComponentLibrary)clazz.newInstance();
@ -165,15 +166,14 @@ public class ComponentLocator implements ComponentLocatorMBean {
_managerMap.putAll(library.getManagers()); _managerMap.putAll(library.getManagers());
adapters.putAll(library.getAdapters()); adapters.putAll(library.getAdapters());
_factories.putAll(library.getFactories()); _factories.putAll(library.getFactories());
checkers = library.getSystemIntegrityCheckers();
} }
_daoMap.putAll(handler.daos); _daoMap.putAll(handler.daos);
_managerMap.putAll(handler.managers); _managerMap.putAll(handler.managers);
_checkerMap.putAll(handler.checkers);
adapters.putAll(handler.adapters); adapters.putAll(handler.adapters);
return new Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>>(handler, adapters, checkers); return new Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>>(handler, adapters);
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
s_logger.error("Unable to load " + _serverName + " due to errors while parsing " + filename, e); s_logger.error("Unable to load " + _serverName + " due to errors while parsing " + filename, e);
System.exit(1); System.exit(1);
@ -194,7 +194,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
} }
protected void parse(String filename) { protected void parse(String filename) {
Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>> result = parse2(filename); Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>> result = parse2(filename);
if (result == null) { if (result == null) {
s_logger.info("Skipping configuration using " + filename); s_logger.info("Skipping configuration using " + filename);
return; return;
@ -203,11 +203,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
XmlHandler handler = result.first(); XmlHandler handler = result.first();
HashMap<String, List<ComponentInfo<Adapter>>> adapters = result.second(); HashMap<String, List<ComponentInfo<Adapter>>> adapters = result.second();
try { try {
if (result.third() != null) { runCheckers();
for (SystemIntegrityChecker checker : result.third()) {
checker.check();
}
}
startDaos(); // daos should not be using managers and adapters. startDaos(); // daos should not be using managers and adapters.
instantiateAdapters(adapters); instantiateAdapters(adapters);
instantiateManagers(); instantiateManagers();
@ -227,6 +223,19 @@ public class ComponentLocator implements ComponentLocatorMBean {
} }
} }
protected void runCheckers() {
Set<Map.Entry<String, ComponentInfo<SystemIntegrityChecker>>> entries = _checkerMap.entrySet();
for (Map.Entry<String, ComponentInfo<SystemIntegrityChecker>> entry : entries) {
ComponentInfo<SystemIntegrityChecker> info = entry.getValue();
try {
info.instance = (SystemIntegrityChecker)createInstance(info.clazz, false, info.singleton);
info.instance.check();
} catch (Exception e) {
s_logger.error("Problems with running checker:" + info.name, e);
System.exit(1);
}
}
}
/** /**
* Daos should not refer to any other components so it is safe to start them * Daos should not refer to any other components so it is safe to start them
* here. * here.
@ -848,6 +857,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
protected class XmlHandler extends DefaultHandler { protected class XmlHandler extends DefaultHandler {
public HashMap<String, List<ComponentInfo<Adapter>>> adapters; public HashMap<String, List<ComponentInfo<Adapter>>> adapters;
public HashMap<String, ComponentInfo<Manager>> managers; public HashMap<String, ComponentInfo<Manager>> managers;
public HashMap<String, ComponentInfo<SystemIntegrityChecker>> checkers;
public LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>> daos; public LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>> daos;
public String parent; public String parent;
public String library; public String library;
@ -865,6 +875,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
parse = false; parse = false;
adapters = new HashMap<String, List<ComponentInfo<Adapter>>>(); adapters = new HashMap<String, List<ComponentInfo<Adapter>>>();
managers = new HashMap<String, ComponentInfo<Manager>>(); managers = new HashMap<String, ComponentInfo<Manager>>();
checkers = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
daos = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>>(); daos = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>>();
value = null; value = null;
parent = null; parent = null;
@ -966,6 +977,12 @@ public class ComponentLocator implements ComponentLocatorMBean {
daos.put(key, info); daos.put(key, info);
} }
currentInfo = info; currentInfo = info;
} else if (qName.equals("checker")) {
ComponentInfo<SystemIntegrityChecker> info = new ComponentInfo<SystemIntegrityChecker>();
fillInfo(atts, SystemIntegrityChecker.class, info);
checkers.put(info.name, info);
s_logger.info("Adding system integrity checker: " + info.name);
currentInfo = info;
} else { } else {
// ignore // ignore
} }

View File

@ -24,5 +24,7 @@ package com.cloud.utils.component;
* database upgrades and other verification to make sure it works. * database upgrades and other verification to make sure it works.
*/ */
public interface SystemIntegrityChecker { public interface SystemIntegrityChecker {
public static final String Name = "system-integrity-checker";
void check(); void check();
} }

View File

@ -29,6 +29,7 @@ import net.sf.cglib.proxy.NoOp;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.Ternary; import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
import com.cloud.utils.db.DatabaseCallback; import com.cloud.utils.db.DatabaseCallback;
import com.cloud.utils.db.DatabaseCallbackFilter; import com.cloud.utils.db.DatabaseCallbackFilter;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
@ -62,10 +63,11 @@ public class MockComponentLocator extends ComponentLocator {
} }
@Override @Override
protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>> parse2(String filename) { protected Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>> parse2(String filename) {
Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>> result = new Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>>(new XmlHandler("fake"), new HashMap<String, List<ComponentInfo<Adapter>>>(), new ArrayList<SystemIntegrityChecker>()); Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>> result = new Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>>(new XmlHandler("fake"), new HashMap<String, List<ComponentInfo<Adapter>>>());
_daoMap = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>>(); _daoMap = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>>();
_managerMap = new LinkedHashMap<String, ComponentInfo<Manager>>(); _managerMap = new LinkedHashMap<String, ComponentInfo<Manager>>();
_checkerMap = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
_adapterMap = new HashMap<String, Adapters<? extends Adapter>>(); _adapterMap = new HashMap<String, Adapters<? extends Adapter>>();
_factories = new HashMap<Class<?>, Class<?>>(); _factories = new HashMap<Class<?>, Class<?>>();
_daoMap.putAll(_library.getDaos()); _daoMap.putAll(_library.getDaos());
@ -88,12 +90,7 @@ public class MockComponentLocator extends ComponentLocator {
} }
protected class MockComponentLibrary extends ComponentLibraryBase implements ComponentLibrary { protected class MockComponentLibrary extends ComponentLibraryBase implements ComponentLibrary {
@Override
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
return new ArrayList<SystemIntegrityChecker>();
}
@Override @Override
public Map<String, List<ComponentInfo<Adapter>>> getAdapters() { public Map<String, List<ComponentInfo<Adapter>>> getAdapters() {
return _adapters; return _adapters;