Top Banner
©2014 IBM Corporation Building a right-sized, do-anything runtime using OSGi technologies a case study (sort of) Erin Schnabel [email protected] @ebullientworks
42

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

Dec 23, 2014

Download

Technology

mfrancis

The WebSphere Application Server Liberty profile uses several OSGi technologies in addition to the Equinox OSGi framework: Configuration Admin, Metatype, and Declarative Services being first and foremost among them.

In this talk, I'll go over how Liberty uses these technologies to create a dynamic flexible runtime that can be right-sized based on the server's configuration. I'll share the lessons we've learned, and what we consider to be best practice for interacting with these three services.

Bio:
Erin Schnabel is the Development lead for the WebSphere Application Server Liberty profile. She has over 12 years of experience in the WebSphere Application Server development organization in various technical roles. Erin has over 15 years of experience working with Java and application middleware across various hardware platforms, including IBM z/OS®. She specializes in composable runtimes, including the application of OSGi, object-oriented and service-oriented technologies and design patterns to decompose existing software systems into flexible, composable units.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building a right sized, do-anything runtime using OSGi technologies: a case study - E Schnabel

©2014 IBM Corporation

Building a right-sized, do-anything runtime

using OSGi technologiesa case study

(sort of)

Erin Schnabel [email protected]

@ebullientworks

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

©2014 IBM Corporation

<background>

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

©2014 IBM Corporation

Some notes on motivationThe 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

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

©2014 IBM Corporation

HistoryWebSphere Application Server (the full profile) has been around forever.

Big codebase

Big customer base

Big workloads

… Big inhibitors to massive change

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

©2014 IBM Corporation

HistoryWebSphere 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.

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

©2014 IBM Corporation

HistoryWebSphere 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.

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

©2014 IBM Corporation

Code that has been around forever…

Doesn’t matter how good you are, or how smart you are

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

©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…

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

©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

?!

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

©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…

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

©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

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

©2014 IBM Corporation

</background>

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

©2014 IBM Corporation

<cleanSlate>

This is the version of the story you won’t have heard before…

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

©2014 IBM Corporation

What if… If we could start over, what would we want?

Developer-friendly

Simple

Dynamic

Light-weight

Composable / Flexible

Extensible

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

©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

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

©2014 IBM Corporation

runtimeonly

some combination of technologies

!app-centered

everything

What if…

grokable config

provisioning

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

©2014 IBM Corporation

What if…

grokable config

provisioning

runtimeonly

some combination of technologies

!app-centered

everything

How do we do this?

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

©2014 IBM Corporation

What if… runtime

only

some combination of technologies

!app-centeredeverything

And yet allow this?

no restarts

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

©2014 IBM Corporation

What if…

And for crying out loud, can we prevent THIS?!

runtime3rd partybundle

B

systembundle

A

Application

X

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

©2014 IBM Corporation

Building a kernel from scratchOSGi-based for all the reasons

First-class use of OSGi services

Must react to configuration changes

Runtime composition on-the-fly

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

©2014 IBM Corporation

ConfigurationSettled 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>

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

©2014 IBM Corporation

ConfigurationComposable system requires composable configuration:

Individual components own their config

No centralized repository

No externally defined global config model

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

©2014 IBM Corporation

ConfigurationComposable system requires composable configuration:

Individual components own their config

No centralized repository

No externally defined global config modelConfiguration Admin and Metatype #FTW!

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

©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)

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

©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.

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

©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

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

©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.

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

©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

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

©2014 IBM Corporation

ProvisioningTwo 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, whichtriggers the creation or removal of services!

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

©2014 IBM Corporation

ProvisioningTwo 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, whichtriggers the creation or removal of services!

Dynamically respond to configuration changes at any time

without requiring a restart. !

#really

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

©2014 IBM Corporation

Using OSGi Services… But who in their right mind wants to manage OSGi services themselves??

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

©2014 IBM Corporation

Using OSGi Services… But who in their right mind wants to manage OSGi services themselves??

Exactly. NOBODY.

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

©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.

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

©2014 IBM Corporation

Declarative ServicesWe 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

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

©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..

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

©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..

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

©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

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

©2014 IBM Corporation

IsolationWe 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!?

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

©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).

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

©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…

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

©2014 IBM Corporation

Dealing with our legacyWe 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

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

©2014 IBM Corporation

Thank you!

Questions?