Provisioning with OSGi 
Subsystems 
and Apache Aries/Felix 
David Bosschaert 
1 of 35
About me 
David Bosschaert (davidb@apache.org) 
⦿ Works at Adobe R&D 
⦿ Co-chair OSGi EEG 
⦿ Open Source committer 
⦿ Cloud enthusiast 
2 of 35
Topics 
⦿ Sample using latest Declarative Services 
⦿ Using Subsystems to package and deploy 
⦿ OSGi Repository to resolve dependencies 
... demo throughout ... 
3 of 35
Running Example 
Device Monitor 
... a little webapp to monitor all your gadgets ... 
4 of 35
Declarative Services 
Being updated for OSGi Enterprise R6 
Improved Configuration Admin 
integration 
Field-based injections 
Introspective API 
Prototype Service Factory 
... other smaller improvements ... 
5 of 35
DS Configured Component 
iimmppoorrtt javax.servlet.SSeerrvvlleett; 
iimmppoorrtt org.osgi.service.component.annotations.*; 
iimmppoorrtt org.osgi.service.http.HHttttppSSeerrvviiccee; 
@Component 
ppuubblliicc ccllaassss DDeevviicceeMMoonniittoorr { 
@FieldReference 
pprriivvaattee HHttttppSSeerrvviiccee httpService; 
@Activate 
ppuubblliicc vvooiidd activate(MMoonniittoorrCCoonnffiigg cfg) { 
SSttrriinngg rootCtx = cfg.ctx_prefix(); 
iiff (!rootCtx.endsWith("/")) 
rootCtx = rootCtx + "/"; 
registerServlet(rootCtx + "dmon", nneeww MMoonniittoorrSSeerrvvlleett()); 
registerServlet(rootCtx + "device", nneeww DDeevviicceeSSeerrvvlleett()); 
} 
pprriivvaattee vvooiidd registerServlet(SSttrriinngg ctx, SSeerrvvlleett servlet) { 
httpService.registerServlet(ctx, servlet, nnuullll, nnuullll); 
} 
} 
6 of 35
Configuration using 
Annotations 
ppuubblliicc @interface MMoonniittoorrCCoonnffiigg { 
SSttrriinngg ctx_prefix() ddeeffaauulltt "/"; 
bboooolleeaann auto_refresh() ddeeffaauulltt ffaallssee; 
iinntt interval() ddeeffaauulltt 30; 
} 
annotation used as an ordinary interface, 
with added defaults 
... weird but works great ... 
7 of 35
Example Bundle Manifest 
BBuunnddllee-MMaanniiffeessttVVeerrssiioonn: 2 
BBuunnddllee-SSyymmbboolliiccNNaammee: devicemon-ds 
BBuunnddllee-VVeerrssiioonn: 0.0.1 
SSeerrvviiccee-CCoommppoonneenntt: OSGI-INF/component.xml 
IImmppoorrtt-PPaacckkaaggee: javax.servlet;version="[2.5,3)", 
org.coderthoughts.devicemon.ssh;version="[1.0,2)", 
org.osgi.service.http;version="[1.2,2)" 
RReeqquuiirree-CCaappaabbiilliittyy: 
osgi.extender;filter:="(&(osgi.extender=osgi.component) 
(version>=1.2.0)(!(version>=2.0.0)))" 
Note that the javax.servlet import should really use 
Portable Contracts (http://www.osgi.org/Specifications 
/ReferenceContract)! 
8 of 35
Finished app... 
2 Bundles 
devicemon.jar 
depends on DS and HTTP Service 
devicemon-ssh.jar 
depends on Apache Mina SSHD 
9 of 35
Deploy it... 
Now I want to easily deploy my app 
⟱ 
create a Subsystem of it! 
10 of 35
Subsystems 
OSGi Enterprise spec 134 
A subsystem... 
collection of bundles put together 
feature - everything shared 
application - isolated, nothing shared out 
composite - configurable in-between 
a zip file with .esa extension 
can be nested 
can depend on bundles or other 
subsystems 
Subsystems can use OSGi Repositories to 
resolve dependencies 
11 of 35
devicemon-ds.esa 
Just a zip file... 
$ tar tvf devicemon-ds.esa 
-rwxrwxrwx 99 8 JJaann 15:40 OSGI-INF/SUBSYSTEM.MF 
-rwxrwxrwx 18184 8 JJaann 16:01 devicemon-ds.jar 
-rwxrwxrwx 5968 8 JJaann 16:02 devicemon-ssh.jar 
Subsystem Manifest 
$ cat OSGI-INF/SUBSYSTEM.MF 
SSuubbssyysstteemm-SSyymmbboolliiccNNaammee: devicemon-ds 
SSuubbssyysstteemm-VVeerrssiioonn: 0.0.1 
SSuubbssyysstteemm-TTyyppee: osgi.subsystem.feature 
note, I didn't put my dependencies in the .esa file 
12 of 35
Feature subsystems 
devicemon-ds.esa: a Feature Subsystem 
All the bundles inside work just as shared bundles 
in OSGi 
Subsystem installed/started/stopped as 1 unit 
Dependencies pulled in either from .esa or from 
repository 
as needed 
are reference-counted 
13 of 35
Apache Felix + Apache Aries Subsystems 
14 of 35
Add HTTP subsystem 
15 of 35
3 bundles in 1 operation 
16 of 35
Our subsystem doesn't install! 
NB: a failed subsystem install doesn't 
leave any bundles behind... 
17 of 35
OSGi Repository 
OSGi Enterprise spec 132 
Inspired by Felix OBR 
Simple but powerful 
Actual repo can be remote or local 
Find resources 
based on their capabilities 
any resource 
any capability 
OSGi has defined: 
standard Bundle capabilities 
Bundle, Subsystem resource types 
some more general capabilities 
18 of 35
Add resources using standard XML 
Example 
<<rreeppoossiittoorryy increment='1389281419631' name='MyRepo' xmlns='http://www.osgi.org/xmlns/repository/v1.0.0'>> 
<<rreessoouurrccee>> 
<<ccaappaabbiilliittyy namespace='osgi.identity'>> 
<<aattttrriibbuuttee name='osgi.identity' value='org.apache.sshd.core'//>> 
<<aattttrriibbuuttee name='type' value='osgi.bundle'//>> 
<<aattttrriibbuuttee name='version' type='Version' value='0.9.0'//>> 
<<//ccaappaabbiilliittyy>> 
<<ccaappaabbiilliittyy namespace='osgi.content'>> 
<<aattttrriibbuuttee name='osgi.content' value='a1c64578808c38a63cd6563e9936f025638aeaf9de70f36765367db81c0afc38' 
<<aattttrriibbuuttee name='url' value='local-repo/sshd-core.jar'//>> 
<<aattttrriibbuuttee name='size' type='Long' value='464733'//>> 
<<aattttrriibbuuttee name='mime' value='application/vnd.osgi.bundle'//>> 
<<//ccaappaabbiilliittyy>> 
<<ccaappaabbiilliittyy namespace='osgi.wiring.package'>> 
<<aattttrriibbuuttee name='osgi.wiring.package' value='org.apache.sshd'//>> 
<<aattttrriibbuuttee name='version' type='Version' value='0.5.0'//>> 
<<aattttrriibbuuttee name='bundle-symbolic-name' value='org.apache.sshd.core'//>> 
<<aattttrriibbuuttee name='bundle-version' type='Version' value='0.9.0'//>> 
<<ddiirreeccttiivvee name='uses' value='org.apache.sshd.client'//>> 
<<//ccaappaabbiilliittyy>> 
<!-- More capabilities --> 
<<rreeqquuiirreemmeenntt namespace='osgi.wiring.package'>> 
<<ddiirreeccttiivvee name='filter' 
value='(&(osgi.wiring.package=org.slf4j)(version>=1.6.0)(!(version>=2.0.0)))'/> 
<<//rreeqquuiirreemmeenntt>> 
<!-- More requirements --> 
<<//rreessoouurrccee>> 
<!-- More resources --> 
<<//rreeppoossiittoorryy>> 
19 of 35
Repository XML 
Format defined by OSGi Repository Spec 
Standard way to feed a repository with information 
Standard way for repositories to exchange data 
Generate it with the bindex/RepoIndex tool: 
https://github.com/osgi/bindex 
(https://github.com/osgi/bindex) 
20 of 35
Repository Service 
Obtain resources from the repository 
Find a bundle... 
RReeppoossiittoorryy repo = ... // from Service Registry ... 
RReeqquuiirreemmeennttBBuuiillddeerr rb = nneeww RReeqquuiirreemmeennttBBuuiillddeerr("osgi.wiring.package"); 
rb.addDirective("filter", 
"(&(osgi.wiring.package=org.apache.ssh)(version=0.5.0))"); 
RReeqquuiirreemmeenntt req = rb.build(); 
CCoolllleeccttiioonn<RReessoouurrccee> bundleResources = repo.findProviders(req); 
... or find some photo's from the North Pole ... 
RReeqquuiirreemmeennttBBuuiillddeerr rb = nneeww RReeqquuiirreemmeennttBBuuiillddeerr("com.acme.photo"); 
rb.addDirective("filter", "(latitude>=66.5622)"); 
RReeqquuiirreemmeenntt req = rb.build(); 
CCoolllleeccttiioonn<RReessoouurrccee> photoResources = repo.findProviders(req); 
21 of 35
Add and prime a Repository 
22 of 35
Our subsystem works! 
23 of 35
Descriptor Subsystems 
A subsystem can be just a descriptor 
... with all resources obtained from a Repository 
$ jar tvf generated/devicemon-ds-decl.esa 
0 TThhuu JJaann 09 12:37:32 GMT 2014 OSGI-INF/ 
175 WWeedd JJaann 08 15:50:28 GMT 2014 OSGI-INF/SUBSYSTEM.MF 
Subsystem Manifest 
$ cat OSGI-INF/SUBSYSTEM.MF 
SSuubbssyysstteemm-SSyymmbboolliiccNNaammee: devicemon-ds-decl 
SSuubbssyysstteemm-VVeerrssiioonn: 0.0.1 
SSuubbssyysstteemm-TTyyppee: osgi.subsystem.feature 
SSuubbssyysstteemm-CCoonntteenntt: devicemon-ds;version=0.0.1, 
devicemon-ssh;version=0.0.1 
25 of 35
Start with only 
Subsystems + Repository 
26 of 35
Dependencies at work 
http.esa pulled in automatically 
27 of 35
Unpredictable dependency 
both 0.9.0 and 0.9.1 satisfy requirement 
28 of 35
Subsystem Deployment Descriptor 
Once QA-ed, create a DEPLOYMENT.MF to fix 
dependencies 
$ jar tvf generated/devicemon-ds-decl-dd.esa 
283 WWeedd JJaann 15 16:39:34 GMT 2014 OSGI-INF/DEPLOYMENT.MF 
175 WWeedd JJaann 08 15:50:28 GMT 2014 OSGI-INF/SUBSYSTEM.MF 
it can freeze deployments 
$ cat OSGI-INF/DEPLOYMENT.MF 
SSuubbssyysstteemm-VVeerrssiioonn: 0.0.1 
SSuubbssyysstteemm-TTyyppee: osgi.subsystem.feature 
DDeeppllooyyeedd-CCoonntteenntt: devicemon-ds;deployed-version=0.0.1, 
devicemon-ssh;deployed-version=0.0.1 
PPrroovviissiioonn-RReessoouurrccee: org.apache.sshd.core;deployed-version=0.9.1, 
org.apache.felix.scr;deployed-version=1.8.2, 
http-subsystem;type=osgi.subsystem.feature;deployed-version=1.2.0 
note version 0.9.1 for org.apache.sshd.core 
Ensures that the runtime deployment is the same as the QA one. 
29 of 35
SSHD dependency now as predicted 
30 of 35
Creating .esa files 
Using Maven with esa-maven-plugin 
From the Apache Aries project 
1.0.0 release available now 
http://aries.apache.org/modules 
/esamavenpluginproject.html 
(http://aries.apache.org/modules 
/esamavenpluginproject.html) 
31 of 35
Where can I get it? 
OSGi Developer Certification: 
http://www.osgi.org/Certification/Developer 
(http://www.osgi.org/Certification/Developer) 
Apache Aries Project: 
http://aries.apache.org (http://aries.apache.org) 
Apache Felix Project: 
http://felix.apache.org (http://felix.apache.org) 
Subsystem Gogo command 
https://github.com/bosschaert/coderthoughts/ 
tree/master/subsystem-gogo-command 
(https://github.com/bosschaert/coderthoughts 
/tree/master/subsystem-gogo-command) 
devicemon project: 32 of 35
https://github.com/bosschaert/devicemon 
(https://github.com/bosschaert/devicemon) 
33 of 35
OSGi Specs 
OSGi Core R6: 
http://www.osgi.org/Specifications/HomePage 
(http://www.osgi.org/Specifications/HomePage) 
Portable Java Contracts: 
http://www.osgi.org/Specifications/ReferenceContract 
(http://www.osgi.org/Specifications/ReferenceContract) 
Enterprise R6 draft: 
http://www.osgi.org/Specifications/Drafts 
(http://www.osgi.org/Specifications/Drafts) 
34 of 35
Questions? 
35 of 35

More Related Content

PDF
Maximize the power of OSGi
PDF
OSGi Cloud Ecosystems (EclipseCon 2013)
PDF
What's cool in the new and updated OSGi Specs (EclipseCon 2014)
PDF
Developing your own OpenStack Swift middleware
PPTX
ARGUS - THE OMNISCIENT CI
PPT
Pemrograman Jaringan
PDF
Second Step to the NoSQL Side: MySQL JSON Functions
PDF
Service Oriented Web Development with OSGi - C Ziegeler
Maximize the power of OSGi
OSGi Cloud Ecosystems (EclipseCon 2013)
What's cool in the new and updated OSGi Specs (EclipseCon 2014)
Developing your own OpenStack Swift middleware
ARGUS - THE OMNISCIENT CI
Pemrograman Jaringan
Second Step to the NoSQL Side: MySQL JSON Functions
Service Oriented Web Development with OSGi - C Ziegeler

What's hot (20)

PPTX
WWHF 2018 - Using PowerUpSQL and goddi for Active Directory Information Gathe...
PDF
NoSQL атакует: JSON функции в MySQL сервере.
PPTX
How to implement a gdpr solution in a cloudera architecture
ODP
Networking and Data Access with Eqela
PDF
Security and performance designs for client-server communications
PDF
MySQL JSON Functions
PPTX
Java Play Restful JPA
PPSX
Oracle Cloud As Services
PPTX
Java Play RESTful ebean
ZIP
Puppet and the Model-Driven Infrastructure
PPTX
Using puppet
PDF
監査ログをもっと身近に!〜統合監査のすすめ〜
PDF
Greach 2019 - Creating Micronaut Configurations
PDF
Fluentd 20150918 no_demo_public
PDF
DB エンジニアのマイクロサービス入門〜Oracle Database と Docker ではじめる API サービス〜
PDF
MySQL Group Replication - Ready For Production? (2018-04)
PDF
CRESTCon Asia 2018 - Config Password Encryption Gone Wrong
PDF
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
PDF
Posh Devcon2009
PDF
Data Encryption at Rest
WWHF 2018 - Using PowerUpSQL and goddi for Active Directory Information Gathe...
NoSQL атакует: JSON функции в MySQL сервере.
How to implement a gdpr solution in a cloudera architecture
Networking and Data Access with Eqela
Security and performance designs for client-server communications
MySQL JSON Functions
Java Play Restful JPA
Oracle Cloud As Services
Java Play RESTful ebean
Puppet and the Model-Driven Infrastructure
Using puppet
監査ログをもっと身近に!〜統合監査のすすめ〜
Greach 2019 - Creating Micronaut Configurations
Fluentd 20150918 no_demo_public
DB エンジニアのマイクロサービス入門〜Oracle Database と Docker ではじめる API サービス〜
MySQL Group Replication - Ready For Production? (2018-04)
CRESTCon Asia 2018 - Config Password Encryption Gone Wrong
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
Posh Devcon2009
Data Encryption at Rest
Ad

Similar to Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix (20)

PDF
OSGi provisioning deep dive and demo (Subsystems, Repository, Contracts and m...
PDF
Subsystems in the Wild - G Charters
PDF
What's new in the OSGi Enterprise Release 5.0
PDF
OSGi Enterprise Expert Group (OSGi Users Forum Germany)
PDF
OSGi Presentation
PDF
Technical Specification Overview - OSGi World Congress 2002 Workshop Intro - ...
PDF
How to Use the OSGi Service Framework in Real-Life Projects - Kai Hackbath, P...
PDF
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...
PDF
Intro to OSGi – the Microservices kernel - P Kriens & T Ward
PDF
Remote Management of OSGi Runtimes - Joachim Ritter, Project Manager, ProSyst...
PPTX
What is os gi and what does osgi
PDF
OSGi Community Event 2010 - App Store for the Connected Home Services
PPTX
OSGi summary
PDF
OSGi and Cloud Computing - David Bosschaert
PDF
Modular Architectures using Micro Services
PPT
OSGi & Blueprint
PPTX
Zero Downtime with OSGi - Chicago Coder Conference 05-15-2015
PDF
Provisioning the IoT
PPTX
Introduction to-osgi
PDF
OSGi Community Event 2010 - OSGi Technical Update
OSGi provisioning deep dive and demo (Subsystems, Repository, Contracts and m...
Subsystems in the Wild - G Charters
What's new in the OSGi Enterprise Release 5.0
OSGi Enterprise Expert Group (OSGi Users Forum Germany)
OSGi Presentation
Technical Specification Overview - OSGi World Congress 2002 Workshop Intro - ...
How to Use the OSGi Service Framework in Real-Life Projects - Kai Hackbath, P...
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...
Intro to OSGi – the Microservices kernel - P Kriens & T Ward
Remote Management of OSGi Runtimes - Joachim Ritter, Project Manager, ProSyst...
What is os gi and what does osgi
OSGi Community Event 2010 - App Store for the Connected Home Services
OSGi summary
OSGi and Cloud Computing - David Bosschaert
Modular Architectures using Micro Services
OSGi & Blueprint
Zero Downtime with OSGi - Chicago Coder Conference 05-15-2015
Provisioning the IoT
Introduction to-osgi
OSGi Community Event 2010 - OSGi Technical Update
Ad

More from David Bosschaert (10)

PDF
Node MCU Fun
PDF
What's cool in the new and updated OSGi Specs (2013)
PDF
Benefits of OSGi in Practise
PDF
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
PDF
OSGi Cloud Ecosystems
PDF
OpenJDK Penrose Presentation (JavaOne 2012)
PDF
Update on the OSGi Enterprise Expert Group
PDF
What's new in the OSGi 4.2 Enterprise Release
PDF
Distributed Services - OSGi 4.2 and possible future enhancements
PDF
Distributed OSGi Demo Eclipsecon 2009
Node MCU Fun
What's cool in the new and updated OSGi Specs (2013)
Benefits of OSGi in Practise
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
OSGi Cloud Ecosystems
OpenJDK Penrose Presentation (JavaOne 2012)
Update on the OSGi Enterprise Expert Group
What's new in the OSGi 4.2 Enterprise Release
Distributed Services - OSGi 4.2 and possible future enhancements
Distributed OSGi Demo Eclipsecon 2009

Recently uploaded (20)

PPTX
Configure Apache Mutual Authentication
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PPTX
Build Your First AI Agent with UiPath.pptx
PPTX
Microsoft User Copilot Training Slide Deck
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
DOCX
search engine optimization ppt fir known well about this
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
4 layer Arch & Reference Arch of IoT.pdf
Configure Apache Mutual Authentication
Basics of Cloud Computing - Cloud Ecosystem
Consumable AI The What, Why & How for Small Teams.pdf
Early detection and classification of bone marrow changes in lumbar vertebrae...
NewMind AI Weekly Chronicles – August ’25 Week IV
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
giants, standing on the shoulders of - by Daniel Stenberg
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Enhancing plagiarism detection using data pre-processing and machine learning...
Comparative analysis of machine learning models for fake news detection in so...
sbt 2.0: go big (Scala Days 2025 edition)
Build Your First AI Agent with UiPath.pptx
Microsoft User Copilot Training Slide Deck
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
search engine optimization ppt fir known well about this
Custom Battery Pack Design Considerations for Performance and Safety
Rapid Prototyping: A lecture on prototyping techniques for interface design
4 layer Arch & Reference Arch of IoT.pdf

Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

  • 1. Provisioning with OSGi Subsystems and Apache Aries/Felix David Bosschaert 1 of 35
  • 2. About me David Bosschaert ([email protected]) ⦿ Works at Adobe R&D ⦿ Co-chair OSGi EEG ⦿ Open Source committer ⦿ Cloud enthusiast 2 of 35
  • 3. Topics ⦿ Sample using latest Declarative Services ⦿ Using Subsystems to package and deploy ⦿ OSGi Repository to resolve dependencies ... demo throughout ... 3 of 35
  • 4. Running Example Device Monitor ... a little webapp to monitor all your gadgets ... 4 of 35
  • 5. Declarative Services Being updated for OSGi Enterprise R6 Improved Configuration Admin integration Field-based injections Introspective API Prototype Service Factory ... other smaller improvements ... 5 of 35
  • 6. DS Configured Component iimmppoorrtt javax.servlet.SSeerrvvlleett; iimmppoorrtt org.osgi.service.component.annotations.*; iimmppoorrtt org.osgi.service.http.HHttttppSSeerrvviiccee; @Component ppuubblliicc ccllaassss DDeevviicceeMMoonniittoorr { @FieldReference pprriivvaattee HHttttppSSeerrvviiccee httpService; @Activate ppuubblliicc vvooiidd activate(MMoonniittoorrCCoonnffiigg cfg) { SSttrriinngg rootCtx = cfg.ctx_prefix(); iiff (!rootCtx.endsWith("/")) rootCtx = rootCtx + "/"; registerServlet(rootCtx + "dmon", nneeww MMoonniittoorrSSeerrvvlleett()); registerServlet(rootCtx + "device", nneeww DDeevviicceeSSeerrvvlleett()); } pprriivvaattee vvooiidd registerServlet(SSttrriinngg ctx, SSeerrvvlleett servlet) { httpService.registerServlet(ctx, servlet, nnuullll, nnuullll); } } 6 of 35
  • 7. Configuration using Annotations ppuubblliicc @interface MMoonniittoorrCCoonnffiigg { SSttrriinngg ctx_prefix() ddeeffaauulltt "/"; bboooolleeaann auto_refresh() ddeeffaauulltt ffaallssee; iinntt interval() ddeeffaauulltt 30; } annotation used as an ordinary interface, with added defaults ... weird but works great ... 7 of 35
  • 8. Example Bundle Manifest BBuunnddllee-MMaanniiffeessttVVeerrssiioonn: 2 BBuunnddllee-SSyymmbboolliiccNNaammee: devicemon-ds BBuunnddllee-VVeerrssiioonn: 0.0.1 SSeerrvviiccee-CCoommppoonneenntt: OSGI-INF/component.xml IImmppoorrtt-PPaacckkaaggee: javax.servlet;version="[2.5,3)", org.coderthoughts.devicemon.ssh;version="[1.0,2)", org.osgi.service.http;version="[1.2,2)" RReeqquuiirree-CCaappaabbiilliittyy: osgi.extender;filter:="(&(osgi.extender=osgi.component) (version>=1.2.0)(!(version>=2.0.0)))" Note that the javax.servlet import should really use Portable Contracts (http://www.osgi.org/Specifications /ReferenceContract)! 8 of 35
  • 9. Finished app... 2 Bundles devicemon.jar depends on DS and HTTP Service devicemon-ssh.jar depends on Apache Mina SSHD 9 of 35
  • 10. Deploy it... Now I want to easily deploy my app ⟱ create a Subsystem of it! 10 of 35
  • 11. Subsystems OSGi Enterprise spec 134 A subsystem... collection of bundles put together feature - everything shared application - isolated, nothing shared out composite - configurable in-between a zip file with .esa extension can be nested can depend on bundles or other subsystems Subsystems can use OSGi Repositories to resolve dependencies 11 of 35
  • 12. devicemon-ds.esa Just a zip file... $ tar tvf devicemon-ds.esa -rwxrwxrwx 99 8 JJaann 15:40 OSGI-INF/SUBSYSTEM.MF -rwxrwxrwx 18184 8 JJaann 16:01 devicemon-ds.jar -rwxrwxrwx 5968 8 JJaann 16:02 devicemon-ssh.jar Subsystem Manifest $ cat OSGI-INF/SUBSYSTEM.MF SSuubbssyysstteemm-SSyymmbboolliiccNNaammee: devicemon-ds SSuubbssyysstteemm-VVeerrssiioonn: 0.0.1 SSuubbssyysstteemm-TTyyppee: osgi.subsystem.feature note, I didn't put my dependencies in the .esa file 12 of 35
  • 13. Feature subsystems devicemon-ds.esa: a Feature Subsystem All the bundles inside work just as shared bundles in OSGi Subsystem installed/started/stopped as 1 unit Dependencies pulled in either from .esa or from repository as needed are reference-counted 13 of 35
  • 14. Apache Felix + Apache Aries Subsystems 14 of 35
  • 15. Add HTTP subsystem 15 of 35
  • 16. 3 bundles in 1 operation 16 of 35
  • 17. Our subsystem doesn't install! NB: a failed subsystem install doesn't leave any bundles behind... 17 of 35
  • 18. OSGi Repository OSGi Enterprise spec 132 Inspired by Felix OBR Simple but powerful Actual repo can be remote or local Find resources based on their capabilities any resource any capability OSGi has defined: standard Bundle capabilities Bundle, Subsystem resource types some more general capabilities 18 of 35
  • 19. Add resources using standard XML Example <<rreeppoossiittoorryy increment='1389281419631' name='MyRepo' xmlns='http://www.osgi.org/xmlns/repository/v1.0.0'>> <<rreessoouurrccee>> <<ccaappaabbiilliittyy namespace='osgi.identity'>> <<aattttrriibbuuttee name='osgi.identity' value='org.apache.sshd.core'//>> <<aattttrriibbuuttee name='type' value='osgi.bundle'//>> <<aattttrriibbuuttee name='version' type='Version' value='0.9.0'//>> <<//ccaappaabbiilliittyy>> <<ccaappaabbiilliittyy namespace='osgi.content'>> <<aattttrriibbuuttee name='osgi.content' value='a1c64578808c38a63cd6563e9936f025638aeaf9de70f36765367db81c0afc38' <<aattttrriibbuuttee name='url' value='local-repo/sshd-core.jar'//>> <<aattttrriibbuuttee name='size' type='Long' value='464733'//>> <<aattttrriibbuuttee name='mime' value='application/vnd.osgi.bundle'//>> <<//ccaappaabbiilliittyy>> <<ccaappaabbiilliittyy namespace='osgi.wiring.package'>> <<aattttrriibbuuttee name='osgi.wiring.package' value='org.apache.sshd'//>> <<aattttrriibbuuttee name='version' type='Version' value='0.5.0'//>> <<aattttrriibbuuttee name='bundle-symbolic-name' value='org.apache.sshd.core'//>> <<aattttrriibbuuttee name='bundle-version' type='Version' value='0.9.0'//>> <<ddiirreeccttiivvee name='uses' value='org.apache.sshd.client'//>> <<//ccaappaabbiilliittyy>> <!-- More capabilities --> <<rreeqquuiirreemmeenntt namespace='osgi.wiring.package'>> <<ddiirreeccttiivvee name='filter' value='(&(osgi.wiring.package=org.slf4j)(version>=1.6.0)(!(version>=2.0.0)))'/> <<//rreeqquuiirreemmeenntt>> <!-- More requirements --> <<//rreessoouurrccee>> <!-- More resources --> <<//rreeppoossiittoorryy>> 19 of 35
  • 20. Repository XML Format defined by OSGi Repository Spec Standard way to feed a repository with information Standard way for repositories to exchange data Generate it with the bindex/RepoIndex tool: https://github.com/osgi/bindex (https://github.com/osgi/bindex) 20 of 35
  • 21. Repository Service Obtain resources from the repository Find a bundle... RReeppoossiittoorryy repo = ... // from Service Registry ... RReeqquuiirreemmeennttBBuuiillddeerr rb = nneeww RReeqquuiirreemmeennttBBuuiillddeerr("osgi.wiring.package"); rb.addDirective("filter", "(&(osgi.wiring.package=org.apache.ssh)(version=0.5.0))"); RReeqquuiirreemmeenntt req = rb.build(); CCoolllleeccttiioonn<RReessoouurrccee> bundleResources = repo.findProviders(req); ... or find some photo's from the North Pole ... RReeqquuiirreemmeennttBBuuiillddeerr rb = nneeww RReeqquuiirreemmeennttBBuuiillddeerr("com.acme.photo"); rb.addDirective("filter", "(latitude>=66.5622)"); RReeqquuiirreemmeenntt req = rb.build(); CCoolllleeccttiioonn<RReessoouurrccee> photoResources = repo.findProviders(req); 21 of 35
  • 22. Add and prime a Repository 22 of 35
  • 24. Descriptor Subsystems A subsystem can be just a descriptor ... with all resources obtained from a Repository $ jar tvf generated/devicemon-ds-decl.esa 0 TThhuu JJaann 09 12:37:32 GMT 2014 OSGI-INF/ 175 WWeedd JJaann 08 15:50:28 GMT 2014 OSGI-INF/SUBSYSTEM.MF Subsystem Manifest $ cat OSGI-INF/SUBSYSTEM.MF SSuubbssyysstteemm-SSyymmbboolliiccNNaammee: devicemon-ds-decl SSuubbssyysstteemm-VVeerrssiioonn: 0.0.1 SSuubbssyysstteemm-TTyyppee: osgi.subsystem.feature SSuubbssyysstteemm-CCoonntteenntt: devicemon-ds;version=0.0.1, devicemon-ssh;version=0.0.1 25 of 35
  • 25. Start with only Subsystems + Repository 26 of 35
  • 26. Dependencies at work http.esa pulled in automatically 27 of 35
  • 27. Unpredictable dependency both 0.9.0 and 0.9.1 satisfy requirement 28 of 35
  • 28. Subsystem Deployment Descriptor Once QA-ed, create a DEPLOYMENT.MF to fix dependencies $ jar tvf generated/devicemon-ds-decl-dd.esa 283 WWeedd JJaann 15 16:39:34 GMT 2014 OSGI-INF/DEPLOYMENT.MF 175 WWeedd JJaann 08 15:50:28 GMT 2014 OSGI-INF/SUBSYSTEM.MF it can freeze deployments $ cat OSGI-INF/DEPLOYMENT.MF SSuubbssyysstteemm-VVeerrssiioonn: 0.0.1 SSuubbssyysstteemm-TTyyppee: osgi.subsystem.feature DDeeppllooyyeedd-CCoonntteenntt: devicemon-ds;deployed-version=0.0.1, devicemon-ssh;deployed-version=0.0.1 PPrroovviissiioonn-RReessoouurrccee: org.apache.sshd.core;deployed-version=0.9.1, org.apache.felix.scr;deployed-version=1.8.2, http-subsystem;type=osgi.subsystem.feature;deployed-version=1.2.0 note version 0.9.1 for org.apache.sshd.core Ensures that the runtime deployment is the same as the QA one. 29 of 35
  • 29. SSHD dependency now as predicted 30 of 35
  • 30. Creating .esa files Using Maven with esa-maven-plugin From the Apache Aries project 1.0.0 release available now http://aries.apache.org/modules /esamavenpluginproject.html (http://aries.apache.org/modules /esamavenpluginproject.html) 31 of 35
  • 31. Where can I get it? OSGi Developer Certification: http://www.osgi.org/Certification/Developer (http://www.osgi.org/Certification/Developer) Apache Aries Project: http://aries.apache.org (http://aries.apache.org) Apache Felix Project: http://felix.apache.org (http://felix.apache.org) Subsystem Gogo command https://github.com/bosschaert/coderthoughts/ tree/master/subsystem-gogo-command (https://github.com/bosschaert/coderthoughts /tree/master/subsystem-gogo-command) devicemon project: 32 of 35
  • 33. OSGi Specs OSGi Core R6: http://www.osgi.org/Specifications/HomePage (http://www.osgi.org/Specifications/HomePage) Portable Java Contracts: http://www.osgi.org/Specifications/ReferenceContract (http://www.osgi.org/Specifications/ReferenceContract) Enterprise R6 draft: http://www.osgi.org/Specifications/Drafts (http://www.osgi.org/Specifications/Drafts) 34 of 35