Package org.opennms.core.schema
Class Migrator
- java.lang.Object
-
- org.opennms.core.schema.Migrator
-
public class Migrator extends Object
Migrator class.
- Version:
- $Id: $
- Author:
- ranger
-
-
Field Summary
Fields Modifier and Type Field Description static String
LIQUIBASE_CHANGELOG_FILENAME
static 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(String databaseName)
void
databaseSetOwner()
databaseSetUserboolean
databaseUserExists()
databaseUserExistsvoid
dropDatabase()
dropDatabasevoid
dropExistingIpLike()
DataSource
getAdminDataSource()
getAdminDataSourceString
getAdminPassword()
getAdminPasswordString
getAdminUser()
getAdminUserorg.springframework.context.ApplicationContext
getApplicationContext()
static String
getClassLoaderUrls(ClassLoader classLoader)
String
getContextClassLoaderUrls()
String
getDatabaseName()
getDatabaseNameString
getDatabasePassword()
getDatabasePasswordString
getDatabaseUser()
getDatabaseUserFloat
getDatabaseVersion()
getDatabaseVersionDataSource
getDataSource()
getDataSourceCollection<org.springframework.core.io.Resource>
getLiquibaseChangelogs(boolean required)
static String
getLiquibaseContexts()
static String
getResourceLoaderClassLoaderUrls(org.springframework.core.io.ResourceLoader resourceLoader)
String
getSchemaName()
static String
getSystemClassLoaderUrls()
protected String
getUserForONMSDB()
boolean
isIpLikeUsable()
isIpLikeUsablevoid
migrate(org.springframework.core.io.Resource changelog)
migratevoid
prepareDatabase()
prepareDatabaseboolean
schemaExists()
void
setAdminDataSource(DataSource dataSource)
setAdminDataSourcevoid
setAdminPassword(String adminPassword)
setAdminPasswordvoid
setAdminUser(String adminUser)
setAdminUservoid
setApplicationContext(org.springframework.context.ApplicationContext context)
void
setCreateDatabase(boolean createDatabase)
setCreateDatabasevoid
setCreateUser(boolean createUser)
setCreateUservoid
setDatabaseName(String databaseName)
setDatabaseNamevoid
setDatabasePassword(String databasePassword)
setDatabasePasswordvoid
setDatabaseUser(String databaseUser)
setDatabaseUservoid
setDataSource(DataSource dataSource)
setDataSourcevoid
setLiquibaseChangelogFilter(java.util.function.Predicate<org.springframework.core.io.Resource> tester)
void
setSchemaName(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 String LIQUIBASE_CHANGELOG_FILENAME
- See Also:
- Constant Field Values
-
LIQUIBASE_CHANGELOG_LOCATION_PATTERN
public static final 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 DataSource getDataSource()
getDataSource
- Returns:
- a
DataSource
object.
-
setDataSource
public void setDataSource(DataSource dataSource)
setDataSource
- Parameters:
dataSource
- aDataSource
object.
-
getAdminDataSource
public DataSource getAdminDataSource()
getAdminDataSource
- Returns:
- a
DataSource
object.
-
setAdminDataSource
public void setAdminDataSource(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)
-
setDatabaseName
public void setDatabaseName(String databaseName)
setDatabaseName
- Parameters:
databaseName
- aString
object.
-
getSchemaName
public String getSchemaName()
-
setSchemaName
public void setSchemaName(String schemaName)
-
setDatabaseUser
public void setDatabaseUser(String databaseUser)
setDatabaseUser
- Parameters:
databaseUser
- aString
object.
-
getDatabasePassword
public String getDatabasePassword()
getDatabasePassword
- Returns:
- a
String
object.
-
setDatabasePassword
public void setDatabasePassword(String databasePassword)
setDatabasePassword
- Parameters:
databasePassword
- aString
object.
-
setAdminUser
public void setAdminUser(String adminUser)
setAdminUser
- Parameters:
adminUser
- aString
object.
-
setAdminPassword
public void setAdminPassword(String adminPassword)
setAdminPassword
- Parameters:
adminPassword
- aString
object.
-
getDatabaseVersion
public 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.
-
getUserForONMSDB
protected String getUserForONMSDB()
-
databaseExists
public boolean databaseExists() throws MigrationException
databaseExists
- Returns:
- a boolean.
- Throws:
MigrationException
- if any.
-
databaseExists
public boolean databaseExists(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.
-
databaseSetOwner
public void databaseSetOwner() throws MigrationException
databaseSetUser
- Throws:
SQLException
- if any.MigrationException
-
vacuumDatabase
public void vacuumDatabase(boolean full) throws MigrationException
vacuumDatabase
- Parameters:
full
- a boolean.- Throws:
SQLException
- if any.MigrationException
-
updateIplike
public void updateIplike() throws MigrationException
updateIplike
- Throws:
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:
Exception
- if any.MigrationException
-
dropDatabase
public void dropDatabase() throws MigrationException
dropDatabase
- Throws:
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 String getLiquibaseContexts()
-
setupDatabase
public void setupDatabase(boolean updateDatabase, boolean vacuum, boolean fullVacuum, boolean iplike, boolean timescaleDB) throws MigrationException, Exception, IOException
- Throws:
MigrationException
Exception
IOException
-
getLiquibaseChangelogs
public Collection<org.springframework.core.io.Resource> getLiquibaseChangelogs(boolean required) throws IOException, Exception
- Throws:
IOException
Exception
-
getContextClassLoaderUrls
public String getContextClassLoaderUrls()
-
getSystemClassLoaderUrls
public static String getSystemClassLoaderUrls()
-
getResourceLoaderClassLoaderUrls
public static String getResourceLoaderClassLoaderUrls(org.springframework.core.io.ResourceLoader resourceLoader)
-
getClassLoaderUrls
public static String getClassLoaderUrls(ClassLoader classLoader)
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext context)
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext()
-
-