Details

    • Type: Task
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Story Points:
      3
    • Sprint:
      Summer 2 2023 May 29, Summer 3 2023 June 12, Summer 4 2023 June 26

      Description

      Situation: This ticket is part of a series of tutorials on OSGI.

      Task: Read and complete this tutorial: https://medium.com/javarevisited/learn-osgi-from-scratch-eclipse-intellij-and-wso2-platform-%EF%B8%8F-bf4c5629e097

      Document how useful this tutorial was and any useful information from the tutorial in the Jira comments below.

        Attachments

          Issue Links

            Activity

            Hide
            kgopu Kaushik Gopu added a comment -

            This is one the best article for learning OSGI in terms of both theoretical and conceptual aspect. This article helped me in creation of OSGI project from scratch. The author covers two examples one is developed on eclipse IDE using MANIFEST.MF file, which is quite older, and the other one is developed on IntelliJ using MAVEN.
            The second example is close to our IGB project in terms of project structure. However, the example is somewhat bigger and it might be difficult to understand in first go. So I recommend to create simple "Hello World" project to understand the basic workflow and configurations of OSGI and then comeback to this example to know how bundles interact with each other in order to deliver end result.

            Show
            kgopu Kaushik Gopu added a comment - This is one the best article for learning OSGI in terms of both theoretical and conceptual aspect. This article helped me in creation of OSGI project from scratch. The author covers two examples one is developed on eclipse IDE using MANIFEST.MF file, which is quite older, and the other one is developed on IntelliJ using MAVEN. The second example is close to our IGB project in terms of project structure. However, the example is somewhat bigger and it might be difficult to understand in first go. So I recommend to create simple "Hello World" project to understand the basic workflow and configurations of OSGI and then comeback to this example to know how bundles interact with each other in order to deliver end result.
            Hide
            ann.loraine Ann Loraine added a comment - - edited

            Tutorial update:

            The tutorial mentions four OSGi framework implementations - Equinox, Knopflerfish, Felix, and Concierge. There is another implementation - Apache Karaf.

            Note that the tutorial is relatively recent - 2021.

            Show
            ann.loraine Ann Loraine added a comment - - edited Tutorial update: The tutorial mentions four OSGi framework implementations - Equinox, Knopflerfish, Felix, and Concierge. There is another implementation - Apache Karaf. Note that the tutorial is relatively recent - 2021.
            Hide
            ann.loraine Ann Loraine added a comment - - edited

            Github link for the Book Inventory (second) tutorial: https://github.com/nipunaupeksha/osgi-book-inventory.

            Made a fork in my "aloraine" account on github: https://github.com/aloraine/osgi-book-inventory
            Cloned it to my local.
            Built jar files from the cloned project with:

            mvn package
            

            jar files:

            local aloraine$ find . | grep jar
            ./org.wso2.carbon.book.provider/target/org.wso2.carbon.book.provider-1.0-SNAPSHOT.jar
            ./org.wso2.carbon.book.reader/target/org.wso2.carbon.book.reader-1.0-SNAPSHOT.jar
            ./.idea/jarRepositories.xml
            

            Unpacked org.wso2.carbon.book.provider-1.0-SNAPSHOT.jar file.
            Examined descriptor file OSGI-INF org.wso2.carbon.book.provider.internal.BookProviderServiceComponent.xml, with contents:

            <?xml version="1.0" encoding="UTF-8"?>
            <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.wso2.carbon.book.provider" activate="activate" deactivate="deactivate">    
                <implementation class="org.wso2.carbon.book.provider.internal.BookProviderServiceComponent"/>
                </scr:component>
            

            Examined the bundle's MANIFEST.MF file:

            MANIFEST.MF 
            Manifest-Version: 1.0
            Bnd-LastModified: 1688057846042
            Build-Jdk: 11.0.18
            Built-By: aloraine
            Bundle-Description: A book shelf for carbon
            Bundle-ManifestVersion: 2
            Bundle-Name: org.wso2.carbon.book.provider
            Bundle-SymbolicName: org.wso2.carbon.book.provider
            Bundle-Version: 1.0.0.SNAPSHOT
            Created-By: Apache Maven Bundle Plugin
            Export-Package: org.wso2.carbon.book.provider;uses:="org.wso2.carbon.boo
             k.provider.model";version="1.0.0.SNAPSHOT",org.wso2.carbon.book.provide
             r.model;version="1.0.0.SNAPSHOT"
            Import-Package: org.osgi.framework;version="[1.7.0,2.0.0)",org.osgi.serv
             ice.component;version="[1.2.0,2.0.0)"
            Service-Component: OSGI-INF/org.wso2.carbon.book.provider.internal.BookP
             roviderServiceComponent.xml
            Tool: Bnd-2.1.0.20130426-122213
            
            Show
            ann.loraine Ann Loraine added a comment - - edited Github link for the Book Inventory (second) tutorial: https://github.com/nipunaupeksha/osgi-book-inventory . Made a fork in my "aloraine" account on github: https://github.com/aloraine/osgi-book-inventory Cloned it to my local. Built jar files from the cloned project with: mvn package jar files: local aloraine$ find . | grep jar ./org.wso2.carbon.book.provider/target/org.wso2.carbon.book.provider-1.0-SNAPSHOT.jar ./org.wso2.carbon.book.reader/target/org.wso2.carbon.book.reader-1.0-SNAPSHOT.jar ./.idea/jarRepositories.xml Unpacked org.wso2.carbon.book.provider-1.0-SNAPSHOT.jar file. Examined descriptor file OSGI-INF org.wso2.carbon.book.provider.internal.BookProviderServiceComponent.xml, with contents: <?xml version= "1.0" encoding= "UTF-8" ?> <scr:component xmlns:scr= "http: //www.osgi.org/xmlns/scr/v1.1.0" immediate= " true " name= "org.wso2.carbon.book.provider" activate= "activate" deactivate= "deactivate" > <implementation class= "org.wso2.carbon.book.provider.internal.BookProviderServiceComponent" /> </scr:component> Examined the bundle's MANIFEST.MF file: MANIFEST.MF Manifest-Version: 1.0 Bnd-LastModified: 1688057846042 Build-Jdk: 11.0.18 Built-By: aloraine Bundle-Description: A book shelf for carbon Bundle-ManifestVersion: 2 Bundle-Name: org.wso2.carbon.book.provider Bundle-SymbolicName: org.wso2.carbon.book.provider Bundle-Version: 1.0.0.SNAPSHOT Created-By: Apache Maven Bundle Plugin Export-Package: org.wso2.carbon.book.provider;uses:="org.wso2.carbon.boo k.provider.model ";version=" 1.0.0.SNAPSHOT",org.wso2.carbon.book.provide r.model;version= "1.0.0.SNAPSHOT" Import-Package: org.osgi.framework;version= "[1.7.0,2.0.0)" ,org.osgi.serv ice.component;version= "[1.2.0,2.0.0)" Service-Component: OSGI-INF/org.wso2.carbon.book.provider.internal.BookP roviderServiceComponent.xml Tool: Bnd-2.1.0.20130426-122213
            Hide
            ann.loraine Ann Loraine added a comment - - edited

            Decided to try load these bundles into karaf.
            Downloaded and installed the latest version of karaf: 4.3.9
            Unpacked karaf "tarball" to a local directory and adding its "bin" directory to my path.
            Started karaf using JDK11 with:

            karaf debug
            

            This launches a command-line interface to the karaf environment.

            Next, I attempted to start the project bundles with:

            bundle:install -s mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT
            karaf@root()> bundle:install -s mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT
            Bundle ID: 52
            Error executing command: Error installing bundles:
            	Unable to start bundle mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT: org.osgi.framework.BundleException: Unable to resolve org.wso2.carbon.book.provider [52](R 52.0): missing requirement [org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0))) Unresolved requirements: [[org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0)))]
            

            Note: the "-s" option also starts the bundle.

            Show
            ann.loraine Ann Loraine added a comment - - edited Decided to try load these bundles into karaf. Downloaded and installed the latest version of karaf: 4.3.9 Unpacked karaf "tarball" to a local directory and adding its "bin" directory to my path. Started karaf using JDK11 with: karaf debug This launches a command-line interface to the karaf environment. Next, I attempted to start the project bundles with: bundle:install -s mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT karaf@root()> bundle:install -s mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT Bundle ID: 52 Error executing command: Error installing bundles: Unable to start bundle mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT: org.osgi.framework.BundleException: Unable to resolve org.wso2.carbon.book.provider [52](R 52.0): missing requirement [org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring. package ; (&(osgi.wiring. package =org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0))) Unresolved requirements: [[org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring. package ; (&(osgi.wiring. package =org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0)))] Note: the "-s" option also starts the bundle.
            Hide
            ann.loraine Ann Loraine added a comment -

            As shown in the preceding comment, the framework lacks the required package org.osgi.service.component.

            Within karaf, I can check all the exported and available packages with:

            karaf@root()> exports | grep org.osgi  
            

            This lists 41 packages, including org.osgi.framework version 1.9.0, which satisfies the first import requirement listed in the bundle MANIFEST for org.wso2.carbon.book.provider.

            Show
            ann.loraine Ann Loraine added a comment - As shown in the preceding comment, the framework lacks the required package org.osgi.service.component. Within karaf, I can check all the exported and available packages with: karaf@root()> exports | grep org.osgi This lists 41 packages, including org.osgi.framework version 1.9.0, which satisfies the first import requirement listed in the bundle MANIFEST for org.wso2.carbon.book.provider.
            Hide
            ann.loraine Ann Loraine added a comment - - edited

            I restart the karaf container, getting rid of any and all bundles and packages except the karaf framework's bundles and packages with:

            karaf clean 
            

            I check the number of packages with:

             
            karaf@root()> exports | wc -l
            807
            

            and the number of bundles with:

            karaf@root()> la | wc -l
            55
            

            and the number of user-installed (by me) bundles with:

            karaf@root()> list
            

            I then try to install the "provider" bundle again with:

            karaf@root()> bundle:install -s mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT                                                     
            Bundle ID: 52
            Error executing command: Error installing bundles:
            	Unable to start bundle mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT: org.osgi.framework.BundleException: Unable to resolve org.wso2.carbon.book.provider [52](R 52.0): missing requirement [org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0))) Unresolved requirements: [[org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0)))]
            

            and check the exported packages count again:

            karaf@root()> exports | wc -l
            809
            

            After trying to install this new bundle, I see there are two more packages being exported.

            They are from our project: org.wso2.carbon.book.provider.model and org.wso2.carbon.book.provider.

            However, the bundles are not started. I guess the packages are available for use? That's interesting.

            Let's check the imports for the "provider" bundle:

            karaf@root()> imports -b 52 --no-format
            org.osgi.framework        	[1.7.0,2.0.0)	        	52	org.wso2.carbon.book.provider
            org.osgi.service.component	[1.2.0,2.0.0)	        	52	org.wso2.carbon.book.provider
            

            Let's use "diag" to assess the problem:

            karaf@root()> diag
            org.wso2.carbon.book.provider (52)
            ----------------------------------
            Status: Installed
            Unsatisfied Requirements:
            [org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0)))
            
            Show
            ann.loraine Ann Loraine added a comment - - edited I restart the karaf container, getting rid of any and all bundles and packages except the karaf framework's bundles and packages with: karaf clean I check the number of packages with: karaf@root()> exports | wc -l 807 and the number of bundles with: karaf@root()> la | wc -l 55 and the number of user-installed (by me) bundles with: karaf@root()> list I then try to install the "provider" bundle again with: karaf@root()> bundle:install -s mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT Bundle ID: 52 Error executing command: Error installing bundles: Unable to start bundle mvn:org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT: org.osgi.framework.BundleException: Unable to resolve org.wso2.carbon.book.provider [52](R 52.0): missing requirement [org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring. package ; (&(osgi.wiring. package =org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0))) Unresolved requirements: [[org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring. package ; (&(osgi.wiring. package =org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0)))] and check the exported packages count again: karaf@root()> exports | wc -l 809 After trying to install this new bundle, I see there are two more packages being exported. They are from our project: org.wso2.carbon.book.provider.model and org.wso2.carbon.book.provider. However, the bundles are not started. I guess the packages are available for use? That's interesting. Let's check the imports for the "provider" bundle: karaf@root()> imports -b 52 --no-format org.osgi.framework [1.7.0,2.0.0) 52 org.wso2.carbon.book.provider org.osgi.service.component [1.2.0,2.0.0) 52 org.wso2.carbon.book.provider Let's use "diag" to assess the problem: karaf@root()> diag org.wso2.carbon.book.provider (52) ---------------------------------- Status: Installed Unsatisfied Requirements: [org.wso2.carbon.book.provider [52](R 52.0)] osgi.wiring. package ; (&(osgi.wiring. package =org.osgi.service.component)(version>=1.2.0)(!(version>=2.0.0)))
            Hide
            ann.loraine Ann Loraine added a comment -

            I located this package / artifact in my ".m2" directory and looked at its POM:

            local aloraine$ more org.osgi.service.component-1.5.1.pom
            <?xml version="1.0" encoding="UTF-8"?>
            <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
              <modelVersion>4.0.0</modelVersion>
              <groupId>org.osgi</groupId>
              <artifactId>org.osgi.service.component</artifactId>
              <version>1.5.1</version>
              <description>OSGi Companion Code for org.osgi.service.component Version 1.5.1</description>
              <name>org.osgi:org.osgi.service.component</name>
              <url>https://docs.osgi.org/</url>
              <organization>
                <name>Eclipse Foundation</name>
              </organization>
            ...
            
            Show
            ann.loraine Ann Loraine added a comment - I located this package / artifact in my ".m2" directory and looked at its POM: local aloraine$ more org.osgi.service.component-1.5.1.pom <?xml version= "1.0" encoding= "UTF-8" ?> <project xmlns= "http: //maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>org.osgi</groupId> <artifactId>org.osgi.service.component</artifactId> <version>1.5.1</version> <description>OSGi Companion Code for org.osgi.service.component Version 1.5.1</description> <name>org.osgi:org.osgi.service.component</name> <url>https: //docs.osgi.org/</url> <organization> <name>Eclipse Foundation</name> </organization> ...
            Hide
            ann.loraine Ann Loraine added a comment -

            Next, I installed this into my karaf session with:

            karaf@root()> bundle:install mvn:org.osgi/org.osgi.service.component
            Bundle ID: 55
            
            Show
            ann.loraine Ann Loraine added a comment - Next, I installed this into my karaf session with: karaf@root()> bundle:install mvn:org.osgi/org.osgi.service.component Bundle ID: 55
            Hide
            ann.loraine Ann Loraine added a comment -

            Summarizing the findings thus far:

            • karaf has many commands that help with detecting and solving errors, such as "import" and "export", which list packages being exported from or imported into various bundles
            • unix commands such as "grep" and "wc -l" are supported, making debugging faster and easier
            • the framework does not appear to contain service component infrastructure needed by this project
            Show
            ann.loraine Ann Loraine added a comment - Summarizing the findings thus far: karaf has many commands that help with detecting and solving errors, such as "import" and "export", which list packages being exported from or imported into various bundles unix commands such as "grep" and "wc -l" are supported, making debugging faster and easier the framework does not appear to contain service component infrastructure needed by this project
            Hide
            ann.loraine Ann Loraine added a comment - - edited

            In the previous comment, I said "the framework does not appear to contain service component infrastructure needed by this project."

            This seems very strange!

            I found a Web page on karaf that mentioned some useful commands, include "feature:list".

            There are 174 "features" listed! One of these is "scr", with Description "Declarative Service support." Its current "State" is "Uninstalled."

            Maybe, if I somehow "install" this feature, I would not need to install the "org.osgi:org.osgi.service.component" bundle from my local "mvn" repository?

            So, I tried to install it with:

            karaf@root()> feature:install scr
            

            After this, the "scr" feature State changed to "Started."

            Show
            ann.loraine Ann Loraine added a comment - - edited In the previous comment, I said "the framework does not appear to contain service component infrastructure needed by this project." This seems very strange! I found a Web page on karaf that mentioned some useful commands, include "feature:list". There are 174 "features" listed! One of these is "scr", with Description "Declarative Service support." Its current "State" is "Uninstalled." Maybe, if I somehow "install" this feature, I would not need to install the "org.osgi:org.osgi.service.component" bundle from my local "mvn" repository? So, I tried to install it with: karaf@root()> feature:install scr After this, the "scr" feature State changed to "Started."
            Hide
            ann.loraine Ann Loraine added a comment -

            I then uninstalled the previously installed bundles. Freshly attempting to re-install and re-start bundle org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT succeeded without any error.

            I then quit and restarted karaf with a fresh, clean environment with "karaf clean".
            I confirmed that the "scr" feature was not active. I then activated it as before with "feature:install scr" and then tried to load the "provider" bundle.

            This time, it loaded without any error.

            Thus, karaf actually does contain support declarative services. You just have to install that feature within the framework to activate it, I guess.

            Show
            ann.loraine Ann Loraine added a comment - I then uninstalled the previously installed bundles. Freshly attempting to re-install and re-start bundle org.wso2.carbon/org.wso2.carbon.book.provider/1.0-SNAPSHOT succeeded without any error. I then quit and restarted karaf with a fresh, clean environment with "karaf clean". I confirmed that the "scr" feature was not active. I then activated it as before with "feature:install scr" and then tried to load the "provider" bundle. This time, it loaded without any error. Thus, karaf actually does contain support declarative services. You just have to install that feature within the framework to activate it, I guess.
            Hide
            ann.loraine Ann Loraine added a comment - - edited

            Trying now to figure out which version of declarative services / scr is used in this tutorial.

            I was able to build it using JDK 11 and run it in the latest version (4.3.9) of karaf, also running in JDK 11. This suggests that maybe the most up-to-date system for declarative services is being used?

            Upon consultation with Nowlan Freese, we realized that the only way to be truly sure about this is to look at the package import statements in the code.

            Investigating the code:

            package org.wso2.carbon.book.provider.internal;
            
            import org.osgi.framework.BundleContext;
            import org.osgi.service.component.ComponentContext;
            import org.osgi.service.component.annotations.Activate;
            import org.osgi.service.component.annotations.Component;
            import org.osgi.service.component.annotations.Deactivate;
            import org.wso2.carbon.book.provider.BookProvider;
            import org.wso2.carbon.book.provider.BookProviderImpl;
            
            import java.util.logging.Logger;
            
            @Component(
                    name = "org.wso2.carbon.book.provider",
                    immediate = true
            )
            
            Show
            ann.loraine Ann Loraine added a comment - - edited Trying now to figure out which version of declarative services / scr is used in this tutorial. I was able to build it using JDK 11 and run it in the latest version (4.3.9) of karaf, also running in JDK 11. This suggests that maybe the most up-to-date system for declarative services is being used? Upon consultation with Nowlan Freese , we realized that the only way to be truly sure about this is to look at the package import statements in the code. Investigating the code: package org.wso2.carbon.book.provider.internal; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.wso2.carbon.book.provider.BookProvider; import org.wso2.carbon.book.provider.BookProviderImpl; import java.util.logging.Logger; @Component( name = "org.wso2.carbon.book.provider" , immediate = true )
            Hide
            ann.loraine Ann Loraine added a comment - - edited

            Now, looking at Component imports in an IGB project (master branch, jdk 1.8 build):

            • ./core/igb-services-api/src/main/java/org/lorainelab/igb/services/search/SearchModeRegistry.java

            imports and Component annotation:

            import aQute.bnd.annotation.component.Component;
            import aQute.bnd.annotation.component.Reference;
            ...
            @Component(name = SearchModeRegistry.COMPONENT_NAME, immediate = true, provide = SearchModeRegistry.class)
            

            Our project (IGB) does not appear to be using felix scr but instead is using something perhaps even older - annotations from package aQute.bnd.annotation.component.

            Show
            ann.loraine Ann Loraine added a comment - - edited Now, looking at Component imports in an IGB project (master branch, jdk 1.8 build): ./core/igb-services-api/src/main/java/org/lorainelab/igb/services/search/SearchModeRegistry.java imports and Component annotation: import aQute.bnd.annotation.component.Component; import aQute.bnd.annotation.component.Reference; ... @Component(name = SearchModeRegistry.COMPONENT_NAME, immediate = true , provide = SearchModeRegistry.class) Our project (IGB) does not appear to be using felix scr but instead is using something perhaps even older - annotations from package aQute.bnd.annotation.component.

              People

              • Assignee:
                kgopu Kaushik Gopu
                Reporter:
                nfreese Nowlan Freese
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: