Repository navigation
Fix state of features with a leading zero in a version segment - #2978
Conversation
A feature version such as 1.0.01 was used as-is in Feature.getId(), while the deployment state keys features by the id of their resolver resource, where the version is an OSGi Version and is therefore normalized to 1.0.1. Because the two ids never matched, such a feature was reported as not installed (UNINSTALLED) even though its bundles were running, feature state changes were ignored, and its configurations and libraries were not installed. Normalize feature ids the OSGi way everywhere they are compared with the deployment state: in FeaturesServiceImpl (isInstalled/getState) and in the Deployer (features by id, requested state changes, configuration and library installation). The persisted state already used the normalized form, so existing installations need no migration. Fixes KARAF-5784 and KARAF-7163. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jbonofre
left a comment
There was a problem hiding this comment.
LGTM. Normalizing feature IDs in Deployer.partitionFeatures, the updateFeaturesState key handling, and FeaturesServiceImpl.normalize makes versions like 1.0.01 match the 1.0.1 form used in the deployment state.
One minor note: updateFeaturesState keys now go through ResourceUtils.normalizeFeatureId, so a key with an unparseable version would throw IllegalArgumentException where it was previously skipped silently. I don't see a realistic caller that does this, so I'm fine with it.
| * <code>1.0.1</code>. | ||
| */ | ||
| public static String getFeatureId(String name, String version) { | ||
| return version != null ? name + "/" + VersionTable.getVersion(version) : name; |
There was a problem hiding this comment.
VersionTable.getVersion throws IllegalStateException when the cleaned version still is not a valid OSGi version. A few inputs that survive VersionCleaner.clean and then fail:
| version | cleaned | result |
|---|---|---|
1.0.0.beta+1 |
1.0.0.beta+1 |
invalid qualifier "beta+1" |
1.0.0.rc 1 |
1.0.0.rc 1 |
invalid qualifier "rc 1" |
20231112093000 |
20231112093000.0.0 |
non-numeric "20231112093000" |
Before this PR, these ids were only cleaned, never parsed, so the method couldn't throw. Since it's now called for every available feature (see the comments on normalize() and partitionFeatures), it needs to fall back instead of failing. Such a feature can't be in the deployment state anyway (FeatureResource would fail to parse it too), so keeping the raw version as the key is safe:
| return version != null ? name + "/" + VersionTable.getVersion(version) : name; | |
| if (version == null) { | |
| return name; | |
| } | |
| try { | |
| return name + "/" + VersionTable.getVersion(version); | |
| } catch (IllegalArgumentException e) { | |
| // not a valid OSGi version even after cleaning, keep it as is | |
| return name + "/" + version; | |
| } |
Could we also add a regression test? A repository with an unused feature that has an invalid version, next to the one being installed:
<feature name="f" version="1.0.0">
<bundle>a100</bundle>
</feature>
<feature name="bad" version="1.0.0.beta+1">
<bundle>a100</bundle>
</feature>Installing f/1.0.0, listInstalledFeatures(), stopping and uninstalling f should all still work.
There was a problem hiding this comment.
Applied, thanks. Added testFeatureWithInvalidVersionDoesNotBreakOtherFeatures: f/1.0.0 is installed first, then a repository with bad/1.0.0.beta+1 is added. Listing, getState/isInstalled of bad, and stopping and uninstalling f all work. Without the fallback it fails at listInstalledFeatures() with IllegalArgumentException: invalid version "1.0.0.beta+1".
| String version = feature.substring(idx + 1); | ||
| return name + VERSION_SEPARATOR + VersionCleaner.clean(version); | ||
| // same form as the ids in the deployment state, so 1.0.01 matches 1.0.1 | ||
| return ResourceUtils.getFeatureId(name, VersionCleaner.clean(version)); |
There was a problem hiding this comment.
This is where it breaks for users. listInstalledFeatures() calls isInstalled() -> normalize() on every cached feature, and installFeatures() calls listInstalledFeatures() via computeFeaturesToAdd(). With an unused bad/1.0.0.beta+1 in any registered repository, installing an unrelated feature fails:
java.lang.IllegalArgumentException: invalid version "1.0.0.beta+1": invalid qualifier "beta+1"
at o.a.k.features.internal.resolver.ResourceUtils.getFeatureId(ResourceUtils.java:100)
at o.a.k.features.internal.service.FeaturesServiceImpl.normalize(FeaturesServiceImpl.java:962)
at o.a.k.features.internal.service.FeaturesServiceImpl.isInstalled(FeaturesServiceImpl.java:688)
at o.a.k.features.internal.service.FeaturesServiceImpl.flattenFeatures(FeaturesServiceImpl.java:683)
at o.a.k.features.internal.service.FeaturesServiceImpl.listInstalledFeatures(FeaturesServiceImpl.java:666)
at o.a.k.features.internal.service.FeaturesServiceImpl.computeFeaturesToAdd(FeaturesServiceImpl.java:835)
at o.a.k.features.internal.service.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:807)
feature:list, the JMX MBean and getState() fail the same way. The fallback in ResourceUtils.getFeatureId fixes it.
There was a problem hiding this comment.
Covered by the fallback. normalize() also no longer cleans the version itself, because VersionTable.getVersion already does that. So for an invalid version it falls back to the same raw string as partitionFeatures.
| features.computeIfAbsent(feature.getName(), name -> new ArrayList<>()).add(feature); | ||
| featuresById.put(feature.getId(), feature); | ||
| // keyed like the deployment state, which uses normalized versions (1.0.01 -> 1.0.1) | ||
| featuresById.put(getFeatureId(feature.getName(), feature.getVersion()), feature); |
There was a problem hiding this comment.
Same issue on the deployment path. Before, only features whose name matched a requirement had their version parsed (in Subsystem/FeatureReq). This loop now parses the version of every available feature. If f was installed first and a repository with bad/1.0.0.beta+1 is added later, every deployment fails, including stopping or uninstalling f:
java.lang.IllegalArgumentException: invalid version "1.0.0.beta+1": invalid qualifier "beta+1"
at o.a.k.features.internal.resolver.ResourceUtils.getFeatureId(ResourceUtils.java:100)
at o.a.k.features.internal.service.Deployer$DeploymentState.partitionFeatures(Deployer.java:234)
at o.a.k.features.internal.service.FeaturesServiceImpl.getDeploymentState(FeaturesServiceImpl.java:1038)
at o.a.k.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1071)
partitionFeatures is also used by AssemblyDeployCallback and VerifyMojo, so profile assembly and karaf:verify are affected too.
The fallback in ResourceUtils.getFeatureId covers this as well.
There was a problem hiding this comment.
Covered by the same fallback, and the test follows this order: the repository with the invalid version is added after f was installed. While there, the config/library loop now uses the featuresById key instead of recomputing it.
ResourceUtils.getFeatureId(name, version) now falls back to the raw version when VersionTable cannot parse it, even after cleaning. Without the fallback, a single feature such as bad/1.0.0.beta+1 in any registered repository made listing, installing, stopping and uninstalling unrelated features fail with an IllegalArgumentException. Such a feature can never be in the deployment state, because FeatureResource cannot parse its version either. The regression test installs f first and then adds the repository with the invalid version, as in the review. The leading-zero test now uses the same bundle mock helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- FeaturesServiceImpl.normalize no longer cleans the version itself: ResourceUtils.getFeatureId already does, and the invalid-version fallback now keeps the same raw version as Deployer.partitionFeatures. - Deployer uses the featuresById key instead of recomputing it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Addressed in 097b0a1 and bc22184. Two related things I left alone because this PR doesn't touch them: Unrelated: could you approve the pending CI run on #2979? It's waiting for maintainer approval after the rebase on |
Fixes KARAF-5784 and KARAF-7163.
Problem
A feature whose version has a leading zero in a numeric segment (e.g.
1.0.01or1.01.1-SNAPSHOT) gets installed: its bundles are deployed and running. Karaf still reports the feature as not installed /Uninstalled, without any error in the log:Started.Cause
Feature ids are built in two different ways:
Feature.getId()(andFeaturesServiceImpl.normalize()) keep the version string as written:f/1.0.01.State.installedFeatures/stateFeatures) is keyed byResourceUtils.getFeatureId(Resource). That method uses the OSGiVersionof the feature resource, which is normalized:f/1.0.1.The two ids never match, so:
isInstalled()/getState()don't find the feature;feature:start/feature:stop(updateFeaturesState) are silently ignored;Deployerdoesn't install (or delete) the feature's configurations and libraries.Resolution itself is not affected, because requirements use version ranges.
Fix
Feature ids are now normalized the OSGi way everywhere they are compared with the deployment state:
ResourceUtils.getFeatureId(String, String)andnormalizeFeatureId(String)produce the same form asgetFeatureId(Resource).FeaturesServiceImpl.normalize()uses that form, which fixesisInstalled()andgetState().Deployeruses it forfeaturesById, for requested state changes, and when installing configurations and libraries.The persisted state already used the normalized form, so existing installations need no migration.
Tests
FeaturesServiceImplTest#testInstallAndStopFeatureWithLeadingZeroInVersioninstalls a1.0.01feature. It checks that the feature is installed andStarted, then stops it through its own id. Without the fix the test fails withFeature f/1.0.01 not installed.mvn -pl features/core install: 141 tests, 0 failures.🤖 Generated with Claude Code