SlideShare a Scribd company logo
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...
PPTX
Riga Dev Day - Automated Android Continuous Integration
DOCX
Tutorial to setup OpenStreetMap tileserver with customized boundaries of India
PDF
App container rkt
PDF
Dependencies Managers in C/C++. Using stdcpp 2014
PPT
Why Managed Service Providers Should Embrace Container Technology
PDF
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
DOCX
Backtrack Manual Part6
DOCX
Prizm Installation Guide
PDF
Spraykatz installation & basic usage
PPTX
HPC_MPI_CICD.pptx
PDF
Bare Metal to OpenStack with Razor and Chef
PDF
Docker and friends at Linux Days 2014 in Prague
PPT
Performance analysis in a multitenant cloud environment Using Hadoop Cluster ...
PDF
Dbdeployer, the universal installer
PPTX
Infrastructure as Code in your CD pipelines - London Microsoft DevOps 0423
KEY
Node.js basics
ODP
Content Staging in Drupal 8
PDF
Pentesting iOS Apps
PDF
Chicago Docker Meetup Presentation - Mediafly
OSGi provisioning deep dive and demo (Subsystems, Repository, Contracts and m...
Riga Dev Day - Automated Android Continuous Integration
Tutorial to setup OpenStreetMap tileserver with customized boundaries of India
App container rkt
Dependencies Managers in C/C++. Using stdcpp 2014
Why Managed Service Providers Should Embrace Container Technology
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Backtrack Manual Part6
Prizm Installation Guide
Spraykatz installation & basic usage
HPC_MPI_CICD.pptx
Bare Metal to OpenStack with Razor and Chef
Docker and friends at Linux Days 2014 in Prague
Performance analysis in a multitenant cloud environment Using Hadoop Cluster ...
Dbdeployer, the universal installer
Infrastructure as Code in your CD pipelines - London Microsoft DevOps 0423
Node.js basics
Content Staging in Drupal 8
Pentesting iOS Apps
Chicago Docker Meetup Presentation - Mediafly
Ad

More from David Bosschaert (12)

PDF
Node MCU Fun
PDF
What's cool in the new and updated OSGi Specs (2013)
PDF
Benefits of OSGi in Practise
PDF
OSGi Enterprise Expert Group (OSGi Users Forum Germany)
PDF
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
PDF
OSGi Cloud Ecosystems
PDF
OpenJDK Penrose Presentation (JavaOne 2012)
PDF
What's new in the OSGi Enterprise Release 5.0
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 Enterprise Expert Group (OSGi Users Forum Germany)
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
OSGi Cloud Ecosystems
OpenJDK Penrose Presentation (JavaOne 2012)
What's new in the OSGi Enterprise Release 5.0
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)

PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
The various Industrial Revolutions .pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Web App vs Mobile App What Should You Build First.pdf
PPT
What is a Computer? Input Devices /output devices
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
project resource management chapter-09.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Getting started with AI Agents and Multi-Agent Systems
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Hindi spoken digit analysis for native and non-native speakers
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
The various Industrial Revolutions .pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Programs and apps: productivity, graphics, security and other tools
Module 1.ppt Iot fundamentals and Architecture
A novel scalable deep ensemble learning framework for big data classification...
Web App vs Mobile App What Should You Build First.pdf
What is a Computer? Input Devices /output devices
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
DP Operators-handbook-extract for the Mautical Institute
O2C Customer Invoices to Receipt V15A.pptx
project resource management chapter-09.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
NewMind AI Weekly Chronicles - August'25-Week II
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Getting started with AI Agents and Multi-Agent Systems
TLE Review Electricity (Electricity).pptx
Developing a website for English-speaking practice to English as a foreign la...
Hindi spoken digit analysis for native and non-native speakers

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 (davidb@apache.org) ⦿ 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