OSGi and the Enterprise - A match made in a … box?

A presentation at Paris Java User Group in June 2010 in Paris, France by Holly Cummins

Slide 1

Slide 1

OSGi aan nd the Ent erprise nte A matc h made iin n a ….. box? tch Holly Cummins Paris Java User Group June 8, 2010

Slide 2

Slide 2

A (very) brief history of programming In the beginning, there were bits … 0101011101001001010010010011011101101101101 Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 2

Slide 3

Slide 3

A (very) brief history of programming Then came words … mov mov int Holly Cummins ah,9 dx,offset hello_message 21h Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 3

Slide 4

Slide 4

A (very) brief history of programming … functions and libraries … #include <stdio.h> main() { printf (“Hello World!\n”); } Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 4

Slide 5

Slide 5

A (very) brief history of programming … objects … public class HelloWorldSayer { public void sayHello() { System.out.println(“Hello, world!\n”); } } Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 5

Slide 6

Slide 6

A (very) brief history of programming … and now - Enterprise OSGi <service ref=”helloservice” interface=”helloworld.HelloWorldService” /> public class HelloWorldClient { HelloWorldService service = null; public void startUp() { service.hello(); } } Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 6

Slide 7

Slide 7

What was wrong with where we were? Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 7

Slide 8

Slide 8

What was wrong with where we were? A question of scale Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 8

Slide 9

Slide 9

Direct dependency Indirect (soft) dependency Optional dependencies Java EE Web te ch nologies tech chn Web Conta taiiner JNDI JAXP JMX JSF JSTL CDI & DI HTTP/SSL JASPIC StAX JAAS EJB JPA JAXR JACC Debug JDBC Common Annotations JCA JTA JMS WS Metadata Web Services JAXB JAX-WS JAX-RPC SAAJ JAX-RS JavaMail JAF IDL Management JSP Servlet RMI-IIOP Ente terrprise APIs in Java SE (Required for Java EE) Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 9

Slide 10

Slide 10

(capability == bloat)? Direct depen dency Indirect (soft) dependen cy Option al dependen cies Ja va EE Web tech no lo g ies chn Web Co nta iner JDBC JNDI JMX JSF JSTL CDI & DI HTTP/SSL JASPIC StAX JAAS JAXP EJB JPA Manage m ent JAXR JACC Debug JAXB JCA JTA JMS JSP Com m on Ann ot ations IDL WS Metadata Web Services JAX-WS JAX-RPC JAF SAAJ JAX-RS JavaMail Servlet RMI-IIOP Enterp ris e A PIs in Ja va S E (Req uired fo r Ja va EE) AP HTTP Session Replication Connection Management Admin Console and scripting Logging and Tracing MBean Server Transport Channels Workload Management Thread management Classloading Persistence Providers DataSources HTTP Serving and routing Provisioning User Registries Messaging Engines High Availability Management Monitoring Policy and SLA mgmt Event Mgmt Security Transaction Logging and Recovery Configuration … Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 10

Slide 11

Slide 11

Beyond Java EE… Di r e c t d e p e n de n c y Java E E Web technolog ogiies I nd i r ec t ( s o f t ) d ep en d enc y Op t i o n a l d e p e n d e n c i e s Web Con onttainer J DB C J ND I J A XP J AAS J MX J SF J S TL C D I & DI HT T P /S S L SCA Business Rules BPM Dynamic Scripting Complex Event Processing … Connection Management MBean Server Transport Channels Workload Management Classloading Persistence Providers Admin Console and scripting Logging and Tracing Thread management Telephony R MI - I I OP E nter pr d for Java E E ) priise APIs inJava SE ( Require red HTTP Session Replication Batch S t AX EJ B J AS PI C J PA em ent Ma n a g De bug J AX B S A AJ J AF I DL J AX R J A CC C o m m o n An n o t a t i o n s J TA J SP J CA J MS WS Me t a d a t a We b S e r vi c e s J AX - WS J AX - R S J AX - R P C J a va Ma i l S e r vl e t DataSources HTTP Serving and routing Provisioning User Registries Messaging Engines High Availability Management Monitoring Policy and SLA mgmt Event Mgmt Security Transaction Logging and Recovery Configuration … Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 11

Slide 12

Slide 12

Modula larrity inside Enterprise platforms The major AppServer and Integration vendors and Open Source communities have all embraced OSGi for their own internal architecture • IBM WebSphere, Oracle WebLogic, Red Hat JBoss, Sun GlassFish, SpringSource dm Server, Paremus Service Fabric, Eclipse Platform, Apache Geronimo, (non-exhaustive list)  http://www.osgi.org/wiki/uploads/News/2008_09_16_worldwide_market.pdf These complex engineering projects required a modular approach to development as they evolved and grew • Breaking the problem into well-defined coherent modules enables development teams to focus on their area of concern. • OSGi not only enables but enforces modularity Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 12

Slide 13

Slide 13

Problems with JARs Java Platform Modularity • Classes encapsulate data • Packages contain classes • Jars contain packages Class visibility: • private, package private, protected, public Jar Package Class No “jar scoped” access modifiers. No means for a jar to declare its dependencies. No versioning. Jars have no modularization characteristics • At runtime there is just a collection of classes on a global classpath Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on Package Class Class Package Class Class 13

Slide 14

Slide 14

The Global Classpath Begin Here Java VM party common resolver axis xerces rt assetmaint catalina mail ez morph xmlapis jce hhfacility base jenks servlets xmlrpc jsse pos. datafile jakarta jetty xmlgraphics plugin content entity log4j looks sunjce_prov. manufact. w idget httpunit jdbm dnsns product … mx4j bsf .. bi rome batik bsh marketing w orkflow jpos18 fop velocity w orkeffort ecommerce jcl tomcat w s-commons ebay oagis barcode4j poi geronimo minerva … freemarker lucene .. minilang googlebase serializ er jdom json accounting order naming commons xalan guiapp ofbiz jython derby w sdl4j Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on Class N ot Found Exception 14

Slide 15

Slide 15

Problems with EARs/W ARs /WA we bA.war WEB-INF/classes/servletA.class Enterprise Apps have isolated classpaths but… Across apps - each archive typically contains all the libraries required by the application WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… we bB.war WEB-INF/classes/servletB.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… • Common libraries/frameworks get installed with each application • Multiple copies of libraries in memory Within apps - 3rd party libraries consume other 3rd party libraries leading to version conflicts we bC.war WEB-INF/classes/servletC.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… plankton.v1 plankton.v2 Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 15

Slide 16

Slide 16

OSGi – The Dynamic Module System for Java The OSGi Service Platform specifies a modular architecture for dynamic component based systems • • • • Execution Environment Module Layer Life Cycle Layer Service Layer Runs on a variety of standard Java profiles. Introduces Bundles as modules Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 16

Slide 17

Slide 17

OSGi Cla lasss Loading No global, flat classpath to search. Each bundle has its own classloader / classpath. More efficient for large systems. Class sharing and visibility is based on declarative dependencies • Not constrained by hierarchical class loader trees built up at runtime. • OSGi f/w takes care of working out the dependencies. Multiple versions of bundles supported concurrently. Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 17

Slide 18

Slide 18

Bundle Metadata META-INF/MANIFEST.MF The higher-level module is the “bundle” which is a normal jar containing: •Classes •Resources •Manifest Manifest­Version: 1.0 Bundle­ManifestVersion: 2 Bundle­Name: MyService bundle Bundle­SymbolicName: com.sample.myservice Bundle­Version: 1.0.0 Bundle­Activator: com.sample.myservice.Activator I m port ­Pa c kage : org.apache.commons.logging;version=”1.0.4” E x port ­Pa c kage : com.sample.myservice.api;version=”1.0.0” Mult iple ver si ons of bundles can be active concurrently. ersi sio Dep ep enden epe enccies on other bundles are explicitly declared Package vi si bilit y outside the bundle is declared. visi sib • Other packages are encapsulated by the bundle. Bundles can act on lifecycle changes Eclipse tooling provides convenient editors for the manifest Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 18

Slide 19

Slide 19

Bundle Lifecycle INSTALLED Optional BundleActivator class has opportunity to initialize and cleanup a bundle • Header in Manifest refers to this class BundleActivator has 2 methods • Start: Initialize bundle • Stop: Cleanup STARTING start RESOLVED ACTIVE stop UNINSTALLED STOPPING Resolution of dependencies at deployment time. If resolution fails, bundle is not available for use. • No ClassNotFoundExceptions at runtime Bundle lifecycle is dynamic and independent of the rest of the f/w. • BundleListener can be registered for bundle state change events. Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 19

Slide 20

Slide 20

S OSGi Services OSGi intrinsically supports SOA through its service layer. The core platform includes a non-durable “Service Registry” component. Services are published to and discovered from this Service Registry. • Services are the primary means of collaboration between bundles. An OSGi service is a POJO published to the SR under one or more Java interface names with optional key/value pair metadata • Service discovery can be filtered on the key/value metadata Services are fully dynamic and typically have the same lifecycle as the bundle that provides them. Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 20

Slide 21

Slide 21

What about the Applications? The enterprise landscape until recently has been OSGi on the inside only. Why? Primarily because: • Java EE defines an enterprise application programming model and container contracts to honour it • OSGi has typically defined platform specifications and services for those platforms.  It hasn’t had much to say on application concerns such as ■ What’s the component model? ■ What’s the persistence architecture? ■ How are qualities of service configured? ■ Remoting This has changed in OSGi v4.2. Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 21

Slide 22

Slide 22

OSGi Enterprise Specification Release date – 22 March 2010 • The product of the OSGi Enterprise Expert Group (EEG) Brings Enterprise technologies and OSGi together Using existing Java SE/EE specifications: • JTA, JPA, JNDI, JMX, WebApps… Adds Spring-derived component model and dependency injection container Java EE provides the core enterprise application progr graamming model Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 22

Slide 23

Slide 23

What’s the benefit? Deploying modules as OSGi bundles • • • • simplifies reuse between applications encourages (and enforces) modular design provides versioning enables dynamic module updates. Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 23

Slide 24

Slide 24

New Open Source Activities Apache “Aries” created as a new Apache incubator project in Sep 2009: • to provide enterprise OSGi spec implementations • to provide an environment for collaboration and innovation about the standards • to build a broad development community Eclipse Enterprise Modules (“Gemini”) - currently being provisioned. • Sub-projects will provide EEG spec implementations http://www.eclipse.org/proposals/gemini/ Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 24

Slide 25

Slide 25

History “Aries” created as a new Apache incubator project in Sep 2009 Available to use now – 0.1 version released last month – Integrated into WebSphere V7 Feature Pack for OSGi Applications – released last week Independent of • OSGi framework provider • Integration/server runtime 43 committers from a broad range of companies Holly Cummins 25

Slide 26

Slide 26

Aries Content includes… Blueprint container JPA integration JTA integration JMX JNDI integration Application assembly and deployment META-INF/services handler Samples, documentation, integrator’s guide Holly Cummins 26

Slide 27

Slide 27

Aries Blu eprint Container lue Managed beans consumes service publishes service OSGI-INF/blueprint/ blueprint.xml Blueprint bundle A static assembly and configuration of components (POJOs) A dependency Injection container • Standardizes established Spring conventions • Part of the server runtime (compared to Spring which is part of the app.) Configuration and dependencies declared in XML “module blueprint”, which is a standardization of Spring “application context” XML. • Extended for OSGi: publishes and consumes components as OSGi services Simplifies using OSGi services • No ServiceTrackers • No lookups Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 27

Slide 28

Slide 28

Exploiting Blu eprint Components and Services lue e-C omme -Co mmerrce bundle <blueprint> <bean id=”shop” class=”org.example.ecomm.ShopImpl”> <property name=”billingService” ref=”billingService” /> </bean> <reference id=”billingService” interface=”org.example.bill.BillingService” /> </blueprint> public class ShopImpl { private BillingService billingService; void setBillingService(BillingService srv) { billingService = srv; } void process(Order o) { billingService.bill(o); } } Holly Cummins e-Commerce -injected service reference -service can change over time -can be temporarily absent without the bundle caring -managed by Blueprint container

Slide 29

Slide 29

Java Persistence and Pe Perrsistence Bundle less Each persistence bundle has its standard JPA metadata located through the Meta-Persistence bundle header. JPA Container locates a JPA Provider • Registers a Provider-created EntityManagerFactory service for each PU • Optionally injects an EntityManager Persistence bundle Bund le Ma nifes t … Meta-Persistence: OSGI-INF/persistence.xml Managed EntityManagerFactory Registered on behalf of the persistence bundle OSGI-INF/ Entities persistence.xml Registers EntityManagerFactory service per PU Uses org.apache.aries.jpa.container Uses Used to build the EntityManagerFactory JPA Provider createContainerEMF (PersistenceUnitInfo) javax.persistence.spi. PersistenceProvider service Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 29

Slide 30

Slide 30

Aries JPA Container – Blueprint Integration Example blueprint with JPA resource injection and container-managed transactions <b blu ep eprrint xmlns=”http://www.osgi.org/xmlns/blueprint/v1.0.0” xmlns:jta=”http://aries.apache.org/xmlns/transactions/v1.0.0” xmlns:jpa=”http://aries.apache.org/xmlns/jpa/v1.0.0”> <b bea n id=“appMgd“ class=“com.acme.AppManaged”> ean <jjpa pa::un it property=”emf” unitname=”myUnit” /> </bea /bea n> /bean <b bea n id=”containerMgd“ class=“com.acme.Container”> ean <jjpa pa::cont ext property=”em” unitname=“myUnit“/> <jjt a:t ran sa sacct ion method=“*” value=“Required” /> </bea /bea n> /bean </b /b /blluep eprrin t > Holly Cummins 30

Slide 31

Slide 31

Aries JTA integration Holly Cummins 31

Slide 32

Slide 32

Aries JND NDII integration Provides JNDI-based access to OSGi Service Registry < b l u e pr in t x m l n s = .. .> < b ea n id = ” b l o g gi ng Se r v i c e C om po ne n t ” cl as s = ” o r g .a pa ch e . a r i e s. Bl og g i n g S e rv ic eI m p l ” > < / be an > < s er vi ce r e f = ” bl og g in gS er v ic eC o mp on en t ” i nt er f a c e = ” or g. ap a c h e . a ri es .s a m p l e s .b lo g. a p i . B l og gi ng S e r v i c e” /> … < / b l u ep ri nt > registerService OSGi Service Registry A way for a Web component to access a Blueprint component getService JNDI Context Holly Cummins InitialContext ic = new InitialContext(); BloggingService blog= ic.lookup(“osgi:services/” + BloggingService.c class.getName()); 32

Slide 33

Slide 33

Aries JMX Integration Implementation of OSGi JMX specification. Aries JMX bundle automatically registers the JMX MBeans into any javax.management.MBeanServer service in the OSGi Service Registry. <<MBean>> Fra m e w ork MBe a n Framework MBeans <<MBean>> Bund le St a t e MBe a n Compendium MBeans <<MBean>> Blue print MBe a n <<MBean>> Pe rmis sion Ad min MBe a n PermissionAdmin <<MBean>> Co nfigura t io n Ad min MBe a n Configuration Admin <<MBean>> Provisi onin g Se rvic e MBe a n Provisioning Service <<MBean>> Use r Adm in MBe a n User Admin MBean Server JMX OSGi Manager Additional Aries MBeans <<MBean>> Se rvic e St a t e MBe a n Holly Cummins <<MBean>> Pa cka ge St a t e MBe a n 33

Slide 34

Slide 34

Web Application Bundle less Bundles are recognized as Web applications if they contain a standard OSGi manifest header to identify the context path  Web-ContextPath: A hosting platform • Listens for bundles starting & stopping with WAB content • Hands the web components of to the Web Container to manage. Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 34

Slide 35

Slide 35

Aries Application Assembly and Deplo loyy Pluggable infrastructure for deployment of an application – A collection of bundles forming a logical unit – Packaged as an enterprise bundle archive (archive with .eba extn). •An “Enterprise OSGi Application”. Constituent bundles may be contained (“by-value”) in the .eba archive or referenced in APPLICATION.MF Only explicitly declared Services are exposed from the application. Config by exception - absence of APPLICATION.MF means: •application content is the set of bundles contained by-value plus any repository-hosted dependencies identified during deployment. Bundl e Rep os epos osiitor oryy Ap p lica tio n Ma nifes t json4j.jar Enumerates constituent bundles Declares Application “externals” blog.eba Holly Cummins blog-persistence.jar blog.jar blog-servlet.jar 35

Slide 36

Slide 36

Module Re-Use Made Easy No JJaava cco ode cha nges; war m odu les -> bun dles mo Common, bun dles may be ea si Rs and u sed at sp eci easi silly fact ored ou t of t he WA WAR spe ciffic ver verssion s we bA.wab WEB-INF/classes/servletA.class we bA.wa r WEB-INF/classes/servletA.class ME TA-IN NIF EST.MF MET INFF/MA MAN we bB.wab WEB-INF/lib/spring.jar WEB-INF/classes/servletB.class WEB-INF/lib/commons-logging.jar META-IN NIF INFF/MA MAN IFEEST.MF WEB-INF/lib/junit.jar… we bC. wab C.w we bB.war WEB-INF/classes/servletC.class WEB-INF/classes/servletB.class ME TA-IN NIF EST.MF MET INFF/MA MAN WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… we bC.war WEB-INF/classes/servletC.class Import-Package WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… Bundl e Rep os epos osiitor oryy WEB-INF/lib/spring.jar;version=“a.b.c” WEB-INF/lib/commons-logging.jar;version=… WEB-INF/lib/json4j.jar;version=… WEB-INF/lib/junit.jar… Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 36

Slide 37

Slide 37

Bundle-level Management WebSphere Administrative Console Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 37

Slide 38

Slide 38

Demo Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 38

Slide 39

Slide 39

On luck … “I’m a great believer in luck and I find the harder I work, the more I have of it.” ■ Holly Cummins Thomas Jefferson Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 39

Slide 40

Slide 40

Demo (maybe) Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 40

Slide 41

Slide 41

Demo (maybe) Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 41

Slide 42

Slide 42

Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 42

Slide 43

Slide 43

Free tools WA S v7 OS Gi F eP Tes t E nviro nme nt F re e E clips e Plugin for OS Gi Applications ree Graphical tools to develop OSGi applications and bundles  Includes features that increase developer productivity  Creates OSGi Applications for any Aries-based server runtime.  Eclipse WTP 3.6 (Helios) M6 or later required P ubl ish and Run WAS v7 S erver S up p o rt Enha nce d Va lid a tio n ced Deve vellop er PPrro d uct ctiivi vitty (e.g. content assist, validation, re-factoring) G ra p hica l Ap p lica cattio n Ed itor http://www.ibm.com/developerworks/rational/downloads /10/rationaldevtoolsforosgiapplications.html Tuto ria ls a nd Do cumenta tio n OS Gi Applic ation S upport in RAD Be ta Gra p hica l Crea tio n Wiza rd s WTP  Provide integrated development and test of OSGi Crea tio n / Imp o rt / Exp o rt To o ls xpo Too Applications on the WebSphere platform  Integrated with Web Tools, JEE productivity tools, and other PDE capabilities in RAD  Supports deployment to WAS v7 OSGi FeP and includes the FeP in the WAS Test Environment Enhanced validation Eclip s e OS Gi A ppl OSG Ap pliica catt ion Plu gin RAD N ext Bet a Toolin g Ne Holly Cummins Q Co n Lo nd o n 2010 Lon https://www14.software.ibm.com/iwm/web/cc/ earlyprograms/rational/radob/index.shtml Ia n Ro b ins on 43

Slide 44

Slide 44

Resources Apache Aries • http://incubator.apache.org/aries/ Free tools • http://www.ibm.com/developerworks/rational/downloads /10/rationaldevtoolsforosgiapplications.html IBM WebSphere Feature Pack for OSGi Applications and Java Persistence API 2.0 • http://www-01.ibm.com/software/webservers/appserv/was/ featurepacks/osgi/ Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 44

Slide 45

Slide 45

In the near future… all major Java enterprise runtimes will support Apps deployed as bundles 45

Slide 46

Slide 46

Any questions? Holly Cummins Q Co n Lo nd o n 2010 Lon Ia n Ro b ins on 46

Slide 47

Slide 47

Futures There are many new application-centric features that Aries may develop including: •message-driven blueprint components and services •declarative role-based security for blueprint components •annotation-based alternative to XML configuration •resource-reference metadata and bindings (Original Proposal: http://wiki.apache.org/incubator/AriesProposal) Interested in getting involved? •http://incubator.apache.org/aries/gettinginvolved.html Holly Cummins 47