Skip to content

Commit

Permalink
Reverted core/upgrade/src/main/resources/default/service-configuratio…
Browse files Browse the repository at this point in the history
…n.xml

back to the 14.0.0 version and changed the ServiceConfigMigratorOffline
test that uses it to only run against installed versions earlier than 14.0.0.
  • Loading branch information
soleger authored and Benjamin Reed committed Nov 24, 2015
1 parent a4c71ce commit 0690ead
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,36 @@ public boolean isMeridian() {
return getOpennmsProductName().equals(MERIDIAN);
}

public static enum VersionOperator {
LT,
LE,
EQ,
GE,
GT
}

protected boolean isInstalledVersion(VersionOperator op, int mayor, int minor, int release) throws OnmsUpgradeException {
int[] installedVersion = getInstalledVersion();

int supplied = versionToInteger(mayor, minor, release);
int installed = versionToInteger(installedVersion[0], installedVersion[1], installedVersion[2]);

switch(op) {
case LT:
return installed < supplied;
case LE:
return installed <= supplied;
case EQ:
return installed == supplied;
case GE:
return installed >= supplied;
case GT:
return installed > supplied;
}

throw new OnmsUpgradeException("Should never happen.");
}

/**
* Checks if the installed version of OpenNMS is greater or equals than the supplied version.
*
Expand All @@ -532,18 +562,20 @@ public boolean isMeridian() {
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
protected boolean isInstalledVersionGreaterOrEqual(int mayor, int minor, int release) throws OnmsUpgradeException {
return isInstalledVersion(VersionOperator.GE, mayor, minor, release);
}

protected int[] getInstalledVersion() throws OnmsUpgradeException {
String version = getOpennmsVersion();
String[] a = version.split("\\.");
int c_major = isMeridian() ? Integer.parseInt(a[0]) + 13 : Integer.parseInt(a[0]); // Meridian ~ 14.0.4
int c_minor = isMeridian() ? Integer.parseInt(a[1]) + 1 :Integer.parseInt(a[1]); // Be sure it's greater than 14.0.3
int c_release = Integer.parseInt(a[2]);
try {
int supplied = mayor * 100 + minor * 10 + release;
int installed = c_major * 100 + c_minor * 10 + c_release;
return installed >= supplied;
} catch (Exception e) {
throw new OnmsUpgradeException("Can't process the OpenNMS version");
}
return new int[] { c_major, c_minor, c_release };
}

protected static int versionToInteger(int mayor, int minor, int release) throws OnmsUpgradeException {
return (mayor * 100 + minor * 10 + release);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void preExecute() throws OnmsUpgradeException {
zipDir(new File(jmxResourceDir.getAbsolutePath() + ZIP_EXT), jmxResourceDir);
}
} else {
throw new OnmsUpgradeException("This upgrade procedure requires at least OpenNMS 1.12.2, the current version is " + getOpennmsVersion());
throw new OnmsUpgradeException("This upgrade procedure requires at least OpenNMS 1.12.2; the current version is " + getOpennmsVersion());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@
*/
public class ServiceConfigMigratorOffline extends AbstractOnmsUpgrade {

/** The base configuration object (or configuration reference). */
/**
* The base configuration object (or configuration reference).
*/
private ServiceConfiguration baseConfig;

/** The services configuration file. */
/**
* The services configuration file.
*/
private File configFile;

/**
* Flag to skip the upgrade if the installed version is 14.0.0 or higher.
*/
private boolean skipMe = false;

/**
* Instantiates a new Service Configuration migrator offline.
*
Expand Down Expand Up @@ -106,6 +115,11 @@ public boolean requiresOnmsRunning() {
*/
@Override
public void preExecute() throws OnmsUpgradeException {
if (isInstalledVersionGreaterOrEqual(14, 0, 0)) {
log("This upgrade procedure should only run against systems older than 14.0.0; the current version is " + getOpennmsVersion() + "\n");
skipMe = true;
return;
}
try {
log("Backing up %s\n", configFile);
zipFile(configFile);
Expand All @@ -119,6 +133,7 @@ public void preExecute() throws OnmsUpgradeException {
*/
@Override
public void postExecute() throws OnmsUpgradeException {
if (skipMe) return;
File zip = new File(configFile.getAbsolutePath() + ZIP_EXT);
if (zip.exists()) {
log("Removing backup %s\n", zip);
Expand All @@ -131,6 +146,7 @@ public void postExecute() throws OnmsUpgradeException {
*/
@Override
public void rollback() throws OnmsUpgradeException {
if (skipMe) return;
log("Restoring backup %s\n", configFile);
File zip = new File(configFile.getAbsolutePath() + ZIP_EXT);
FileUtils.deleteQuietly(configFile);
Expand All @@ -142,6 +158,7 @@ public void rollback() throws OnmsUpgradeException {
*/
@Override
public void execute() throws OnmsUpgradeException {
if (skipMe) return;
try {
ServiceConfiguration currentCfg = JaxbUtils.unmarshal(ServiceConfiguration.class, configFile);
int index = 0;
Expand Down Expand Up @@ -170,9 +187,13 @@ public void execute() throws OnmsUpgradeException {
}
Attribute a = getLoggingPrefix(localSvc);
if (a != null) {
log("Fixing logging prefix for service %s\n", localSvc.getName());
String prefix = a.getValue().getContent().toLowerCase();
a.getValue().setContent(prefix);
// If the logging prefix isn't already lower case...
if (!a.getValue().getContent().equals(prefix)) {
// then set it to the lower case value
log("Fixing logging prefix for service %s\n", localSvc.getName());
a.getValue().setContent(prefix);
}
}
index++;
}
Expand Down Expand Up @@ -200,7 +221,7 @@ public void execute() throws OnmsUpgradeException {
* @param serviceName the service name
* @return the service
*/
private Service getService(ServiceConfiguration svcConfig, String serviceName) {
private static Service getService(ServiceConfiguration svcConfig, String serviceName) {
for(Service s : svcConfig.getServiceCollection()) {
if (s.getName().equals(serviceName)) {
return s;
Expand All @@ -215,7 +236,7 @@ private Service getService(ServiceConfiguration svcConfig, String serviceName) {
* @param svc the OpenNMS service
* @return the logging prefix attribute
*/
private Attribute getLoggingPrefix(Service svc) {
private static Attribute getLoggingPrefix(Service svc) {
for (Attribute a : svc.getAttributeCollection()) {
if (a.getName().equals("LoggingPrefix")) {
return a;
Expand Down
24 changes: 24 additions & 0 deletions core/upgrade/src/main/resources/default/service-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@
<invoke at="status" pass="0" method="status"/>
<invoke at="stop" pass="0" method="stop"/>
</service>
<service enabled="false">
<name>OpenNMS:Name=Linkd</name>
<class-name>org.opennms.netmgt.linkd.jmx.Linkd</class-name>
<invoke at="start" pass="0" method="init"/>
<invoke at="start" pass="1" method="start"/>
<invoke at="status" pass="0" method="status"/>
<invoke at="stop" pass="0" method="stop"/>
</service>
<service enabled="false">
<name>OpenNMS:Name=Correlator</name>
<class-name>org.opennms.netmgt.correlation.jmx.Correlator</class-name>
Expand All @@ -319,6 +327,22 @@
<invoke at="status" pass="0" method="status"/>
<invoke at="stop" pass="0" method="stop"/>
</service>
<service enabled="false">
<name>OpenNMS:Name=Xmlrpcd</name>
<class-name>org.opennms.netmgt.xmlrpcd.jmx.Xmlrpcd</class-name>
<invoke at="start" pass="0" method="init"/>
<invoke at="start" pass="1" method="start"/>
<invoke at="status" pass="0" method="status"/>
<invoke at="stop" pass="0" method="stop"/>
</service>
<service enabled="false">
<name>OpenNMS:Name=XmlrpcProvisioner</name>
<class-name>org.opennms.netmgt.xmlrpcd.jmx.Provisioner</class-name>
<invoke at="start" pass="0" method="init"/>
<invoke at="start" pass="1" method="start"/>
<invoke at="status" pass="0" method="status"/>
<invoke at="stop" pass="0" method="stop"/>
</service>
<service enabled="false">
<name>OpenNMS:Name=AsteriskGateway</name>
<class-name>org.opennms.netmgt.asterisk.agi.jmx.AsteriskGateway</class-name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public void testFixingConfig() throws Exception {
// Checking parsing the fixed file (it should contain all the services)
File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.SERVICE_CONF_FILE_NAME);
ServiceConfiguration cfg = JaxbUtils.unmarshal(ServiceConfiguration.class, cfgFile);
Assert.assertEquals(35, cfg.getServiceCount());

// Do not change this value: the config file behind this test should always contain
// the content for OpenNMS 14.0.0, regardless of whether or not services are added,
// changed, or removed in the latest version.
Assert.assertEquals(38, cfg.getServiceCount());

// Checking Service Factory (it should return only the enabled services)
ServiceConfigFactory factory = new ServiceConfigFactory();
Expand Down

0 comments on commit 0690ead

Please sign in to comment.