deep dive
play

Deep Dive Subsystems, Repository, Contracts and more... David - PDF document

OSGi Application Provisioning Deep Dive Subsystems, Repository, Contracts and more... David Bosschaert 1 of 41 About me David Bosschaert (davidb@apache.org) Works at Adobe R&D Basel Co-chair OSGi EEG Apache committer


  1. OSGi Application Provisioning Deep Dive Subsystems, Repository, Contracts and more... David Bosschaert 1 of 41

  2. About me David Bosschaert (davidb@apache.org) ⦿ Works at Adobe R&D Basel ⦿ Co-chair OSGi EEG ⦿ Apache committer ⦿ Open-source and cloud enthusiast 2 of 41

  3. Topics ⦿ A look at the latest Declarative Services ⦿ Using Subsystems to package and deploy ⦿ OSGi Repository to resolve dependencies ⦿ Portable Java Contracts ... demo throughout ... 3 of 41

  4. Running Example Device Monitor ... a little webapp to monitor all your gadgets ... 4 of 41

  5. Declarative Services Being updated for Enterprise R6 Improved Configuration Admin integration Introspective API Prototype Service Factory ... other smaller improvements ... 5 of 41

  6. DS Configured Component i im mp po or rt t javax.servlet.S Se er rv vl le et t; i im mp po or rt t org.osgi.service.component.annotations.*; i im mp po or rt t org.osgi.service.http.H Ht tt tp pS Se er rv vi ic ce e; @Component p pu ub bl li ic c c cl la as ss s D De ev vi ic ce eM Mo on ni it to or r { p pr ri iv va at te e H Ht tt tp pS Se er rv vi ic ce e httpService; @Reference p pu ub bl li ic c v vo oi id d setHttpService(H Ht tt tp pS Se er rv vi ic ce e svc) { httpService = svc; } @Activate p pu ub bl li ic c v vo oi id d activate(M Mo on ni it to or rC Co on nf fi ig g cfg) { S St tr ri in ng g rootCtx = cfg.ctxPrefix(); i if f (!rootCtx.endsWith("/")) rootCtx = rootCtx + "/"; registerServlet(rootCtx + "dmon", n ne ew w M Mo on ni it to or rS Se er rv vl le et t()); registerServlet(rootCtx + "device", n ne ew w D De ev vi ic ce eS Se er rv vl le et t()); } p pr ri iv va at te e v vo oi id d registerServlet(S St tr ri in ng g ctx, S Se er rv vl le et t servlet) { httpService.registerServlet(ctx, servlet, n nu ul ll l, n nu ul ll l); } } 6 of 41

  7. Configuration using Annotations p pu ub bl li ic c @interface M Mo on ni it to or rC Co on nf fi ig g { S St tr ri in ng g ctxPrefix() d de ef fa au ul lt t "/"; b bo oo ol le ea an n autoRefresh() d de ef fa au ul lt t f fa al ls se e; i in nt t interval() d de ef fa au ul lt t 30; } annotation used as an ordinary interface, with added defaults ... weird but works great ... 7 of 41

  8. Example Bundle Manifest B Bu un nd dl le e-M Ma an ni if fe es st tV Ve er rs si io on n: 2 B Bu un nd dl le e-S Sy ym mb bo ol li ic cN Na am me e: devicemon-ds B Bu un nd dl le e-V Ve er rs si io on n: 0.0.1 S Se er rv vi ic ce e-C Co om mp po on ne en nt t: OSGI-INF/component.xml I Im mp po or rt t-P Pa ac ck ka ag ge e: javax.servlet;version="[2.5,3)", org.coderthoughts.devicemon.ssh;version="[1.0,2)", org.osgi.service.http;version="[1.2,2)" R Re eq qu ui ir re e-C Ca ap pa ab bi il li it ty y: osgi.extender;filter:="(&(osgi.extender=osgi.component) (version>=1.2.0)(!(version>=2.0.0)))", osgi.whiteboard;filter:="(osgi.whiteboard=osgi.http)" Note that the javax.servlet import should really use contracts! 8 of 41

  9. Finished app... 2 Bundles devicemon.jar depends on DS and HTTP Service devicemon-ssh.jar depends on Apache Mina SSHD 9 of 41

  10. Deploy it... Now I want to easily deploy my app ⟱ create a Subsystem of it! 10 of 41

  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 41

  12. devicemon-ds.esa Just a zip file... $ tar tvf devicemon-ds.esa -rwxrwxrwx 99 8 J Ja an n 15:40 OSGI-INF/SUBSYSTEM.MF -rwxrwxrwx 18184 8 J Ja an n 16:01 devicemon-ds.jar -rwxrwxrwx 5968 8 J Ja an n 16:02 devicemon-ssh.jar Subsystem Manifest $ cat OSGI-INF/SUBSYSTEM.MF S Su ub bs sy ys st te em m-S Sy ym mb bo ol li ic cN Na am me e: devicemon-ds S Su ub bs sy ys st te em m-V Ve er rs si io on n: 0.0.1 S Su ub bs sy ys st te em m-T Ty yp pe e: osgi.subsystem.feature note, I didn't put my dependencies in the .esa file 12 of 41

  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 41

  14. Apache Felix + Apache Aries Subsystems 14 of 41

  15. Add HTTP subsystem 15 of 41

  16. 3 bundles in 1 operation 16 of 41

  17. Our subsystem doesn't install! NB: a failed subsystem install doesn't leave any bundles behind... 17 of 41

  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 41

  19. Add resources using standard XML Example < <r re ep po os si it to or ry y increment='1389281419631' name='MyRepo' xmlns='http://www.osgi.org/xmlns/repository/v1.0.0'> > < <r re es so ou ur rc ce e> > < <c ca ap pa ab bi il li it ty y namespace='osgi.identity'> > < <a at tt tr ri ib bu ut te e name='osgi.identity' value='org.apache.sshd.core'/ /> > < <a at tt tr ri ib bu ut te e name='type' value='osgi.bundle'/ /> > < <a at tt tr ri ib bu ut te e name='version' type='Version' value='0.9.0'/ /> > < </ /c ca ap pa ab bi il li it ty y> > < <c ca ap pa ab bi il li it ty y namespace='osgi.content'> > < <a at tt tr ri ib bu ut te e name='osgi.content' value='a1c64578808c38a63cd6563e9936f025638aeaf9de70f36765367db81c0afc38' < <a at tt tr ri ib bu ut te e name='url' value='local-repo/sshd-core.jar'/ /> > < <a at tt tr ri ib bu ut te e name='size' type='Long' value='464733'/ /> > < <a at tt tr ri ib bu ut te e name='mime' value='application/vnd.osgi.bundle'/ /> > < </ /c ca ap pa ab bi il li it ty y> > < <c ca ap pa ab bi il li it ty y namespace='osgi.wiring.package'> > < <a at tt tr ri ib bu ut te e name='osgi.wiring.package' value='org.apache.sshd'/ /> > < <a at tt tr ri ib bu ut te e name='version' type='Version' value='0.5.0'/ /> > < <a at tt tr ri ib bu ut te e name='bundle-symbolic-name' value='org.apache.sshd.core'/ /> > < <a at tt tr ri ib bu ut te e name='bundle-version' type='Version' value='0.9.0'/ /> > < <d di ir re ec ct ti iv ve e name='uses' value='org.apache.sshd.client'/ /> > < </ /c ca ap pa ab bi il li it ty y> > <!-- More capabilities --> < <r re eq qu ui ir re em me en nt t namespace='osgi.wiring.package'> > < <d di ir re ec ct ti iv ve e name='filter' value='(&(osgi.wiring.package=org.slf4j)(version>=1.6.0)(!(version>=2.0.0)))'/> < </ /r re eq qu ui ir re em me en nt t> > <!-- More requirements --> < </ /r re es so ou ur rc ce e> > <!-- More resources --> < </ /r re ep po os si it to or ry y> > 19 of 41

  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 41

  21. Repository Service Obtain resources from the repository Find a bundle... R Re ep po os si it to or ry y repo = ... // from Service Registry ... R Re eq qu ui ir re em me en nt tB Bu ui il ld de er r rb = n ne ew w R Re eq qu ui ir re em me en nt tB Bu ui il ld de er r("osgi.wiring.package"); rb.addDirective("filter", "(&(osgi.wiring.package=org.apache.ssh)(version=0.5.0))"); R Re eq qu ui ir re em me en nt t req = rb.build(); C Co ol ll le ec ct ti io on n<R Re es so ou ur rc ce e> bundleResources = repo.findProviders(req); ... or find some photo's from the North Pole ... R Re eq qu ui ir re em me en nt tB Bu ui il ld de er r rb = n ne ew w R Re eq qu ui ir re em me en nt tB Bu ui il ld de er r("com.acme.photo"); rb.addDirective("filter", "(latitude>=66.5622)"); R Re eq qu ui ir re em me en nt t req = rb.build(); C Co ol ll le ec ct ti io on n<R Re es so ou ur rc ce e> photoResources = repo.findProviders(req); 21 of 41

  22. Add and prime a Repository 22 of 41

  23. Our subsystem works! 23 of 41

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend