OSGi Framework for Modular Java Applications

undefined
 
The SENSE Project
 
How to build an ENOS application
 
John MacAuley
macauley@es.net
 
Application Architecture
 
9/8/2024
 
 
2
 
 
 
 
 
Netshell Kernel
Netshell API
Java
Python
Persistence
OSGi
Users
ACL
logging
Scheduler
Interactive
Shell
Resources
 
 
 
 
 
 
ENOS Services
Topology Service
OSCARS
TP Driver
ScienceDMZ
TP Driver
Multipoint VPN Service
ODL
Srvc Driver
OSCARS
Srvc Driver
Monitoring Service
perfSONA
R
Driver
MonALISA
Driver
Policy Services
AuthN Services
Service specific API
SSHD
Messaging/
Events
Web Container (Jetty)
OSGi Runtime API
JAX-RS Connector
Jersey Client
Web Management Console
Servlet Container
OSGi Srvc
Registry
OSGi Shell
Application
 
Why OSGi as a runtime?
 
A dynamic module system for Java - modules can be loaded,
unloaded, and upgraded on a running system
Provides a service-oriented, component-based environment
for developers
Offers standardized ways to manage the software lifecycle of
an application
Runtime supports a standard set of application design patterns
with built in framework features
Used in projects such as Eclipse, IBM Webshpere, ODL, ONOS,
and many more
 
9/8/2024
 
 
3
 
Apache Karaf
 
9/8/2024
 
 
4
 
ENOS utilizes the Apache Karaf OSGi  implementation aligning with
ODL and ONOS
http://karaf.apache.org/
 
OSGi Framework Layering
 
Provides a publish/find/bind service
model to decouple bundles
 
Manages the life cycle of a bundle in
the framework without requiring the
VM to be restarted
Creates the concept of a module (aka.
Bundles)
 
OSGi Minimum Execution
Environment (JavaSE)
 
9/8/2024
 
 
5
Service Model
Lifecycle
Module
Execution Environment
 
OSGi Modules
 
Unit of deployment is the bundle i.e., a JAR with extra metadata
Separate class loader per bundle
Independent namespaces
Class sharing at the Java package level
Multiple version support (i.e. side-by-side versions)
Explicit code boundaries and dependencies (i.e. package imports and
exports)
Support for various sharing policies (i.e. arbitrary version range support)
Arbitrary import/export package (influence package selection)
Sophisticated class space consistency model to ensure code constraints are
not violated
 
9/8/2024
 
 
6
 
Maven support for OSGi
 
Maven supports generation of OSGi compliant bundles (JAR file) through
the org.apache.felix.maven-bundle-plugin
 
9/8/2024
 
 
7
 
Features repository
 
A simple and flexible way to provision applications
A feature describes an application as:
a name
a version
an optional description (eventually with a long description)
a set of bundles
optionally a set configurations or configuration files
optionally a set of dependency features
When you install a feature, Apache Karaf installs all resources described in
the feature
Automatically resolves and installs all bundles, configurations, and
dependency features described in the feature
 
9/8/2024
 
 
8
 
Features repository
 
features.xml file is added to maven repository along with the JAR bundles
and is used to aid in automatic feature and dependency discovery
 
9/8/2024
 
 
9
 
karaf
@root()> feature:repo-add mvn:net.es/sense-service/1.0-SNAPSHOT/xml/features
Adding feature url mvn:net.es/sense-service/1.0-SNAPSHOT/xml/features
karaf
@root()> feature:install sense-service
SENSE service: started
karaf
@root()>
 
Application Lifecycle
 
9/8/2024
 
 
10
Installed
Resolved
Starting
Stopping
Active
Uninstalled
 
Start
 
End
 
install
 
uninstall
 
start
 
stop
 
Participating in the lifecycle
 
OSGi allows an application to provide hooks into the lifecycle
state machine through the use of an activator
 
9/8/2024
 
 
11
 
Why do I care?
 
Perform application initialization (start) and cleanup (stop)
Register public interfaces (start) and unregister interfaces
(stop) with the OSGi Service Registry
Lookup service interface for needed dependencies (start) and
free reference to interface (stop)
Determine status of other bundles through API or via events
through listener
 
9/8/2024
 
 
12
 
Inversion of Control and Annotations
 
Inject lifecycle events, register services, or inject references to
services into your existing code without having to interact
directly with the OSGi framework
Use the OSGi Declarative Services or iPOJO to inject through
XML descriptors (inversion of control) or annotations
SpringDM provides a Spring IoC compliant framework for OSGi
 
9/8/2024
 
 
13
 
Annotations
 
9/8/2024
 
 
14
 
The Service Registry
 
The OSGi framework promotes a service oriented interaction
pattern among bundles to decouple dependencies
 
9/8/2024
 
 
15
Service
Registry
Service
Requester
Service
Provider
 
find
 
interact
 
publish
 
Manipulating the Service Registry
 
 
// Add topology service to OSGi service registry.
BundleContext context = getBundleContext();
ESnetTopologyIf topologyService =  new ESnetTopology();
ServiceRegistration registration =
 
context.registerService(ESnetTopologyIf.class.getName(),
 
topologyService, null);
 
// Lookup topology service in OSGi service registry.
BundleContext context = getBundleContext();
ServiceReference ref =
 
context.getServiceReference(ESnetTopologyIf.class.getName());
ESnetTopologyIf topologyService = (ESnetTopologyIf) context.getService(ref);
 
9/8/2024
 
 
16
 
JAX-RS Auto-wiring
 
The OSGi JAX-RS Connector connects Jersey and OSGi at the service level
OSGi services can be published as RESTful web services by simply registering them as
OSGi services
When the connector discovers a service that is annotated with the JAX-RS annotations
@Path/@Provider it automatically hooks these services into Jersey and the OSGi
HTTPService
REST services can also be directly consumed as OSGi services
To configure, specify the jax-rs-connector bundle, making sure the system scr and http
bundles have been installed:
 
karaf
@root()> feature:install scr http
karaf
@root()> feature:install webconsole
karaf
@root()> feature:repo-add mvn:com.eclipsesource.jaxrs/features/5.3/xml/features
Adding feature url mvn:com.eclipsesource.jaxrs/features/5.3/xml/features
karaf
@root()> feature:install jax-rs-connector
karaf
@root()> feature:install jax-rs-provider-moxy
karaf
@root()>
 
9/8/2024
 
 
17
 
Register your web service
 
Either register the JAX-RS service directly with the OSGI Service Registry, or
use one of the OSGi Declarative Services frameworks to annotate the
service
 
9/8/2024
 
 
18
 
RESTful Services using JAX-RS
 
9/8/2024
 
 
19
 
Extending the Karaf shell
 
9/8/2024
 
 
20
 
Karaf Web Console
 
http://localhost:8181/system/console
 
9/8/2024
 
 
21
 
Starting minimum runtime
 
Download and install Apache karaf
Download and build Netshell
https://github.com/esnet/netshell
Download and build ENOS
https://github.com/esnet/enos
Configure the Netshell runtime
ReadMe @ https://github.com/esnet/enos
Start karaf
 
9/8/2024
 
 
22
 
Starting minimum runtime
 
Load Web components into Karaf:
karaf@root()> 
feature:install scr http
karaf@root()> feature:install webconsole
karaf@root()> feature:repo-add mvn:com.eclipsesource.jaxrs/features/5.3/xml/features
karaf@root()> 
feature:install jax-rs-connector
karaf@root()> 
feature:install jax-rs-provider-moxy
Load Netshell and ENOS features from local maven repo into karaf:
karaf@root()> feature:repo-add mvn:net.es/netshell-kernel/1.0-SNAPSHOT/xml/features
karaf@root()> 
feature:install netshell-kernel
karaf@root()> 
feature:install netshell-python
karaf@root()> feature:repo-add mvn:net.es/enos-esnet/1.0-SNAPSHOT/xml/features
karaf@root()> 
feature:install enos-esnet
 
 
 
 
 
9/8/2024
 
 
23
 
Topics to complete
 
Minimum configuration to get started (i.e. I don’t need ODL)
Authentication and authorization for application web services
within SENSE and ENOS
Defining and interacting with application specific ACLs
Netshell users and how they apply to applications
Data persistence
 
9/8/2024
 
 
24
Slide Note
Embed
Share

OSGi, a dynamic module system for Java, enables loading, unloading, and upgrading modules on a running system. It provides a service-oriented, component-based environment for developers, standardized software lifecycle management, and supports various application design patterns. Apache Karaf aligns with ODL and ONOS to leverage OSGi implementation, while OSGi Framework Layering offers a model to decouple bundles and manage their lifecycle without restarting the VM. OSGi modules enhance deployment with bundle-based JAR files, separate class loaders, and support for multiple versions and code boundaries.

  • OSGi Framework
  • Java Applications
  • Modular Development
  • Apache Karaf
  • Software Lifecycle

Uploaded on Sep 08, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. The SENSE Project John MacAuley How to build an ENOS application macauley@es.net

  2. Application Architecture Web Container (Jetty) Jersey Client JAX-RS Connector Web Management Console Servlet Container OSGi Runtime API OSGi Srvc Registry Application OSGi Shell Service specific API Topology Service Multipoint VPN Service Monitoring Service Policy Services perfSONA R Driver OSCARS TP Driver ScienceDMZ TP Driver ODL OSCARS Srvc Driver MonALISA Driver AuthN Services Srvc Driver ENOS Services Netshell API Interactive Shell Messaging/ Events logging Scheduler Users ACL Resources Netshell Kernel Persistence OSGi SSHD Java Python 2 9/8/2024

  3. Why OSGi as a runtime? A dynamic module system for Java - modules can be loaded, unloaded, and upgraded on a running system Provides a service-oriented, component-based environment for developers Offers standardized ways to manage the software lifecycle of an application Runtime supports a standard set of application design patterns with built in framework features Used in projects such as Eclipse, IBM Webshpere, ODL, ONOS, and many more 3 9/8/2024

  4. Apache Karaf ENOS utilizes the Apache Karaf OSGi implementation aligning with ODL and ONOS http://karaf.apache.org/ 4 9/8/2024

  5. OSGi Framework Layering Provides a publish/find/bind service model to decouple bundles Service Model Manages the life cycle of a bundle in the framework without requiring the VM to be restarted Lifecycle Creates the concept of a module (aka. Bundles) Module OSGi Minimum Execution Environment (JavaSE) Execution Environment 5 9/8/2024

  6. OSGi Modules Unit of deployment is the bundle i.e., a JAR with extra metadata Separate class loader per bundle Independent namespaces Class sharing at the Java package level Multiple version support (i.e. side-by-side versions) Explicit code boundaries and dependencies (i.e. package imports and exports) Support for various sharing policies (i.e. arbitrary version range support) Arbitrary import/export package (influence package selection) Sophisticated class space consistency model to ensure code constraints are not violated 6 9/8/2024

  7. Maven support for OSGi Maven supports generation of OSGi compliant bundles (JAR file) through the org.apache.felix.maven-bundle-plugin 7 9/8/2024

  8. Features repository A simple and flexible way to provision applications A feature describes an application as: a name a version an optional description (eventually with a long description) a set of bundles optionally a set configurations or configuration files optionally a set of dependency features When you install a feature, Apache Karaf installs all resources described in the feature Automatically resolves and installs all bundles, configurations, and dependency features described in the feature 8 9/8/2024

  9. Features repository features.xml file is added to maven repository along with the JAR bundles and is used to aid in automatic feature and dependency discovery karaf@root()> feature:repo-add mvn:net.es/sense-service/1.0-SNAPSHOT/xml/features Adding feature url mvn:net.es/sense-service/1.0-SNAPSHOT/xml/features karaf@root()> feature:install sense-service SENSE service: started karaf@root()> 9 9/8/2024

  10. Application Lifecycle Start install Installed Starting start Active Resolved stop uninstall Stopping End Uninstalled 10 9/8/2024

  11. Participating in the lifecycle OSGi allows an application to provide hooks into the lifecycle state machine through the use of an activator 11 9/8/2024

  12. Why do I care? Perform application initialization (start) and cleanup (stop) Register public interfaces (start) and unregister interfaces (stop) with the OSGi Service Registry Lookup service interface for needed dependencies (start) and free reference to interface (stop) Determine status of other bundles through API or via events through listener 12 9/8/2024

  13. Inversion of Control and Annotations Inject lifecycle events, register services, or inject references to services into your existing code without having to interact directly with the OSGi framework Use the OSGi Declarative Services or iPOJO to inject through XML descriptors (inversion of control) or annotations SpringDM provides a Spring IoC compliant framework for OSGi 13 9/8/2024

  14. Annotations 14 9/8/2024

  15. The Service Registry The OSGi framework promotes a service oriented interaction pattern among bundles to decouple dependencies Service Registry publish find Service Provider Service Requester interact 15 9/8/2024

  16. Manipulating the Service Registry // Add topology service to OSGi service registry. BundleContext context = getBundleContext(); ESnetTopologyIf topologyService = new ESnetTopology(); ServiceRegistration registration = context.registerService(ESnetTopologyIf.class.getName(), topologyService, null); // Lookup topology service in OSGi service registry. BundleContext context = getBundleContext(); ServiceReference ref = context.getServiceReference(ESnetTopologyIf.class.getName()); ESnetTopologyIf topologyService = (ESnetTopologyIf) context.getService(ref); 16 9/8/2024

  17. JAX-RS Auto-wiring The OSGi JAX-RS Connector connects Jersey and OSGi at the service level OSGi services can be published as RESTful web services by simply registering them as OSGi services When the connector discovers a service that is annotated with the JAX-RS annotations @Path/@Provider it automatically hooks these services into Jersey and the OSGi HTTPService REST services can also be directly consumed as OSGi services To configure, specify the jax-rs-connector bundle, making sure the system scr and http bundles have been installed: karaf@root()> feature:install scr http karaf@root()> feature:install webconsole karaf@root()> feature:repo-add mvn:com.eclipsesource.jaxrs/features/5.3/xml/features Adding feature url mvn:com.eclipsesource.jaxrs/features/5.3/xml/features karaf@root()> feature:install jax-rs-connector karaf@root()> feature:install jax-rs-provider-moxy karaf@root()> 17 9/8/2024

  18. Register your web service Either register the JAX-RS service directly with the OSGI Service Registry, or use one of the OSGi Declarative Services frameworks to annotate the service 18 9/8/2024

  19. RESTful Services using JAX-RS http://localhost:8181/services/sense?name=SENSE%20Project! { "message": "Hello SENSE Project! } 19 9/8/2024

  20. Extending the Karaf shell 20 9/8/2024

  21. Karaf Web Console http://localhost:8181/system/console 21 9/8/2024

  22. Starting minimum runtime Download and install Apache karaf Download and build Netshell https://github.com/esnet/netshell Download and build ENOS https://github.com/esnet/enos Configure the Netshell runtime ReadMe @ https://github.com/esnet/enos Start karaf 22 9/8/2024

  23. Starting minimum runtime Load Web components into Karaf: karaf@root()> feature:install scr http karaf@root()> feature:install webconsole karaf@root()> feature:repo-add mvn:com.eclipsesource.jaxrs/features/5.3/xml/features karaf@root()> feature:install jax-rs-connector karaf@root()> feature:install jax-rs-provider-moxy Load Netshell and ENOS features from local maven repo into karaf: karaf@root()> feature:repo-add mvn:net.es/netshell-kernel/1.0-SNAPSHOT/xml/features karaf@root()> feature:install netshell-kernel karaf@root()> feature:install netshell-python karaf@root()> feature:repo-add mvn:net.es/enos-esnet/1.0-SNAPSHOT/xml/features karaf@root()> feature:install enos-esnet 23 9/8/2024

  24. Topics to complete Minimum configuration to get started (i.e. I don t need ODL) Authentication and authorization for application web services within SENSE and ENOS Defining and interacting with application specific ACLs Netshell users and how they apply to applications Data persistence 24 9/8/2024

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#