【问题标题】:Karaf feature install missing requirement osgi.service but it is thereKaraf 功能安装缺少要求 osgi.service 但它在那里
【发布时间】:2017-02-27 01:46:45
【问题描述】:

我有一个将数据源导出为 OSGi 服务的数据源功能:

> services -p 2038
OPS4J Pax JDBC Config (2038) provides:
--------------------------------------
objectClass = [org.osgi.service.cm.ManagedServiceFactory]
service.bundleid = 2038
service.id = 211
service.pid = org.ops4j.datasource
service.scope = singleton
----
databaseName = foobar
dataSourceName = fooDatasource
felix.fileinstall.filename = file:/home/foousr/apache-karaf-4.0.6/etc/org.ops4j.datasource-foo.cfg
objectClass = [javax.sql.DataSource]
osgi.jndi.service.name = fooDatasource
service.bundleid = 2038
service.factoryPid = org.ops4j.datasource
service.id = 251
service.pid = org.ops4j.datasource.b3020619-71b9-4876-94c3-477f3e4a503d
service.scope = singleton
url = jdbc:oracle:thin:@dbserver:99999/foo
user = FOOUSR

作为创建和注册此数据源服务的 ds-feature 的一部分,它还包含一个可用于测试数据源的 ping-ds 包:

> jdbc:ping-ds fooDatasource
Ping from localhost(127.0.0.1) as FOOUSR to schema FOOUSR on dbserver/foo

我有一个使用该数据源的蓝图包:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/blueprint"
    xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0
       http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint
       http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
       http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
       http://svn.apache.org/repos/asf/aries/trunk/blueprint/blueprint-cm/src/main/resources/org/apache/aries/blueprint/compendium/cm/blueprint-cm-1.1.0.xsd">
    <reference id="ds" interface="javax.sql.DataSource" filter="(dataSourceName=fooDatasource)"/>
    <camelContext id="fooDatasourceTestContext" trace="true" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="fooDatasourceTest">
            <from uri="timer:/fooDatasourceTest?fixedRate=true&amp;repeatCount=1"/>
            <setBody>
                <simple>
                    select * from FOOUSR.FOOTABLE
                </simple>
            </setBody>
            <to uri="jdbc:ds" />
            <to uri="log:fooDatasourceTest?showBody=true"/>
        </route>
    </camelContext>
</blueprint>

当我执行feature:install foo-datasource-test-feature 时,我收到一个错误,抱怨无法找到数据源服务 - 但它在那里,我可以使用我的 ping-ds cmd 访问它。

    Error executing command: Unable to resolve root: missing requirement [root] osgi.identity;
 osgi.identity=foo-datasource-test-feature; type=karaf.feature; version="[0.0.1.SNAPSHOT,0.0.1.SNAPSHOT]";
 filter:="(&(osgi.identity=foo-datasource-test-feature)(type=karaf.feature)(version>=0.0.1.SNAPSHOT)(version<=0.0.1.SNAPSHOT))"
 [caused by: Unable to resolve foo-datasource-test-feature/0.0.1.SNAPSHOT: missing requirement
 [foo-datasource-test-feature/0.0.1.SNAPSHOT] osgi.identity; osgi.identity=com.company.project.foo-datasource-test;
 type=osgi.bundle; version="[0.0.1.SNAPSHOT,0.0.1.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve
 com.company.project.foo-datasource-test/0.0.1.SNAPSHOT: missing requirement
 [com.company.project.foo-datasource-test/0.0.1.SNAPSHOT] osgi.service; effective:=active;
 filter:="(&(objectClass=javax.sql.DataSource)(dataSourceName=fooDatasource))"]]

似乎在抱怨找不到已安装的 OSGi 服务的数据源:

osgi.service; effective:=active;
 filter:="(&(objectClass=javax.sql.DataSource)(dataSourceName=fooDatasource))"]]

奇怪的是,除了我编写的 ping-ds 命令可以正常工作之外,如果我只是安装它所抱怨的功能中的测试包,它就可以正常工作。这意味着这是功能的某种问题:安装过程本身。

在 foo-datasource-test-feature 功能中,我包含一个引用 ds-feature 的 foo-core-feature:

foo-datasource-test-feature.xml:

<?xml version="1.0" encoding="utf-8"?>
<features name="foo-datasource-test" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
    <feature name="foo-datasource-test-feature" version="${project.version}">
        <feature>foo-core-feature</feature>
        <bundle>mvn:com.company.project/foo-datasource-test/${project.version}</bundle>
    </feature>
</features

foo-core-feature.xml:

<?xml version="1.0" encoding="utf-8"?>
<features name="foo-core" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
    <feature name="foo-core-feature" version="${project.version}">
        <feature>ds-feature</feature>
        ...
    </feature>
</features>

ds-features.xml:

<?xml version="1.0" encoding="UTF-8"?>
<features name="ds-features" xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
    <feature name="ds-feature" version="${project.version}" >
        <feature>pax-jdbc-config</feature>
        ...
        <bundle start-level="86">mvn:com.company.commons/foo-datasource/${project.version}</bundle>
    </feature>
    <feature name="ds-ping-datasource" version="${project.version}" >
        <bundle start-level="80">mvn:com.company.commons/foo-ping-datasource/${project.version}</bundle>
        <feature>pax-jdbc-config</feature>
    </feature>
</features>

这会导致问题吗?如果是这样,由于 foo-datasource-test-feature 依赖于已经安装的数据源服务,那么在我的功能中描述这种依赖关系的正确方法是什么?

使用:

卡拉夫版本 4.0.6

骆驼版 2.16.5

更新

我注释掉了对核心功能的引用,因此只有捆绑包在测试功能中,它仍然会抱怨。所以这与特征依赖无关。

我要试试 karaf 4.1.0 版。

更新

在 4.1.0 上没有乐趣。附带说明一下,由于尚未构建 activemq-client 5.14.4,因此存在更多问题。

【问题讨论】:

    标签: installation karaf


    【解决方案1】:

    显然,feature:install 不是在 OSGi 服务注册表中寻找服务,而是在其他地方的 MANIFEST 中寻找服务。一位同事让我查看 MANIFEST 文件,我在 foo-datasource-test 中注意到它的 MANIFEST 文件中有一个 Import-Service 标头:

    Import-Service: javax.sql.DataSource;multiple:=false;filter=(dataSourceName=fooDatasource)
    

    似乎错误是因为它正在执行我的 MANIFEST 文件要求它执行的操作 - 即导入服务。为什么它在 OSGi 服务注册表中找不到它,我不知道。但是在任何 MANIFEST 文件中都没有相应的 Export-Service。但是,由于 Import-Service 和 Export-Service 显然已被弃用,并且我正在迁移到 karaf 的旧代码运行在保险丝上并没有得到通知 ;-) 我决定简单地找到一种方法来删除任何 Import- 或 Export-服务标头。

    this advice之后,我添加了

    <_removeheaders>Import-Service,Export-Service</_removeheaders>
    

    进入我的 foo-core-feature pom.xml 中的 maven-bundle-plugin 的说明部分(回想一下 foo-datasource-test-feature 依赖于 foo-core-feature):

    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>3.2.0</version>
                    <extensions>true</extensions>
                    <configuration>
                        <instructions>
                        . . .
                            <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                            <Import-Package>*,org.apache.camel.core.osgi</Import-Package>
                            <_removeheaders>Import-Service,Export-Service</_removeheaders>
                        </instructions>
                    </configuration>
                </plugin>
            <plugins>
    </build>
    

    mvn clean deploy 之后,feature:install 工作正常,运行良好(找到数据源,使用它并返回 sql 结果集)。

    和往常一样,找了很久,还是很简单或者基本的东西。我不确定为什么feature:install 无论如何都不会检查 OSGi 注册表,但可能有一个很好的理由(我希望)它不依赖它并寻找 MANIFEST 标头。不确定Provide-Capability 标头在这种情况下是否运行得更好,但可以尝试一下。

    【讨论】:

    • activemq-client 修复是为今天的 5.14.4 (repository.apache.org/content/repositories/releases/org/apache/…) 构建的,所以我切换回使用 karaf 4.1.0 并使用以下版本:activemq.version=5.14.4 camel .version=2.18.2 spring.version=4.3.5.RELEASE
    • 我刚刚遇到了同样的问题,只是 Require-Capability 标头在带有持久性单元的捆绑包中自动生成。有趣的是,它已经起作用了,然后“突然”停止了。可悲的是,卡拉夫有很多东西写得很糟糕。
    猜你喜欢
    • 2017-04-11
    • 2021-09-20
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2012-03-23
    • 2018-04-12
    相关资源
    最近更新 更多