我正在使用Apache Karaf 4.1.1和Karaf Cellar。我寫了兩個捆綁包。第一個bundle提供了一個ITrackerManager類型的服務。第二個bundle有一個引用ITrackerManager的組件。我的最終目標是見證第二個包中的組件成功獲取對運行在不同節點上的第一個包中的ITrackerManager服務的引用。這是我對分佈式OSGi的探索的一部分。Apache Karaf Cellar的分佈式OSGi示例 - 由於無法找到分佈式服務,客戶端軟件包無法激活
當我安裝第二個軟件包時,實際發生的事情是它已安裝,但由於缺少服務引用而無法激活。我必須錯誤地進行我的測試。 關於如何去展示我的最終目標的任何想法;節點B上的組件成功使用節點A上的服務?
這是我迄今爲止如何運行我的測試。
節點A
[email protected]()> cluster:node-list
| Id | Alias | Host Name | Port
--+-------------------+-------+--------------+-----
x | 159.4.251.58:5701 | | 159.4.251.58 | 5701
| 159.4.251.58:5702 | | 159.4.251.58 | 5702
節點B
[email protected]()> cluster:node-list
| Id | Alias | Host Name | Port
--+-------------------+-------+--------------+-----
| 159.4.251.58:5701 | | 159.4.251.58 | 5701
x | 159.4.251.58:5702 | | 159.4.251.58 | 5702
到目前爲止好。我在我的電腦上運行兩個卡拉夫實例。兩個實例都可以看到對方。現在我想僅將第一個包安裝到節點A.爲了實現這個目標,我安裝包到集羣,然後專門從節點B.刪除
節點A
[email protected]()> cluster:bundle-install -s default mvn:myCompany/dosgi-example-part1/1.0-SNAPSHOT
[email protected]()> cluster:bundle-list default
Bundles in cluster group default
ID | State | Lvl | Located | Blocked | Version | Name
---+----------+-----+---------------+---------+----------------+--------------------------------------------------------------
0 | Active | | cluster/local | | 5.6.2 | System Bundle
...
67 | Active | | cluster/local | | 1.0.0.SNAPSHOT | Distributed OSGi Example Part 1
[email protected]()> cluster:service-list
Service Class | Provider Node
--------------------------+------------------
myCompany.ITrackerManager | 159.4.251.58:5701
| 159.4.251.58:5702
仍在尋找好。我的軟件包位於集羣中,在節點A(此時爲節點B)上爲本地節點,服務由集羣識別並在節點A和節點B上可用。現在從節點B移除該軟件包。
節點B
[email protected]()> cluster:bundle-list default
Bundles in cluster group default
ID | State | Lvl | Located | Blocked | Version | Name
---+----------+-----+---------------+---------+----------------+-------------------------------------------------------------
67 | Active | | cluster/local | | 1.0.0.SNAPSHOT | Distributed OSGi Example Part 1
[email protected]()> bundle:list
START LEVEL 100 , List Threshold: 50
ID | State | Lvl | Version | Name
---+--------+-----+----------------+-----------------------------------------------
75 | Active | 80 | 1.0.0.SNAPSHOT | Distributed OSGi Example Part 1
[email protected]()> bundle:uninstall 75
[email protected]()> cluster:bundle-list default
Bundles in cluster group default
ID | State | Lvl | Located | Blocked | Version | Name
---+----------+-----+---------------+---------+----------------+--------------------------------------------------------------
67 | Active | | cluster | | 1.0.0.SNAPSHOT | Distributed OSGi Example Part 1
[email protected]()> cluster:service-list
Service Class | Provider Node
--------------------------+------------------
myCompany.ITrackerManager | 159.4.251.58:5701
優秀。第一個包已從節點B中刪除,但仍顯示爲處於羣集中。兩個節點都同意我的服務現在僅在節點A上可用(因爲該節點已從節點B中刪除)。現在我只會在節點B上加載我的第二個包。這是我遇到問題的地方。我不使用cluster:bundle-install命令加載第二個bundle,因爲我不希望它以節點A結束。因此,我使用常規bundle:install命令來安裝第二個bundle。這會導致關於不滿意的參考的錯誤。
節點B
[email protected]()> bundle:install -s mvn:otherCompany/dosgi-example-part2/1.0-SNAPSHOT
Bundle ID: 76
Error executing command: Error installing bundles:
Unable to start bundle mvn:otherCompany/dosgi-example-part2/1.0-SNAPSHOT: org.osgi.framework.BundleException: Unable to resolve otherCompany.dosgi-example-part2 [76](R 76.0): missing requirement [otherCompany.dosgi-example-part2 [76](R 76.0)] osgi.wiring.package; (&(osgi.wiring.package=myCompany)(version>=1.0.0)(!(version>=2.0.0))) Unresolved requirements: [[otherCompany.dosgi-example-part2 [76](R 76.0)] osgi.wiring.package; (&(osgi.wiring.package=myCompany)(version>=1.0.0)(!(version>=2.0.0)))]
[email protected]()> bundle:list
START LEVEL 100 , List Threshold: 50
ID | State | Lvl | Version | Name
---+-----------+-----+----------------+-----------------------------------------------------------------------------------------------------
76 | Installed | 80 | 1.0.0.SNAPSHOT | Distributed OSGi Example Part 2
所以它就在那裏。我只在NodeB上安裝第二個軟件包,期望它能夠成功使用駐留在節點A上的所需服務。不幸的是,這並沒有發生。相反,我收到錯誤消息,指出有未解決的要求。它似乎表現得好像DOSGI不可用。如果我將兩個軟件包安裝在同一個節點上,則第二個軟件包將激活而不會出現任何錯誤。任何見解你可能會感激。
我發現了一個karaf-cellar示例,它完全符合我的要求,在Node B上使用分佈式OSGi在客戶端調用的節點A上創建了一項服務。這些說明可以在下面的URL中找到。我運行了這個例子,它在我現有的Karaf實例中運行正常。我需要做更多的挖掘工作來弄清楚他們的例子與我的不同之處,以便確定我爲什麼不工作。 [工作Karaf Cellar DOSGi示例](https://github.com/apache/karaf-cellar/tree/master/samples/dosgi-greeter) – jonathan