Jump to: navigation, search

Difference between revisions of "Gyrex/Multi Tenancy Use Cases"

(started page)
 
Line 4: Line 4:
  
 
== Managing Tenants ==
 
== Managing Tenants ==
Tenants can be managed programmatically using a Gyrex APIs, administered via the command line or using a web browser through the Gyrex Admin Console.
+
Tenants can be managed programmatically using a Gyrex APIs, administered via the command line or using a web browser through the Gyrex Admin Console. Technically, they are called "a context" in Gyrex. Therefore, you will create contexts in a hierarchy which will represent your tenants.
  
=== Create Tenants using Gyrex Admin ===
+
=== Creating Tenants ===
Before you start creating tenants you need to think about the structure. Tenants can be organized hierarchically in Gyrex. The ROOT is represented using a simple slash (/). We recommend to create another hierarchy between the root and a tenant which identifies a common relationships of all the tenants. For example, if you are building a blogging muti-tenant blogging system, the common relationship for all tenants is typically you: the vendor of the system.
+
Before you start creating tenants you need to think about the structure. Tenants can be organized hierarchically in Gyrex. The ROOT is represented using a simple slash (/). We recommend creating another hierarchy between the root and a tenant which identifies a common relationships of all the tenants.  
  
 +
Let's look at an example. If you are building a multi tenant blogging system, the common relationship for all tenants is typically you: the vendor of the system. Now in order to create the first tenant (eg. a blog about nice kitchens), you would create a context for "Cool Blogs" (the vendor) first and then another context below the "Cool Blogs" context for the "Nice Kitchens" blog. This results in three contexts:
 +
# Root (<code>/</code>)
 +
# Cool Blogs (<code>/coolblogs</code>)
 +
# Nice Kitchens (<code>/coolblogs/kitchens</code>)
  
 +
=== Accessing a Tenant's Context ===
 +
A context can be accessed programmatically in Gyrex as an <code>IRuntimeContext</code> object. Typically, the <code>IRuntimeContext</code> is provided to your code from Gyrex. Thus, you don't need to deal with the concern of detecting and establishing a <code>IRuntimeContext</code> object.
 +
 +
In rare cases - for example, when you are building code that is managing/accessing multiple contexts - you can lookup a <code>IRuntimeContext</code> from an <code>IRuntimeContextRegistry</code> OSGi service.
 +
 +
 +
== Multi-Tenant Web Applications ==
 +
[[Gyrex/Concepts/Http_Applications|Web applications]] in Gyrex come with multi-tenancy support out of the box. Any Gyrex web application is associated with a context and bound to a specific URL. Thus, for every incoming web request, Gyrex will detect the application and the tenant. Your code can access the <code>IRuntimeContext</code> from the <code>ServletContext</code> or the <code>Application</code> instance. Additionally, if you register servlet classes instance of objects, you can use <code>@Inject</code> annotations and let Gyrex inject <code>IRuntimeContext</code>, context specific objects and/or context specific OSGi services (more below) into your servlets.
  
  
 
== Multi-Tenant Web APIs ==
 
== Multi-Tenant Web APIs ==
 +
Multi-tenant web APIs using JAX-RS are implemented as Gyrex web applications. Your JAX-RS resources should use <code>@Inject</code>/<code>@Context</code> annotations for injecting <code>IRuntimeContext</code>, context specific objects and/or context specific OSGi services (more below) into your servlets.
 +
 +
 +
== Tenant specific OSGi Services ==
 +
A <code>IRuntimeContext</code> provides a way for looking up OSGi services filtered specifically for the context.

Revision as of 13:40, 3 November 2013

Gyrex
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse SourceProject Set File

Multi-tenancy in Gyrex is available using the context runtime, which provides a lot flexibility. This page lists a few multi-tenancy use cases and explains how they are supported in Gyrex.

Managing Tenants

Tenants can be managed programmatically using a Gyrex APIs, administered via the command line or using a web browser through the Gyrex Admin Console. Technically, they are called "a context" in Gyrex. Therefore, you will create contexts in a hierarchy which will represent your tenants.

Creating Tenants

Before you start creating tenants you need to think about the structure. Tenants can be organized hierarchically in Gyrex. The ROOT is represented using a simple slash (/). We recommend creating another hierarchy between the root and a tenant which identifies a common relationships of all the tenants.

Let's look at an example. If you are building a multi tenant blogging system, the common relationship for all tenants is typically you: the vendor of the system. Now in order to create the first tenant (eg. a blog about nice kitchens), you would create a context for "Cool Blogs" (the vendor) first and then another context below the "Cool Blogs" context for the "Nice Kitchens" blog. This results in three contexts:

  1. Root (/)
  2. Cool Blogs (/coolblogs)
  3. Nice Kitchens (/coolblogs/kitchens)

Accessing a Tenant's Context

A context can be accessed programmatically in Gyrex as an IRuntimeContext object. Typically, the IRuntimeContext is provided to your code from Gyrex. Thus, you don't need to deal with the concern of detecting and establishing a IRuntimeContext object.

In rare cases - for example, when you are building code that is managing/accessing multiple contexts - you can lookup a IRuntimeContext from an IRuntimeContextRegistry OSGi service.


Multi-Tenant Web Applications

Web applications in Gyrex come with multi-tenancy support out of the box. Any Gyrex web application is associated with a context and bound to a specific URL. Thus, for every incoming web request, Gyrex will detect the application and the tenant. Your code can access the IRuntimeContext from the ServletContext or the Application instance. Additionally, if you register servlet classes instance of objects, you can use @Inject annotations and let Gyrex inject IRuntimeContext, context specific objects and/or context specific OSGi services (more below) into your servlets.


Multi-Tenant Web APIs

Multi-tenant web APIs using JAX-RS are implemented as Gyrex web applications. Your JAX-RS resources should use @Inject/@Context annotations for injecting IRuntimeContext, context specific objects and/or context specific OSGi services (more below) into your servlets.


Tenant specific OSGi Services

A IRuntimeContext provides a way for looking up OSGi services filtered specifically for the context.