54
Liferay portal modern architecting and development MODULARITY PATTERNS USING OSGI INNOVSQUARE Rafik HARABI EclipseCon Europe 2015

EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Embed Size (px)

Citation preview

Page 1: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay portal modern architecting and developmentMODULARITY PATTERNS USING OSGI

INNOVSQUARE

Rafik HARABI

EclipseCon Europe 2015

Page 2: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Who am I ? Software Architect and Liferay Specialist.

Building portal using Liferay since 2009 (more then 15 portals).

@innovsquare

linkedin.com/rafik.harabi

INNOVSQUARE

https://github.com/innovsquare

[email protected]

EclipseCon Europe 2015

Page 3: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Who are you ?Before we get started...

We are building portals at work,

We are building Portal using Liferay,

We have heard about Liferay Portal and we want to learn more.

INNOVSQUARE EclipseCon Europe 2015

Page 4: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

This talk ...Liferay monolithic architecture

Modularity promises

Liferay 7 modular architecture

Building modules in Liferay 7: the OSGi way

Customizing & extending modules

Lessons learned & takeaways

INNOVSQUARE EclipseCon Europe 2015

Page 5: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

A few words about LiferayOpen source leader Portal that implement Portlet API 1.0 (JSR 168) and Portlet 2.0 (JSR 286)

Lines of Code : 5. 1 Millions

About 70 Out of The Box Portlets

Features: Web Content Management, Document Management, Workflow, Search, Enterprise Collaboration & Social Networking, …

A marketplace: 490 apps http://liferay.com/marketplace

INNOVSQUARE EclipseCon Europe 2015

Page 6: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

A few words about Liferay

Portal Instance

Site

Portal Instance

Site Site Site Site Site

PortletsInstances

INNOVSQUARE EclipseCon Europe 2015

System

Page 7: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay monolithic architecture

Portlet Application

Liferay Portal WAR

Core Services Web Content Management WikiBlog

Application Server

Portlet Application Portlet Application

INNOVSQUARE EclipseCon Europe 2015

Page 8: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay class loading hierarchy

JDK Class Loaders

Application Server Class Loaders

Portal Class Loader Plugin A Plugin B Plugin C

Service A Service B Service C

Portal Services API

Portal Services Impl

INNOVSQUARE EclipseCon Europe 2015

WAR WAR WARWAR

Page 9: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay class loading hierarchy

JDK Class Loaders

Application Server Class Loaders

Portal Class Loader Plugin A Plugin B Plugin C

Service A Service B Service C

Portal services api

INNOVSQUARE EclipseCon Europe 2015

WARWAR WAR WAR

Portal Services Impl

Page 10: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay class loading hierarchy

JDK Class Loaders

Application Server Class Loaders

Portal Class Loader Plugin A Plugin B Plugin C

Service A Service B Service C

Portal services api

INNOVSQUARE EclipseCon Europe 2015

Portal Services Impl

WARWAR WAR WAR

Page 11: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay class loading hierarchy

JDK Class Loaders

Application Server Class Loaders

Portal Class Loader Plugin A Plugin B Plugin C

Service A Service B Service C

Portal services api

INNOVSQUARE EclipseCon Europe 2015

Portal Services Impl

WARWAR WAR WAR

Page 12: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal customization capabilities

* Liferay Buyer’s Checklist

INNOVSQUARE EclipseCon Europe 2015

Page 13: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal customization capabilities

INNOVSQUARE EclipseCon Europe 2015

Extend menu

Add Entry

Customize

Page 14: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal customization capabilities

INNOVSQUARE EclipseCon Europe 2015

Extend menuAdd Entry

Customize

Customization should be a first class citizen

Page 15: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay releases vs Business agility2012 2013 2014 2015 2016

6.1.0 6.2.0 6.2.1 6.2.2

> 1 year

Business agilityRecurrent incremental change

services building and delivery are going from few months to few weeks to few days

INNOVSQUARE EclipseCon Europe 2015

Page 16: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Limits of the Liferay monolithic architectureInvoking service between plugins /portlets:No standard solution

Technical debt: hard to maintain

An All-in-One PackageOne big war of 230 MB

Cannot deploy only what is needed: minimal version

Cannot manage portal features separately

Deployment depends on app server

Scalability: only one dimension scaling

Marketplace: overriding JSP creates conflicts

INNOVSQUARE EclipseCon Europe 2015

Page 17: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Modularity promises Portlet independent versioning from Liferay PortalOSGi semantic versioning

Business Agility:More frequent delivery of new features or improvements

Easy and decoupled development process.

Contract first approach / Loose coupling

Dynamic extensions

INNOVSQUAREINNOVSQUARE EclipseCon Europe 2015

Page 18: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Modularity promisesResiliency /design for failure

Enhance Security : bundle isolation/seal

Patching : just replace the bundle

Microservices: small and independent (both for development and deployment)

Make your product Powerfully customizable

INNOVSQUARE EclipseCon Europe 2015

Page 19: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Modularity challengesCommunications challenges

=> OSGi provides in VM-microservices.

Zero configuration.

How do I manage the configuration ?OSGi Framework provides Configuration Admin service.

INNOVSQUARE EclipseCon Europe 2015

Page 20: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

From monolithic to microservices

INNOVSQUARE EclipseCon Europe 2015

Core Services (ldap auth, messaging, cache …)

WikiBlog

Liferay Portal WAR OSGi Container

ldap auth messaging cache

OSGi Service Registry

Blog UI

Blog API

Blog Service

Wiki UI

Wiki API

Wiki Service

Page 21: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay 7 modular architecture

OSGI Container

Module

ModuleModule

AppApp

App App

Liferay Portal Core (not yet extracted)

Log Service

Http Service

JSP Support

Config Admin

INNOVSQUARE EclipseCon Europe 2015

Application Server

Page 22: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay 7 modular architecture

Statistics (based on Liferay 7 alpha1):

Number of extracted bundles: 326

Number of integration points > 200

INNOVSQUARE EclipseCon Europe 2015

Page 23: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay module frameworkbase path of the module framework

Module bundles

Portal core’s services bundles

framework persistence directory

INNOVSQUARE EclipseCon Europe 2015

Liferay’s module framework bundles

Testing bundles

Bundles to start with the module framework

Test utility

Tools

Page 24: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay module frameworkLiferay Portal

OSGi Container

OSGi Service Registry

Bundle A Bundle B Bundle C

IndexPostProcessorWrapperServiceRegistryWrapperLiferay custom bundle registration Utility (Service Tracker)

Hot deploy listeners

Module deploy folder

INNOVSQUARE EclipseCon Europe 2015

Liferay Service Registry Liferay Service Tracker

Liferay Core’sServices

Page 25: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Liferay module framework Liferay 7 owns the deployment Lifecycle: no longer relaying on application server for deployment.

Dynamically manage module lifecycles.

Liferay modules are versioned and explicitly declare dependencies.

INNOVSQUARE EclipseCon Europe 2015

Page 26: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Building modules with OSGi Liferay support various OSGi framework: OSGi API

Blueprint

iPOJO

OSGi Declarative Services

INNOVSQUARE EclipseCon Europe 2015

Page 27: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Building modules with OSGiWhich technology is recommended by Liferay ?

Liferay recommendation is to use

declarative services.

INNOVSQUARE EclipseCon Europe 2015

Page 28: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portlets using Declaratives Services

6.2 and earlier 7.0

portlet.xml

liferay-portlet.xml

liferay-display.xml

XML Configuration Annotation (DS)

Portlet as a service

INNOVSQUARE EclipseCon Europe 2015

Page 29: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Modularize the service builderService builder : Liferay service layer code scaffolding

6.2 and earlier 7.0

API (jar)

Service Impl

Portlet UI (JSP, …)

Portlet Application (WAR) Bundles (Jars)

Service Registry

API

Service

Test

INNOVSQUARE EclipseCon Europe 2015

Page 30: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Sharing services between applications Zero Effort, Zero Configuration !

All what you need is to publish your services in the OSGi service registry.

Service A

Service B

Service C

Service D

Portlet 1

Portlet 2

Portlet 3

Service Registry

INNOVSQUARE EclipseCon Europe 2015

Page 31: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Overriding Liferay’s services

INNOVSQUARE EclipseCon Europe 2015

Page 32: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Overriding core servicesdeploy a service with a higher service ranking than the original

Using OSGi service ranking :

property= {"service.ranking:Integer=100"}

INNOVSQUARE EclipseCon Europe 2015

Page 33: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portlet Filter6.2 and earlier 7.0

Portlet Application (WAR)

Portlet Filter

- Defined inside the portlet app !- Hard to implement filter for OTB portlets

Bundles (Jars)

INNOVSQUARE EclipseCon Europe 2015

Page 34: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portlet Filter6.2 and earlier 7.0

Portlet Application (WAR)

Portlet Filter

- Defined inside the portlet app !- Hard to implement filter for OTB portlets

Portlet Filter

Bundles (Jars)

Portlet

INNOVSQUARE EclipseCon Europe 2015

Page 35: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Split into modules : Form Builder as example

INNOVSQUARE EclipseCon Europe 2015

Page 36: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Split into microservices: Form Builder as example

6.2 (Monolithic) 7 (OSGI)

INNOVSQUARE EclipseCon Europe 2015

Page 37: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Split into microservices: Form Builder as example

com.liferay.dynamic.data.mapping.type.checkbox.jar

com.liferay.dynamic.data.mapping.type.radio.jar

com.liferay.dynamic.data.mapping.type.text.jar

com.liferay.dynamic.data.mapping.type.select.jar

INNOVSQUARE EclipseCon Europe 2015

Page 38: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Split into microservices: build for extension

My custom type

INNOVSQUARE EclipseCon Europe 2015

Page 39: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal Configuration APIAvailable Configuration for Liferay 6:

Portal properties files:don’t have types

restart on every change

Portal.properties file:One big file with 10000 lines

Portlets preferences:XML based

don’t support types

INNOVSQUARE EclipseCon Europe 2015

Page 40: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal Configuration APIConfiguration management based on :

OSGi Configuration Admin

OSGi MetaType

Properties are typed

Properties are well separated by modules

Dynamically load properties on runtime

INNOVSQUARE EclipseCon Europe 2015

Page 41: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal Configuration API

INNOVSQUARE EclipseCon Europe 2015

Page 42: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal Configuration API - Scopes

Portal Instance

Site

Portal Instance

Site Site Site Site Site

Portlets

System

INNOVSQUARE EclipseCon Europe 2015

Page 43: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal Configuration API –Customize propertiesCustomize properties using Configuration Admin portlet:

INNOVSQUARE EclipseCon Europe 2015

Page 44: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Portal Configuration API –Customize properties Locate the Configuration class : annotated with :

Create a .cfg file with the id:

Add properties with the new values:

[email protected]

[email protected]

Drop it into the deploy folder of Liferay

INNOVSQUARE EclipseCon Europe 2015

Page 45: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

UI customization & extensionextensible user interfaces using the already built in mechanisms into the platform.

Dynamic include using the Liferay extension points :

<liferay-util:dynamic-include key=“com.liferay.frontend.editors.web"/>

INNOVSQUARE EclipseCon Europe 2015

Page 46: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Customizing UI ComponentsWhy: provide a better configuration for your needs.

INNOVSQUARE EclipseCon Europe 2015

Page 47: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Customizing UI Components

INNOVSQUARE EclipseCon Europe 2015

Page 48: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Dev Tools BND Tools:

Robust OSGi bundles build tools.

Blade Tools: Liferay tools to build modules

https://github.com/gamerson/blade.tools

Liferay provide also a set of plugins to build custom modules:

com.liferay.portal.tools.sample.sql.buildercom.liferay.portal.tools.service.buildercom.liferay.portal.tools.upgrade.table.buildercom.liferay.portal.tools.wsdd.builder

INNOVSQUARE EclipseCon Europe 2015

Page 49: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Useful Resources Liferay developer network:

https://dev.liferay.com/develop/

Liferay DevCon 2015: https://www.liferay.com/fr/web/events2015/devcon/recap

Liferay Blade project:

https://github.com/rotty3000/blade

Liferay Blade Tools:

https://github.com/gamerson/blade.tools

INNOVSQUAREINNOVSQUARE EclipseCon Europe 2015

Page 50: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Conclusion – lessons learnedBe realistic & do it in steps: leaving Rome wasn't built in a day !First step: In-VM microservices

Choose robust tools and standards: OSGi is one of the best for java world.

Provide dev and migration tools :very important for your customers.

Focus on Single Responsibility Principle (SRP)

INNOVSQUARE EclipseCon Europe 2015

Page 51: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Conclusion – takeaways Each @Component can be replaced with your own.

Reusable components: Taglibs, Item Selector, Portlet decorator …

Customize and extend

INNOVSQUARE EclipseCon Europe 2015

Page 52: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

Questions ?

INNOVSQUARE EclipseCon Europe 2015

Page 53: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi
Page 54: EclipseCon Europe 2015 - liferay modularity patterns using OSGi -Rafik Harabi

You want to learn more ?2 talks by Ray Augé :

Today : Tomorrow: