Multitenancy prototype
Goal
To manually deploy the same application for two tenants (T1, T2) on a shared JOnAS. This step aims to identify changes to be made on the AS to isolate the contexts.Assumptions
- Web, ejb3 components
- JPA persistence Note : JPA persistence is implemented natively in JOnAS by adding the provider (eclipselink2.3) definition in JOnAS.properties. No need to patch JOnAS with eclipselink
Environment
- jonas-full-5.3.0-M6
- 2 projects :
- javaee5-earsampleT1
- javaee5-earsampleT2
Implementation
When we have a new tenant, we have to :- create a directory in $JONAS_BASE which contains elements to deploy (.ear, datasource, connectors ...)
- add the deployment plan in $JONAS_BASE/deploy
- define a private repository url for each tenant in $JONAS_BASE/deploy
- $JONAS_BASE/repositoryT1
- $JONAS_BASE/repositoryT2
- create HTTP connector per tenant
- create Datasource per tenant
- activate Java security to ban creation of files, sockets, threads ...
- Customize the application
- Define the tenantId in persistence.xml
- Costumize the url of each tenant in web.xml
build.xml
- Customize the ear name for each tenant :
<jonas:ear dest="${ear.dir}/javaee5-earsampleT1.ear"/>
- Set the property
<property name="dist.repo.dir" value="${jonas.base}/repositoryT1" />
persistence.xml
- Customize the JNDI name :
<jta-data-source> jdbc_javaee5-earsample-T1 </jta-data-source>
- add properties
<property name="eclipselink.tenant-id" value="T1" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.logger" value="ServerLogger" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.logger" value="ServerLogger" />
- for the tenant T2, replace drop-and-create-tables option by create-tables (use the same database).
application.xml
- Customize the context root : T1/javaee5-earsample
Datasource
- Customize the JNDI name (the same as in persistence.xml) "jdbc_javaee5-earsample-T1"
JMS
- Customize the JNDI name "SampleQueue-javaee5-earsample-T1"
- Edit the file JMSMessageBean.java and customize the name.
- Edit the file JMSApplicationClieant.java and customize the name in @Ressource. Customize JQCF (JQCF-T1)
HTTP connectors
- Add the file tomcat7-server.xml
- Port 9100 in HTTP and 9101 in AJP for T1
- Port 9200 in HTTP and 9201 in AJP for T2
Realm
- Add a new realm "memrlm_T1" whith user T1 and group groupT1
- Same thing for T2
- Add the file context.xml in etc/META-INF and set the realm
EJB JNDI name
- disabling remote interfaces
- Setting of mappedname
- Project
- Demos
- Services
- Documentation
- Downloads
- Community
- Developers