从一个来源安装多个捆绑包

发布于 2024-09-14 00:02:40 字数 1392 浏览 10 评论 0 原文

我使用 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 创建多个捆绑包?

I'm using Apache Karaf as an OSGi container. Karaf have url wrapper which can install bundles directly from maven repository

> install mvn:com.farpost.billing/background-service/2.2-SNAPSHOT
Bundle ID: 139

All works just fine. But I want to start several bundles from given source. This make sense if new bundle occasionally broke production service and I want to rollback. With OSGi this is very straightforward

 > 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

The problem is I can not create several bundles from one source:

> 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

Second install call doesn't do anything but returns already existed bundle id. So my question, is there any way to create several bundles from one source url?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴随着你 2024-09-21 00:02:41

可以使用功能文件一次安装多个捆绑包。目前,我们有一个功能文件,定义了大约 6-7 个捆绑包。最重要的是,该文件包含一个需要其他 6-7 个功能的功能。通过安装“master”功能,Karaf 会同时安装以下所有捆绑包。如果您愿意,您可以让 Karaf 在启动时运行这些捆绑包。

为此:

  1. 创建一个功能文件。更多信息可以在这里找到:外部源

  2. 将该功能文件放在您的 m2 目录中的某个位置。

  3. 修改Karaf主目录中的org.apache.karaf.features.cfg。将刚刚创建的功能文件的 mvn URL 添加到“featuresRepositories”标签中。 (可选)如果您希望在启动时加载功能,请将功能名称添加到“featuresBoot”。

  4. 启动 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:

  1. Create a features file. More can be found here: external source

  2. Put that features file somewhere in your m2 directory.

  3. 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.

  4. 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.

草莓味的萝莉 2024-09-21 00:02:41

编辑:刚刚看到这篇文章已有一年了! Stackoverflow RSS feed 将此放在我的列表顶部!?!

+1 给 Marcel &托尼,两者都是正确的。

处于 RESOLVED 状态的包正在导出活动/importing packages (ACTIVE 表示任何激活服务已启动并完成),并且您应该使用 Karaf 功能。
目前,我们手动滚动我们的 karaf-features 文件(请参阅发行版下载中的 PDF 文档),因为 v2.x 插件为每个依赖项创建一个单独的功能,并且有点古怪(我没有尝试过 trunk/v3,但它似乎是已修复

)正在尝试有两个问题;

  1. pax maven url 处理程序命令将识别该捆绑包已安装并且不执行任何操作
  2. 即使安装了,第二个捆绑包也会失败,因为很可能符号名称将与第一个

相同(最差) ) 选项 1:

如果您真的迫切希望专门解决此问题,假设您使用 maven-bundle-plugin,请添加 buildnumber-maven-plugin 并将其添加到捆绑包配置中:

<Bundle-SymbolicName>${project.artifactId} ${buildNumber}</Bundle-SymbolicName>

然后,当您安装捆绑包时,使用显式快照版本(版本名称中的快照在概念上只是一个存储库到最新时间戳版本的软链接):

install mvn:com.farpost.billing/background-service/2.2-20100812-1354

使用此选项,正如 Marcel 所说,您可以将其他捆绑包导入连接到 已解决 捆绑包/Bundle.html#ACTIVE" rel="nofollow">ACTIVE 捆绑包 - 因此类不匹配会破坏您的系统。

(不太糟糕)选项 2:

稍微好一点(并且对 pom.xml 没有任何更改):

  1. 记下捆绑包的确切时间戳版本
  2. 调用 refresh 命令
  3. 要回滚、卸载捆绑包并安装前面提到的版本

使用此选项,正如托尼所说,您将单独管理所有这些捆绑包,这是痛苦且危险的(什么与什么一起使用?这写在哪里?)。 Karaf 功能和 versions-maven-plugin 插件将是一个更好的解决方案

(好)选项 3:

  1. 将您的捆绑包分成两部分; API 包和实现包 - 这样切换您的实现包(服务和实际逻辑)不会影响包接线,只会影响服务解析
  2. 使用 OSGi 版本控制方案,它与 maven 版本控制具有合理的协同作用(请参阅 语义版本控制 pdf 和 Peter Kriens 在 否定限定符)。该方案是 MAJOR.MINOR.MICO.qualifier,其中除了错误修复快照之外不添加任何新功能的微数字
  3. 应该仅用于开发而不是生产,因为您正在使用未经测试的、可能会发生变化的移动目标(在您必须使用快照的情况下,通过使用带时间戳的版本将它们锁定到您实际使用过的版本(对于第 3 方依赖项,您必须使用快照版本,versions-maven-plugin lock-snapshots 目标可以在这里提供帮助)
  4. 使用 Karaf 功能,它可以制作大型套件捆绑包更易于管理(使用一个命令部署整个堆栈并进行类似的升级)

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;

  1. The pax maven url handler command will recognise that the bundle is already installed and do nothing
  2. Even if it did then the 2nd bundle would fail as most likely the symbolic name would be identical to 1st

(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:

<Bundle-SymbolicName>${project.artifactId} ${buildNumber}</Bundle-SymbolicName>

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):

install mvn:com.farpost.billing/background-service/2.2-20100812-1354

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):

  1. Note the exact timestamped version of the bundle
  2. Invoke the refresh command
  3. To rollback, uninstall the bundle and install the previously noted version

With 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:

  1. Split your bundle in two; an API bundle and implementation bundle - that way switching out your implementation bundle (services and actual logic) wouldn't affect the package wiring just the service resolution
  2. Use the OSGi versioning scheme, it has reasonable synergy with maven versioning (see the semantic versioning pdf and Peter Kriens post on negative qualifiers). The scheme is MAJOR.MINOR.MICO.qualifier, where the micro numbers which add no new functionality other than bug fixes
  3. SNAPSHOTs should be used only for development not production as you're working with a untested, subject-to-change, moving target (where you do have to use snapshots lock them down to a version you've actually worked with by using the timestamped version (for 3rd party dependencies, that you must use the SNAPSHOT version, the versions-maven-plugin lock-snapshots goal can help here)
  4. Use Karaf features, it makes large suites of bundles much easier to manage (deploy you're entire stack with one command and similarly upgrade)
黒涩兲箜 2024-09-21 00:02:40

您遇到的问题是,您无法安装具有相同符号名称和版本的捆绑包的多个副本。

即使可以,在您描述的场景中安装同一捆绑包的两个不同版本也会产生副作用,因为只要安装了捆绑包,就可以使用它来解析包。在您的场景中,这可能不是您想要的,因为您想使用一个或另一个捆绑包,而不是混合使用。

最后我建议您只安装您想要的捆绑包。如果存在问题,请通过卸载有问题的捆绑包并安装旧版本来回滚。如果您想要自动安装和更新(一组)捆绑包,请查看 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文