Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Replaces org.ofbiz by org.apache.ofbiz

...

Info
titleImportant!

This tutorial is intended to be used with SVN revisions greater than 927271. It will not work with Release 4 or 9.04. Note also that some multi-tenants related commits have been applied since r927271... Currently the Ecommerce for Tenants is not supported.

Introduction

Multi-tenancy has been introduced in OFBiz at rev 927271. Multi-tenancy is the ability to run separate data instances (tenants) from a single copy of OFBiz. Each data instance is kept in a separate database. A user logs into a data instance (or tenant) by specifying the tenant ID in the login form. Note that a default database is still used.

...

Panel

<Tenant tenantId="TENANT" tenantName="Tenant Name"/>
<TenantDataSource tenantId="TENANT" entityGroupName="org.apache.ofbiz" jdbcUri="jdbc:postgresql://host:port/DEMO1_db" jdbcUsername="username" jdbcPassword="password"/>
<TenantDataSource tenantId="TENANT" entityGroupName="org.apache.ofbiz.olap" jdbcUri="jdbc:derby:ofbizolap_TENANT; create=true" jdbcUsername="username" jdbcPassword="password"/>

Note

The JDBC URIs follow the naming convention for JDBC connection strings. Credentials as you please. Of course you can add any data source to any of the two entity groups. Do not specify a datasource for entity group 'org.apache.ofbiz.tenant' here!

This information will be stored on the database that you specify underneath the org.apache.ofbiz.tenant entity group on entityengine.xml.

...

This means: If you decide to assign this file load to the reader="ext", you need to execute the following data read sequence before you can access the tenant databases:

Code Block

$ java -Xmx512m -XX:MaxPermSize=128m -jar ofbiz.jar -install -readers=seed -delegator=default
$ java -Xmx512m -XX:MaxPermSize=128m -jar ofbiz.jar -install -readers=seed-initial -delegator=default
$ java -Xmx512m -XX:MaxPermSize=128m -jar ofbiz.jar -install -readers=ext -delegator=default

Of course you can group this all into a single data loader run:

Code Block

$ java -Xmx512m -XX:MaxPermSize=128m -jar ofbiz.jar -install -readers=seed,seed-initial,ext -delegator=default

...

Panel

<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
(...)
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localpostnewtenants"/>
(...)
</delegator>

...

To load the multi-tenant demo, run ant run-install-multitenant OR ant load-demo-multitenant.

To set up the databases for multi-tenancy and load the seed data only, do the following:

Info

All of the following commands must be executed in sequence.

Code Block

$ svn co [https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk] ofbiz
$ ant
$ java \-Xmx512m \-XX:MaxPermSize=128m \-jar ofbiz.jar \-install \-readers=seed \-delegator=default
$ java \-Xmx512m \-XX:MaxPermSize=128m \-jar ofbiz.jar \-install \-readers=seed \-delegator=default#DEMO1
$ java \-Xmx512m \-XX:MaxPermSize=128m \-jar ofbiz.jar \-install \-readers=seed \-delegator=default#DEMO2
$ ant run
Info

Note that the long java lines instead of something like "ant run-install" are used in order to be able to specify a delegatorName.

Starting with revision New Revision: 1172989 two new ant command are added which will load all seed/demo data of components which are not connected to a tenant or connected with this specific tenant, or load all tenants this way.

In order to know which component are connected to which tenant, 2 entities were added:
1. Component (is automatically loaded by ant run-install)
2. TenantComponent

With the following xml file lines these entities can be connected with a tenant
<TenantComponent tenantId="tn1" componentName="cpn1"/>

Available command detail:
1. By using: "ant run-install-tenant" (load specify component data filter with tenantId)
1.1 "ant run-install-tenant" will install all tenant data (reader=tenant)
1.2 "ant run-install-tenant -DtenantId=<tenantId>" will install all tenant data and then run install all default OFBiz components and only components related to tenant (all readers).
1.3 "ant run-install-tenant -DtenantId=<tenantId> -Ddata-readers=seed,seed-initial,..." will install all tenant data and then run install all default OFBiz components and only components related to tenant (specify readers).
1.4 "ant run-install-tenant -DtenantId=<tenantId> -Dcomponent=<componentName>" will install all tenant data and then run install all default OFBiz components and and only one component.

2. By using: "ant run-install-all-tenants" (load all tenant and all data)
2.1 "ant run-install-all-tenants" will install all tenant data and then install all data (separate data by each tenant).
2.2 "ant run-install-all-tenants -Ddata-readers=seed,seed-initial,..." will install all tenant data and then load specify reader (seperate data by each tenant).

Practical hint on entity readers

...

Then, ensure that exists a "ProductStore" related with the "WebSite" settled in the parameter webSiteId of the previous web.xml file. You can load a demo product store (related with the websiteId "WebStore") doing this:

Code Block

$OFBIZ_HOME> java -Xmx512m -XX:MaxPermSize=128m -jar ofbiz.jar -install -readers=seed,demo -delegator=default#tenantId

...

You can determine a initial path used in the tenant

Code Block

<Tenant tenantId="TENANT" tenantName="Tenant Name" domainName="domain.name" initialPath="/initial"/>

...