Package org.opennms.upgrade.api
Class AbstractOnmsUpgrade
- java.lang.Object
-
- org.opennms.upgrade.api.AbstractOnmsUpgrade
-
- All Implemented Interfaces:
OnmsUpgrade
- Direct Known Subclasses:
DataCollectionConfigMigrator17Offline
,DataCollectionConfigMigratorOffline
,DiscoveryConfigurationLocationMigratorOffline
,DiscoveryConfigurationMigratorOffline
,EOLServiceConfigMigratorOffline
,EventParameterMigratorOffline
,JettyConfigMigratorOffline
,JmxRrdMigratorOffline
,KscReportsMigrator
,MagicUsersMigratorOffline
,RemotePollerServiceConfigMigratorOffline
,RequisitionsMigratorOffline
,ServiceConfig1701MigratorOffline
,ServiceConfigMigratorOffline
,SnmpInterfaceRrdMigratorOnline
,VmwareAssetsMigratorOffline
public abstract class AbstractOnmsUpgrade extends java.lang.Object implements OnmsUpgrade
The Abstract class for OpenNMS Upgrade Implementations.This contains the basic methods that may be required for several implementations.
- Author:
- Alejandro Galue
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractOnmsUpgrade.VersionOperator
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ZIP_EXT
The Constant ZIP_EXT.
-
Constructor Summary
Constructors Constructor Description AbstractOnmsUpgrade()
Instantiates a new abstract OpenNMS upgrade.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.sql.Connection
getDbConnection()
Gets the DB connection.protected java.io.File[]
getFiles(java.io.File resourceDir, java.lang.String ext)
Gets the files.protected java.lang.String
getHomeDirectory()
Gets the home directory.java.lang.String
getId()
Gets the id.protected int[]
getInstalledVersion()
protected java.util.Properties
getMainProperties()
Gets the main properties.java.lang.String
getOpennmsProductDescription()
Gets the OpenNMS product description.java.lang.String
getOpennmsProductName()
Gets the OpenNMS product name.protected java.lang.String
getOpennmsVersion()
Gets the currently installed OpenNMS version.protected java.lang.String
getRrdExtension()
Gets the RRD extension.protected java.util.Properties
getRrdProperties()
Gets the RRD properties.protected java.lang.String
getRrdStrategy()
Gets the RRD strategy.protected void
initializeDatasource()
Initializes the data source.protected boolean
isInstalledVersion(AbstractOnmsUpgrade.VersionOperator op, int mayor, int minor, int release)
protected boolean
isInstalledVersionGreaterOrEqual(int mayor, int minor, int release)
Checks if the installed version of OpenNMS is greater or equals than the supplied version.boolean
isMeridian()
Checks if is meridian.protected boolean
isRrdToolEnabled()
Checks if is RRDtool enabled.protected boolean
isStoreByForeignSourceEnabled()
Checks if storeByForeignSource is enabled.protected boolean
isStoreByGroupEnabled()
Checks if storeByGroup is enabled.protected void
loadProperties(java.util.Properties properties, java.lang.String fileName)
Load properties.protected void
log(java.lang.String msgFormat, java.lang.Object... args)
Log.protected void
printFullSettings()
Prints the full settings.protected void
printMainSettings()
Prints the settings.protected void
registerProperties(java.util.Properties properties)
Register properties.protected void
setProductDescription(java.lang.String productDescription)
Sets the product description.protected void
setProductName(java.lang.String productName)
Sets the product name.protected void
setVersion(java.lang.String version)
Sets the version.protected void
unzipFile(java.io.File zipFile, java.io.File outputFolder)
UNZIP a file.protected static int
versionToInteger(int mayor, int minor, int release)
protected void
zipDir(java.io.File zipFile, java.io.File sourceFolder)
ZIP a directory.protected java.io.File
zipFile(java.io.File sourceFile)
ZIP a file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opennms.upgrade.api.OnmsUpgrade
execute, getDescription, getOrder, postExecute, preExecute, requiresOnmsRunning, rollback
-
-
-
-
Field Detail
-
ZIP_EXT
public static final java.lang.String ZIP_EXT
The Constant ZIP_EXT.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractOnmsUpgrade
public AbstractOnmsUpgrade() throws OnmsUpgradeException
Instantiates a new abstract OpenNMS upgrade.- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
-
Method Detail
-
setVersion
protected void setVersion(java.lang.String version)
Sets the version.This method is intended for JUnit tests.
- Parameters:
version
- the new version
-
setProductName
protected void setProductName(java.lang.String productName)
Sets the product name.This method is intended for JUnit tests.
- Parameters:
productName
- the new product name
-
setProductDescription
protected void setProductDescription(java.lang.String productDescription)
Sets the product description.This method is intended for JUnit tests.
- Parameters:
productDescription
- the new product description
-
getId
public java.lang.String getId()
Description copied from interface:OnmsUpgrade
Gets the id.This is for informational purposes, and will be used to store the execution status.
It is recommended to use the class-name, but any other text can be used.
- Specified by:
getId
in interfaceOnmsUpgrade
- Returns:
- the id
-
getHomeDirectory
protected java.lang.String getHomeDirectory()
Gets the home directory.- Returns:
- the home directory
-
getFiles
protected java.io.File[] getFiles(java.io.File resourceDir, java.lang.String ext)
Gets the files.- Parameters:
resourceDir
- the resource directoryext
- the file extension- Returns:
- the files
-
registerProperties
protected void registerProperties(java.util.Properties properties)
Register properties.- Parameters:
properties
- the properties
-
loadProperties
protected void loadProperties(java.util.Properties properties, java.lang.String fileName) throws OnmsUpgradeException
Load properties.- Parameters:
properties
- the propertiesfileName
- the file name- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getMainProperties
protected java.util.Properties getMainProperties() throws OnmsUpgradeException
Gets the main properties.- Returns:
- the main properties
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getRrdProperties
protected java.util.Properties getRrdProperties() throws OnmsUpgradeException
Gets the RRD properties.- Returns:
- the RRD properties
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
isStoreByGroupEnabled
protected boolean isStoreByGroupEnabled()
Checks if storeByGroup is enabled.- Returns:
- true, if storeByGroup is enabled
-
isStoreByForeignSourceEnabled
protected boolean isStoreByForeignSourceEnabled()
Checks if storeByForeignSource is enabled.- Returns:
- true, if storeByForeignSource is enabled
-
getRrdStrategy
protected java.lang.String getRrdStrategy() throws OnmsUpgradeException
Gets the RRD strategy.- Returns:
- the RRD strategy
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
isRrdToolEnabled
protected boolean isRrdToolEnabled() throws OnmsUpgradeException
Checks if is RRDtool enabled.- Returns:
- true, if is RRDtool enabled
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getRrdExtension
protected java.lang.String getRrdExtension() throws OnmsUpgradeException
Gets the RRD extension.- Returns:
- the RRD extension
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getDbConnection
protected java.sql.Connection getDbConnection() throws OnmsUpgradeException
Gets the DB connection.- Returns:
- the DB connection
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
initializeDatasource
protected void initializeDatasource() throws OnmsUpgradeException
Initializes the data source.- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
zipDir
protected void zipDir(java.io.File zipFile, java.io.File sourceFolder) throws OnmsUpgradeException
ZIP a directory.- Parameters:
zipFile
- the output ZIP filesourceFolder
- the source folder- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
zipFile
protected java.io.File zipFile(java.io.File sourceFile) throws OnmsUpgradeException
ZIP a file.The name of the ZIP file will be the name of the source file plus ".zip"
- Parameters:
sourceFile
- the source file- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
unzipFile
protected void unzipFile(java.io.File zipFile, java.io.File outputFolder) throws OnmsUpgradeException
UNZIP a file.- Parameters:
zipFile
- the input ZIP fileoutputFolder
- the output folder- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getOpennmsVersion
protected java.lang.String getOpennmsVersion() throws OnmsUpgradeException
Gets the currently installed OpenNMS version.- Returns:
- the OpenNMS version
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getOpennmsProductName
public java.lang.String getOpennmsProductName()
Gets the OpenNMS product name.- Returns:
- the OpenNMS product name
-
getOpennmsProductDescription
public java.lang.String getOpennmsProductDescription()
Gets the OpenNMS product description.- Returns:
- the OpenNMS product description
-
isMeridian
public boolean isMeridian()
Checks if is meridian.- Returns:
- true, if is meridian
-
isInstalledVersion
protected boolean isInstalledVersion(AbstractOnmsUpgrade.VersionOperator op, int mayor, int minor, int release) throws OnmsUpgradeException
- Throws:
OnmsUpgradeException
-
isInstalledVersionGreaterOrEqual
protected boolean isInstalledVersionGreaterOrEqual(int mayor, int minor, int release) throws OnmsUpgradeException
Checks if the installed version of OpenNMS is greater or equals than the supplied version.- Parameters:
mayor
- the mayorminor
- the minorrelease
- the release- Returns:
- true, if the current installed version is greater or equals than $major.$minor.$release
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getInstalledVersion
protected int[] getInstalledVersion() throws OnmsUpgradeException
- Throws:
OnmsUpgradeException
-
versionToInteger
protected static int versionToInteger(int mayor, int minor, int release) throws OnmsUpgradeException
- Throws:
OnmsUpgradeException
-
printMainSettings
protected void printMainSettings() throws OnmsUpgradeException
Prints the settings.- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
printFullSettings
protected void printFullSettings() throws OnmsUpgradeException
Prints the full settings.- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
log
protected void log(java.lang.String msgFormat, java.lang.Object... args)
Log.- Parameters:
msgFormat
- the message formatargs
- the message's arguments
-
-