OSGi is great at enabling you to build your systems out of sets of bundles. In a way, your bundles are your configuration. However, this also requires you to master the identification, assembly and provisioning of all of the components that make-up your system.
* How do you hot-deploy bundles for delivery?
* Is there a simple way of bootstrapping your system with specific configurations that are easy to assemble and kick-start?
* Once your system is "out there" how can you take things one-step further and manage the provisioning remotely?
* Is there an easy way to let the user discover and deploy what he wants, when he wants it?
* How can you do all of these things using existing technologies?
Well, you've come to the right place. In this workshop we will focus on ways to manage OSGi installations. Using a simple example application, we will show you how you can:
* use Fileinstall to hot-deploy bundles into your live application environment
* take advantage of Pax Runner to create and easily bootstrap configurations of bundles
* remotely manage, provision, and audit systems in the field with Apache Ace
* provide, discover, and deploy bundles using Apache Felix OBR
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
OSGI workshop - Become A Certified Bundle Manager
1. Become a Cer*fied
Bundle Manager
today
Karl Pauls & Marcel Offermans
!"#$%&'&()"*
2. Karl @ Akquinet
• Member Apache So8ware Founda<on
• PMC Felix, Sling, Incubator
• PPMC Ace, Clerezza
• So8ware Architect at akquinet
• Co-‐Author „OSGi in Ac<on“
• karl.pauls@akquinet.de
3. Marcel @ luminis
• Member Apache So8ware Founda<on
• CommiMer and PMC member at
Apache Felix and Apache ACE
• So8ware architect at Luminis Technologies
• Luminis: group of companies, strong focus on
technical excellence, offices in The
Netherlands and the United Kingdom
• marcel.offermans@luminis.nl
16. ... with OSGi
!"#$%&"
• L3 -‐ Provides a publish/find/bind
service model to decouple bundles
• L2 -‐ Manages the lifecycle of bundle in
+%,"-&.&+" a bundle repository without requiring
the VM be restarted
• L1 -‐ Creates the concept of bundles
that use classes from each other in a
'()*+" controlled way according to constraints
17. Experience: oHen, it’s not OSGi
• Real world applica<ons run on
• an opera<ng system, inside a virtual machine
• and have:
• databases
• non-‐OSGi clients
• other (na<ve) files / data
• For the BEST experience, make everything
deployable
18. Modularity
• What?
• Separa<on of concerns
• Structure
• Encapsula<on
• Focuses on
• Cohesion (low is bad, high is good)
• Coupling (low is good, high is bad)
• Why?
• Independent development
• Independent maintenance
• Improve reusability
19. OSGi Bundle
• A bundle is a module in OSGi terminology
• A bundle is a JAR file containing
• Code
• Resources )*+"''
)*+"''
)*+"''
• Metadata ),!+-.)/0&1
),!+-.)/0&1
),!+-.)/0&1
-.&(*) !"#$%&
-.&(*)
-.&(*)
!"#$%&'(
20. Bundle Metadata
• Bundle metadata captures
• Human-‐readable informa<on
• Bundle iden<fica<on
• Code visibility
• Stored in the JAR manifest as proper<es
21. Version Format
• OSGi uses a 4-‐part version numbering scheme
• <major>.<minor>.<micro>.<qualifier>
• Major, minor, and micro are numeric values
• Qualifier is a string value
• Valid examples
• 1, 1.10, 1.9.9.alpha, 0.2.0.SNAPSHOT
• Invalid examples
• 0.2.SNAPSHOT, 1.9.9-‐alpha
• Comparison (not always intui<ve)
• 1.0.0 < 1.9.9 < 1.10
• 1.0.0.beta > 1.0.0.alpha > 1.0.0
22. Version Range Format
• Interval nota<on is used for version ranges
• Use '[' or ']' for inclusive values
• Use '(' or ')' for exclusive values
• Example (quotes needed)
• "[1.0.0,2.0.0)" == (1.0.0 <= v < 2.0.0)
• When a version range is expected, a single value
represents an infinite range
• "1.0.0" == (1.0.0 <= v < ∞)
• To specify a precise version
• "[1.0.0,1.0.0]"
23. Experience: versioning
• Choose a versioning policy and s<ck with it
• Version all packages you export
• Use version ranges on import that are
consistent with policy
• If you FORGET this you will REGRET it
• Do not be tempted to mis-‐use commercial
versions internally
• Only bump versions on actual changes
24. Version Policy
• Major number change – signifies an incompa<ble
update.
• Minor number change – signifies a backward
compa<ble update.
• Micro number change – signifies an internal update
(e.g., a bug fix or performance improvement).
• Qualifier change – signifies a trivial internal change
with “outward” no<ceable difference, but
nonetheless is a new ar<fact (e.g., line number
refactoring).
28. Best Prac*ce
!!"#$%&'(")) !"#" *++
*+,-./0,-1
*+,-./+,+1
$%&'#%#()"
*++,-.$
29. Impor*ng & Expor*ng a Package (1/4)
• Imagine bundle A somehow gets servlet
instances from bundle B
/,%&'(
)*+*,-./'+0/(
"
#$%&'( -10*..
)*+*,-./'+0/(
!
&2/31&%43&5
)*+*,-./'+0/(
30. Impor*ng & Expor*ng a Package (1/4)
• What if bundle A also wanted to get servlet
instances somehow from bundle C?
/,%&'(
)*+*,-./'+0/(
"
#$%&'( -10*..
)*+*,-./'+0/(
!
&2/31&%43&5
)*+*,-./'+0/(
31. Impor*ng & Expor*ng a Package (2/4)
• Bundle C could import from bundle B, but
then it is dependent on it
#$%&'(
)*+*,-./'+0/(
6
/,%&'(
)*+*,-./'+0/(
"
#$%&'( -10*..
)*+*,-./'+0/(
!
&2/31&%43&5
)*+*,-./'+0/(
32. Impor*ng & Expor*ng a Package (3/4)
• Bundle C could export its own servlet
package, but bundle A could only see either C
or B /,%&'(
)*+*,-./'+0/(
"
-10*..
#$%&'(
)*+*,-./'+0/(
! (2&31&%#/.3&4
666 )*+*,-./'+0/(
5
-10*..
/,%&'(
)*+*,-./'+0/(
33. Impor*ng & Expor*ng a Package (4/4)
• Bundle C could both import and export
servlet to solve the dilemma
/,%&'(1*231#$%&'(
)*+*,-./'+0/(
"
-40*.. /,%&'(1*231#$%&'(
)*+*,-./'+0/(
5
#$%&'( -40*..
)*+*,-./'+0/(
!
34. Advanced Consistency Checking
• Some<mes more advanced consistency
checking is necessary, consider this
Interface
package org.foo.http;
import javax.servlet;
public interface HttpService {
void registerServlet(Sting alias, Servlet servlet);
}
Metadata
Export-Package: org.foo.http; version="1.0.0"
Import-Package: javax.servlet; version="2.3.0"
35. Advanced Consistency Checking
• Some<mes more advanced consistency
checking is necessary, consider this
),-.'/ &2-.'/
&2-.'/ 01(123%&'(4&/ 01(123%&'(4&/
.':3;..3<=- (&'%).5673839 (&'%).5673839
!""#$ +
%&'()*&
37. Advanced Consistency Checking
• Some<mes more advanced consistency
checking is necessary, consider this
&,-.'/ &,-.'/
01(1,2%&'(3&/ &,-.'/ 01(1,2%&'(3&/
(&'%).4562>28 .'92:..2;<- (&'%).4562728
= !""#$ !""#$ +
*3)&4/ %&'()*&
38. Advanced Consistency Checking
• Some<mes more advanced consistency
checking is necessary, consider this
&,-.'/ &,-.'/
01(1,2%&'(3&/ &,-.'/ 01(1,2%&'(3&/
(&'%).4562>28 .'92:..2;<- (&'%).4562728
= !""#$ !""#$ +
*3)&4/ %&'()*&
This would result in a
ClassCastExcep<on,
why?
39. Advanced Consistency Checking
• Some<mes more advanced consistency
checking is necessary, consider this
&,-.'/ &,-.'/
01(1,2%&'(3&/ &,-.'/ 01(1,2%&'(3&/
(&'%).4562>28 .'92:..2;<- (&'%).4562728
= !""#$ !""#$ +
*3)&4/ %&'()*&
40. Advanced Consistency Checking
• Some<mes more advanced consistency
checking is necessary, consider this
We need to declare such
internal dependencies!
&,-.'/ &,-.'/
01(1,2%&'(3&/ &,-.'/ 01(1,2%&'(3&/
(&'%).4562>28 .'92:..2;<- (&'%).4562728
= !""#$ !""#$ +
*3)&4/ %&'()*&
?@%&%?
Metadata
Export-Package: org.foo.http; version="1.0.0";
uses:="javax.servlet"
Import-Package: javax.servlet; version="2.3.0"
41. Run-‐Time Bundle Iden*fica*on
• Bundle symbolic name plus bundle version
• Assigned in the bundle metadata
• Install loca<on
• Assigned when installing bundle
• Typically the URL from which the bundle is retrieved
• Bundle iden<fier
• Assigned by the framework
• A long value which increases for each installed
bundled
42. Framework Bundle Cache
• The framework maintains a bundle cache
• Installing a bundle saves it to the cache
• Once installed, the original bundle JAR file is no longer needed
• Subsequent framework execu<ons will reload the cached bundles
• The framework also saves the bundle state in the
bundle cache
• When a bundle is started, it is persistently recorded as being
ac<ve
• Ac<ve bundles will be restarted in subsequent framework
execu<ons
• Upda<ng and uninstalling bundles also impact the
cache, but it is a liMle more complicated
43. Package Admin
• Framework provides special API for this
purpose
public interface PackageAdmin {
static final int BUNDLE_TYPE_FRAGMENT = 0x00000001;
Bundle getBundle(Class clazz);
Bundle[] getBundles(String symbolicName, String versionRange);
int getBundleType(Bundle bundle);
ExportedPackage getExportedPackage(String name);
ExportedPackage[] getExportedPackages(Bundle bundle);
ExportedPackage[] getExportedPackages(String name);
Bundle[] getFragments(Bundle bundle);
RequiredBundle[] getRequiredBundles(String symbolicName);
Bundle[] getHosts(Bundle bundle);
void refreshPackages(Bundle[] bundles);
boolean resolveBundles(Bundle[] bundles);
}
47. Experience: Swing
• First of all, how do you modularize a UI?
• Second, how dynamic do you want it to be?
• Third: dealing with already instan<ated stuff
(panels, look and feel, ...)
• For more info:
hMp://lsd.luminis.nl/swing-‐and-‐osgi
48. Pax Runner
• Hosted at OPS4J
• Bootstrapper for OSGi frameworks
• ini<al provisioning of bundles
• great tool for developers
49. Pax Runner
• Unzip the archive, add to path
• selec<ng the framework
• op<ons, op<ons, op<ons
• profiles and ini<al provisioning
• crea<ng a distribu<on
50. Pax Runner -‐ Frameworks
• Run the default framework:
pax-‐run.sh
• Run Equinox version 3.5.1:
pax-‐run.sh -‐-‐playorm=equinox -‐-‐version=3.5.1
• Run with a pre-‐defined profile:
pax-‐run.sh -‐-‐profiles=felix.webconsole
51. Pax Runner -‐ Windows FAQ
009. I'm using Pax Runner on DOS/Windows, I have the right
command but I'm ge{ng strange errors
DOS/Windows shell seems to strip the equals (=) from the
command line and treats the leD and right side of the equals as
separate arguments for the batch file. Thus, the arguments to
the java executable for an argument like (for example) -‐-‐
profiles=log will be split in two arguments as -‐-‐profiles and log.
To avoid this you will have to enclose the en9re argument
between quotes (") as in "-‐-‐profiles=log".
Source: h*p://paxrunner.ops4j.org/display/paxrunner/FAQ
52. Pax Runner -‐ Provisioning
• Provisioning your own bundles:
• Create a text file with the bundle URLs (called
“profile”):
file:paint/servicebased.host-‐1.0.0.jar
file:paint/servicebased.circle-‐1.0.0.jar
• Point to the file when launching:
pax-‐run.sh -‐-‐args=file:profile
• Provisioning all bundles in a directory:
pax-‐run.sh mybundledir/
53. Pax Runner -‐ Crea*ng scripts
• Crea<ng a script to launch a framework
without Pax Runner:
pax-‐run.sh -‐-‐executor=script
-‐-‐workingDirectory=.
• Create an archive containing everything you
need to run:
pax-‐run.sh -‐-‐executor=zip
-‐-‐profiles=felix.webconsole,compendium
54. Excercises
• Launch Pax Runner with different fw’s
• Launch a profile (felix.webconsole)
hMp://localhost:8080/system/console
and log in as admin/admin
• Create a profile for the Paint Program
• Add webconsole (for monitoring)
• Create a distributable ZIP file with Pax Runner
55. Experience: Pax Runner
• great for development
• nicely integrates into build environment
• base for Pax Exam (tes<ng framework)
• don’t ship to customers (needs online
connec<on, usually you don’t want that much
freedom)
56. Apache Felix File Install
• Simple and Lightweight deployer
• Hotdeploy directory
• The content of the directory represents the content in the
framework
• Support for bundles and configura<ons
57. Apache Felix File Install
• Take all bundles in a given directory and install
them
• Start all bundles
• If a bundle can‘t be resolved try it again the next <me
• Monitor the directory and
• if a bundle gets removed uninstall it
• if a bundle gets added install and start it
• if a bundle gets updated update and refresh it
• Same for configura<ons
58. Summary
• File Install adds hotdeploy directory
• Supports hotdeploy of bundles and
configura<ons
• Can be extended for other types of
deployments
• Good for development
59. Exercises
• Launch a framework with File Install and Web
Console
pax-‐run.sh
-‐-‐profiles=felix.config,felix.fileinstall
• Check the bundles with Web Console
• Deploy the main paint applica<on and some
shapes
• Add and remove shapes to see how the
applica<on behaves
60. Experience: File Install
• Great for development, hot deployment
• In general not so great for produc<on: limited
control, does your app really support hot
deployment at “every” point in <me?
• IF you use it in produc<on, at least customize
it, but look for other solu<ons
61. OBR
• OBR aMempts to define a common bundle
repository
• Enable to share, discover, and deploy
• Addresses:
• Inability of developers to discover and re-‐use exis<ng
bundles
• Difficulty in deploying exis<ng bundles
62. OBR Status
• Oscar bundle repository
• OSGi Bundle Repository RFC 112
• Current status unsure
• Might become the felix bundlerepository
63. OBR Design
• Generic capability/requirement model
• XML representa<on
• Models package, bundle, fragments, na<ve, and
service dependencies (plus arbitrary ones)
• Repository Admin Service for discovery and
deployment of bundles
68. Summary
• OBR is addressing to
• find exis<ng bundles
• use exis<ng bundles
• share bundles
• OBR allows to resolve the transi<ve closure
over the dependencies of a bundle
69. Example
• Launch a framework with OBR
pax-‐run.sh
-‐-‐profiles=felix.obr
• Add repository to OBR
• Deploy bundles from OBR via shell
71. Apache ACE
• Started in incubator on april 24th 2009
• So8ware distribu<on framework
based on OSGi
• 12 commiMers
• working codebase
• hMp://incubator.apache.org/ace/
73. Keeping the history
last year
!"#$%&'(! *%"+,'(!
last month
!"#$%&'(!
!"#$%&'() *%"+,'(!
last week
!"#$%&'(!
!"#$%&'() +%",-'(!
*%"+,'(-
*%"+,'() now
!"#$%&'(! +%",-'(!
!"#$%&'() +%",-'()
*%"+,'(-
!"#$%&'()
!"#$%&'(* +%",-'()
+%",-'(*
!"#$%&'(* +%",-'(*
74. Why?
• Automate deployment
• Insight into who uses what
• History of each system
• Consistent development, tes<ng, produc<on
• Basis for several possible extensions
79. Organizing ar*facts
• group ar<facts: makes them manageable
• two levels: feature and distribu<on
• Analogy: IKEA catalog
• data is kept in “store repository”
!"#$%&'%(#)*"#$+
,$-./0" 5%/"3$% 1*)"$*23-#4
80. Mapping them onto targets
• mapping distribu<ons to targets
• some<mes done by an external system
• data kept in “license repository”
!"#$%&$'($)*&"+*,-
."&+,"/01*% 23,4$+
87. Deployment Admin
• deployment packages
• versioned set of ar<facts
• transac<onal install/update
• fix packages provide deltas
• signing makes them secure
• extensible through resource processors
• AutoConfig defines configura<on admin data
88. From dependency to deployment
!"#$%&'%(#)*"#$+ 6*0%4)%&'%(#)*"#$+ 1%(9#+:%4"&'%(#)*"#$+
,$-./0" 5%/"3$% 1*)"$*23-#4
+ 1*)"$*23-#4 7/$8%"
= 7/$8%" ,$-./0"
92. Experience: embedded
• Characteris<cs: long running, deployed in
places you cannot reach, not always on, not
“reachable” from the server
• most “conven<onal” management tooling is
fairly useless (JMX, web console, ...)
• make sure you can deploy, make sure you can
see
93. Exercises
• Launch ACE
unzip, then go into folder and start run.sh/bat
• Browse to the UI
hMp://localhost:8080/webui/
• Upload the set of bundles for the Paint app
put in store/ folder
• Launch a target, hook it up
unzip, then go into folder and start run.sh/bat
• Add and remove things
94. Experience: source to produc*on
• developer runs on local machine (build
creates bundles, auto deploys to ACE)
• con<nuous build feeds test servers (deploy
like you would in produc<on)
• QA team uses the same bundles, performs
test on provisioned systems
• release management finally ships to customer
95. Ques*ons
We, Karl Pauls and Marcel Offermans, hereby
declare that this participant officially became a:
Certified
bundle manager
Full Name
Marcel and Karl are both OSGi experts. For additional training or help with your
project, contact them directly or via their companies’ websites.
Marcel Offermans Karl Pauls
marcel.offermans@luminis.nl karl.pauls@akquinet.de
!"#$%&%'()**%% !"#$%"&&"'(
+$,%-./0,)1)2$.*34/5%678%9):$1.%