从一个来源安装多个捆绑包
我使用 Apache Karaf 作为 OSGi 容器。 Karaf 有 url 包装器,可以直接从 Maven 存储库安装捆绑包,
> install mvn:com.farpost.billing/background-service/2.2-SNAPSHOT
Bundle ID: 139
一切正常。但我想从给定的源开始几个捆绑包。如果新的捆绑包偶尔会破坏生产服务并且我想回滚,这是有意义的。对于 OSGi,这非常简单。
> list
[ 139] [Active ] [ ] [Started] [ 60] Billing background service (2.2-20100811-1232)
[ 140] [Resolved ] [ ] [ ] [ 60] Billing background service (2.2-20100809-1127)
> update 140
> list
[ 139] [Active ] [ ] [Started] [ 60] Billing background service (2.2-20100811-1232)
[ 140] [Resolved ] [ ] [ ] [ 60] Billing background service (2.2-20100812-1354)
> start 140
> stop 139
> list
[ 139] [Resolved ] [ ] [ ] [ 60] Billing background service (2.2-20100811-1232)
[ 140] [Active ] [ ] [Started] [ 60] Billing background service (2.2-20100812-1354)
#################
# suppose we need to rollback here
#################
> start 139
> stop 140
问题是我无法从一个源创建多个捆绑包:
> install mvn:com.farpost.billing/background-service/2.2-SNAPSHOT
Bundle ID: 139
> install mvn:com.farpost.billing/background-service/2.2-SNAPSHOT
Bundle ID: 139
第二个 install
调用不执行任何操作,但返回已经存在的捆绑包 ID。所以我的问题是,有没有办法从一个源 url 创建多个捆绑包?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以使用功能文件一次安装多个捆绑包。目前,我们有一个功能文件,定义了大约 6-7 个捆绑包。最重要的是,该文件包含一个需要其他 6-7 个功能的功能。通过安装“master”功能,Karaf 会同时安装以下所有捆绑包。如果您愿意,您可以让 Karaf 在启动时运行这些捆绑包。
为此:
创建一个功能文件。更多信息可以在这里找到:外部源
将该功能文件放在您的 m2 目录中的某个位置。
修改Karaf主目录中的org.apache.karaf.features.cfg。将刚刚创建的功能文件的 mvn URL 添加到“featuresRepositories”标签中。 (可选)如果您希望在启动时加载功能,请将功能名称添加到“featuresBoot”。
启动 Karaf 后,您可以输入“features:install name_of_feature”。这将启动该功能以及功能文件定义的功能所需的任何其他内容。
然后您可以输入 list 来验证所有必需的捆绑包是否正在运行。这样做的缺点是,如果任何捆绑包发生更改或添加新捆绑包,则需要更新。
希望这有帮助。
It's possible to install several bundles at once by using a features file. Currently, we have a features file that defines about 6-7 bundles. On top of that, the file contains one feature that requires the other 6-7. By installing the "master" feature, Karaf installs all the following bundles at the same time. And if you want, you can have Karaf run these bundles on start-up.
In order to do this:
Create a features file. More can be found here: external source
Put that features file somewhere in your m2 directory.
Modify org.apache.karaf.features.cfg in the Karaf home directory. Add the mvn URL to the features file you just created to the "featuresRepositories" tag. Optionally, add the name of the feature to "featuresBoot" if you want it to load them on start-up.
After you start Karaf, you can type "features:install name_of_feature". This will start the feature and anything else the features needs as defined by the features file.
Then you can type list to verify all the required bundles are running. This has the drawback of needing to be updated if any bundles change, or new bundles are added.
Hope this helps.
编辑:刚刚看到这篇文章已有一年了! Stackoverflow RSS feed 将此放在我的列表顶部!?!
+1 给 Marcel &托尼,两者都是正确的。
处于 RESOLVED 状态的包正在导出活动/importing packages (ACTIVE 表示任何激活服务已启动并完成),并且您应该使用 Karaf 功能。
目前,我们手动滚动我们的 karaf-features 文件(请参阅发行版下载中的 PDF 文档),因为 v2.x 插件为每个依赖项创建一个单独的功能,并且有点古怪(我没有尝试过 trunk/v3,但它似乎是已修复
)正在尝试有两个问题;
相同(最差) ) 选项 1:
如果您真的迫切希望专门解决此问题,假设您使用 maven-bundle-plugin,请添加 buildnumber-maven-plugin 并将其添加到捆绑包配置中:
然后,当您安装捆绑包时,使用显式快照版本(版本名称中的快照在概念上只是一个存储库到最新时间戳版本的软链接):
使用此选项,正如 Marcel 所说,您可以将其他捆绑包导入连接到 已解决 捆绑包/Bundle.html#ACTIVE" rel="nofollow">ACTIVE 捆绑包 - 因此类不匹配会破坏您的系统。
(不太糟糕)选项 2:
稍微好一点(并且对 pom.xml 没有任何更改):
refresh
命令使用此选项,正如托尼所说,您将单独管理所有这些捆绑包,这是痛苦且危险的(什么与什么一起使用?这写在哪里?)。 Karaf 功能和 versions-maven-plugin 插件将是一个更好的解决方案
(好)选项 3:
EDIT: Just saw this post is a year old! Stackoverflow RSS feed put this at the top of my list !?!
+1's to Marcel & Tony, as a both correct.
A bundle in the RESOLVED state is activity exporting/importing packages (ACTIVE means any activation of services has been initiated and completed), and you should be using Karaf features.
Currently we hand-roll our karaf-features file (see the PDF docs in the distribution download), as the v2.x plugin creates a separate feature for each dependency and is a bit quirky (I haven't tried trunk/v3 but it appears to be fixed)
What you're trying has two gotchas;
(Worst) Option 1:
If you're really desperate to specifically work around this, assuming your using the maven-bundle-plugin, add the buildnumber-maven-plugin and this to the bundle config:
Then when you're installing the bundles use the explicit snapshot version (SNAPSHOT in a version name is conceptually just a repository soft-link to the latest timestamped version):
With this option, as Marcel states, you could have other bundles package imports wired to the RESOLVED bundle while importing services from the ACTIVE bundle - so class mismatches will break you system.
(Less Bad) Option 2:
Slightly better (and with no changes to pom.xml):
refresh
commandWith this option, as Tony states, you're managing all those bundles individually which is a pain and dangerous (what works with what? where's this written down?). Karaf features and the versions-maven-plugin plugin would be a much better solution
(Good) Option 3:
您遇到的问题是,您无法安装具有相同符号名称和版本的捆绑包的多个副本。
即使可以,在您描述的场景中安装同一捆绑包的两个不同版本也会产生副作用,因为只要安装了捆绑包,就可以使用它来解析包。在您的场景中,这可能不是您想要的,因为您想使用一个或另一个捆绑包,而不是混合使用。
最后我建议您只安装您想要的捆绑包。如果存在问题,请通过卸载有问题的捆绑包并安装旧版本来回滚。如果您想要自动安装和更新(一组)捆绑包,请查看 Apache ACE,它是 OSGi 的软件配置框架,它将帮助您自动执行此类场景(并管理一般的 OSGi 系统)。
You're running into the problem that you can not install more than one copy of a bundle with the same symbolic name and version.
Even if you could, there are side effects of having two different versions of the same bundle installed in the scenario you describe, because as long as a bundle is installed, it can be used to resolve packages from. In your scenario, that is probably not what you want, since you want to use either one or the other bundle, but not a mix.
In the end I would advise you to install just the bundle you want. If there are issues with it, roll back by uninstalling the faulty bundle and installing the older version. In case you want to automate the installation and update of (sets of) bundles, take a look at Apache ACE, a software provisioning framework for OSGi that will help you automate such scenarios (and manage OSGi systems in general).