mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
9a5304911b
commit
1381c58fa1
6
agent/src/com/cloud/agent/configuration/AgentComponentLibraryBase.java
Normal file → Executable file
6
agent/src/com/cloud/agent/configuration/AgentComponentLibraryBase.java
Normal file → Executable file
@ -30,12 +30,6 @@ import com.cloud.utils.db.GenericDao;
|
||||
|
||||
|
||||
public class AgentComponentLibraryBase extends ComponentLibraryBase {
|
||||
|
||||
@Override
|
||||
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() {
|
||||
return null;
|
||||
|
||||
@ -23,6 +23,11 @@
|
||||
documented, please contact the author.
|
||||
-->
|
||||
<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"/>
|
||||
<management-server class="com.cloud.server.ManagementServerImpl" library="com.cloud.configuration.DefaultComponentLibrary">
|
||||
<adapters key="com.cloud.agent.manager.allocator.HostAllocator">
|
||||
@ -99,7 +104,7 @@
|
||||
|
||||
</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">
|
||||
<param name="premium">false</param>
|
||||
</dao>
|
||||
|
||||
3
server/src/com/cloud/cluster/ManagementServerNode.java
Normal file → Executable file
3
server/src/com/cloud/cluster/ManagementServerNode.java
Normal file → Executable file
@ -17,10 +17,13 @@
|
||||
*/
|
||||
package com.cloud.cluster;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.MacAddress;
|
||||
|
||||
@Local(value = {SystemIntegrityChecker.class})
|
||||
public class ManagementServerNode implements SystemIntegrityChecker {
|
||||
private static final long s_nodeId = MacAddress.getMacAddress().toLong();
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
9
server/src/com/cloud/configuration/DefaultComponentLibrary.java
Normal file → Executable file
9
server/src/com/cloud/configuration/DefaultComponentLibrary.java
Normal file → Executable file
@ -157,15 +157,6 @@ import com.cloud.vm.dao.UserVmDetailsDaoImpl;
|
||||
import com.cloud.vm.dao.VMInstanceDaoImpl;
|
||||
|
||||
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() {
|
||||
addDao("StackMaidDao", StackMaidDaoImpl.class);
|
||||
addDao("VMTemplateZoneDao", VMTemplateZoneDaoImpl.class);
|
||||
|
||||
4
server/src/com/cloud/servlet/CloudStartupServlet.java
Normal file → Executable file
4
server/src/com/cloud/servlet/CloudStartupServlet.java
Normal file → Executable file
@ -29,6 +29,8 @@ import com.cloud.server.ConfigurationServer;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
@ -41,6 +43,8 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
/* System Integrity checker will run before all components really loaded */
|
||||
ComponentLocator.getComponent(SystemIntegrityChecker.Name);
|
||||
// Save Configuration Values
|
||||
//ComponentLocator loc = ComponentLocator.getLocator(ConfigurationServer.Name);
|
||||
ConfigurationServer c = (ConfigurationServer)ComponentLocator.getComponent(ConfigurationServer.Name);
|
||||
|
||||
3
server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
Normal file → Executable file
3
server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
Normal file → Executable file
@ -31,6 +31,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
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.exception.CloudRuntimeException;
|
||||
|
||||
@Local(value = {SystemIntegrityChecker.class})
|
||||
public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
|
||||
private final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class);
|
||||
|
||||
|
||||
7
utils/src/com/cloud/utils/component/ComponentLibrary.java
Normal file → Executable file
7
utils/src/com/cloud/utils/component/ComponentLibrary.java
Normal file → Executable file
@ -34,13 +34,6 @@ import com.cloud.utils.db.GenericDao;
|
||||
*
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
||||
@ -94,6 +94,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
|
||||
protected HashMap<String, Adapters<? extends Adapter>> _adapterMap;
|
||||
protected HashMap<String, ComponentInfo<Manager>> _managerMap;
|
||||
protected HashMap<String, ComponentInfo<SystemIntegrityChecker>> _checkerMap;
|
||||
protected LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>> _daoMap;
|
||||
protected String _serverName;
|
||||
protected Object _component;
|
||||
@ -123,12 +124,13 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
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 {
|
||||
SAXParserFactory spfactory = SAXParserFactory.newInstance();
|
||||
SAXParser saxParser = spfactory.newSAXParser();
|
||||
_daoMap = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>>();
|
||||
_managerMap = new LinkedHashMap<String, ComponentInfo<Manager>>();
|
||||
_checkerMap = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
|
||||
_adapterMap = new HashMap<String, Adapters<? extends Adapter>>();
|
||||
_factories = new HashMap<Class<?>, Class<?>>();
|
||||
File file = PropertiesUtil.findConfigFile(filename);
|
||||
@ -157,7 +159,6 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
}
|
||||
|
||||
ComponentLibrary library = null;
|
||||
List<SystemIntegrityChecker> checkers = null;
|
||||
if (handler.library != null) {
|
||||
Class<?> clazz = Class.forName(handler.library);
|
||||
library = (ComponentLibrary)clazz.newInstance();
|
||||
@ -165,15 +166,14 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
_managerMap.putAll(library.getManagers());
|
||||
adapters.putAll(library.getAdapters());
|
||||
_factories.putAll(library.getFactories());
|
||||
checkers = library.getSystemIntegrityCheckers();
|
||||
}
|
||||
|
||||
_daoMap.putAll(handler.daos);
|
||||
_managerMap.putAll(handler.managers);
|
||||
_checkerMap.putAll(handler.checkers);
|
||||
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) {
|
||||
s_logger.error("Unable to load " + _serverName + " due to errors while parsing " + filename, e);
|
||||
System.exit(1);
|
||||
@ -194,7 +194,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
}
|
||||
|
||||
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) {
|
||||
s_logger.info("Skipping configuration using " + filename);
|
||||
return;
|
||||
@ -203,11 +203,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
XmlHandler handler = result.first();
|
||||
HashMap<String, List<ComponentInfo<Adapter>>> adapters = result.second();
|
||||
try {
|
||||
if (result.third() != null) {
|
||||
for (SystemIntegrityChecker checker : result.third()) {
|
||||
checker.check();
|
||||
}
|
||||
}
|
||||
runCheckers();
|
||||
startDaos(); // daos should not be using managers and adapters.
|
||||
instantiateAdapters(adapters);
|
||||
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
|
||||
* here.
|
||||
@ -848,6 +857,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
protected class XmlHandler extends DefaultHandler {
|
||||
public HashMap<String, List<ComponentInfo<Adapter>>> adapters;
|
||||
public HashMap<String, ComponentInfo<Manager>> managers;
|
||||
public HashMap<String, ComponentInfo<SystemIntegrityChecker>> checkers;
|
||||
public LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>> daos;
|
||||
public String parent;
|
||||
public String library;
|
||||
@ -865,6 +875,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
parse = false;
|
||||
adapters = new HashMap<String, List<ComponentInfo<Adapter>>>();
|
||||
managers = new HashMap<String, ComponentInfo<Manager>>();
|
||||
checkers = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
|
||||
daos = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>>();
|
||||
value = null;
|
||||
parent = null;
|
||||
@ -966,6 +977,12 @@ public class ComponentLocator implements ComponentLocatorMBean {
|
||||
daos.put(key, 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 {
|
||||
// ignore
|
||||
}
|
||||
|
||||
2
utils/src/com/cloud/utils/component/SystemIntegrityChecker.java
Normal file → Executable file
2
utils/src/com/cloud/utils/component/SystemIntegrityChecker.java
Normal file → Executable file
@ -24,5 +24,7 @@ package com.cloud.utils.component;
|
||||
* database upgrades and other verification to make sure it works.
|
||||
*/
|
||||
public interface SystemIntegrityChecker {
|
||||
public static final String Name = "system-integrity-checker";
|
||||
|
||||
void check();
|
||||
}
|
||||
|
||||
11
utils/test/com/cloud/utils/component/MockComponentLocator.java
Normal file → Executable file
11
utils/test/com/cloud/utils/component/MockComponentLocator.java
Normal file → Executable file
@ -29,6 +29,7 @@ import net.sf.cglib.proxy.NoOp;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
|
||||
import com.cloud.utils.db.DatabaseCallback;
|
||||
import com.cloud.utils.db.DatabaseCallbackFilter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
@ -62,10 +63,11 @@ public class MockComponentLocator extends ComponentLocator {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>> 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>());
|
||||
protected Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>> parse2(String filename) {
|
||||
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>>>();
|
||||
_managerMap = new LinkedHashMap<String, ComponentInfo<Manager>>();
|
||||
_checkerMap = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
|
||||
_adapterMap = new HashMap<String, Adapters<? extends Adapter>>();
|
||||
_factories = new HashMap<Class<?>, Class<?>>();
|
||||
_daoMap.putAll(_library.getDaos());
|
||||
@ -89,11 +91,6 @@ public class MockComponentLocator extends ComponentLocator {
|
||||
|
||||
protected class MockComponentLibrary extends ComponentLibraryBase implements ComponentLibrary {
|
||||
|
||||
@Override
|
||||
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
|
||||
return new ArrayList<SystemIntegrityChecker>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<ComponentInfo<Adapter>>> getAdapters() {
|
||||
return _adapters;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user