Introduction to OSGi using Apache Karaf
Ioannis Canellos JHUG / 16 April 2011
Presenting today
OSGi
Open Services Gateway initiative, since 1999 Initially targeted embedded devices OSGi containers: Felix, Equinox, Knoperfish, Concierge Most known use is Eclipse IDE
Apache Karaf
Apache OSGi runtime runs on any OSGi container Born inside Service Mix, now is Top level project Standard runtime for Geronimo, Service Mix, Sling Ecosystem for deploying OSGi/EE applications
Part I
Introduction to OSGi
Introduction to OSGi
Problem Solution Architecture Tools
OSGi in the Enterprise
Questions & Answers
The problem
aspects
Dependency management
Version Hell Conflicting dependencies Class loading issues
Dynamic behavior
Difficulties to control component lifecycle
Lack of a pure modularity solution
The problems
Dependency management
Large number of transitive dependencies Conflicts among among dependencies Class loading issues
Boot class loader
System class loader
JTA
war
war
JTA
The problems
Dynamic Behavior
Components & Services need come and go Components need to get updated / replaced Components need to started / stopped Real life examples Eclipse IDE Adding/Removing plugins Ebay Multiple version of the same component
The problems
Modularity
The JVM does not address need for modularity
The class path paradox The jar is a black box
No dependencies & No version
The pastitsio example
The WORA promise was repeatedly failed
JavaBeans EJBs
Has the quest for modularity failed ? Project Jigsaw will be shipped with JDK 8 OSGi is already here
The OSGi Solution
Overview
A Layer A deployment infrastructure
Bundles = class + metadata (import/exports) Bundles have a lifecycle Bundles have their own Class loader Class loading delegation between dependant bundles
A service platform
Defines a Service Registry Bundles provide or request services The service can come and go
Architecture
Architecture Execution Environment
The Runtime where the bundles live A bundle can bound to an Execution Environment
JRE-1.5
JRE-1.3 J OSGi/Minimum-1.0
Architecture Module Layer
Bundles import, export or have private packages Each package can be assigned version range
A bundle (fragment) can be attached to a bundle (host)
Export Package javax.transaction 1.01B Import Package javax.transaction [1.0,1.1)
Export Package Bundle Name: JMS API javax.transaction 1.1 Import Package: javax.transaction Export Package: javax.jms Bundle-RequiredExecutionEnvironment: J2SE-1.5
Architecture Module Layer
a MANIFEST.MF example
Manifest-Version: 1.0
Import-Package: javax.transaction;version="1.1, javax.transaction.xa;version="1.1 Export-Package: javax.jms;version="1.1 Bundle-SymbolicName: org.apache.geronimo.specs.geronimo-jms_1.1_spec Tool: Bnd-0.0.227
Architecture Lifecycle Layer
Installed start update resolve Resolved Starting
refresh Started
uninstall
uninstall stop Uninstalled Stopped
Architecture Service Layer
Each bundle can register or lookup a Service Each service corresponds to one or more interfaces Each service can be assigned and queried using properties
register Service Registry lookup
Service Provider
Service Consumer
OSGi Tools working with services
Managing Services programmatically Using the OSGi blueprint
Spring Dynamic Modules Apache Aries
Felix i-Pojo
OSGi Tools creating bundles
Manually providing the MANIFEST.MF Bnd command line tool Maven Bundle Plug-in Springs Bundlor
Maven plug-in flavor Command line flavor
OSGi Tools OSGi Bundle Repository
Simplifies the provisioning of bundles The apt-get install for the OSGi Integrates with public repositories
Eclipse Orbit Springs Enterprise Bundle Repository
OSGi End of Part I
Questions & Answers
Part II
Getting started with Apache Karaf
Apache Karaf agenda
Overview Shell Console Deployer Features Concept Demo Questions and Answers
Security
Logging Service
Apache Karaf Overview
Born as Service Mix Kernel project Grown inside Apache Felix project Become a Top Level Apache project last year
Extensible
Apache Karaf Shell Console
Auto complete & coloring support
Rich command set, covers most OSGi concepts/services Special commands for the development phase
File Scanner
Apache Karaf Deployer
Transformatio n
Configuration
Bundles
War Transformer Spring Transformer Blueprint Transformer Maven Handler HTTP Handler OBR Handler
Configuration Admin
URL Handler
Hot deployment
Large number of supported artifacts Large number of installation mediums
Apache Karaf Features Concept
A Karaf feature is a descriptor which defines
A set of bundles A set of configurations A set of other features
Allows provisioning of applications
Maven integration
OBR integration
Apache Karaf Features Example
<feature name="http" version=2.2.0 resolver=(obr)> <config name="org.ops4j.pax.web>
org.osgi.service.http.port=8181
</config> <feature version="[7.0,8.0)">jetty</feature> <bundle dependency=true>mvn:javax.servlet/servlet-api</bundle> <bundle>mvn:org.ops4j.pax.web/pax-web-api</bundle> </feature>
Apache Karaf Security
JAAS based security Multiple login module implementations
Property Login Module JDBC Login Module LDAP Login Module
Command line support
Provisioning of any JASS realm Add users roles etc
Apache Karaf Logging Service
Centralized Logging configuration Supports most logging APIs
Log4J Slf4j Commons Logging
Command line support
clear, display, tail change threshold etc.
OSGi integration
per bundle appender, osgi specific attributes
Apache Karaf End of Part II
Questions & Answers
Thank you