©2014 IBM Corporation
Building a right-sized,
do-anything runtime
using OSGi technologies
a case study 

(sort of)
Erin Schnabel
schnabel@us.ibm.com
@ebullientworks
©2014 IBM Corporation
<background>
©2014 IBM Corporation
Some notes on motivation
The full profile of WebSphere application server is awesome in
its capabilities
It is also well-known that the full profile is not well-suited
for development
We did and do listen… and were presented with a challenge: 

“Create a light-weight profile of WebSphere that starts in
under 2 seconds… [but] Don’t break any eggs” — Ian Robinson
©2014 IBM Corporation
History
WebSphere Application Server (the full profile) has been around
forever.
Big codebase
Big customer base
Big workloads
… Big inhibitors to massive change

©2014 IBM Corporation
History
WebSphere Application Server (the full profile) has been around
forever.
Big codebase
Big customer base
Big workloads
… Big inhibitors to massive change

This is not a complaint.
This is a problem we are

happy to have.
©2014 IBM Corporation
History
WebSphere Application Server (the full profile) has been around
forever.
Big codebase
Big customer base
Big workloads
… Big inhibitors to massive change

This is not a complaint.
This is a problem we are

happy to have.
But it is still a problem.
©2014 IBM Corporation
Code that has been around
forever…
Doesn’t matter how good you are, 

or how smart you are













©2014 IBM Corporation
Code that has been around
forever…
Doesn’t matter how good you are, 

or how smart you are
If your code lives long enough, 

and is used enough, 

it ends up looking like… 





©2014 IBM Corporation
Code that has been around
forever…
No matter how good you are, 

or how smart you are
If your code lives long enough, 

and is used enough, 

it ends up looking like… 




 dragons
?!
©2014 IBM Corporation
Code that has been around
forever…
No matter how good you are, 

or how smart you are
If your code lives long enough, 

and is used enough, 

it ends up looking like… 




 dragons
?!
Especially code that has roots 

going back to late ‘90s…
©2014 IBM Corporation
OSGi and WAS:
The first pass…
OSGi was included in WAS v6.1, in 2006
Went from lots of arbitrary jars to a few bundles
Achieved some modularity enforced by OSGi
We did not use or expose OSGi services
Compatibility constraints: WAS is the bottom of the stack
Assumptions about resource initialization and availability
Entrenched dependencies between some core elements
©2014 IBM Corporation
</background>
©2014 IBM Corporation
<cleanSlate>
This is the version of the story you won’t have
heard before…
©2014 IBM Corporation
What if…
If we could start over, what would we want?
Developer-friendly
Simple
Dynamic
Light-weight
Composable / Flexible
Extensible
©2014 IBM Corporation
What if…
If we could start over, what would we want?
Developer-friendly
Simple
Dynamic
Light-weight
Composable / Flexible
Extensible
selectable content
clear API/SPI
runtime/app isolation
human usable
configuration
©2014 IBM Corporation
runtime

only
some combination of

technologies

!
app-centered
everything
What if…
grokable
config
provisioning
©2014 IBM Corporation
What if…
grokable
config
provisioning
runtime

only
some combination of

technologies

!
app-centered
everything
How do we do this?
©2014 IBM Corporation
What if…
runtime

only
some combination of

technologies

!
app-centeredeverything
And yet allow this?
no restarts
©2014 IBM Corporation
What if…
And for crying out loud,
can we prevent THIS?!
runtime3rd party

bundle

B
system

bundle

A
Application
X
©2014 IBM Corporation
Building a kernel from scratch
OSGi-based for all the reasons
First-class use of OSGi services
Must react to configuration changes
Runtime composition on-the-fly





©2014 IBM Corporation
Configuration
Settled on XML for configuration format
Ubiquitous
Expressive
BUT, for simplicity:
single file
usable defaults
<server description=“simple”>
<featureManager>
<feature>jsp-2.2</feature>
</featureManager>
!
<httpEndpoint id=“defaultHttpEndpoint” 

httpPort=“9080” httpsPort=“9443” />
</server>
©2014 IBM Corporation
Configuration
Composable system requires composable configuration:
Individual components own their config

No centralized repository
No externally defined global config model
©2014 IBM Corporation
Configuration
Composable system requires composable configuration:
Individual components own their config

No centralized repository
No externally defined global config model
Configuration Admin and Metatype #FTW!
©2014 IBM Corporation
Configuration Admin
We rolled our own (sorry)
Parse and merge user configuration and bundle-provided
defaults
Resolve variables
Provide configuration to consumers as required by the spec
(mostly)











©2014 IBM Corporation
Metatype
Equinox impl + extensions
http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/
rwlp_extensions_osgi_metatype.html
Uniform validation of user input
Define configuration and constraints in one place, it gets used everywhere else.
We favor metatype.xml for this reason
Custom namespace for additional types and validators
ibm:type — duration, location, password
pid/reference
unique, final, variable, etc.
©2014 IBM Corporation
Uniform validation of user input
Define configuration and constraints in one place, it gets used everywhere else.
We favor metatype.xml for this reason
Custom namespace for additional types and validators
ibm:type — duration, location, password
pid/reference
unique, final, variable, etc.
Metatype
Equinox impl + extensions
http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/
rwlp_extensions_osgi_metatype.html
human readable:

1h30m converted to unit of choice used by developer tools to help
prompt for the right kind of path:
file vs. url
©2014 IBM Corporation
Uniform validation of user input
Define configuration and constraints in one place, it gets used everywhere else.
We favor metatype.xml for this reason
Custom namespace for additional types and validators
ibm:type — duration, location, password
pid/reference
unique, final, variable, etc.
Metatype
Equinox impl + extensions
http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/
rwlp_extensions_osgi_metatype.html
type=“String”

ibm:type=“password”



The value is a “SerializedProtectedString”, 

which is not a String.


Developer tools display encoding options: xor or aes, etc.
©2014 IBM Corporation
Uniform validation of user input
Define configuration and constraints in one place, it gets used everywhere else.
We favor metatype.xml for this reason
Custom namespace for additional types and validators
ibm:type — duration, location, password
pid/reference
unique, final, variable, etc.
Metatype
Equinox impl + extensions
http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/
rwlp_extensions_osgi_metatype.html
This is some crazy stuff.



ibm:type=“pid”

ibm:reference=“specific.service.pid” 



Allows nested configuration elements 

to define service relationships



#awesome
©2014 IBM Corporation
Provisioning
Two phases of provisioning:
Bootstrap the kernel to get configuration
Add or remove features based on configuration update
Features as in Subsystem features 

(*.esa files, metadata, etc.)
Adding or removing features 

installs or uninstalls bundles, which 

adds or removes configurations, which

triggers the creation or removal of services!
©2014 IBM Corporation
Provisioning
Two phases of provisioning:
Bootstrap the kernel to get configuration
Add or remove features based on configuration update
Features as in Subsystem features 

(*.esa files, metadata, etc.)
Adding or removing features 

installs or uninstalls bundles, which 

adds or removes configurations, which

triggers the creation or removal of services!
Dynamically respond to
configuration changes at any time
without requiring a restart.
!
#really
©2014 IBM Corporation
Using OSGi Services…
But who in their right mind wants to manage OSGi
services themselves??
©2014 IBM Corporation
Using OSGi Services…
But who in their right mind wants to manage OSGi
services themselves??
Exactly. NOBODY.
©2014 IBM Corporation
Using OSGi Services…
But who in their right mind wants to manage OSGi
services themselves??
Exactly. NOBODY.
?
BlueprintDeclarative Services
yes, there are others. 

We focused on these two.
©2014 IBM Corporation
Declarative Services
We chose DS for two main reasons:
Timing: Blueprint and Aries were just getting started
Integration with Configuration Admin and Metatype!
Config injected as one unit
activate/modified/updated methods
Service instance creation based on metatype-declared factory pid
DS target filters can be set via configuration
©2014 IBM Corporation
DS is AWESOME!
DS is a central part of the Liberty runtime
CA + M + DS = “magic”

We do insane things with config-derived target filters
Our runtime would not be what it is without DS in the
middle of it
BUT..
©2014 IBM Corporation
Service dynamics can hurt!
Service dynamics are a huge hurdle for “new” developers
DI and IoC can turn even experienced brains inside out if they
aren’t prepared.

Thankfully, they do seem to recover.
Utilities created to “help” can have unintended consequences. 

Especially if cut and paste are involved.
There is definitely a “better way” to do things with DS..
©2014 IBM Corporation
Let DS do it. Really.
DS is excellent at managing service dynamics.
DS is excellent at managing non-trivial service dependencies
It is very unlikely that you will be able to do better— just let
DS do it. That means:
Don’t register services inside a component
Don’t manage references inside a component
©2014 IBM Corporation
Isolation
We mean this in a good way.
Liberty runtime serves two masters:
Typical Application Server paradigm

(apps strictly separated from runtime) — API
Platform extender paradigm

(the “app” is the runtime) — SPI
Persistent problem:

how to allow apps or extensions to use their own versions of libraries that don't
conflict with the runtime!?
©2014 IBM Corporation
Subsystems, Resolver Hooks, and
Regions… (oh my!)
Features must explicitly declare API and SPI packages 

(IBM-* metadata in the feature manifest)
Isolation between API/SPI, apps/extensions/runtime is
enforced in a few ways:
Subsystems (the Aries impl) for OSGi Applications (API)
Resolver hooks and/or Eclipse Regions for isolation
between runtime, extensions (SPI), and containers (API).
©2014 IBM Corporation
</cleanSlate>
Of course, we didn’t really get a clean slate.

Application compatibility had to be preserved.
!
But that still gave us a LOT of room…
©2014 IBM Corporation
Dealing with our legacy
We did start over with our kernel
Used the new base to re-group…
Lots of code still common with full profile
Wrap/Shim: New face on old code
Patch: tweak and replace bits where necessary
©2014 IBM Corporation
Thank you!
Questions?

Building a right sized, do-anything runtime using OSGi technologies: a case study - E Schnabel

  • 1.
    ©2014 IBM Corporation Buildinga right-sized, do-anything runtime using OSGi technologies a case study 
 (sort of) Erin Schnabel schnabel@us.ibm.com @ebullientworks
  • 2.
  • 3.
    ©2014 IBM Corporation Somenotes on motivation The full profile of WebSphere application server is awesome in its capabilities It is also well-known that the full profile is not well-suited for development We did and do listen… and were presented with a challenge: 
 “Create a light-weight profile of WebSphere that starts in under 2 seconds… [but] Don’t break any eggs” — Ian Robinson
  • 4.
    ©2014 IBM Corporation History WebSphereApplication Server (the full profile) has been around forever. Big codebase Big customer base Big workloads … Big inhibitors to massive change

  • 5.
    ©2014 IBM Corporation History WebSphereApplication Server (the full profile) has been around forever. Big codebase Big customer base Big workloads … Big inhibitors to massive change
 This is not a complaint. This is a problem we are
 happy to have.
  • 6.
    ©2014 IBM Corporation History WebSphereApplication Server (the full profile) has been around forever. Big codebase Big customer base Big workloads … Big inhibitors to massive change
 This is not a complaint. This is a problem we are
 happy to have. But it is still a problem.
  • 7.
    ©2014 IBM Corporation Codethat has been around forever… Doesn’t matter how good you are, 
 or how smart you are
 
 
 
 
 
 

  • 8.
    ©2014 IBM Corporation Codethat has been around forever… Doesn’t matter how good you are, 
 or how smart you are If your code lives long enough, 
 and is used enough, 
 it ends up looking like… 
 
 

  • 9.
    ©2014 IBM Corporation Codethat has been around forever… No matter how good you are, 
 or how smart you are If your code lives long enough, 
 and is used enough, 
 it ends up looking like… 
 
 
 dragons ?!
  • 10.
    ©2014 IBM Corporation Codethat has been around forever… No matter how good you are, 
 or how smart you are If your code lives long enough, 
 and is used enough, 
 it ends up looking like… 
 
 
 dragons ?! Especially code that has roots 
 going back to late ‘90s…
  • 11.
    ©2014 IBM Corporation OSGiand WAS: The first pass… OSGi was included in WAS v6.1, in 2006 Went from lots of arbitrary jars to a few bundles Achieved some modularity enforced by OSGi We did not use or expose OSGi services Compatibility constraints: WAS is the bottom of the stack Assumptions about resource initialization and availability Entrenched dependencies between some core elements
  • 12.
  • 13.
    ©2014 IBM Corporation <cleanSlate> Thisis the version of the story you won’t have heard before…
  • 14.
    ©2014 IBM Corporation Whatif… If we could start over, what would we want? Developer-friendly Simple Dynamic Light-weight Composable / Flexible Extensible
  • 15.
    ©2014 IBM Corporation Whatif… If we could start over, what would we want? Developer-friendly Simple Dynamic Light-weight Composable / Flexible Extensible selectable content clear API/SPI runtime/app isolation human usable configuration
  • 16.
    ©2014 IBM Corporation runtime
 only somecombination of
 technologies
 ! app-centered everything What if… grokable config provisioning
  • 17.
    ©2014 IBM Corporation Whatif… grokable config provisioning runtime
 only some combination of
 technologies
 ! app-centered everything How do we do this?
  • 18.
    ©2014 IBM Corporation Whatif… runtime
 only some combination of
 technologies
 ! app-centeredeverything And yet allow this? no restarts
  • 19.
    ©2014 IBM Corporation Whatif… And for crying out loud, can we prevent THIS?! runtime3rd party
 bundle
 B system
 bundle
 A Application X
  • 20.
    ©2014 IBM Corporation Buildinga kernel from scratch OSGi-based for all the reasons First-class use of OSGi services Must react to configuration changes Runtime composition on-the-fly
 
 

  • 21.
    ©2014 IBM Corporation Configuration Settledon XML for configuration format Ubiquitous Expressive BUT, for simplicity: single file usable defaults <server description=“simple”> <featureManager> <feature>jsp-2.2</feature> </featureManager> ! <httpEndpoint id=“defaultHttpEndpoint” 
 httpPort=“9080” httpsPort=“9443” /> </server>
  • 22.
    ©2014 IBM Corporation Configuration Composablesystem requires composable configuration: Individual components own their config
 No centralized repository No externally defined global config model
  • 23.
    ©2014 IBM Corporation Configuration Composablesystem requires composable configuration: Individual components own their config
 No centralized repository No externally defined global config model Configuration Admin and Metatype #FTW!
  • 24.
    ©2014 IBM Corporation ConfigurationAdmin We rolled our own (sorry) Parse and merge user configuration and bundle-provided defaults Resolve variables Provide configuration to consumers as required by the spec (mostly)
 
 
 
 
 

  • 25.
    ©2014 IBM Corporation Metatype Equinoximpl + extensions http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/ rwlp_extensions_osgi_metatype.html Uniform validation of user input Define configuration and constraints in one place, it gets used everywhere else. We favor metatype.xml for this reason Custom namespace for additional types and validators ibm:type — duration, location, password pid/reference unique, final, variable, etc.
  • 26.
    ©2014 IBM Corporation Uniformvalidation of user input Define configuration and constraints in one place, it gets used everywhere else. We favor metatype.xml for this reason Custom namespace for additional types and validators ibm:type — duration, location, password pid/reference unique, final, variable, etc. Metatype Equinox impl + extensions http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/ rwlp_extensions_osgi_metatype.html human readable:
 1h30m converted to unit of choice used by developer tools to help prompt for the right kind of path: file vs. url
  • 27.
    ©2014 IBM Corporation Uniformvalidation of user input Define configuration and constraints in one place, it gets used everywhere else. We favor metatype.xml for this reason Custom namespace for additional types and validators ibm:type — duration, location, password pid/reference unique, final, variable, etc. Metatype Equinox impl + extensions http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/ rwlp_extensions_osgi_metatype.html type=“String”
 ibm:type=“password”
 
 The value is a “SerializedProtectedString”, 
 which is not a String. 
 Developer tools display encoding options: xor or aes, etc.
  • 28.
    ©2014 IBM Corporation Uniformvalidation of user input Define configuration and constraints in one place, it gets used everywhere else. We favor metatype.xml for this reason Custom namespace for additional types and validators ibm:type — duration, location, password pid/reference unique, final, variable, etc. Metatype Equinox impl + extensions http://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/ rwlp_extensions_osgi_metatype.html This is some crazy stuff.
 
 ibm:type=“pid”
 ibm:reference=“specific.service.pid” 
 
 Allows nested configuration elements 
 to define service relationships
 
 #awesome
  • 29.
    ©2014 IBM Corporation Provisioning Twophases of provisioning: Bootstrap the kernel to get configuration Add or remove features based on configuration update Features as in Subsystem features 
 (*.esa files, metadata, etc.) Adding or removing features 
 installs or uninstalls bundles, which 
 adds or removes configurations, which
 triggers the creation or removal of services!
  • 30.
    ©2014 IBM Corporation Provisioning Twophases of provisioning: Bootstrap the kernel to get configuration Add or remove features based on configuration update Features as in Subsystem features 
 (*.esa files, metadata, etc.) Adding or removing features 
 installs or uninstalls bundles, which 
 adds or removes configurations, which
 triggers the creation or removal of services! Dynamically respond to configuration changes at any time without requiring a restart. ! #really
  • 31.
    ©2014 IBM Corporation UsingOSGi Services… But who in their right mind wants to manage OSGi services themselves??
  • 32.
    ©2014 IBM Corporation UsingOSGi Services… But who in their right mind wants to manage OSGi services themselves?? Exactly. NOBODY.
  • 33.
    ©2014 IBM Corporation UsingOSGi Services… But who in their right mind wants to manage OSGi services themselves?? Exactly. NOBODY. ? BlueprintDeclarative Services yes, there are others. 
 We focused on these two.
  • 34.
    ©2014 IBM Corporation DeclarativeServices We chose DS for two main reasons: Timing: Blueprint and Aries were just getting started Integration with Configuration Admin and Metatype! Config injected as one unit activate/modified/updated methods Service instance creation based on metatype-declared factory pid DS target filters can be set via configuration
  • 35.
    ©2014 IBM Corporation DSis AWESOME! DS is a central part of the Liberty runtime CA + M + DS = “magic”
 We do insane things with config-derived target filters Our runtime would not be what it is without DS in the middle of it BUT..
  • 36.
    ©2014 IBM Corporation Servicedynamics can hurt! Service dynamics are a huge hurdle for “new” developers DI and IoC can turn even experienced brains inside out if they aren’t prepared.
 Thankfully, they do seem to recover. Utilities created to “help” can have unintended consequences. 
 Especially if cut and paste are involved. There is definitely a “better way” to do things with DS..
  • 37.
    ©2014 IBM Corporation LetDS do it. Really. DS is excellent at managing service dynamics. DS is excellent at managing non-trivial service dependencies It is very unlikely that you will be able to do better— just let DS do it. That means: Don’t register services inside a component Don’t manage references inside a component
  • 38.
    ©2014 IBM Corporation Isolation Wemean this in a good way. Liberty runtime serves two masters: Typical Application Server paradigm
 (apps strictly separated from runtime) — API Platform extender paradigm
 (the “app” is the runtime) — SPI Persistent problem:
 how to allow apps or extensions to use their own versions of libraries that don't conflict with the runtime!?
  • 39.
    ©2014 IBM Corporation Subsystems,Resolver Hooks, and Regions… (oh my!) Features must explicitly declare API and SPI packages 
 (IBM-* metadata in the feature manifest) Isolation between API/SPI, apps/extensions/runtime is enforced in a few ways: Subsystems (the Aries impl) for OSGi Applications (API) Resolver hooks and/or Eclipse Regions for isolation between runtime, extensions (SPI), and containers (API).
  • 40.
    ©2014 IBM Corporation </cleanSlate> Ofcourse, we didn’t really get a clean slate.
 Application compatibility had to be preserved. ! But that still gave us a LOT of room…
  • 41.
    ©2014 IBM Corporation Dealingwith our legacy We did start over with our kernel Used the new base to re-group… Lots of code still common with full profile Wrap/Shim: New face on old code Patch: tweak and replace bits where necessary
  • 42.