Package org.opennms.core.schema
Class Migrator
- java.lang.Object
-
- org.opennms.core.schema.Migrator
-
public class Migrator extends java.lang.Object
Migrator class.
- Version:
- $Id: $
- Author:
- ranger
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
LIQUIBASE_CHANGELOG_FILENAME
static java.lang.String
LIQUIBASE_CHANGELOG_LOCATION_PATTERN
-
Constructor Summary
Constructors Constructor Description Migrator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTimescaleDBExtension(boolean isNewDatabase)
This method creates the Timescale extension If is a new database will add it to template1 so any other database created after has access to Timescale extension If the database (opennms) already exists the it will enfoce the extension on that database and template1.void
addTimescaleDBExtensionOnDatabase()
This method creates the Timescale extension on the user database (opennms) and then on template1 to give access to the extension to new databases.void
checkTime()
void
checkUnicode()
checkUnicodevoid
createDatabase()
createDatabasevoid
createLangPlPgsql()
createLangPlPgsqlstatic java.util.function.Predicate<org.springframework.core.io.Resource>
createProductionLiquibaseChangelogFilter()
void
createSchema()
void
createUser()
createUserboolean
databaseExists()
databaseExistsboolean
databaseExists(java.lang.String databaseName)
void
databaseSetOwner()
databaseSetUserboolean
databaseUserExists()
databaseUserExistsvoid
dropDatabase()
dropDatabasevoid
dropExistingIpLike()
javax.sql.DataSource
getAdminDataSource()
getAdminDataSourcejava.lang.String
getAdminPassword()
getAdminPasswordjava.lang.String
getAdminUser()
getAdminUserorg.springframework.context.ApplicationContext
getApplicationContext()
static java.lang.String
getClassLoaderUrls(java.lang.ClassLoader classLoader)
java.lang.String
getContextClassLoaderUrls()
java.lang.String
getDatabaseName()
getDatabaseNamejava.lang.String
getDatabasePassword()
getDatabasePasswordjava.lang.String
getDatabaseUser()
getDatabaseUserjava.lang.Float
getDatabaseVersion()
getDatabaseVersionjavax.sql.DataSource
getDataSource()
getDataSourcejava.util.Collection<org.springframework.core.io.Resource>
getLiquibaseChangelogs(boolean required)
static java.lang.String
getLiquibaseContexts()
static java.lang.String
getResourceLoaderClassLoaderUrls(org.springframework.core.io.ResourceLoader resourceLoader)
java.lang.String
getSchemaName()
static java.lang.String
getSystemClassLoaderUrls()
boolean
isIpLikeUsable()
isIpLikeUsablevoid
migrate(org.springframework.core.io.Resource changelog)
migratevoid
prepareDatabase()
prepareDatabaseboolean
schemaExists()
void
setAdminDataSource(javax.sql.DataSource dataSource)
setAdminDataSourcevoid
setAdminPassword(java.lang.String adminPassword)
setAdminPasswordvoid
setAdminUser(java.lang.String adminUser)
setAdminUservoid
setApplicationContext(org.springframework.context.ApplicationContext context)
void
setCreateDatabase(boolean createDatabase)
setCreateDatabasevoid
setCreateUser(boolean createUser)
setCreateUservoid
setDatabaseName(java.lang.String databaseName)
setDatabaseNamevoid
setDatabasePassword(java.lang.String databasePassword)
setDatabasePasswordvoid
setDatabaseUser(java.lang.String databaseUser)
setDatabaseUservoid
setDataSource(javax.sql.DataSource dataSource)
setDataSourcevoid
setLiquibaseChangelogFilter(java.util.function.Predicate<org.springframework.core.io.Resource> tester)
void
setSchemaName(java.lang.String schemaName)
void
setupDatabase(boolean updateDatabase, boolean vacuum, boolean fullVacuum, boolean iplike, boolean timescaleDB)
void
setupPlPgsqlIplike()
setupPlPgsqlIplikevoid
setValidateDatabaseVersion(boolean validate)
setValidateDatabaseVersionvoid
updateIplike()
updateIplikevoid
vacuumDatabase(boolean full)
vacuumDatabasevoid
validateDatabaseVersion()
validateDatabaseVersion
-
-
-
Field Detail
-
LIQUIBASE_CHANGELOG_FILENAME
public static final java.lang.String LIQUIBASE_CHANGELOG_FILENAME
- See Also:
- Constant Field Values
-
LIQUIBASE_CHANGELOG_LOCATION_PATTERN
public static final java.lang.String LIQUIBASE_CHANGELOG_LOCATION_PATTERN
- See Also:
- Constant Field Values
-
-
Method Detail
-
createProductionLiquibaseChangelogFilter
public static java.util.function.Predicate<org.springframework.core.io.Resource> createProductionLiquibaseChangelogFilter()
-
getDataSource
public javax.sql.DataSource getDataSource()
getDataSource
- Returns:
- a
DataSource
object.
-
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
setDataSource
- Parameters:
dataSource
- aDataSource
object.
-
getAdminDataSource
public javax.sql.DataSource getAdminDataSource()
getAdminDataSource
- Returns:
- a
DataSource
object.
-
setAdminDataSource
public void setAdminDataSource(javax.sql.DataSource dataSource)
setAdminDataSource
- Parameters:
dataSource
- aDataSource
object.
-
setValidateDatabaseVersion
public void setValidateDatabaseVersion(boolean validate)
setValidateDatabaseVersion
- Parameters:
validate
- a boolean.
-
setCreateUser
public void setCreateUser(boolean createUser)
setCreateUser
- Parameters:
createUser
- a boolean.
-
setCreateDatabase
public void setCreateDatabase(boolean createDatabase)
setCreateDatabase
- Parameters:
createDatabase
- a boolean.
-
setLiquibaseChangelogFilter
public void setLiquibaseChangelogFilter(java.util.function.Predicate<org.springframework.core.io.Resource> tester)
-
getDatabaseName
public java.lang.String getDatabaseName()
getDatabaseName
- Returns:
- a
String
object.
-
setDatabaseName
public void setDatabaseName(java.lang.String databaseName)
setDatabaseName
- Parameters:
databaseName
- aString
object.
-
getSchemaName
public java.lang.String getSchemaName()
-
setSchemaName
public void setSchemaName(java.lang.String schemaName)
-
getDatabaseUser
public java.lang.String getDatabaseUser()
getDatabaseUser
- Returns:
- a
String
object.
-
setDatabaseUser
public void setDatabaseUser(java.lang.String databaseUser)
setDatabaseUser
- Parameters:
databaseUser
- aString
object.
-
getDatabasePassword
public java.lang.String getDatabasePassword()
getDatabasePassword
- Returns:
- a
String
object.
-
setDatabasePassword
public void setDatabasePassword(java.lang.String databasePassword)
setDatabasePassword
- Parameters:
databasePassword
- aString
object.
-
getAdminUser
public java.lang.String getAdminUser()
getAdminUser
- Returns:
- a
String
object.
-
setAdminUser
public void setAdminUser(java.lang.String adminUser)
setAdminUser
- Parameters:
adminUser
- aString
object.
-
getAdminPassword
public java.lang.String getAdminPassword()
getAdminPassword
- Returns:
- a
String
object.
-
setAdminPassword
public void setAdminPassword(java.lang.String adminPassword)
setAdminPassword
- Parameters:
adminPassword
- aString
object.
-
getDatabaseVersion
public java.lang.Float getDatabaseVersion() throws MigrationException
getDatabaseVersion
- Returns:
- a
Float
object. - Throws:
MigrationException
- if any.
-
validateDatabaseVersion
public void validateDatabaseVersion() throws MigrationException
validateDatabaseVersion
- Throws:
MigrationException
- if any.
-
createLangPlPgsql
public void createLangPlPgsql() throws MigrationException
createLangPlPgsql
- Throws:
MigrationException
- if any.
-
databaseUserExists
public boolean databaseUserExists() throws MigrationException
databaseUserExists
- Returns:
- a boolean.
- Throws:
MigrationException
- if any.
-
createUser
public void createUser() throws MigrationException
createUser
- Throws:
MigrationException
- if any.
-
databaseExists
public boolean databaseExists() throws MigrationException
databaseExists
- Returns:
- a boolean.
- Throws:
MigrationException
- if any.
-
databaseExists
public boolean databaseExists(java.lang.String databaseName) throws MigrationException
- Throws:
MigrationException
-
createSchema
public void createSchema() throws MigrationException
- Throws:
MigrationException
-
schemaExists
public boolean schemaExists() throws MigrationException
- Throws:
MigrationException
-
createDatabase
public void createDatabase() throws MigrationException
createDatabase
- Throws:
MigrationException
- if any.
-
checkUnicode
public void checkUnicode() throws java.lang.Exception
checkUnicode
- Throws:
java.lang.Exception
- if any.
-
databaseSetOwner
public void databaseSetOwner() throws MigrationException
databaseSetUser
- Throws:
java.sql.SQLException
- if any.MigrationException
-
vacuumDatabase
public void vacuumDatabase(boolean full) throws MigrationException
vacuumDatabase
- Parameters:
full
- a boolean.- Throws:
java.sql.SQLException
- if any.MigrationException
-
updateIplike
public void updateIplike() throws MigrationException
updateIplike
- Throws:
java.lang.Exception
- if any.MigrationException
-
isIpLikeUsable
public boolean isIpLikeUsable() throws MigrationException
isIpLikeUsable
- Returns:
- a boolean.
- Throws:
MigrationException
-
dropExistingIpLike
public void dropExistingIpLike() throws MigrationException
- Throws:
MigrationException
-
setupPlPgsqlIplike
public void setupPlPgsqlIplike() throws MigrationException
setupPlPgsqlIplike
- Throws:
java.lang.Exception
- if any.MigrationException
-
dropDatabase
public void dropDatabase() throws MigrationException
dropDatabase
- Throws:
java.sql.SQLException
- if any.MigrationException
-
addTimescaleDBExtension
public void addTimescaleDBExtension(boolean isNewDatabase) throws MigrationException
This method creates the Timescale extension If is a new database will add it to template1 so any other database created after has access to Timescale extension If the database (opennms) already exists the it will enfoce the extension on that database and template1.- Parameters:
isNewDatabase
-- Throws:
MigrationException
-
addTimescaleDBExtensionOnDatabase
public void addTimescaleDBExtensionOnDatabase() throws MigrationException
This method creates the Timescale extension on the user database (opennms) and then on template1 to give access to the extension to new databases.- Throws:
MigrationException
-
prepareDatabase
public void prepareDatabase() throws MigrationException
prepareDatabase
- Throws:
MigrationException
- if any.
-
migrate
public void migrate(org.springframework.core.io.Resource changelog) throws MigrationException
migrate
- Parameters:
changelog
-- Throws:
MigrationException
- if any.
-
getLiquibaseContexts
public static java.lang.String getLiquibaseContexts()
-
checkTime
public void checkTime() throws java.lang.Exception
- Throws:
java.lang.Exception
-
setupDatabase
public void setupDatabase(boolean updateDatabase, boolean vacuum, boolean fullVacuum, boolean iplike, boolean timescaleDB) throws MigrationException, java.lang.Exception, java.io.IOException
- Throws:
MigrationException
java.lang.Exception
java.io.IOException
-
getLiquibaseChangelogs
public java.util.Collection<org.springframework.core.io.Resource> getLiquibaseChangelogs(boolean required) throws java.io.IOException, java.lang.Exception
- Throws:
java.io.IOException
java.lang.Exception
-
getContextClassLoaderUrls
public java.lang.String getContextClassLoaderUrls()
-
getSystemClassLoaderUrls
public static java.lang.String getSystemClassLoaderUrls()
-
getResourceLoaderClassLoaderUrls
public static java.lang.String getResourceLoaderClassLoaderUrls(org.springframework.core.io.ResourceLoader resourceLoader)
-
getClassLoaderUrls
public static java.lang.String getClassLoaderUrls(java.lang.ClassLoader classLoader)
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext context)
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext()
-
-