use of com.evolveum.midpoint.repo.sql.SqlRepositoryFactory in project midpoint by Evolveum.
the class Initializer method init.
public void init(OperationResult result) throws TaskManagerInitializationException {
MidpointConfiguration midpointConfiguration = taskManager.getMidpointConfiguration();
LOGGER.info("Task Manager initialization.");
// get the configuration (general section + JDBC section as well)
TaskManagerConfiguration configuration = taskManager.getConfiguration();
configuration.checkAllowedKeys(midpointConfiguration);
configuration.setBasicInformation(midpointConfiguration);
configuration.validateBasicInformation();
LOGGER.info("Task Manager: Quartz Job Store: " + (configuration.isJdbcJobStore() ? "JDBC" : "in-memory") + ", " + (configuration.isClustered() ? "" : "NOT ") + "clustered. Threads: " + configuration.getThreads());
if (configuration.isJdbcJobStore()) {
// quartz properties related to database connection will be taken from SQL repository
String defaultJdbcUrlPrefix = null;
SqlRepositoryConfiguration sqlConfig = null;
try {
SqlRepositoryFactory sqlRepositoryFactory = (SqlRepositoryFactory) taskManager.getBeanFactory().getBean("sqlRepositoryFactory");
sqlConfig = sqlRepositoryFactory.getSqlConfiguration();
if (sqlConfig.isEmbedded()) {
defaultJdbcUrlPrefix = sqlRepositoryFactory.prepareJdbcUrlPrefix(sqlConfig);
}
} catch (NoSuchBeanDefinitionException e) {
LOGGER.info("SqlRepositoryFactory is not available, JDBC Job Store configuration will be taken from taskManager section only.");
LOGGER.trace("Reason is", e);
} catch (RepositoryServiceFactoryException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot determine default JDBC URL for embedded database", e);
}
configuration.setJdbcJobStoreInformation(midpointConfiguration, sqlConfig, defaultJdbcUrlPrefix);
configuration.validateJdbcJobStoreInformation();
}
// register node
// may throw initialization exception
taskManager.getClusterManager().createNodeObject(result);
if (!taskManager.getConfiguration().isTestMode()) {
// in test mode do not start cluster manager thread nor verify cluster config
// does not throw exceptions, sets the ERROR state if necessary, however
taskManager.getClusterManager().checkClusterConfiguration(result);
}
NoOpTaskHandler.instantiateAndRegister(taskManager);
WaitForSubtasksByPollingTaskHandler.instantiateAndRegister(taskManager);
WaitForTasksTaskHandler.instantiateAndRegister(taskManager);
// unfortunately, there seems to be no clean way of letting jobs know the taskManager
JobExecutor.setTaskManagerQuartzImpl(taskManager);
// the same here
JobStarter.setTaskManagerQuartzImpl(taskManager);
taskManager.getExecutionManager().initializeLocalScheduler();
if (taskManager.getLocalNodeErrorStatus() != NodeErrorStatusType.OK) {
taskManager.getExecutionManager().shutdownLocalSchedulerChecked();
}
// populate the scheduler with jobs (if RAM-based), or synchronize with midPoint repo
if (taskManager.getExecutionManager().synchronizeJobStores(result) == false) {
if (!configuration.isJdbcJobStore()) {
LOGGER.error("Some or all tasks could not be imported from midPoint repository to Quartz job store. They will therefore not be executed.");
} else {
LOGGER.warn("Some or all tasks could not be synchronized between midPoint repository and Quartz job store. They may not function correctly.");
}
}
LOGGER.trace("Quartz scheduler initialized (not yet started, however)");
LOGGER.info("Task Manager initialized");
}
use of com.evolveum.midpoint.repo.sql.SqlRepositoryFactory in project midpoint by Evolveum.
the class TestSqlRepositoryBeanPostProcessor method postProcessAfterInitialization.
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if ((bean instanceof SqlRepositoryFactory) || (bean instanceof SessionFactory) || (bean instanceof SqlRepositoryServiceImpl)) {
LOGGER.info("Post process: " + bean.getClass().getName());
}
if (!(bean instanceof SessionFactory)) {
return bean;
}
LOGGER.info("Postprocessing session factory - removing everything from database if necessary.");
TestSqlRepositoryFactory factory = context.getBean(TestSqlRepositoryFactory.class);
//we'll attempt to drop database objects if configuration contains dropIfExists=true and embedded=false
SqlRepositoryConfiguration config = factory.getSqlConfiguration();
if (!config.isDropIfExists() || config.isEmbedded()) {
LOGGER.info("We're not deleting objects from DB, drop if exists=false or embedded=true.");
return bean;
}
LOGGER.info("Deleting objects from database.");
SessionFactory sessionFactory = (SessionFactory) bean;
Session session = sessionFactory.openSession();
try {
session.beginTransaction();
Query query;
if (useProcedure(factory.getSqlConfiguration())) {
LOGGER.info("Using truncate procedure.");
query = session.createSQLQuery("{ call " + TRUNCATE_PROCEDURE + "() }");
query.executeUpdate();
} else {
LOGGER.info("Using truncate function.");
query = session.createSQLQuery("select " + TRUNCATE_FUNCTION + "();");
query.uniqueResult();
}
session.getTransaction().commit();
} catch (Exception ex) {
LOGGER.error("Couldn't cleanup database, reason: " + ex.getMessage(), ex);
if (session != null && session.isOpen()) {
Transaction transaction = session.getTransaction();
if (transaction != null && transaction.isActive()) {
transaction.rollback();
}
}
throw new BeanInitializationException("Couldn't cleanup database, reason: " + ex.getMessage(), ex);
} finally {
if (session != null && session.isOpen()) {
session.close();
}
}
return bean;
}
use of com.evolveum.midpoint.repo.sql.SqlRepositoryFactory in project midpoint by Evolveum.
the class WfConfiguration method initialize.
@PostConstruct
void initialize() {
Configuration c = midpointConfiguration.getConfiguration(WF_CONFIG_SECTION);
checkAllowedKeys(c, KNOWN_KEYS, DEPRECATED_KEYS);
enabled = c.getBoolean(KEY_ENABLED, true);
if (!enabled) {
LOGGER.info("Workflows are disabled.");
return;
}
// activiti properties related to database connection will be taken from SQL repository
SqlRepositoryConfiguration sqlConfig = null;
String defaultJdbcUrlPrefix = null;
dropDatabase = false;
try {
RepositoryFactory repositoryFactory = (RepositoryFactory) beanFactory.getBean("repositoryFactory");
if (!(repositoryFactory.getFactory() instanceof SqlRepositoryFactory)) {
// it may be null as well
LOGGER.debug("SQL configuration cannot be found; Activiti database configuration (if any) will be taken from 'workflow' configuration section only");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("repositoryFactory.getFactory() = " + repositoryFactory);
}
} else {
SqlRepositoryFactory sqlRepositoryFactory = (SqlRepositoryFactory) repositoryFactory.getFactory();
sqlConfig = sqlRepositoryFactory.getSqlConfiguration();
if (sqlConfig.isEmbedded()) {
defaultJdbcUrlPrefix = sqlRepositoryFactory.prepareJdbcUrlPrefix(sqlConfig);
dropDatabase = sqlConfig.isDropIfExists();
}
}
} catch (NoSuchBeanDefinitionException e) {
LOGGER.debug("SqlRepositoryFactory is not available, Activiti database configuration (if any) will be taken from 'workflow' configuration section only.");
LOGGER.trace("Reason is", e);
} catch (RepositoryServiceFactoryException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot determine default JDBC URL for embedded database", e);
}
String explicitJdbcUrl = c.getString(KEY_JDBC_URL, null);
if (explicitJdbcUrl == null) {
if (sqlConfig == null || sqlConfig.isEmbedded()) {
jdbcUrl = defaultJdbcUrlPrefix + "-activiti;DB_CLOSE_ON_EXIT=FALSE;MVCC=FALSE";
} else {
jdbcUrl = sqlConfig.getJdbcUrl();
}
} else {
jdbcUrl = explicitJdbcUrl;
}
dataSource = c.getString(KEY_DATA_SOURCE, null);
if (dataSource == null && explicitJdbcUrl == null && sqlConfig != null) {
// we want to use wf-specific JDBC if there is one (i.e. we do not want to inherit data source from repo in such a case)
dataSource = sqlConfig.getDataSource();
}
if (dataSource != null) {
LOGGER.info("Activiti database is at " + dataSource + " (a data source)");
} else {
LOGGER.info("Activiti database is at " + jdbcUrl + " (a JDBC URL)");
}
boolean defaultSchemaUpdate = sqlConfig == null || "update".equals(sqlConfig.getHibernateHbm2ddl());
activitiSchemaUpdate = c.getBoolean(KEY_ACTIVITI_SCHEMA_UPDATE, defaultSchemaUpdate);
LOGGER.info("Activiti automatic schema update: {}", activitiSchemaUpdate);
jdbcDriver = c.getString(KEY_JDBC_DRIVER, sqlConfig != null ? sqlConfig.getDriverClassName() : null);
jdbcUser = c.getString(KEY_JDBC_USERNAME, sqlConfig != null ? sqlConfig.getJdbcUsername() : null);
jdbcPassword = c.getString(KEY_JDBC_PASSWORD, sqlConfig != null ? sqlConfig.getJdbcPassword() : null);
autoDeploymentFrom = c.getStringArray(KEY_AUTO_DEPLOYMENT_FROM);
if (autoDeploymentFrom.length == 0) {
autoDeploymentFrom = new String[] { AUTO_DEPLOYMENT_FROM_DEFAULT };
}
// hibernateDialect = sqlConfig != null ? sqlConfig.getHibernateDialect() : "";
validate();
}
Aggregations