Top Banner
and Apache Aries/Felix David Bosschaert Provisioning with OSGi Subsystems 1 of 35
34
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: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

and Apache Aries/FelixDavid Bosschaert

Provisioning with OSGi

Subsystems

1 of 35

Page 2: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

About me

David Bosschaert ([email protected])⦿ Works at Adobe R&D⦿ Co-chair OSGi EEG⦿ Open Source committer⦿ Cloud enthusiast

2 of 35

Page 3: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Topics

⦿ Sample using latest Declarative Services⦿ Using Subsystems to package and deploy⦿ OSGi Repository to resolve dependencies

... demo throughout ...

3 of 35

Page 4: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Running ExampleDevice Monitor

... a little webapp to monitor all your gadgets ...

4 of 35

Page 5: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Declarative ServicesBeing updated for OSGi Enterprise R6

Improved Configuration AdminintegrationField-based injectionsIntrospective APIPrototype Service Factory... other smaller improvements ...

5 of 35

Page 6: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

DS Configured Componentiimmppoorrtt javax.servlet.SSeerrvvlleett;iimmppoorrtt org.osgi.service.component.annotations.*;iimmppoorrtt org.osgi.service.http.HHttttppSSeerrvviiccee;

@Componentppuubblliicc 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

Page 7: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Configuration usingAnnotationsppuubblliicc @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

Page 8: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Example Bundle ManifestBBuunnddllee-MMaanniiffeessttVVeerrssiioonn: 2BBuunnddllee-SSyymmbboolliiccNNaammee: devicemon-dsBBuunnddllee-VVeerrssiioonn: 0.0.1SSeerrvviiccee-CCoommppoonneenntt: OSGI-INF/component.xmlIImmppoorrtt-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

Page 9: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Finished app...2 Bundles

devicemon.jardepends on DS and HTTP Service

devicemon-ssh.jardepends on Apache Mina SSHD

9 of 35

Page 10: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Deploy it...Now I want to easily deploy my app

⟱create a Subsystem of it!

10 of 35

Page 11: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

SubsystemsOSGi Enterprise spec 134

A subsystem...collection of bundles put together

feature - everything sharedapplication - isolated, nothing shared outcomposite - configurable in-between

a zip file with .esa extensioncan be nestedcan depend on bundles or othersubsystems

Subsystems can use OSGi Repositories toresolve dependencies

11 of 35

Page 12: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

devicemon-ds.esaJust 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.MFSSuubbssyysstteemm-SSyymmbboolliiccNNaammee: devicemon-dsSSuubbssyysstteemm-VVeerrssiioonn: 0.0.1SSuubbssyysstteemm-TTyyppee: osgi.subsystem.feature

note, I didn't put my dependencies in the .esa file

12 of 35

Page 13: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Feature subsystemsdevicemon-ds.esa: a Feature Subsystem

All the bundles inside work just as shared bundlesin OSGiSubsystem installed/started/stopped as 1 unitDependencies pulled in either from .esa or fromrepository

as neededare reference-counted

13 of 35

Page 14: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Apache Felix + Apache Aries Subsystems

14 of 35

Page 15: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Add HTTP subsystem

15 of 35

Page 16: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

3 bundles in 1 operation

16 of 35

Page 17: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Our subsystem doesn't install!

NB: a failed subsystem install doesn'tleave any bundles behind...

17 of 35

Page 18: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

OSGi RepositoryOSGi Enterprise spec 132

Inspired by Felix OBRSimple but powerfulActual repo can be remote or localFind resources

based on their capabilitiesany resourceany capability

OSGi has defined:standard Bundle capabilitiesBundle, Subsystem resource typessome more general capabilities

18 of 35

Page 19: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

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

Page 20: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Repository XML

Format defined by OSGi Repository SpecStandard way to feed a repository with informationStandard way for repositories to exchange dataGenerate it with the bindex/RepoIndex tool:

https://github.com/osgi/bindex(https://github.com/osgi/bindex)

20 of 35

Page 21: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Repository ServiceObtain resources from the repositoryFind 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

Page 22: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Add and prime a Repository

22 of 35

Page 23: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Our subsystem works!

23 of 35

Page 24: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Descriptor SubsystemsA 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.MFSSuubbssyysstteemm-SSyymmbboolliiccNNaammee: devicemon-ds-declSSuubbssyysstteemm-VVeerrssiioonn: 0.0.1SSuubbssyysstteemm-TTyyppee: osgi.subsystem.featureSSuubbssyysstteemm-CCoonntteenntt: devicemon-ds;version=0.0.1, devicemon-ssh;version=0.0.1

25 of 35

Page 25: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Start with only

Subsystems + Repository

26 of 35

Page 26: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Dependencies at work

http.esa pulled in automatically

27 of 35

Page 27: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Unpredictable dependency

both 0.9.0 and 0.9.1 satisfy requirement

28 of 35

Page 28: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Subsystem Deployment DescriptorOnce QA-ed, create a DEPLOYMENT.MF to fixdependencies$ 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.MFSSuubbssyysstteemm-VVeerrssiioonn: 0.0.1SSuubbssyysstteemm-TTyyppee: osgi.subsystem.featureDDeeppllooyyeedd-CCoonntteenntt: devicemon-ds;deployed-version=0.0.1, devicemon-ssh;deployed-version=0.0.1PPrroovviissiioonn-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

Page 29: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

SSHD dependency now as predicted

30 of 35

Page 30: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Creating .esa filesUsing Maven with esa-maven-plugin

From the Apache Aries project1.0.0 release available nowhttp://aries.apache.org/modules/esamavenpluginproject.html(http://aries.apache.org/modules/esamavenpluginproject.html)

31 of 35

Page 31: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

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 commandhttps://github.com/bosschaert/coderthoughts/

tree/master/subsystem-gogo-command

(https://github.com/bosschaert/coderthoughts

/tree/master/subsystem-gogo-command)

devicemon project:32 of 35

Page 32: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

https://github.com/bosschaert/devicemon

(https://github.com/bosschaert/devicemon)

33 of 35

Page 33: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

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

Page 34: Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix

Questions?

35 of 35