Creating DataSource in a Talend Runtime Container using OPS4J - Cloud - 8.0

Talend ESB Container Administration Guide

Version
Cloud
8.0
Language
English
Product
Talend Cloud
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Module
Talend ESB
Talend Runtime
Content
Administration and Monitoring
Design and Development
Installation and Upgrade

About this task

It is easy to create a data source using OPS4J which does not require other tools as an editor.

Procedure

  1. Start the karaf client.
    1. Change to the Talend Runtime installation directory.
      cd <RuntimeContainerPath>
    2. Run the client.
      • bin\client.bat (Windows)
      • bin\client (Linux)
  2. Add a feature repository and install required features.
    feature:repo-add pax-jdbc 1.3.0 
    feature:install transaction jndi pax-jdbc-postgresql pax-jdbc-pool-dbcp2 pax-jdbc-config
  3. Check if the desired JDBC driver is installed and ready to use.
    service:list DataSourceFactory 
    The information about the JDBC driver is returned, as shown below.
    [org.osgi.service.jdbc.DataSourceFactory]
    -----------------------------------------
     service.id = 386
     osgi.jdbc.driver.version = 42.2.8
     service.bundleid = 236
     service.scope = singleton
     osgi.jdbc.driver.name = PostgreSQL JDBC Driver
     osgi.jdbc.driver.class = org.postgresql.Driver
    Provided by :
     PostgreSQL JDBC Driver JDBC42 (236)
  4. Configure a new datasource based on the configuration files.

    Create a file in the <RuntimeContainerPath>\etc folder with the name prefix org.ops4j.datasource- and the extension .cfg (between minus and extension add your name).

    The jdbc-config feature scans the etc files for such a file and react to every change to it. You can now create additional datasources just by creating new files here.

    A sample configuration file org.ops4j.datasource-etlcontrol.cfg is shown below:
    osgi.jdbc.driver.name=PostgreSQL JDBC Driver
    pool=dbcp2
    serverName=ubuntuserver.local
    databaseName=etlcontrol
    portNumber=5432
    user=username
    password=password
    dataSourceName=jdbc/etlcontrol-ds
    factory.defaultAutoCommit=true
    factory.validationQuery=select current_date
    pool.timeBetweenEvictionRunsMillis=60000
    pool.minEvictableIdleTimeMillis=20000
    pool.maxTotal=300
    pool.maxIdle=300
    
  5. Check if the datasource is available.
    service:list DataSource
    The following result is returned:
    [javax.sql.DataSource]
    ----------------------
     factory.defaultAutoCommit = true
     pax.jdbc.managed = true
     service.id = 400
     pool.minEvictableIdleTimeMillis = 20000
     service.bundleid = 228
     service.scope = singleton
     dataSourceName = jdbc/etlcontrol-ds
     user = username
     pool.timeBetweenEvictionRunsMillis = 60000
     osgi.jdbc.driver.name = PostgreSQL JDBC Driver
     pool.maxIdle = 300
     portNumber = 5432
     pool.maxTotal = 300
     password = password
     databaseName = etlcontrol
     osgi.jndi.service.name = jdbc/etlcontrol-ds
     serverName = ubuntuserver.local
     factory.validationQuery = select current_date
     service.factoryPid = org.ops4j.datasource
     felix.fileinstall.filename = file:/C:/builds/Talend-ESB-V7.4.1-SNAPSHOT/container/etc/org.ops4j.datasource-etlcontrol.cfg
     service.pid = org.ops4j.datasource.6c3f8581-958d-4ef6-9c7c-28700126ed8b
    Provided by :
     OPS4J Pax JDBC Config (228)
  6. Check log output.
    log:display
    You can see the following log information:
    12:47:39.628 INFO [fileinstall-C:\builds\Talend-ESB-V7.3.1-SNAPSHOT\container\etc] Creating configuration from org.ops4j.datasource-etlcontrol.cfg
    12:47:39.633 INFO [CM Configuration Updater (Update: pid=org.ops4j.datasource.6c3f8581-958d-4ef6-9c7c-28700126ed8b)] Obtained service dependency: (&(objectClass=org.ops4j.pax.jdbc.pool.common.PooledDataSourceFactory)(pool=dbcp2)(xa=false))
    12:47:39.635 INFO [CM Configuration Updater (Update: pid=org.ops4j.datasource.6c3f8581-958d-4ef6-9c7c-28700126ed8b)] Obtained service dependency: (&(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.name=PostgreSQL JDBC Driver))
    12:47:39.635 INFO [CM Configuration Updater (Update: pid=org.ops4j.datasource.6c3f8581-958d-4ef6-9c7c-28700126ed8b)] Found DataSourceFactory. Creating DataSource jdbc/etlcontrol-ds