1. timemachine
  2. scheduler

Wiki

Clone wiki

scheduler / HibernateDataStoreConfig

From the ReferenceManual you've seen that we use MemoryDataStore as default data store service that keep job information in memory. But we also allow you to persist data in a database. For this you will use the HibernateDataStore. This page describe the details on how to configure this service.

Scheduler Config Properties

We allow you to customize the HibernateDataStore right in the scheduler's config properties file. The format is as follow:

# Using the HibernateDataStore
timemachine.scheduler.dataStore.class = timemachine.scheduler.hibernate.HibernateDataStore
timemachine.scheduler.dataStore.hibernateDataStore.<hibernate_param_name> = <hibernate_param_value>

Here are typical hibernate parameters:

timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.driver_class = <your_db_driver>
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.url = <your_db_url>
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.username = <your_db_username>
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.password = <your_db_password>
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.dialect = <hibernate_database_dialect_for_your_db>
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.show_sql = <false|true>

#timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.pool_size = <db_connection_pool_size>
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.min_size=1
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.max_size=5

For complete list of hibernate configuration settings reference, please see http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html

If you must, you can even completely replace a customized hibernate.cfg.xml file.

timemachine.scheduler.dataStore.hibernateDataStore.hibernate.cfg.xml = classpath:///timemachine/scheduler/hibernate/hibernate.cfg.xml

Our default hibernate.cfg.xml looks like this

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping resource="timemachine/scheduler/hibernate/SchedulerNode.hbm.xml"/>
        <mapping resource="timemachine/scheduler/hibernate/Schedule.hbm.xml"/>
        <mapping resource="timemachine/scheduler/hibernate/JobDef.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

We only load the entity mappings in hibernate.cfg.xml, but we also combine the scheduler config properties for hibernate together to build the Hibernate session factory object. This gives you the most flexibility in configuration.

First time database schema tables creation

Before you use HibernateDataStore, you need to setup the schema tables in your database. You may use Hibernate's SchemaExport tool to do this, and you can use our SchedulerServer to execute and create the initial schema.

You need to create a config/scheduler-db-init.properties like bellow:

timemachine.scheduler.dataStore.class = timemachine.scheduler.hibernate.HibernateDataStore
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.hbm2ddl.auto = create

# set your connection setting here.
#timemachine.scheduler.dataStore.hibernateDataStore.<hibernate_param_name> = <hibernate_param_value>

Then you can run it with our scheduler server with --initOnly option.

$ bin/scheduler.sh --initOnly config/scheduler-db-init.properties

WARN: The hibernate.hbm2ddl.auto = create hibernate parameter will ERASE your existing data! So you only want to run this ONCE, unless you willing to lose existing data.

Specific Database Initial Setup

H2 Database

1. The default scheduler distribution comes with H2Database pre-package, and it default store data into $HOME/h2-tmscheduler folder. So you do not have to setup database.

2. We default load these hibernate properties for H2 database, which you may override any of them in the main scheduler config file.

# These are default values for HibernateDatatStore loading when user don't specify them in scheduler.properties
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.driver_class = org.h2.Driver
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.url = jdbc:h2:~/h2-tmscheduler
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.username = admin
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.password = admin123
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.dialect = org.hibernate.dialect.H2Dialect
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.hbm2ddl.auto = create
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.current_session_context_class = thread
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.cache.provider_class = org.hibernate.cache.NoCacheProvider
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.min_size=1
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.max_size=5
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.preferredTestQuery=SELECT 1

3. Create the initial scheduler tables by adding timemachine.scheduler.dataStore.hibernateDataStore.hibernate.hbm2ddl.auto = create to the config. Run it through bin/scheduler.sh --initOnly <scheduler-config.propertise>.

4. Now remove the timemachine.scheduler.dataStore.hibernateDataStore.hibernate.hbm2ddl.auto = create property and restart scheduler server as many times as you want. Your data should persist from now on.

TIP: If you are upgrading TimeMachine Scheduler that has schema changes, try replace create with update value instead.

MySQL

1. You would need to create an empty database, user and grant proper permission first.

mysql> create database tmscheduler;
mysql> create user 'admin'@'localhost' identified by 'admin123';
mysql> grant all privileges on tmscheduler.* to 'admin'@'localhost';

2. Create a scheduler properties with MySQL specific connection properties like this:

# Use MySQL for scheduler as data store
timemachine.scheduler.dataStore.class = timemachine.scheduler.hibernate.HibernateDataStore
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.driver_class = com.mysql.jdbc.Driver
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.url = jdbc:mysql://localhost:3306/tmscheduler
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.username = admin
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.connection.password = admin123
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.dialect = org.hibernate.dialect.MySQLDialect
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.show_sql = false
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.min_size=1
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.max_size=5
timemachine.scheduler.dataStore.hibernateDataStore.hibernate.c3p0.preferredTestQuery=SELECT 1 FROM DUAL

3. Create the initial scheduler tables by adding timemachine.scheduler.dataStore.hibernateDataStore.hibernate.hbm2ddl.auto = create to the config. Run it through bin/scheduler.sh --initOnly <scheduler-config.propertise>.

4. Now remove the timemachine.scheduler.dataStore.hibernateDataStore.hibernate.hbm2ddl.auto = create property and restart scheduler server as many times as you want. Your data should persist from now on.

Updated