Search in sources :

Example 1 with JdbcRepositoryConfiguration

use of com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration in project midpoint by Evolveum.

the class TaskManagerConfiguration method setJdbcJobStoreInformation.

void setJdbcJobStoreInformation(MidpointConfiguration masterConfig, JdbcRepositoryConfiguration jdbcConfig) {
    Configuration taskManagerConf = masterConfig.getConfiguration(MidpointConfiguration.TASK_MANAGER_CONFIGURATION);
    database = jdbcConfig != null ? jdbcConfig.getDatabaseType() : null;
    String defaultSqlSchemaFile = SCHEMAS.get(database);
    String defaultDriverDelegate = DELEGATES.get(database);
    sqlSchemaFile = taskManagerConf.getString(SQL_SCHEMA_FILE_CONFIG_ENTRY, defaultSqlSchemaFile);
    jdbcDriverDelegateClass = taskManagerConf.getString(JDBC_DRIVER_DELEGATE_CLASS_CONFIG_ENTRY, defaultDriverDelegate);
    createQuartzTables = taskManagerConf.getBoolean(CREATE_QUARTZ_TABLES_CONFIG_ENTRY, CREATE_QUARTZ_TABLES_DEFAULT);
    databaseIsEmbedded = jdbcConfig != null && jdbcConfig.isEmbedded();
    String explicitJdbcUrl = taskManagerConf.getString(JDBC_URL_CONFIG_ENTRY, null);
    useRepositoryConnectionProvider = taskManagerConf.getBoolean(USE_REPOSITORY_CONNECTION_PROVIDER_CONFIG_ENTRY, repositoryService.isNative() && explicitJdbcUrl == null);
    if (useRepositoryConnectionProvider) {
        LOGGER.info("Using connection provider from repository (ignoring all the other database-related configuration)");
        if (jdbcConfig != null && jdbcConfig.isUsingH2()) {
            LOGGER.warn("This option is not supported for H2! Please change the task manager configuration.");
        }
    } else {
        jdbcDriver = taskManagerConf.getString(JDBC_DRIVER_CONFIG_ENTRY, jdbcConfig != null ? jdbcConfig.getDriverClassName() : null);
        if (explicitJdbcUrl == null) {
            if (jdbcConfig != null) {
                if (jdbcConfig.isEmbedded()) {
                    jdbcUrl = jdbcConfig.getDefaultEmbeddedJdbcUrlPrefix() + "-quartz;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE";
                } else {
                    jdbcUrl = jdbcConfig.getJdbcUrl("mp-scheduler");
                }
            } else {
                jdbcUrl = null;
            }
        } else {
            jdbcUrl = explicitJdbcUrl;
        }
        dataSource = taskManagerConf.getString(DATA_SOURCE_CONFIG_ENTRY, null);
        if (dataSource == null && explicitJdbcUrl == null && jdbcConfig != null) {
            // we want to use quartz-specific JDBC if there is one (i.e. we do not want to inherit data source from repo in such a case)
            dataSource = jdbcConfig.getDataSource();
        }
        if (dataSource != null) {
            LOGGER.info("Quartz database is at {} (a data source)", dataSource);
        } else {
            LOGGER.info("Quartz database is at {} (a JDBC URL)", jdbcUrl);
        }
        jdbcUser = taskManagerConf.getString(JDBC_USER_CONFIG_ENTRY, jdbcConfig != null ? jdbcConfig.getJdbcUsername() : null);
        jdbcPassword = taskManagerConf.getString(JDBC_PASSWORD_CONFIG_ENTRY, jdbcConfig != null ? jdbcConfig.getJdbcPassword() : null);
    }
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) Configuration(org.apache.commons.configuration2.Configuration) JdbcRepositoryConfiguration(com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration)

Example 2 with JdbcRepositoryConfiguration

use of com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration in project midpoint by Evolveum.

the class UpAndDown method initInternal.

private void initInternal(OperationResult result) throws TaskManagerInitializationException {
    LOGGER.info("Task Manager initialization.");
    // get the configuration (general section + JDBC section as well)
    configuration.checkAllowedKeys(midpointConfiguration);
    configuration.setBasicInformation(midpointConfiguration, result);
    configuration.validateBasicInformation();
    LOGGER.info("Task Manager: Quartz Job Store: " + (configuration.isJdbcJobStore() ? "JDBC" : "in-memory") + ", " + (configuration.isClustered() ? "" : "NOT ") + "clustered. Threads: " + configuration.getThreads());
    if (configuration.isJdbcJobStore()) {
        // Let's find Quartz JDBC setup fallback (which will be used very likely)
        JdbcRepositoryConfiguration jdbcConfig = null;
        try {
            jdbcConfig = beanFactory.getBean(JdbcRepositoryConfiguration.class);
        } catch (NoSuchBeanDefinitionException e) {
            LOGGER.info("JdbcRepositoryConfiguration is not available, JDBC Job Store" + " configuration will be taken from taskManager section only.");
            LOGGER.trace("Reason is", e);
        }
        configuration.setJdbcJobStoreInformation(midpointConfiguration, jdbcConfig);
        configuration.validateJdbcJobStoreInformation();
    }
    // register node
    // may throw initialization exception
    NodeType node = clusterManager.createOrUpdateNodeInRepo(result);
    if (!configuration.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.
        clusterManager.checkClusterConfiguration(result);
    }
    // unfortunately, there seems to be no clean way of letting jobs know the taskManager
    JobExecutor.setTaskManagerQuartzImpl(taskManager);
    // the same here
    JobStarter.setTaskManagerQuartzImpl(taskManager);
    localScheduler.initializeScheduler();
    if (localNodeState.getErrorState() == NodeErrorStateType.OK) {
        localScheduler.setLocalExecutionLimitations(node.getTaskExecutionLimitations());
    } else {
        localScheduler.shutdownScheduler();
    }
    // populate the scheduler with jobs (if RAM-based), or synchronize with midPoint repo
    if (!taskSynchronizer.synchronizeJobStores(result)) {
        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");
    // if running in test mode, the postInit will not be executed... so we have to start scheduler here
    if (configuration.isTestMode()) {
        startSchedulerIfNeeded(result);
    }
}
Also used : NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) JdbcRepositoryConfiguration(com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Aggregations

JdbcRepositoryConfiguration (com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration)2 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)1 NodeType (com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)1 Configuration (org.apache.commons.configuration2.Configuration)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1