Skip to content

Commit 262e678

Browse files
committed
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
1 parent b06896c commit 262e678

11 files changed

Lines changed: 55 additions & 93 deletions

File tree

‎agent/src/com/cloud/agent/configuration/AgentComponentLibraryBase.java‎

100644100755
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030

3131

3232
public class AgentComponentLibraryBase extends ComponentLibraryBase {
33-
34-
@Override
35-
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
36-
return null;
37-
}
38-
3933
@Override
4034
public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() {
4135
return null;

‎client/tomcatconf/components.xml.in‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
documented, please contact the author.
2424
-->
2525
<components.xml>
26+
<system-integrity-checker class="com.cloud.upgrade.DatabaseUpgradeChecker">
27+
<checker name="ManagementServerNode" class="com.cloud.cluster.ManagementServerNode"/>
28+
<checker name="DatabaseUpgradeChecker" class="com.cloud.upgrade.DatabaseUpgradeChecker"/>
29+
</system-integrity-checker>
30+
2631
<interceptor library="com.cloud.configuration.DefaultInterceptorLibrary"/>
2732
<management-server class="com.cloud.server.ManagementServerImpl" library="com.cloud.configuration.DefaultComponentLibrary">
2833
<adapters key="com.cloud.agent.manager.allocator.HostAllocator">
@@ -99,7 +104,7 @@
99104

100105
</management-server>
101106

102-
<configuration-server class="com.cloud.server.ConfigurationServerImpl" library="com.cloud.configuration.ConfigurationCompoentLibrary">
107+
<configuration-server class="com.cloud.server.ConfigurationServerImpl">
103108
<dao name="Configuration configuration server" class="com.cloud.configuration.dao.ConfigurationDaoImpl" singleton="false">
104109
<param name="premium">false</param>
105110
</dao>

‎server/src/com/cloud/cluster/ManagementServerNode.java‎

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
*/
1818
package com.cloud.cluster;
1919

20+
import javax.ejb.Local;
21+
2022
import com.cloud.utils.component.SystemIntegrityChecker;
2123
import com.cloud.utils.exception.CloudRuntimeException;
2224
import com.cloud.utils.net.MacAddress;
2325

26+
@Local(value = {SystemIntegrityChecker.class})
2427
public class ManagementServerNode implements SystemIntegrityChecker {
2528
private static final long s_nodeId = MacAddress.getMacAddress().toLong();
2629

‎server/src/com/cloud/configuration/ConfigurationCompoentLibrary.java‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎server/src/com/cloud/configuration/DefaultComponentLibrary.java‎

100644100755
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,6 @@
162162
import com.cloud.vm.dao.VMInstanceDaoImpl;
163163

164164
public class DefaultComponentLibrary extends ComponentLibraryBase implements ComponentLibrary {
165-
166-
@Override
167-
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
168-
ArrayList<SystemIntegrityChecker> checkers = new ArrayList<SystemIntegrityChecker>();
169-
checkers.add(new ManagementServerNode());
170-
checkers.add(new DatabaseUpgradeChecker());
171-
return checkers;
172-
}
173-
174165
protected void populateDaos() {
175166
addDao("StackMaidDao", StackMaidDaoImpl.class);
176167
addDao("VMTemplateZoneDao", VMTemplateZoneDaoImpl.class);

‎server/src/com/cloud/servlet/CloudStartupServlet.java‎

100644100755
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.cloud.server.ManagementServer;
3030
import com.cloud.utils.SerialVersionUID;
3131
import com.cloud.utils.component.ComponentLocator;
32+
import com.cloud.utils.component.SystemIntegrityChecker;
33+
3234
import javax.servlet.ServletContextEvent;
3335
import javax.servlet.ServletContextListener;
3436

@@ -40,9 +42,11 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
4042
protected static ComponentLocator s_locator;
4143

4244
@Override
43-
public void init() throws ServletException {
44-
// Save Configuration Values
45-
//ComponentLocator loc = ComponentLocator.getLocator(ConfigurationServer.Name);
45+
public void init() throws ServletException {
46+
/* System Integrity checker will run before all components really loaded */
47+
ComponentLocator.getComponent(SystemIntegrityChecker.Name);
48+
// Save Configuration Values
49+
//ComponentLocator loc = ComponentLocator.getLocator(ConfigurationServer.Name);
4650
ConfigurationServer c = (ConfigurationServer)ComponentLocator.getComponent(ConfigurationServer.Name);
4751
//ConfigurationServer c = new ConfigurationServerImpl();
4852
try {

‎server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java‎

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.List;
3232
import java.util.TreeMap;
3333

34+
import javax.ejb.Local;
35+
3436
import org.apache.log4j.Logger;
3537

3638
import com.cloud.cluster.ClusterManagerImpl;
@@ -58,6 +60,7 @@
5860
import com.cloud.utils.db.Transaction;
5961
import com.cloud.utils.exception.CloudRuntimeException;
6062

63+
@Local(value = {SystemIntegrityChecker.class})
6164
public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
6265
private final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class);
6366

‎utils/src/com/cloud/utils/component/ComponentLibrary.java‎

100644100755
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,7 @@
3333
* within the components.xml overrides the one within ComponentLibrary.
3434
*
3535
*/
36-
public interface ComponentLibrary {
37-
/**
38-
* @return a list of SytemIntegrityCheckers which is run before other
39-
* components are started to check if the system are fit to check
40-
* the system.
41-
*/
42-
List<SystemIntegrityChecker> getSystemIntegrityCheckers();
43-
36+
public interface ComponentLibrary {
4437
/**
4538
* @return all of the daos
4639
*/

‎utils/src/com/cloud/utils/component/ComponentLocator.java‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
9494

9595
protected HashMap<String, Adapters<? extends Adapter>> _adapterMap;
9696
protected HashMap<String, ComponentInfo<Manager>> _managerMap;
97+
protected HashMap<String, ComponentInfo<SystemIntegrityChecker>> _checkerMap;
9798
protected LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>> _daoMap;
9899
protected String _serverName;
99100
protected Object _component;
@@ -123,12 +124,13 @@ public String getName() {
123124
return getLocatorName();
124125
}
125126

126-
protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>> parse2(String filename) {
127+
protected Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>> parse2(String filename) {
127128
try {
128129
SAXParserFactory spfactory = SAXParserFactory.newInstance();
129130
SAXParser saxParser = spfactory.newSAXParser();
130131
_daoMap = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ? extends Serializable>>>();
131132
_managerMap = new LinkedHashMap<String, ComponentInfo<Manager>>();
133+
_checkerMap = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
132134
_adapterMap = new HashMap<String, Adapters<? extends Adapter>>();
133135
_factories = new HashMap<Class<?>, Class<?>>();
134136
File file = PropertiesUtil.findConfigFile(filename);
@@ -157,23 +159,21 @@ protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, Lis
157159
}
158160

159161
ComponentLibrary library = null;
160-
List<SystemIntegrityChecker> checkers = null;
161162
if (handler.library != null) {
162163
Class<?> clazz = Class.forName(handler.library);
163164
library = (ComponentLibrary)clazz.newInstance();
164165
_daoMap.putAll(library.getDaos());
165166
_managerMap.putAll(library.getManagers());
166167
adapters.putAll(library.getAdapters());
167168
_factories.putAll(library.getFactories());
168-
checkers = library.getSystemIntegrityCheckers();
169169
}
170170

171171
_daoMap.putAll(handler.daos);
172172
_managerMap.putAll(handler.managers);
173+
_checkerMap.putAll(handler.checkers);
173174
adapters.putAll(handler.adapters);
174175

175-
return new Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>>(handler, adapters, checkers);
176-
176+
return new Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>>(handler, adapters);
177177
} catch (ParserConfigurationException e) {
178178
s_logger.error("Unable to load " + _serverName + " due to errors while parsing " + filename, e);
179179
System.exit(1);
@@ -194,7 +194,7 @@ protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, Lis
194194
}
195195

196196
protected void parse(String filename) {
197-
Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, List<SystemIntegrityChecker>> result = parse2(filename);
197+
Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>> result = parse2(filename);
198198
if (result == null) {
199199
s_logger.info("Skipping configuration using " + filename);
200200
return;
@@ -203,11 +203,7 @@ protected void parse(String filename) {
203203
XmlHandler handler = result.first();
204204
HashMap<String, List<ComponentInfo<Adapter>>> adapters = result.second();
205205
try {
206-
if (result.third() != null) {
207-
for (SystemIntegrityChecker checker : result.third()) {
208-
checker.check();
209-
}
210-
}
206+
runCheckers();
211207
startDaos(); // daos should not be using managers and adapters.
212208
instantiateAdapters(adapters);
213209
instantiateManagers();
@@ -227,6 +223,19 @@ protected void parse(String filename) {
227223
}
228224
}
229225

226+
protected void runCheckers() {
227+
Set<Map.Entry<String, ComponentInfo<SystemIntegrityChecker>>> entries = _checkerMap.entrySet();
228+
for (Map.Entry<String, ComponentInfo<SystemIntegrityChecker>> entry : entries) {
229+
ComponentInfo<SystemIntegrityChecker> info = entry.getValue();
230+
try {
231+
info.instance = (SystemIntegrityChecker)createInstance(info.clazz, false, info.singleton);
232+
info.instance.check();
233+
} catch (Exception e) {
234+
s_logger.error("Problems with running checker:" + info.name, e);
235+
System.exit(1);
236+
}
237+
}
238+
}
230239
/**
231240
* Daos should not refer to any other components so it is safe to start them
232241
* here.
@@ -848,6 +857,7 @@ public void addParameter(String name, String value) {
848857
protected class XmlHandler extends DefaultHandler {
849858
public HashMap<String, List<ComponentInfo<Adapter>>> adapters;
850859
public HashMap<String, ComponentInfo<Manager>> managers;
860+
public HashMap<String, ComponentInfo<SystemIntegrityChecker>> checkers;
851861
public LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>> daos;
852862
public String parent;
853863
public String library;
@@ -865,6 +875,7 @@ public XmlHandler(String serverName) {
865875
parse = false;
866876
adapters = new HashMap<String, List<ComponentInfo<Adapter>>>();
867877
managers = new HashMap<String, ComponentInfo<Manager>>();
878+
checkers = new HashMap<String, ComponentInfo<SystemIntegrityChecker>>();
868879
daos = new LinkedHashMap<String, ComponentInfo<GenericDao<?, ?>>>();
869880
value = null;
870881
parent = null;
@@ -966,6 +977,12 @@ public void startElement(String namespaceURI, String localName, String qName, At
966977
daos.put(key, info);
967978
}
968979
currentInfo = info;
980+
} else if (qName.equals("checker")) {
981+
ComponentInfo<SystemIntegrityChecker> info = new ComponentInfo<SystemIntegrityChecker>();
982+
fillInfo(atts, SystemIntegrityChecker.class, info);
983+
checkers.put(info.name, info);
984+
s_logger.info("Adding system integrity checker: " + info.name);
985+
currentInfo = info;
969986
} else {
970987
// ignore
971988
}

‎utils/src/com/cloud/utils/component/SystemIntegrityChecker.java‎

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@
2424
* database upgrades and other verification to make sure it works.
2525
*/
2626
public interface SystemIntegrityChecker {
27+
public static final String Name = "system-integrity-checker";
28+
2729
void check();
2830
}

0 commit comments

Comments
 (0)