2017-02-27 142 views
3

我有一个数据源功能,出口数据源作为OSGi服务:Karaf功能安装缺少的要求osgi.service但它的存在

> 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-功能,创建并注册这个数据源服务的一部分,它还包含一个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命令访问它。

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))"]] 

什么奇怪的是,除了一个事实,即平DS命令我写的作品就好了,如果我只是安装了它所抱怨的功能中的测试包,它工作得很好。这意味着这是功能的一些问题:安装过程本身。

在FOO-数据源测试特征的特征,我包括foo的核特征,其引用DS-特征:

FOO-数据源 - 测试 - 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芯-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依赖于已经安装的数据源服务,那么在我的特性中描述这种依赖关系的正确方法是什么呢?

使用:

Karaf版本4.0.6

骆驼版本2.16.5

UPDATE

我注释掉参考核心功能,使刚刚束是在测试功能,它仍然抱怨。因此,这与功能依赖关系的功能无关。

我打算试试卡拉夫版本4.1.0。

UPDATE

4.1.0上没有喜悦。作为一个侧面说明,由于activemq-client 5.14.4尚未构建,所以发生了更多问题。

回答

2

显然,feature:install正在寻找不在OSGi服务注册表中的服务,而是在其他地方的MANIFEST中寻找服务。一位同事让我看清单的文件和我在FOO-数据源测试发现,它有一个Import-Service首部在它的manifest文件:

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

那好像是错误的,因为它是做我MANIFEST文件要求它做的 - 即导入服务。为什么它无法在OSGi服务注册表中找到它,我不知道。但是在任何MANIFEST文件中都没有相应的导出服务。但是,由于导入服务和导出服务显然已被弃用,并且我正在迁移到卡拉夫的保险丝上运行的旧代码没有被通知;-)我决定只找到一种方法来删除任何导入或导出服务,服务标题。

this advice,我加

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

到我foo的核心特征的pom.xml行家束-插件的部分指令(记得,FOO-数据源测试,功能上FOO依赖-core-功能):

mvn clean deploy
<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> 

后,feature:install工作,它跑了就好了(找到数据源,用它和SQL返回结果集)。

像往常一样,寻找很长一段时间后,它是简单或基本的东西。我不知道为什么feature:install不会只是检查OSGi注册表,但可能有一个很好的理由(我希望),因为它不依赖于此并寻找一个MANIFEST标题。不知道在这种情况下Provide-Capability标头是否运行得更好,但可以试试。

+0

activemq-client修复程序是为5.14.4今天(https://repository.apache.org/content/repositories/releases/org/apache/activemq/activemq-client/5.14.4/)构建的,所以我切换回到使用karaf 4.1.0和我使用以下版本:activemq.version = 5.14.4 camel.version = 2.18.2 spring.version = 4.3.5.RELEASE – bmcdonald

+0

我刚刚得到同样的问题,只有其中Require-Capability头自动与持久性单元捆绑在一起生成。有趣的是,它已经工作了,然后“突然”停了下来。可悲的是,卡拉夫有很多东西写得非常糟糕。 –

相关问题