Introduction to OSGi using Apache Karaf Ioannis CanellosJHUG / 16 April 2011
Presenting today…OSGiOpen Services Gateway initiative, since 1999Initially targeted embedded devicesOSGi containers: Felix, Equinox, Knoperfish, ConciergeMost known use is Eclipse IDEApache KarafApache OSGi runtime runs on any OSGi containerBorn inside Service Mix, now is Top level projectStandard runtime for Geronimo, Service Mix, SlingEcosystem for deploying OSGi/EE applications
Part IIntroduction to OSGi
Introduction to OSGiProblem SolutionArchitectureToolsOSGi in the EnterpriseQuestions & Answers
The problemaspects Dependency managementVersion HellConflicting dependenciesClass loading issuesDynamic behaviorDifficulties to control component lifecycleLack of a pure modularity solution
The problemsDependency managementLarge number of transitive dependenciesConflicts among among dependenciesClass loading issuesBoot class loaderJTASystem class loaderJTAwarwar
The problemsDynamic BehaviorComponents & Services need come and goComponents need to get updated / replacedComponents need to started / stoppedReal life examplesEclipse IDEAdding/Removing “plugins”EbayMultiple version of the same component
The problemsModularityThe JVM does not address need for modularityThe class path paradoxThe jar is a “black box”No dependencies & No versionThe pastitsioexampleThe “WORA” promise was repeatedly failedJavaBeansEJBsHas the quest for modularity failed ?Project Jigsaw will be shipped with JDK 8 OSGi is already here
The OSGi SolutionOverviewA Layer …A deployment infrastructureBundles = class + metadata (import/exports)Bundles have a lifecycleBundles have their own Class loaderClass loading delegation between dependant bundles A service platformDefines  a Service RegistryBundles provide or request servicesThe service can “come and go”
Architecture
Architecture  Execution EnvironmentThe Runtime where the bundles liveA bundle can bound to an Execution EnvironmentJRE-1.5JJRE-1.3OSGi/Minimum-1.0
Architecture  Module LayerBundles import, export or have private packagesEach package can be assigned version rangeA bundle (fragment)can be attached to a bundle (host)Export Packagejavax.transaction 1.01BImport Packagejavax.transaction [1.0,1.1)Export Packagejavax.transaction 1.1Bundle Name: JMS APIImport Package: javax.transactionExport Package: javax.jmsBundle-RequiredExecutionEnvironment: J2SE-1.5
Architecture  Module Layera MANIFEST.MF exampleManifest-Version:1.0Import-Package:javax.transaction;version="1.1”, javax.transaction.xa;version="1.1”Export-Package:javax.jms;version="1.1”Bundle-SymbolicName:org.apache.geronimo.specs.geronimo-jms_1.1_specTool:Bnd-0.0.227
InstalledStartingArchitecture  Lifecycle Layerstartupdate refreshresolveStartedResolveduninstalluninstallstopStoppedUninstalled
Architecture  Service LayerEach bundle can register or lookup a ServiceEach service corresponds to one or more interfacesEach service can be assigned and queried using propertiesService RegistryregisterlookupServiceProviderService Consumer
OSGi Tools		working with servicesManaging Services programmaticallyUsing the OSGi blueprintSpring Dynamic ModulesApache AriesFelix i-Pojo
OSGi Tools		creating bundlesManually providing the MANIFEST.MFBnd command line toolMaven Bundle Plug-inSpring’s BundlorMaven plug-in flavorCommand line flavor
OSGi Tools		OSGi Bundle RepositorySimplifies the provisioning of bundlesThe “apt-get install” for the OSGiIntegrates with public repositoriesEclipse OrbitSpring’s Enterprise Bundle Repository
OSGiEnd of Part IQuestions & Answers
Part IIGetting started with Apache Karaf
Apache KarafagendaOverview	Shell ConsoleDeployerFeatures ConceptSecurityLogging ServiceDemoQuestions and Answers
Apache KarafOverviewBorn as Service Mix Kernel projectGrown inside Apache Felix projectBecome a Top Level Apache project last year
Apache KarafShell ConsoleExtensible	Auto complete & coloring supportRich command set, covers most OSGi concepts/servicesSpecial commands for the development phase
Apache KarafDeployerFile ScannerWar TransformerConfigurationBundlesTransformationSpringTransformerBlueprintTransformerConfigurationAdminURLHandlerMaven HandlerHTTP HandlerHot deploymentLarge number of supported artifactsLarge number of installation mediumsOBR Handler
Apache KarafFeatures ConceptA Karaf feature is a descriptor which defines…A set of bundlesA set of configurationsA set of other featuresAllows provisioning of applicationsMaven integrationOBR integration
Apache KarafFeatures Example<feature name="http" version=”2.2.0” resolver=“(obr)”><configname="org.ops4j.pax.web”>           org.osgi.service.http.port=8181 </config><feature version="[7.0,8.0)">jetty</feature>     <bundle dependency=“true”>mvn:javax.servlet/servlet-api</bundle>     <bundle>mvn:org.ops4j.pax.web/pax-web-api</bundle></feature>
Apache KarafSecurityJAAS based securityMultiple login module implementationsProperty Login ModuleJDBC Login ModuleLDAP Login ModuleCommand line supportProvisioning of any JASS realm Add users roles etc
Apache KarafLogging ServiceCentralized Logging configurationSupports most logging APIsLog4JSlf4j Commons LoggingCommand line supportclear, display, tail change threshold etc.OSGi integrationper bundle appender, osgi specific attributes
Apache Karaf	End of Part IIQuestions & Answers
Thank you

Introduction to-osgi

  • 1.
    Introduction to OSGiusing Apache Karaf Ioannis CanellosJHUG / 16 April 2011
  • 2.
    Presenting today…OSGiOpen ServicesGateway initiative, since 1999Initially targeted embedded devicesOSGi containers: Felix, Equinox, Knoperfish, ConciergeMost known use is Eclipse IDEApache KarafApache OSGi runtime runs on any OSGi containerBorn inside Service Mix, now is Top level projectStandard runtime for Geronimo, Service Mix, SlingEcosystem for deploying OSGi/EE applications
  • 3.
  • 4.
    Introduction to OSGiProblemSolutionArchitectureToolsOSGi in the EnterpriseQuestions & Answers
  • 5.
    The problemaspects DependencymanagementVersion HellConflicting dependenciesClass loading issuesDynamic behaviorDifficulties to control component lifecycleLack of a pure modularity solution
  • 6.
    The problemsDependency managementLargenumber of transitive dependenciesConflicts among among dependenciesClass loading issuesBoot class loaderJTASystem class loaderJTAwarwar
  • 7.
    The problemsDynamic BehaviorComponents& Services need come and goComponents need to get updated / replacedComponents need to started / stoppedReal life examplesEclipse IDEAdding/Removing “plugins”EbayMultiple version of the same component
  • 8.
    The problemsModularityThe JVMdoes not address need for modularityThe class path paradoxThe jar is a “black box”No dependencies & No versionThe pastitsioexampleThe “WORA” promise was repeatedly failedJavaBeansEJBsHas the quest for modularity failed ?Project Jigsaw will be shipped with JDK 8 OSGi is already here
  • 9.
    The OSGi SolutionOverviewALayer …A deployment infrastructureBundles = class + metadata (import/exports)Bundles have a lifecycleBundles have their own Class loaderClass loading delegation between dependant bundles A service platformDefines a Service RegistryBundles provide or request servicesThe service can “come and go”
  • 10.
  • 11.
    Architecture ExecutionEnvironmentThe Runtime where the bundles liveA bundle can bound to an Execution EnvironmentJRE-1.5JJRE-1.3OSGi/Minimum-1.0
  • 12.
    Architecture ModuleLayerBundles import, export or have private packagesEach package can be assigned version rangeA bundle (fragment)can be attached to a bundle (host)Export Packagejavax.transaction 1.01BImport Packagejavax.transaction [1.0,1.1)Export Packagejavax.transaction 1.1Bundle Name: JMS APIImport Package: javax.transactionExport Package: javax.jmsBundle-RequiredExecutionEnvironment: J2SE-1.5
  • 13.
    Architecture ModuleLayera MANIFEST.MF exampleManifest-Version:1.0Import-Package:javax.transaction;version="1.1”, javax.transaction.xa;version="1.1”Export-Package:javax.jms;version="1.1”Bundle-SymbolicName:org.apache.geronimo.specs.geronimo-jms_1.1_specTool:Bnd-0.0.227
  • 14.
    InstalledStartingArchitecture LifecycleLayerstartupdate refreshresolveStartedResolveduninstalluninstallstopStoppedUninstalled
  • 15.
    Architecture ServiceLayerEach bundle can register or lookup a ServiceEach service corresponds to one or more interfacesEach service can be assigned and queried using propertiesService RegistryregisterlookupServiceProviderService Consumer
  • 16.
    OSGi Tools working withservicesManaging Services programmaticallyUsing the OSGi blueprintSpring Dynamic ModulesApache AriesFelix i-Pojo
  • 17.
    OSGi Tools creating bundlesManuallyproviding the MANIFEST.MFBnd command line toolMaven Bundle Plug-inSpring’s BundlorMaven plug-in flavorCommand line flavor
  • 18.
    OSGi Tools OSGi BundleRepositorySimplifies the provisioning of bundlesThe “apt-get install” for the OSGiIntegrates with public repositoriesEclipse OrbitSpring’s Enterprise Bundle Repository
  • 19.
    OSGiEnd of PartIQuestions & Answers
  • 20.
    Part IIGetting startedwith Apache Karaf
  • 21.
    Apache KarafagendaOverview Shell ConsoleDeployerFeaturesConceptSecurityLogging ServiceDemoQuestions and Answers
  • 22.
    Apache KarafOverviewBorn asService Mix Kernel projectGrown inside Apache Felix projectBecome a Top Level Apache project last year
  • 23.
    Apache KarafShell ConsoleExtensible Autocomplete & coloring supportRich command set, covers most OSGi concepts/servicesSpecial commands for the development phase
  • 24.
    Apache KarafDeployerFile ScannerWarTransformerConfigurationBundlesTransformationSpringTransformerBlueprintTransformerConfigurationAdminURLHandlerMaven HandlerHTTP HandlerHot deploymentLarge number of supported artifactsLarge number of installation mediumsOBR Handler
  • 25.
    Apache KarafFeatures ConceptAKaraf feature is a descriptor which defines…A set of bundlesA set of configurationsA set of other featuresAllows provisioning of applicationsMaven integrationOBR integration
  • 26.
    Apache KarafFeatures Example<featurename="http" version=”2.2.0” resolver=“(obr)”><configname="org.ops4j.pax.web”> org.osgi.service.http.port=8181 </config><feature version="[7.0,8.0)">jetty</feature> <bundle dependency=“true”>mvn:javax.servlet/servlet-api</bundle> <bundle>mvn:org.ops4j.pax.web/pax-web-api</bundle></feature>
  • 27.
    Apache KarafSecurityJAAS basedsecurityMultiple login module implementationsProperty Login ModuleJDBC Login ModuleLDAP Login ModuleCommand line supportProvisioning of any JASS realm Add users roles etc
  • 28.
    Apache KarafLogging ServiceCentralizedLogging configurationSupports most logging APIsLog4JSlf4j Commons LoggingCommand line supportclear, display, tail change threshold etc.OSGi integrationper bundle appender, osgi specific attributes
  • 29.
    Apache Karaf End ofPart IIQuestions & Answers
  • 30.