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 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
-
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 Connection
getDbConnection()
Gets the DB connection.protected File[]
getFiles(File resourceDir, String ext)
Gets the files.protected String
getHomeDirectory()
Gets the home directory.String
getId()
Gets the id.protected int[]
getInstalledVersion()
protected Properties
getMainProperties()
Gets the main properties.String
getOpennmsProductDescription()
Gets the OpenNMS product description.String
getOpennmsProductName()
Gets the OpenNMS product name.protected String
getOpennmsVersion()
Gets the currently installed OpenNMS version.protected String
getRrdExtension()
Gets the RRD extension.protected Properties
getRrdProperties()
Gets the RRD properties.protected 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(Properties properties, String fileName)
Load properties.protected void
log(String msgFormat, Object... args)
Log.protected void
printFullSettings()
Prints the full settings.protected void
printMainSettings()
Prints the settings.protected void
registerProperties(Properties properties)
Register properties.protected void
setProductDescription(String productDescription)
Sets the product description.protected void
setProductName(String productName)
Sets the product name.protected void
setVersion(String version)
Sets the version.protected void
unzipFile(File zipFile, File outputFolder)
UNZIP a file.protected static int
versionToInteger(int mayor, int minor, int release)
protected void
zipDir(File zipFile, File sourceFolder)
ZIP a directory.protected File
zipFile(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 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(String version)
Sets the version.This method is intended for JUnit tests.
- Parameters:
version
- the new version
-
setProductName
protected void setProductName(String productName)
Sets the product name.This method is intended for JUnit tests.
- Parameters:
productName
- the new product name
-
setProductDescription
protected void setProductDescription(String productDescription)
Sets the product description.This method is intended for JUnit tests.
- Parameters:
productDescription
- the new product description
-
getId
public 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 String getHomeDirectory()
Gets the home directory.- Returns:
- the home directory
-
getFiles
protected File[] getFiles(File resourceDir, String ext)
Gets the files.- Parameters:
resourceDir
- the resource directoryext
- the file extension- Returns:
- the files
-
registerProperties
protected void registerProperties(Properties properties)
Register properties.- Parameters:
properties
- the properties
-
loadProperties
protected void loadProperties(Properties properties, String fileName) throws OnmsUpgradeException
Load properties.- Parameters:
properties
- the propertiesfileName
- the file name- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getMainProperties
protected Properties getMainProperties() throws OnmsUpgradeException
Gets the main properties.- Returns:
- the main properties
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getRrdProperties
protected 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 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 String getRrdExtension() throws OnmsUpgradeException
Gets the RRD extension.- Returns:
- the RRD extension
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getDbConnection
protected 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(File zipFile, File sourceFolder) throws OnmsUpgradeException
ZIP a directory.- Parameters:
zipFile
- the output ZIP filesourceFolder
- the source folder- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
zipFile
protected File zipFile(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(File zipFile, File outputFolder) throws OnmsUpgradeException
UNZIP a file.- Parameters:
zipFile
- the input ZIP fileoutputFolder
- the output folder- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getOpennmsVersion
protected String getOpennmsVersion() throws OnmsUpgradeException
Gets the currently installed OpenNMS version.- Returns:
- the OpenNMS version
- Throws:
OnmsUpgradeException
- the OpenNMS upgrade exception
-
getOpennmsProductName
public String getOpennmsProductName()
Gets the OpenNMS product name.- Returns:
- the OpenNMS product name
-
getOpennmsProductDescription
public 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
-
-