47
Carbon and OSGi Deep Dive Sameera Jayasoma Software Architect WSO2 Meetup 18/12/2014

Carbon and OSGi Deep Dive

Embed Size (px)

Citation preview

Page 1: Carbon and OSGi Deep Dive

Carbon and OSGi Deep Dive

Sameera JayasomaSoftware Architect

WSO2 Meetup18/12/2014

Page 2: Carbon and OSGi Deep Dive

Overview

● What is Carbon?

● OSGi, P2.

● OSGI, P2 and Carbon integration.

● How carbon starts up?

● Carbon and OSGi bundles.

● Bundle pooling and multi-profiles support.

● Carbon and OSGi services.

● Axis2 OSGi integration in Carbon.

● Carbon, Components, Features,

● Carbon as a server building framework.

Page 3: Carbon and OSGi Deep Dive

?

Page 4: Carbon and OSGi Deep Dive

WSO2 Carbon

● Server building framework ○ offers a lean, modular platform to build servers/middleware products

● All WSO2 middleware products are developed based on this core

framework.

● Provides all the key ingredients to build enterprise-class servers.

● Servers built on top of this Carbon are designed as a set of reusable

modules/components.

Page 5: Carbon and OSGi Deep Dive

Pre-Carbon Era

● Before 2008.

● We had,○ Three separate products○ Three code bases○ Three teams○ Similar features were available in these products but NO code has been

shared.

● This model wasn’t a scalable one.

● Therefore we decided to build our products in a

modular/componentized way to solve above issues.

● Realized the need of a solid foundation to achieve this.

Page 6: Carbon and OSGi Deep Dive

OSGi to the rescue!!!

Page 7: Carbon and OSGi Deep Dive

OSGi

● OSGi framework is a dynamic module system and a services platform for Java programming language.

● OSGi defines a set of rules to build modules, to manage their lifecycles and to communicate among these modules at runtime (in-VM SOA).

● Modules(Bundles) in OSGi can be installed, updated and uninstalled without restarting the JVM.

● Carbon has achieved modularity and dynamism through the concepts defined in the OSGi framework.

Page 8: Carbon and OSGi Deep Dive

Bundle

● The unit of modularization in OSGi

● Traditional Java app. is a collection of Jars. But an OSGi based

system is a collection of bundles.

● Bundle is just a JAR with some additional metadata(manifest

headers) in the MANIFEST.MF file

● A java package is the unit of information hiding.

Page 9: Carbon and OSGi Deep Dive

Bundle and Java packages

● Bundles can share packages with other bundles or hide packages.

● Bundles can declare dependencies on java packages exported by

other bundles.

Page 10: Carbon and OSGi Deep Dive

Life Cycle of a Bundle

Page 11: Carbon and OSGi Deep Dive

OSGi Services

● An OSGi service is a java object, registered into OSGi runtime with a

set of properties.

● Any java object can be registered as a service, but typically it should

implements a well-known interface.

● Its a mechanism for bundles to collaborate at runtime.

● OSGi services provides in-VM SOA model for bundles.

Page 12: Carbon and OSGi Deep Dive

Equinox P2

● A provision platform for OSGi based systems.

● p2 stands for “Provisioning Platform”

● Provides a well defined model for provisioning OSGi bundles

● p2 allows us to manage feature in a controlled manner

○ Install, Uninstall, Revert

○ Based on a web or file based repository

■ Can be hosted internally for an organization

○ Three approaches:

■ Command line

■ Web console

■ Secure remote API

Page 13: Carbon and OSGi Deep Dive

OSGi, P2 and Carbon

● Carbon is tightly coupled with OSGi and P2, if you look at it in a deep

technical level.

● Carbon has achieved modularity and dynamism through the module

system and service platform concepts defined in OSGi spec.

● Everything in Carbon is a bundle.

● These bundles share Java packages among each other, some of

these bundles share Java objects as OSGi services to communicate

with each other.

Page 14: Carbon and OSGi Deep Dive

OSGi, P2 and Carbon

● P2 has enabled the provisioning aspect in Carbon.

● P2 brings the concept of a "Feature" which means a logically related

set of bundles. In other words you can think of it as a functionality in

the system. E.g.

○ Service Management Feature.

○ Registry Feature.

○ JMS Transport Feature.

● You can combine a set of these features into a "Repository" and host

it online or as a distribution to download.

● With P2 you can easily install, update, uninstall features from

repository and customize products.

Page 15: Carbon and OSGi Deep Dive

How Carbon Starts up?...

Page 16: Carbon and OSGi Deep Dive

How Carbon Starts up?

● Carbon Kernel contains many different OSGi bundles which needs to be

loaded up and activated in a particular order to complete Carbon

Initialization.

○ e.g. opening ports only after the server initialization is completed.

● We cannot rely on the OSGi bundle startup order as the startup order is

unpredictable.

Page 17: Carbon and OSGi Deep Dive

How Carbon Starts up?...

Page 18: Carbon and OSGi Deep Dive

OSGi Repository in Carbon

${CARBON.HOME}/repository/components

Page 19: Carbon and OSGi Deep Dive

Everything in Carbon is an OSGi Bundle

● Static resources (java packages/classes) are shared with the bundles using the Export-Package manifest header.

● Carbon APIs classes shared while hiding implementation classes.

● Import-Package is used to declared dependencies to java packages exposed from other bundles.

● Private packages (which are not supposed to be shared) are grouped under the package called “internal”○ e.g. org.wso2.carbon.caching.internal

● Usage of “maven-bundle-plugin” to build OSGi bundles.

Page 20: Carbon and OSGi Deep Dive

maven-bundle-plugin

● Allows you to generate OSGi bundles from Maven project. ○ Generate manifest.mf file with the required OSGi manifest headers

● It automatically generate imports and exports if you haven’t specified explicitly. ○ We recommend you to specify the list of of import and export packages

with versions explicitly in the pom.xml.

Page 21: Carbon and OSGi Deep Dive

Jars to Bundles Converter

● Legacy jar files are covered the OSGi bundles on the fly.

● A Useful feature in Carbon which gives a quick and easy way for developers to expose their legacy libraries to OSGi runtime. ○ Installing DB drivers into OSGi runtime.

● But we do not recommend this. ○ Because these converted bundles do not export or import packages

with versions. No way to specify bundle activators etc.

● This conversion happens during the server startup. just before launching the OSGi runtime in Carbon.

Page 22: Carbon and OSGi Deep Dive

Orbit Bundles

● Some third-party libraries are not available as OSGi bundles.

● Hence Carbon orbit bundles project was initiated to wrap these

libraries as OSGi bundles.

● Now it hosts many different orbit bundles required for many different

components in the Carbon platform.

○ Apache Tomcat OSGi bundle,

○ Apache Axis2 bundles,

○ Hazelcast bundle etc.

https://github.com/wso2/orbit

Page 23: Carbon and OSGi Deep Dive

Bundle pooling

● Ability to share a common plugins directory by multiple applications.

● No duplication of content

● No duplicated downloads when upgrading your applications.

● Allows multiple modes/profiles of a single application to co-exists in single distribution

http://wiki.eclipse.org/Equinox_p2_Getting_Started#Bundle_pooling

Page 24: Carbon and OSGi Deep Dive

Multi-profile support

● One download, multiple servers.e.g. sh wso2carbon.sh -Dprofile=profile_name

● Enables a product to run in multiple modes/profiles

● A profile of a product describes the runtime behaviour.

● Each profile contains only the required set of components

○ E.g. A single API Manager distribution can play following roles.

API Publisher

API Subscriber

API Gateway

Auth Server

Page 25: Carbon and OSGi Deep Dive

Multi-profile support...

Page 26: Carbon and OSGi Deep Dive

Demo

Page 27: Carbon and OSGi Deep Dive

Role of OSGi Services in Carbon

● Shares state among modules. ○ e.g. carbon.xml configuration is shared among bundles as an OSGi

service

● Orders the initialization of modules during the server startup.

● Decouples to APIs from implementation classes.

● Means of extending the behaviour dynamically.○ e.g. Registering a Servlet as an OSGi service

Page 28: Carbon and OSGi Deep Dive

Apache Axis2

● A Web Services Engine.

● Java runtime for hosting services.

● Runs standalone or in conjunction Application servers such as

Apache Tomcat.

● Supports both SOAP and REST

● It is extensible.

○ Axis2 Modules.

○ Axis2 Deployers

○ Transports

○ Message Formatters and Message Builders.

○ etc..

Page 29: Carbon and OSGi Deep Dive

Apache Axis2 and Carbon Integration: Motivation

● Facilitate using Apache Axis2 in OSGI based environments

● Improved class loading mechanism for deployed services and other

Axis2 extensions such as Modules.

● Deploying Web services reside in Bundles

● Deploying Axis2 Extensions(Modules, Service Deployers, etc.) reside

in Bundles.

Page 30: Carbon and OSGi Deep Dive

Problems faced

● Existence of splitted packages among axis2 jar files

● Dependencies of Axis2 are not yet available as OSGi bundles.

● Modules are required to be deployed before Web services in Axis2.

Page 31: Carbon and OSGi Deep Dive

One Big Bundle

● Axis2 consists of several application jar files and third party libraries.

○ axis2-kernal.jar

○ axis2-adb.jar and many more..

● Some Java packages are splitted among these jar files.

○ org.apache.axis2.util package is available in both axis2-kernal.jar

and axis2-adb.jar.

● A package can only be exported by a single bundle, if the version is

same.

● Solution: Bundled all these axis2 jars files into single Big Bundle.

Page 32: Carbon and OSGi Deep Dive

Web Services in Bundles

● Implemented a custom Service Deployer to handle Web services

reside in Bundles.

● Used OSGi extender pattern to detect the list of bundles which has

Web services.

● BundleListeners are used listen to bundle events.

● Only the bundles in ACTIVE state are taken into consideration.

● Bundle classloader is set as the Service classloader to give a better

class loading mechanism for Web Services.

Page 33: Carbon and OSGi Deep Dive

Axis2 Extension in Bundles

● Extensions such as Axis2 Modules, Service Deployers, etc. in

bundles are required to be deployed in Axis2.

● Here also, OSGi extender pattern is used.

● Bundles specify a custom manifest header.

○ Axis2Deployer: POJODeployer

○ Axis2Module: rampart

● Filter the list of bundles having Axis2 extensions using these

manifest headers.

Page 34: Carbon and OSGi Deep Dive

Modules before Services

● Problem: In Axis2, modules should be deployed before services.

Otherwise services become faulty and also these faulty services

cannot be recovered.

● In OSGi, bundle starting order is unpredictable.Hence bundles with

Axis2 Services may become ACTIVE before bundles with Axis2

Modules.

● Possibility of services being deployed before modules.

Page 35: Carbon and OSGi Deep Dive

WSO2 Carbon based products

● Product is a distribution artifact which combines Carbon kernel and a set of logically related features.

● Following is a list of products offered by WSO2.

Page 36: Carbon and OSGi Deep Dive

What is a Carbon Component?

● A set of OSGi Bundles.

● Lives in the Carbon Platform. Hence should conform to rules define

in the Carbon Platform.

● Uses Core Carbon Services

○ Via OSGi service registry

○ e.g. Registry Service, UserManager Service, etc.

Page 37: Carbon and OSGi Deep Dive

What is a Carbon Feature?

● In Eclipse world

○ Feature is a grouping of set of logically related plug-ins/ OSGi

bundles

○ Feature can be installed into Eclipse platform using its Update

Manager

Page 38: Carbon and OSGi Deep Dive

What is a Carbon Feature?

● In Carbon world

○ Feature can be thought of as an installable form of one or more

logically related Carbon component

■ Service Management Component

● What you develop

■ Service Management Feature

● What you install

○ Feature is a grouping of one or more logically related Carbon

components

○ Features can be installed into Carbon based product using

Feature Manager.

Page 39: Carbon and OSGi Deep Dive

WSO2 Carbon: Component Architecture

Page 40: Carbon and OSGi Deep Dive

WSO2 Carbon Kernel

Page 41: Carbon and OSGi Deep Dive

WSO2 Carbon: Feature Library

Page 42: Carbon and OSGi Deep Dive

WSO2 Carbon: Distribution Artifacts

Page 43: Carbon and OSGi Deep Dive

WSO2 Carbon: Adaptability

Page 44: Carbon and OSGi Deep Dive

Key Features offered by Carbon

● User Management API

● Registry/Repository API

● Caching API

● Clustering

● Pluggable Transports

● Artifact Deployment Engine

● Ghost Deployment of Artifacts

● Deployment Synchronization

● UI Framework

● Configuration and Context model (CarbonContext API)

● Multi-tenancy

Page 45: Carbon and OSGi Deep Dive

Server Building Framework

Page 46: Carbon and OSGi Deep Dive

http://awaytogarden.com/questions-anyone-or-careful-what-you-ask/

Page 47: Carbon and OSGi Deep Dive

http://www.funlava.com/thank-you-quotes/