SlideShare a Scribd company logo
1 of 37
Download to read offline
Globalcode	
  –	
  Open4education
Suportando Aplicações
Multi-tenancy com Java EE
Rodrigo Cândido da Silva
@rcandidosilva
Globalcode	
  –	
  Open4education
Agenda
!   Modelos de Serviço
!   SaaS Market
!   Multi-tenancy
!  Desafios
!  Pros and Cons
!  Tipos de Implementação
!   Java EE + Multi-tenancy
!   Segurança + Multi-tenancy
!   Cloud + Multi-tenancy
!   JVM Multi-tenancy
Globalcode	
  –	
  Open4education
Modelos de Serviço
Globalcode	
  –	
  Open4education
SaaS Market
Globalcode	
  –	
  Open4education
Multi-tenancy
!   Uma única instância
da aplicação
atendendo múltiplos
clientes (tenant)
! Contrário da
arquitetura de
múltiplas instâncias
Globalcode	
  –	
  Open4education
Multi-instances vs. Multi-tenant
Globalcode	
  –	
  Open4education
Cloud != Multi-tenancy
Globalcode	
  –	
  Open4education
Desafios
!   Separação dos dados
!   Personalização
!   Controle de acesso
!   Provisionamento de recursos
!   Integrações
!   Atualização da aplicação
!   Recuperação à falhas
Globalcode	
  –	
  Open4education
Pros and Cons
!   Pros
! Reduz o custo de manutenção
! Único código para todos os clientes
! Aumenta a escalabilidade
! Beneficia compartilhamento recursos entre clientes
!   Cons
! Aumenta a complexidade
! Separação por tenant-id
! Maior risco de falhas
! Quebra da aplicação compartilhada para todos clientes
! Reduz a flexibilidade para os clientes
Globalcode	
  –	
  Open4education
Multi-tenancy
!   4 possíveis níveis implementações
! Nível 1 (Personalizado)
!  [N] aplicações e [N] databases
! Nível 2 (Configurável)
!  [1] aplicação e [N] databases
! Nível 3 (Configurável e eficiente)
!  [N] aplicações e [1] database
! Nível 4 (Escalável, configurável e eficiente)
!  [1] aplicação e [1] database
Globalcode	
  –	
  Open4education
Nível 1 - Personalizado
!   [N] aplicações e [N] databases
Globalcode	
  –	
  Open4education
Nível 2 - Configurável
!   [1] aplicação e [N] databases
Globalcode	
  –	
  Open4education
Nível 3 - Eficiente
!   [N] aplicações e [1] database
Globalcode	
  –	
  Open4education
Nível 4 - Escalável
!   [1] aplicação e [1] database
Globalcode	
  –	
  Open4education
Java EE + Multi-tenancy
!   Database
!  JPA + Multi-tenancy
!   Customização UI
!  JSF + Multi-tenancy
!   Segurança
!   Java EE 8 com suporte Cloud
Globalcode	
  –	
  Open4education
JPA + Multi-tenancy
!   EclipseLink
!  Suporte a multi-tenancy @Multitenant
!  Disponibiliza 3 estratégias
!  @Multitenant(SINGLE_TABLE) – default
!  @Multitenant(TABLE_PER_TENANT)
!  @Multitenant(VPD)
!  Shared Cache by tenant
Globalcode	
  –	
  Open4education
EclipseLink SINGLE_TABLE
@Entity
@Table(name=“EMP”)
@Multitenant(SINGLE_TABLE)
@TenantDiscriminatorColumn(name = “TENANT_ID”,
contextProperty = “tenant-id”)
public class Employee {
...
}
HashMap properties = new HashMap();
properties.put("tenant.id", "707");
...
EntityManager em = Persistence
.createEntityManagerFactory(
"multi-tenant”,properties)
.createEntityManager();
<persistence-unit name="multi-tenant">
...
<properties>
<property name="tenant.id"
value="707"/>
...
</properties>
</persistence-unit>
Globalcode	
  –	
  Open4education
EclipseLink TABLE_PER_TENANT
<entity class="Employee">
<multitenant type="TABLE_PER_TENANT">
<tenant-table-discriminator type="SCHEMA" context-
property="eclipselink.tenant-id"/>
</multitenant>
<table name="EMP">
...
</entity>
@Entity
@Table(name=“EMP”)
@Multitenant(TABLE_PER_TENANT)
@TenantTableDiscriminator(type=SCHEMA,
contextProperty="eclipselink.tenant-id")
public class Employee {
...
}
Globalcode	
  –	
  Open4education
EclipseLink VPD
@Entity
@Multitenant
@TenantDiscriminatorColumn(name = "USER_ID",
contextProperty = "tenant.id")
@Cacheable(false)
public class Task implements Serializable {
...
CALL DBMS_RLS.ADD_POLICY
('SCOTT', 'TASK', 'todo_list_policy',
'SCOTT', 'ident_func', 'select, update,
delete'));
<properties>
<property name="eclipselink.session.customizer"
value="example.VPDSessionCustomizer" />
<property name="eclipselink.session-event-listener"
value="example.VPDSessionEventAdapter" />
<property
name="eclipselink.jdbc.exclusive-connection.mode"
value="Always" />
</properties>
Globalcode	
  –	
  Open4education
JPA Caching
!   Shared Cache disabled
Globalcode	
  –	
  Open4education
JPA Caching
!   Shared Cache by tenant
Globalcode	
  –	
  Open4education
JSF + Multi-tenancy
!   Arquitetura extensível
!   Artefatos podem ser encapsulados em JARs
!   Composição at runtime
!   Templates
!   Resource library
!   Look-and-feel customization
!   RenderKit
!   Localization
Globalcode	
  –	
  Open4education
JSF Facelets
The Facelets Gazette
Site
Navigation
●Events
●Docs
●Forums
About Contact Site Map
Template File name
_template.html
Insertion points
Resources
css classes, scripts, images
Globalcode	
  –	
  Open4education
JSF Multi-templating
contractA
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractB
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractC
• Declared Templates
• Declared Insertion Points
• Declared Resources
<web-app-root>/contracts
contractD
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractE
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractF
• Declared Templates
• Declared Insertion Points
• Declared Resources
JAR files in WEB-INF/lib
contractA
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractB
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractC
• Declared Templates
• Declared Insertion Points
• Declared Resources
<web-app-root>/contracts
contractD
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractE
• Declared Templates
• Declared Insertion Points
• Declared Resources
contractF
• Declared Templates
• Declared Insertion Points
• Declared Resources
JAR files in WEB-INF/lib
Set of available contracts
Facelet 1 Facelet 3Facelet 2
faces-config.xml
Globalcode	
  –	
  Open4education
JSF Multi-templating
<html xmlns="http://www.w3.org/1999/xhtml”
xmlns:h="http://java.sun.com/jsf/html”
xmlns:ui="http://java.sun.com/jsf/
facelets">
<body>
<ui:composition template="#{template}”>
...
</ui:composition>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<context-param>
<param-name>javax.faces.view.TEMPLATE</param-
name>
<param-value>mybusiness</param-value>
</context-param>
</web-app>
Globalcode	
  –	
  Open4education
Segurança + Multi-tenancy
!   PicketLink
!  Java EE security framework
!  Identity Management (IDM)
!  Federation support (SAML, OAuth2, OpenID)
!  Social Login support
!  Multi-tenancy support
Globalcode	
  –	
  Open4education
Picketlink
Globalcode	
  –	
  Open4education
Picketlink
@Named
public class RealmSelector implements
Serializable {
@Inject
private PartitionManager partitionManager;
private Realm realm;
@Produces
@PicketLink
public Realm select() {
return this.realm;
}
…
}
@RequestScoped
public class LoginController {
@Inject
private Identity identity;
public String login() {
this.identity.login();
…
}
public String logout() {
this.identity.logout();
return "/home.xhtml";
}
}
public class Resources {
public enum REALM {acme, umbrella,
wayne}
@Produces
@Named("supportedRealms")
public Enum[] supportedRealms() {
return REALM.values();
}
Globalcode	
  –	
  Open4education
Cloud + Multi-tenancy
!   Namespace API
! com.google.appengine.api.NamespaceManager
! Suporte aos seguintes serviços
!  Google Datastore
! Memcached
!  Task Queue
!  Search
Globalcode	
  –	
  Open4education
Namespace API
// Filter to set the Google Apps
// domain as the namespace.
public class NamespaceFilter implements javax.servlet.Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
// Make sure set() is only called if the current namespace is not
already set.
if (NamespaceManager.get() == null) {
NamespaceManager.set(NamespaceManager.getGoogleAppsNamespace());
}
}
}
// Assuming there is a logged in user.
namespace = UserServiceFactory.getUserService()
.getCurrentUser().getUserId();
NamespaceManager.set(namespace);
<filter>
<filter-name>NamespaceFilter</filter-name>
<filter-class>package.NamespaceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>NamespaceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Globalcode	
  –	
  Open4education
Namespace API
!   Search
// Set the current namespace to "aSpace"
NamespaceManager.set("aSpace");
// Create a SearchService with the namespace "aSpace"
SearchService searchService =
SearchServiceFactory.getSearchService();
// Create a MemcacheService that uses the namespace "abc".
MemcacheService explicit =
MemcacheServiceFactory.getMemcacheService("abc");
explicit.put("key", value); // stores value in namespace "abc"
// Increment the count for the current namespace asynchronously.
QueueFactory.getDefaultQueue().add(
TaskOptions.Builder.url("/_ah/update_count")
.param("countName", "SomeRequest"));
!   Memcached
!   Task Queue
Globalcode	
  –	
  Open4education
JVM + Multi-tenancy
!   Multi-tenancy no nível da JVM
!   IBM SDK JVM
!   Static field isolation
!   Controle by tenant
!   CPU time
!   Heap size
!   Thread count
!   File IO, Socket IO
!   Limitações
!   Java Native Interface (JNI)
!   JVMT (Tool interface)
!   GUI Libraries (GWT, Swing, etc)
!   EXPERIMENTAL !!!
Globalcode	
  –	
  Open4education
JVM + Multi-tenancy
Globalcode	
  –	
  Open4education
JVM + Multi-tenancy
Globalcode	
  –	
  Open4education
Perguntas
?
Globalcode	
  –	
  Open4education
Referências
! http://msdn.microsoft.com/en-us/library/aa479086.aspx
! https://developers.google.com/appengine/docs/java/multitenancy/
! http://www.ibm.com/developerworks/java/library/j-multitenant-java/index.html
! http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/
a_multitenant.htm
! http://2012.con-fess.com/sessions/-/details/122/JSF-and-JavaEE-7-for-multi-
tenant-applications
! http://jdevelopment.nl/jsf-22/
! http://picketlink.org
! https://developers.google.com/appengine/docs/java/multitenancy/
! http://www.jboss.org/quickstarts/picketlink/picketlink-authentication-idm-multi-
tenancy/
! http://wiki.eclipse.org/EclipseLink/Examples/MySports
Globalcode	
  –	
  Open4education
Obrigado!
@rcandidosilva
rodrigocandido.me

More Related Content

Viewers also liked

TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2
Rodrigo Cândido da Silva
 
How to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring EditionHow to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring Edition
Stephan Hochdörfer
 

Viewers also liked (20)

Multi-tenancy in Java
Multi-tenancy in JavaMulti-tenancy in Java
Multi-tenancy in Java
 
JVM Support for Multitenant Applications - Steve Poole (IBM)
JVM Support for Multitenant Applications - Steve Poole (IBM)JVM Support for Multitenant Applications - Steve Poole (IBM)
JVM Support for Multitenant Applications - Steve Poole (IBM)
 
GUJavaSC - Unit Testing com Java EE
GUJavaSC - Unit Testing com Java EEGUJavaSC - Unit Testing com Java EE
GUJavaSC - Unit Testing com Java EE
 
JavaOne LATAM 2015 - Segurança em Recursos RESTful com OAuth2
JavaOne LATAM 2015 - Segurança em Recursos RESTful com OAuth2JavaOne LATAM 2015 - Segurança em Recursos RESTful com OAuth2
JavaOne LATAM 2015 - Segurança em Recursos RESTful com OAuth2
 
GUJavaSC - Mini-curso Java EE
GUJavaSC - Mini-curso Java EEGUJavaSC - Mini-curso Java EE
GUJavaSC - Mini-curso Java EE
 
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
 
GUJavaSC - Java EE 7 In Action
GUJavaSC - Java EE 7 In ActionGUJavaSC - Java EE 7 In Action
GUJavaSC - Java EE 7 In Action
 
JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...
JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...
JavaOne LATAM 2015 - Batch Processing: Processamento em Lotes no Mundo Corpor...
 
JavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EEJavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EE
 
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data RESTJavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
 
Batch Processing - Processamento em Lotes no Mundo Corporativo
Batch Processing - Processamento em Lotes no Mundo CorporativoBatch Processing - Processamento em Lotes no Mundo Corporativo
Batch Processing - Processamento em Lotes no Mundo Corporativo
 
GUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com JavaGUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com Java
 
TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2
 
GUJavaSC - Combinando AngularJS com Java EE
GUJavaSC - Combinando AngularJS com Java EEGUJavaSC - Combinando AngularJS com Java EE
GUJavaSC - Combinando AngularJS com Java EE
 
Multi-Tenancy with Spring Boot
Multi-Tenancy with Spring Boot Multi-Tenancy with Spring Boot
Multi-Tenancy with Spring Boot
 
TDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring CloudTDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
 
JavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EEJavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EE
 
QCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EEQCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EE
 
ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2
 
How to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring EditionHow to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring Edition
 

Similar to Suportando Aplicações Multi-tenancy com Java EE

Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
Fermin Galan
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
FIWARE
 
Java Technology
Java TechnologyJava Technology
Java Technology
ifnu bima
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
SPTechCon
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins
buildacloud
 

Similar to Suportando Aplicações Multi-tenancy com Java EE (20)

Android training in mumbai
Android training in mumbaiAndroid training in mumbai
Android training in mumbai
 
Android - Anatomy of android elements & layouts
Android - Anatomy of android elements & layoutsAndroid - Anatomy of android elements & layouts
Android - Anatomy of android elements & layouts
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud Foundry
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
What is DDD and how could it help you
What is DDD and how could it help youWhat is DDD and how could it help you
What is DDD and how could it help you
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins
 
Hexagonal architecture in PHP
Hexagonal architecture in PHPHexagonal architecture in PHP
Hexagonal architecture in PHP
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
 
CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
 
SOA with C, C++, PHP and more
SOA with C, C++, PHP and moreSOA with C, C++, PHP and more
SOA with C, C++, PHP and more
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 

More from Rodrigo Cândido da Silva

QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
Rodrigo Cândido da Silva
 

More from Rodrigo Cândido da Silva (15)

Java 9, 10 e ... 11
Java 9, 10 e ... 11Java 9, 10 e ... 11
Java 9, 10 e ... 11
 
Cloud Native Java EE
Cloud Native Java EECloud Native Java EE
Cloud Native Java EE
 
Protegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de ImplementaçãoProtegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de Implementação
 
Protecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and StrategiesProtecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and Strategies
 
As novidades da nova versão do Java 9
As novidades da nova versão do Java 9As novidades da nova versão do Java 9
As novidades da nova versão do Java 9
 
Workshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e KubernetesWorkshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
 
Workshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSSWorkshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSS
 
Workshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring BootWorkshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring Boot
 
Workshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura MicroservicesWorkshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura Microservices
 
GUJavaSC - Protegendo Microservices em Java
GUJavaSC - Protegendo Microservices em JavaGUJavaSC - Protegendo Microservices em Java
GUJavaSC - Protegendo Microservices em Java
 
TDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com JavaTDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com Java
 
GUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOpsGUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOps
 
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
 
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EEConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
 
JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 

Suportando Aplicações Multi-tenancy com Java EE

  • 1. Globalcode  –  Open4education Suportando Aplicações Multi-tenancy com Java EE Rodrigo Cândido da Silva @rcandidosilva
  • 2. Globalcode  –  Open4education Agenda !   Modelos de Serviço !   SaaS Market !   Multi-tenancy !  Desafios !  Pros and Cons !  Tipos de Implementação !   Java EE + Multi-tenancy !   Segurança + Multi-tenancy !   Cloud + Multi-tenancy !   JVM Multi-tenancy
  • 5. Globalcode  –  Open4education Multi-tenancy !   Uma única instância da aplicação atendendo múltiplos clientes (tenant) ! Contrário da arquitetura de múltiplas instâncias
  • 8. Globalcode  –  Open4education Desafios !   Separação dos dados !   Personalização !   Controle de acesso !   Provisionamento de recursos !   Integrações !   Atualização da aplicação !   Recuperação à falhas
  • 9. Globalcode  –  Open4education Pros and Cons !   Pros ! Reduz o custo de manutenção ! Único código para todos os clientes ! Aumenta a escalabilidade ! Beneficia compartilhamento recursos entre clientes !   Cons ! Aumenta a complexidade ! Separação por tenant-id ! Maior risco de falhas ! Quebra da aplicação compartilhada para todos clientes ! Reduz a flexibilidade para os clientes
  • 10. Globalcode  –  Open4education Multi-tenancy !   4 possíveis níveis implementações ! Nível 1 (Personalizado) !  [N] aplicações e [N] databases ! Nível 2 (Configurável) !  [1] aplicação e [N] databases ! Nível 3 (Configurável e eficiente) !  [N] aplicações e [1] database ! Nível 4 (Escalável, configurável e eficiente) !  [1] aplicação e [1] database
  • 11. Globalcode  –  Open4education Nível 1 - Personalizado !   [N] aplicações e [N] databases
  • 12. Globalcode  –  Open4education Nível 2 - Configurável !   [1] aplicação e [N] databases
  • 13. Globalcode  –  Open4education Nível 3 - Eficiente !   [N] aplicações e [1] database
  • 14. Globalcode  –  Open4education Nível 4 - Escalável !   [1] aplicação e [1] database
  • 15. Globalcode  –  Open4education Java EE + Multi-tenancy !   Database !  JPA + Multi-tenancy !   Customização UI !  JSF + Multi-tenancy !   Segurança !   Java EE 8 com suporte Cloud
  • 16. Globalcode  –  Open4education JPA + Multi-tenancy !   EclipseLink !  Suporte a multi-tenancy @Multitenant !  Disponibiliza 3 estratégias !  @Multitenant(SINGLE_TABLE) – default !  @Multitenant(TABLE_PER_TENANT) !  @Multitenant(VPD) !  Shared Cache by tenant
  • 17. Globalcode  –  Open4education EclipseLink SINGLE_TABLE @Entity @Table(name=“EMP”) @Multitenant(SINGLE_TABLE) @TenantDiscriminatorColumn(name = “TENANT_ID”, contextProperty = “tenant-id”) public class Employee { ... } HashMap properties = new HashMap(); properties.put("tenant.id", "707"); ... EntityManager em = Persistence .createEntityManagerFactory( "multi-tenant”,properties) .createEntityManager(); <persistence-unit name="multi-tenant"> ... <properties> <property name="tenant.id" value="707"/> ... </properties> </persistence-unit>
  • 18. Globalcode  –  Open4education EclipseLink TABLE_PER_TENANT <entity class="Employee"> <multitenant type="TABLE_PER_TENANT"> <tenant-table-discriminator type="SCHEMA" context- property="eclipselink.tenant-id"/> </multitenant> <table name="EMP"> ... </entity> @Entity @Table(name=“EMP”) @Multitenant(TABLE_PER_TENANT) @TenantTableDiscriminator(type=SCHEMA, contextProperty="eclipselink.tenant-id") public class Employee { ... }
  • 19. Globalcode  –  Open4education EclipseLink VPD @Entity @Multitenant @TenantDiscriminatorColumn(name = "USER_ID", contextProperty = "tenant.id") @Cacheable(false) public class Task implements Serializable { ... CALL DBMS_RLS.ADD_POLICY ('SCOTT', 'TASK', 'todo_list_policy', 'SCOTT', 'ident_func', 'select, update, delete')); <properties> <property name="eclipselink.session.customizer" value="example.VPDSessionCustomizer" /> <property name="eclipselink.session-event-listener" value="example.VPDSessionEventAdapter" /> <property name="eclipselink.jdbc.exclusive-connection.mode" value="Always" /> </properties>
  • 20. Globalcode  –  Open4education JPA Caching !   Shared Cache disabled
  • 21. Globalcode  –  Open4education JPA Caching !   Shared Cache by tenant
  • 22. Globalcode  –  Open4education JSF + Multi-tenancy !   Arquitetura extensível !   Artefatos podem ser encapsulados em JARs !   Composição at runtime !   Templates !   Resource library !   Look-and-feel customization !   RenderKit !   Localization
  • 23. Globalcode  –  Open4education JSF Facelets The Facelets Gazette Site Navigation ●Events ●Docs ●Forums About Contact Site Map Template File name _template.html Insertion points Resources css classes, scripts, images
  • 24. Globalcode  –  Open4education JSF Multi-templating contractA • Declared Templates • Declared Insertion Points • Declared Resources contractB • Declared Templates • Declared Insertion Points • Declared Resources contractC • Declared Templates • Declared Insertion Points • Declared Resources <web-app-root>/contracts contractD • Declared Templates • Declared Insertion Points • Declared Resources contractE • Declared Templates • Declared Insertion Points • Declared Resources contractF • Declared Templates • Declared Insertion Points • Declared Resources JAR files in WEB-INF/lib contractA • Declared Templates • Declared Insertion Points • Declared Resources contractB • Declared Templates • Declared Insertion Points • Declared Resources contractC • Declared Templates • Declared Insertion Points • Declared Resources <web-app-root>/contracts contractD • Declared Templates • Declared Insertion Points • Declared Resources contractE • Declared Templates • Declared Insertion Points • Declared Resources contractF • Declared Templates • Declared Insertion Points • Declared Resources JAR files in WEB-INF/lib Set of available contracts Facelet 1 Facelet 3Facelet 2 faces-config.xml
  • 25. Globalcode  –  Open4education JSF Multi-templating <html xmlns="http://www.w3.org/1999/xhtml” xmlns:h="http://java.sun.com/jsf/html” xmlns:ui="http://java.sun.com/jsf/ facelets"> <body> <ui:composition template="#{template}”> ... </ui:composition> </body> </html> <?xml version="1.0" encoding="UTF-8"?> <web-app> <context-param> <param-name>javax.faces.view.TEMPLATE</param- name> <param-value>mybusiness</param-value> </context-param> </web-app>
  • 26. Globalcode  –  Open4education Segurança + Multi-tenancy !   PicketLink !  Java EE security framework !  Identity Management (IDM) !  Federation support (SAML, OAuth2, OpenID) !  Social Login support !  Multi-tenancy support
  • 28. Globalcode  –  Open4education Picketlink @Named public class RealmSelector implements Serializable { @Inject private PartitionManager partitionManager; private Realm realm; @Produces @PicketLink public Realm select() { return this.realm; } … } @RequestScoped public class LoginController { @Inject private Identity identity; public String login() { this.identity.login(); … } public String logout() { this.identity.logout(); return "/home.xhtml"; } } public class Resources { public enum REALM {acme, umbrella, wayne} @Produces @Named("supportedRealms") public Enum[] supportedRealms() { return REALM.values(); }
  • 29. Globalcode  –  Open4education Cloud + Multi-tenancy !   Namespace API ! com.google.appengine.api.NamespaceManager ! Suporte aos seguintes serviços !  Google Datastore ! Memcached !  Task Queue !  Search
  • 30. Globalcode  –  Open4education Namespace API // Filter to set the Google Apps // domain as the namespace. public class NamespaceFilter implements javax.servlet.Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // Make sure set() is only called if the current namespace is not already set. if (NamespaceManager.get() == null) { NamespaceManager.set(NamespaceManager.getGoogleAppsNamespace()); } } } // Assuming there is a logged in user. namespace = UserServiceFactory.getUserService() .getCurrentUser().getUserId(); NamespaceManager.set(namespace); <filter> <filter-name>NamespaceFilter</filter-name> <filter-class>package.NamespaceFilter</filter-class> </filter> <filter-mapping> <filter-name>NamespaceFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
  • 31. Globalcode  –  Open4education Namespace API !   Search // Set the current namespace to "aSpace" NamespaceManager.set("aSpace"); // Create a SearchService with the namespace "aSpace" SearchService searchService = SearchServiceFactory.getSearchService(); // Create a MemcacheService that uses the namespace "abc". MemcacheService explicit = MemcacheServiceFactory.getMemcacheService("abc"); explicit.put("key", value); // stores value in namespace "abc" // Increment the count for the current namespace asynchronously. QueueFactory.getDefaultQueue().add( TaskOptions.Builder.url("/_ah/update_count") .param("countName", "SomeRequest")); !   Memcached !   Task Queue
  • 32. Globalcode  –  Open4education JVM + Multi-tenancy !   Multi-tenancy no nível da JVM !   IBM SDK JVM !   Static field isolation !   Controle by tenant !   CPU time !   Heap size !   Thread count !   File IO, Socket IO !   Limitações !   Java Native Interface (JNI) !   JVMT (Tool interface) !   GUI Libraries (GWT, Swing, etc) !   EXPERIMENTAL !!!
  • 36. Globalcode  –  Open4education Referências ! http://msdn.microsoft.com/en-us/library/aa479086.aspx ! https://developers.google.com/appengine/docs/java/multitenancy/ ! http://www.ibm.com/developerworks/java/library/j-multitenant-java/index.html ! http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/ a_multitenant.htm ! http://2012.con-fess.com/sessions/-/details/122/JSF-and-JavaEE-7-for-multi- tenant-applications ! http://jdevelopment.nl/jsf-22/ ! http://picketlink.org ! https://developers.google.com/appengine/docs/java/multitenancy/ ! http://www.jboss.org/quickstarts/picketlink/picketlink-authentication-idm-multi- tenancy/ ! http://wiki.eclipse.org/EclipseLink/Examples/MySports