bmc*_*ald 5 installation karaf
我有一个数据源功能,可以将数据源导出为 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
Run Code Online (Sandbox Code Playgroud)
作为创建和注册此数据源服务的 ds-feature 的一部分,它还包含一个 ping-ds 包,我可以用它来测试数据源:
> jdbc:ping-ds fooDatasource
Ping from localhost(127.0.0.1) as FOOUSR to schema FOOUSR on dbserver/foo
Run Code Online (Sandbox Code Playgroud)
我有一个使用该数据源的蓝图包:
<?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&repeatCount=1"/>
<setBody>
<simple>
select * from FOOUSR.FOOTABLE
</simple>
</setBody>
<to uri="jdbc:ds" />
<to uri="log:fooDatasourceTest?showBody=true"/>
</route>
</camelContext>
</blueprint>
Run Code Online (Sandbox Code Playgroud)
当我执行 a 时,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))"]]
Run Code Online (Sandbox Code Playgroud)
它似乎在抱怨它找不到已安装的 OSGi 服务的数据源:
osgi.service; effective:=active;
filter:="(&(objectClass=javax.sql.DataSource)(dataSourceName=fooDatasource))"]]
Run Code Online (Sandbox Code Playgroud)
奇怪的是,除了我编写的 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
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
这会导致问题吗?如果是这样,由于 foo-datasource-test-feature 依赖于已经安装的数据源服务,那么在我的功能中描述这种依赖关系的正确方法是什么?
使用:
卡拉夫版本 4.0.6
骆驼版本 2.16.5
更新
我注释掉了对核心功能的引用,所以只有包在测试功能中,它仍然抱怨。所以这与特征依赖关系无关。
我将尝试使用 karaf 4.1.0 版。
更新
4.1.0 没有快乐。附带说明一下,由于尚未构建 activemq-client 5.14.4,因此存在更多问题。
显然,feature:install我们不是在 OSGi 服务注册表中查找该服务,而是在其他地方的 MANIFEST 中查找该服务。一位同事让我查看 MANIFEST 文件,我在 foo-datasource-test 中注意到它的 MANIFEST 文件中有一个 Import-Service 标头:
Import-Service: javax.sql.DataSource;multiple:=false;filter=(dataSourceName=fooDatasource)
Run Code Online (Sandbox Code Playgroud)
看起来错误是因为它正在执行我的 MANIFEST 文件要求它执行的操作 - 即导入服务。为什么它在 OSGi 服务注册表中找不到它,我不知道。但任何 MANIFEST 文件中都没有相应的 Export-Service。但是,由于导入服务和导出服务显然已被弃用,并且我在迁移到 karaf 的旧代码上运行的旧代码没有得到通知;-) 我决定简单地找到一种方法来删除任何导入或导出-服务标头。
根据这个建议,我添加了
<_removeheaders>Import-Service,Export-Service</_removeheaders>
Run Code Online (Sandbox Code Playgroud)
进入我的 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>
Run Code Online (Sandbox Code Playgroud)
之后mvn clean deploy,feature:install工作正常,运行得很好(找到数据源,使用它并返回sql结果集)。
和往常一样,找了很长一段时间后,发现这是一些简单或基本的东西。我不确定为什么feature:install不只是检查 OSGi 注册表,但可能有一个很好的理由(我希望)它不依赖它并寻找 MANIFEST 标头。不确定Provide-Capability标头在这种情况下是否运行得更好,但可以尝试一下。
| 归档时间: |
|
| 查看次数: |
3342 次 |
| 最近记录: |