use of com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration in project midpoint by Evolveum.
the class JdbcPingTaskHandler method run.
@Override
public TaskRunResult run(Task task) {
long progress = task.getProgress();
OperationResult opResult = new OperationResult(JdbcPingTaskHandler.class.getName() + ".run");
int tests = get(task, SchemaConstants.JDBC_PING_TESTS_QNAME, 0);
int interval = get(task, SchemaConstants.JDBC_PING_INTERVAL_QNAME, 10);
String testQuery = get(task, SchemaConstants.JDBC_PING_TEST_QUERY_QNAME, "select 1");
SqlRepositoryConfiguration config = sqlRepositoryFactory != null ? sqlRepositoryFactory.getSqlConfiguration() : null;
String jdbcDriver = get(task, SchemaConstants.JDBC_PING_DRIVER_CLASS_NAME_QNAME, config != null ? config.getDriverClassName() : "");
String jdbcUrl = get(task, SchemaConstants.JDBC_PING_JDBC_URL_QNAME, config != null ? config.getJdbcUrl() : "");
String jdbcUsername = get(task, SchemaConstants.JDBC_PING_JDBC_USERNAME_QNAME, config != null ? config.getJdbcUsername() : "");
String jdbcPassword = get(task, SchemaConstants.JDBC_PING_JDBC_PASSWORD_QNAME, config != null ? config.getJdbcPassword() : "");
boolean logOnInfoLevel = get(task, SchemaConstants.JDBC_PING_LOG_ON_INFO_LEVEL_QNAME, true);
LOGGER.info("JdbcPingTaskHandler run starting; with progress = {}", progress);
LOGGER.info("Tests to be executed: {}", tests > 0 ? tests : "(unlimited)");
LOGGER.info("Interval between tests: {} seconds", interval);
LOGGER.info("SQL query to be used: {}", testQuery);
LOGGER.info("JDBC:");
LOGGER.info(" - driver: {}", jdbcDriver);
LOGGER.info(" - URL: {}", jdbcUrl);
LOGGER.info(" - username: {}", jdbcUsername);
LOGGER.info("Log on info level: {}", logOnInfoLevel);
Statistics connectionStatistics = new Statistics();
Statistics queryStatistics = new Statistics();
for (int i = 0; task.canRun() && (tests == 0 || i < tests); i++) {
Connection connection = null;
try {
Class.forName(jdbcDriver);
long connStart = System.currentTimeMillis();
connection = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword);
long connTime = System.currentTimeMillis() - connStart;
connectionStatistics.record((int) connTime);
if (logOnInfoLevel) {
LOGGER.info("Successfully connected to database in {} milliseconds", connTime);
} else {
LOGGER.debug("Successfully connected to database in {} milliseconds", connTime);
}
try {
long queryStart = System.currentTimeMillis();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(testQuery);
int rowCount = 0;
while (rs.next()) {
rowCount++;
}
long queryTime = System.currentTimeMillis() - queryStart;
queryStatistics.record((int) queryTime);
if (logOnInfoLevel) {
LOGGER.info("Test query executed successfully in {} milliseconds, returned {} rows", queryTime, rowCount);
} else {
LOGGER.debug("Test query executed successfully in {} milliseconds, returned {} rows", queryTime, rowCount);
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute test query '" + testQuery + "'", t);
queryStatistics.recordFailure();
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't connect to '" + jdbcUrl + "'", t);
connectionStatistics.recordFailure();
}
if (logOnInfoLevel) {
LOGGER.info("Connection statistics: {}", connectionStatistics);
LOGGER.info("Query statistics: {}", queryStatistics);
} else {
LOGGER.debug("Connection statistics: {}", connectionStatistics);
LOGGER.debug("Query statistics: {}", queryStatistics);
}
if (connection != null) {
try {
connection.close();
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't close DB connection", t);
}
}
progress++;
try {
Thread.sleep(1000L * interval);
} catch (InterruptedException e) {
break;
}
}
opResult.computeStatusIfUnknown();
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(opResult);
// would be overwritten when problem is encountered
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
runResult.setProgress(progress);
LOGGER.info("JdbcPingTaskHandler run finishing; progress = " + progress + " in task " + task.getName());
LOGGER.info("Connection statistics: {}", connectionStatistics);
LOGGER.info("Query statistics: {}", queryStatistics);
return runResult;
}
use of com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration in project midpoint by Evolveum.
the class TestSqlRepositoryConfigurationFactory method createSqlRepositoryConfiguration.
public SqlRepositoryConfiguration createSqlRepositoryConfiguration() throws RepositoryServiceFactoryException {
Configuration rawRepoConfig = midpointConfiguration.getConfiguration(MidpointConfiguration.REPOSITORY_CONFIGURATION);
String configFile = System.getProperty(PROPERTY_CONFIG);
if (StringUtils.isNotEmpty(configFile)) {
LOGGER.info("Overriding loaded configuration with values from '{}'", configFile);
updateConfigurationFromFile(rawRepoConfig, configFile);
}
updateConfigurationFromProperties(rawRepoConfig, null);
SqlRepositoryConfiguration config = new SqlRepositoryConfiguration(rawRepoConfig);
config.validate();
return config;
}
use of com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration in project midpoint by Evolveum.
the class SchemaChecker method determineDeclaredVersion.
private DeclaredVersion determineDeclaredVersion() {
SqlRepositoryConfiguration cfg = baseHelper.getConfiguration();
if (cfg.getSchemaVersionOverride() != null) {
return new DeclaredVersion(DeclaredVersion.State.VERSION_VALUE_EXTERNALLY_SUPPLIED, cfg.getSchemaVersionOverride());
}
String entityName = RGlobalMetadata.class.getSimpleName();
try (Session session = baseHelper.beginReadOnlyTransaction()) {
// noinspection JpaQlInspection
List<?> result = session.createQuery("select value from " + entityName + " where name = '" + RGlobalMetadata.DATABASE_SCHEMA_VERSION + "'").list();
if (result.isEmpty()) {
if (cfg.getSchemaVersionIfMissing() != null) {
return new DeclaredVersion(DeclaredVersion.State.VERSION_VALUE_EXTERNALLY_SUPPLIED, cfg.getSchemaVersionIfMissing());
} else {
return new DeclaredVersion(DeclaredVersion.State.VERSION_VALUE_MISSING, null);
}
} else if (result.size() == 1) {
return new DeclaredVersion(DeclaredVersion.State.VERSION_VALUE_PRESENT, (String) result.get(0));
} else {
throw new IllegalStateException("More than one value of " + RGlobalMetadata.DATABASE_SCHEMA_VERSION + " present: " + result);
}
} catch (Throwable t) {
LOGGER.warn("Database schema version could not be determined: {}", t.getMessage());
LOGGER.debug("Database schema version could not be determined: {}", t.getMessage(), t);
if (cfg.getSchemaVersionIfMissing() != null) {
return new DeclaredVersion(DeclaredVersion.State.VERSION_VALUE_EXTERNALLY_SUPPLIED, cfg.getSchemaVersionIfMissing());
} else {
return new DeclaredVersion(DeclaredVersion.State.METADATA_TABLE_MISSING, null);
}
}
}
use of com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration in project midpoint by Evolveum.
the class OrgClosureManager method initialize.
@PostConstruct
public void initialize() {
OperationResult result = new OperationResult(OrgClosureManager.class.getName() + ".initialize");
if (!isEnabled()) {
return;
}
SqlRepositoryConfiguration repoConfiguration = baseHelper.getConfiguration();
if (isOracle()) {
initializeOracleTemporaryTable();
}
boolean check, rebuild;
switch(repoConfiguration.getOrgClosureStartupAction()) {
case NONE:
return;
case CHECK:
check = true;
rebuild = false;
break;
case REBUILD_IF_NEEDED:
check = true;
rebuild = true;
break;
case ALWAYS_REBUILD:
check = false;
rebuild = true;
break;
default:
throw new IllegalArgumentException("Invalid value: " + repoConfiguration.getOrgClosureStartupAction());
}
checkAndOrRebuild(check, rebuild, repoConfiguration.isStopOnOrgClosureStartupFailure(), true, result);
}
use of com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration in project midpoint by Evolveum.
the class DataSourceTestBeanPostprocessor method postProcessAfterInitialization.
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (!(bean instanceof RepositoryFactory)) {
return bean;
}
TestSqlRepositoryFactory factory = context.getBean("testSqlRepositoryFactory", TestSqlRepositoryFactory.class);
SqlRepositoryConfiguration config = factory.getSqlConfiguration();
if (!config.isUsingH2()) {
return bean;
}
System.out.println("Changing hibernate.hbm2ddl.auto to update");
LOGGER.info("Changing hibernate.hbm2ddl.auto to update");
config.setHibernateHbm2ddl("update");
return bean;
}
Aggregations