How to use a different Business Data database for a new tenant on your Bonita Platform?

marielle.spiteri's picture
marielle.spiteri
Blog Categories: 

A Business Data Model (BDM) is defined at the tenant level. When you use the multi-tenancy, you will use a different BDM and therefore you'll need to connect your new tenant to a different Business data Database.

Prerequisites

Your new tenant (for example 101), must be created using the documentation: https://documentation.bonitasoft.com/bonita/7.11/multi-tenancy-and-tenant-configuration

Important: There are 2 ways to create a new tenant: use the REST API if you plan to use the portal to access the new tenant.

You have created a dedicated database (for example business_data101) for the tenant's Business data, following the documentation: https://documentation.bonitasoft.com/bonita/7.11/database-configuration#toc4

Important: You have granted all privileges to the username on the new business data database for your new tenant! (see mysql official documentation https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_all)

Important: Test this procedure on a Non-Production environment first, before applying it to Production.

How to configure the new tenant's Business Data datasources in the Bonita Tomcat Bundle

(for version 7.9+ and higher - if you use another version, click here)

Add additional datasources in setup/tomcat-templates

In this example, we are using a MySQL database

  • Once the new tenant is created (see Prerequisites), in this example our new tenant id is 101.
  • Run the Setup tool to download the configuration from database to the disk:
cd setup/  
setup.[bat|sh] pull
  • Edit the setup/tomcat-templates/bonita.xml file
  • Add a datasource, before the closing </Context> element:
    in this example names with suffix 101 (RawBusinessDataDS101, BusinessDataDS101 and NotManagedBizDataDS101 and database name business_data101):
 <!-- ##################################################### -->
<!-- Configure Business Data Datasource for tenant 101 -->
 <!-- ##################################################### -->
   <Resource name="RawBusinessDataDS101"
              auth="Container"
              type="com.mysql.cj.jdbc.MysqlXADataSource"
              class="com.mysql.cj.jdbc.MysqlXADataSource"
              factory="com.mysql.cj.jdbc.MysqlDataSourceFactory"
              description="Raw Bonita Business Data Datasource"
              closeMethod="close"
              loginTimeout="0"
              serverName="localhost"
              portNumber="3306"
              port="3306"
              databaseName="business_data101"
              user="bonita"
              password="bpm"
              explicitUrl="true"
              url="jdbc:mysql://localhost:3306/business_data101?dontTrackOpenResources=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true" />

    <Resource
            name="BusinessDataDS101"
            uniqueName="jdbc/BusinessDataDSXA101"
            auth="Container"
            factory="org.jboss.narayana.tomcat.jta.TransactionalDataSourceFactory"
            transactionManager="TransactionManager"
            type="javax.sql.XADataSource"
            initialSize="4"
            maxTotal="20"
            minIdle="4"
            maxIdle="10"
            defaultAutoCommit="false"
            removeAbandonedOnBorrow="true"
            removeAbandonedOnMaintenance="true"
            logAbandoned="true"
            testOnBorrow="true"
            validationQuery="SELECT 1"
            xaDataSource="RawBusinessDataDS101" />

    <Resource name="NotManagedBizDataDS101"
              auth="Container"
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"
              maxTotal="5"
              minIdle="1"
              maxIdle="5"
              maxWaitMillis="10000"
              initialSize="1"
              removeAbandonedOnBorrow="true"
              removeAbandonedOnMaintenance="true"
              logAbandoned="true"
              testOnBorrow="true"
              validationQuery="SELECT 1"
              username="bonita"
              password="bpm"
              driverClassName="com.mysql.cj.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/business_data101?dontTrackOpenResources=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true" />

</Context>

Add configuration in the new tenant to use the datasources

  • After you've created the tenant (see Prerequisites), and run the command setup.sh pull (see step 1), you have the folder 101 in you current configuration.
  • Edit setup/platform_conf/current/tenants/101/tenant_engine/bonita-tenant-community-custom.properties file
  • Below the tenant administrator configuration that was generated when you created your tenant add the following lines, and save the file:
# This was created with your tenant
#Tue Jun 05 16:32:41 PDT 2018      
userPassword=install    
userName=install      

# This below is what you need to add    
## Business data configuration for tenant 101
bdm.db.vendor=mysql
bdm.datasource.jndi.path=java:comp/env/BusinessDataDS101
bdm.notmanageddatasource.jndi.path=java:comp/env/NotManagedBizDataDS101
bdm.hibernate.transaction.jta_platform=${sysprop.bonita.hibernate.transaction.jta_platform:org.bonitasoft.engine.persistence.Narayana5HibernateJtaPlatform}

Save (push) the new configuration in database and restart

  • Run the Setup tool to push the configuration from the disk to the database:
cd setup/
setup.[bat|sh] push
  • Restart the server

How to configure the new tenant's Business Data datasources in the Bonita Tomcat Bundle (for version 7.8+ and lower)

Add additional datasources in setup/tomcat-templates

In this example, we are using a MySQL database:

The datasource class name for XA transactions is: com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
The driver class name is: com.mysql.jdbc.Driver

  • Once the new tenant is created (see Prerequisites), in this example our new tenant id is 101.
  • Run the Setup tool to download the configuration from database to the disk:
cd setup/  
setup.[bat|sh] pull
  • Edit setup/tomcat-templates/bitronix-resources.properties file
  • Add the following datasource at the bottom of the file, in this example we call it BusinessDataDSXA101, and save the file:
####################################
BONITA 'Business Data' Datasource TENANT 101
###################################
resource.ds3.uniqueName=jdbc/BusinessDataDSXA101
resource.ds3.minPoolSize=0
resource.ds3.maxPoolSize=5
# Properties common to all DB vendors:
resource.ds3.className=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
resource.ds3.driverProperties.user=bonita
resource.ds3.driverProperties.password=bpm
resource.ds3.testQuery=SELECT 1
  • Edit the setup/tomcat-templates/bonita.xml file
  • Add a datasource, before the closing </Context> element:
    in this example names with suffix 101 (BusinessDataDS101 and NotManagedBizDataDS101 and database name business_data101):
<Resource name="BusinessDataDS101" auth="Container" type="javax.sql.DataSource" factory="bitronix.tm.resource.ResourceObjectFactory" uniqueName="jdbc/BusinessDataDSXA101" />`

<Resource name="NotManagedBizDataDS101"
      auth="Container"
      type="javax.sql.DataSource"
      factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
      maxActive="17"
      minIdle="5"
      maxIdle="17"
      maxWait="10000"
      initialSize="3"
      validationInterval="30000"
      removeAbandoned="true"
      logAbandoned="true"
      testOnBorrow="true"
      validationQuery="SELECT 1"
     username="bonita"
      password="bpm"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/business_data101?dontTrackOpenResources=true&amp;seUnicode=true&amp;characterEncoding=UTF-8" />
</Context>

Add configuration in the new tenant to use the datasources

  • After you've created the tenant (see Prerequisites), and run the command setup.sh pull (see step 1), you have the folder 101 in you current configuration.
  • Edit setup/platform_conf/current/tenants/101/tenant_engine/bonita-tenant-community-custom.properties file
  • Below the tenant administrator configuration that was generated when you created your tenant add the following lines, and save the file:
# This was created with your tenant
#Tue Jun 05 16:32:41 PDT 2018      
userPassword=install    
userName=install      

# This below is what you need to add    
## Business data configuration for tenant 101          
bdm.db.vendor=mysql    
bdm.datasource.jndi.path=java:comp/env/BusinessDataDS101    
bdm.notmanageddatasource.jndi.path=java:comp/env/NotManagedBizDataDS101
bdm.hibernate.transaction.jta_platform=${sysprop.bonita.hibernate.transaction.jta_platform:org.bonitasoft.engine.persistence.JNDIBitronixJtaPlatform}

Save (push) the new configuration in database and restart

  • Run the Setup tool to push the configuration from the disk to the database:
cd setup/
setup.[bat|sh] push
  • Restart the server

How to configure the new tenant's Business Data datasources in the Bonita WildFly Bundle (for version 7.9+ and lower)

In the following example, the information for my dedicated database is: vendor: mysql
database name: business_data101
database username: bonita
database password: bpm

Important: I have granted all privileges to the username bonita on the new business data business_data101 database for my new tenant! (see mysql official documentation https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_all)

Add additional datasources in setup/wildfly-templates

  • Once the new tenant is created (see Prerequisites), in this example our new tenant id is 101.
  • Run the Setup tool to download the configuration from database to the disk:
cd setup/  
setup.[bat|sh] pull
  • Edit the setup/wildfly-templates/standalone.xml file
  • Add a datasource, before the closing </datasources> element:
    in this example names with suffix 101 (BusinessDataDS101 and NotManagedBizDataDS101 and database name business_data101):
  • Find the comment that says:
<!-- #################################################################################################################### -->
<!-- ########################         END OF TEMPLATE MODIFIED BY BONITA SETUP TOOL             ######################### -->
<!-- ###################            YOU CAN ADD CUSTOM CONFIGURATION *BELOW* THIS TEMPLATE              ################# -->
<!-- #################################################################################################################### -->
  • And bellow that comment, add the datasources. You must adapt it to the RDBMS server used: this example is for MySQL, datasources are BusinessDataDS101 and NotManagedBizDataDS101:
<!-- Start tenant 101 Business data datasource configuration -->

<xa-datasource jndi-name="java:jboss/datasources/BusinessDataDS101"
           pool-name="BusinessDataDS101" enabled="true" use-ccm="false"
           use-java-context="false">
    <driver>mysql</driver>

    <xa-datasource-property name="URL">jdbc:mysql://localhost:3306/business_data101?dontTrackOpenResources=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true</xa-datasource-property>

    <xa-pool>
           <min-pool-size>1</min-pool-size>
           <max-pool-size>50</max-pool-size>
           <prefill>true</prefill>
    </xa-pool>
    <security>
           <user-name>bonita</user-name>
           <password>bpm</password>
    </security>
    <validation>
           <background-validation>true</background-validation>
           <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
           <background-validation-millis>90000</background-validation-millis>
    </validation>
    <timeout>
           <idle-timeout-minutes>1</idle-timeout-minutes>
    </timeout>
    <statement>
           <share-prepared-statements>false</share-prepared-statements>
     </statement>
</xa-datasource>
   <datasource jta="false"
            jndi-name="java:jboss/datasources/NotManagedBizDataDS101"
            pool-name="NotManagedBizDataDS101" enabled="true" use-ccm="false"
            use-java-context="false">
     <driver>mysql</driver>
     <connection-url>jdbc:mysql://localhost:3306/business_data101?dontTrackOpenResources=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true</connection-url>
     <pool>
           <min-pool-size>3</min-pool-size>
           <max-pool-size>12</max-pool-size>
           <prefill>true</prefill>
     </pool>
     <security>
           <user-name>bonita</user-name>
           <password>bpm</password>
     </security>
     <validation>
           <background-validation>true</background-validation>
           <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
           <background-validation-millis>90000</background-validation-millis>
     </validation>
     <timeout>
           <idle-timeout-minutes>1</idle-timeout-minutes>
     </timeout>
     <statement>
           <share-prepared-statements>false</share-prepared-statements>
     </statement>
   </datasource>
</datasources>
<!-- End tenant 101 Business data datasource configuration -->

Add configuration in the new tenant to use the datasources

  • After you've created the tenant (see Prerequisites), and run the command setup.sh pull (see step 1), you have the folder 101 in your current configuration.
  • Edit setup/platform_conf/current/tenants/101/tenant_engine/bonita-tenant-community-custom.properties file
  • Below the tenant administrator configuration that was generated when you created your tenant add the following lines, and save the file:
# This was created with your tenant (for example if you've created it with user/password : install/install)  
#Tue Jun 05 16:32:41 PDT 2018  
userPassword=install  
userName=install

# This below is what you need to add  
## Business data configuration for tenant 101
bdm.db.vendor=mysql  
bdm.datasource.jndi.path=java:jboss/datasources/BusinessDataDS101  
bdm.notmanageddatasource.jndi.path=java:jboss/datasources/NotManagedBizDataDS101  
bdm.hibernate.transaction.jta_platform=${sysprop.bonita.hibernate.transaction.jta_platform:org.bonitasoft.engine.persistence.Narayana5HibernateJtaPlatform}

Save (push) the new configuration in database and restart

  • Run the Setup tool to push the configuration from the disk to the database:
cd setup/
setup.[bat|sh] push
  • Restart the server
Notifications