You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2017/11/21 17:08:20 UTC
[5/8] brooklyn-server git commit: bundle-force-remove: handle install
of mvn urls
bundle-force-remove: handle install of mvn urls
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/353bc540
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/353bc540
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/353bc540
Branch: refs/heads/master
Commit: 353bc5408115121da6ce95093e3891b021fd2ccb
Parents: b971077
Author: Aled Sage <al...@gmail.com>
Authored: Fri Nov 17 16:05:15 2017 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Nov 17 16:05:15 2017 +0000
----------------------------------------------------------------------
.../core/mgmt/ha/OsgiArchiveInstaller.java | 34 +++++++++++++++++---
.../core/mgmt/ha/OsgiArchiveInstallerTest.java | 12 +++++++
.../BrooklynLauncherUpgradeCatalogOsgiTest.java | 5 +--
3 files changed, 45 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/353bc540/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
index 41164cb..183d15a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
@@ -367,10 +367,25 @@ class OsgiArchiveInstaller {
// Before even trying to find or download the bundle, check if it is supposed to be forcibly replaced.
// If so, return the replacement (if any).
- if (suppliedKnownBundleMetadata != null && suppliedKnownBundleMetadata.isNameResolved()) {
- Maybe<VersionedName> forcedReplacementBundle = CatalogUpgrades.tryGetBundleForcedReplaced(mgmt(), suppliedKnownBundleMetadata.getVersionedName());
- if (forcedReplacementBundle.isPresent()) {
- return generateForciblyRemovedResult(suppliedKnownBundleMetadata.getVersionedName(), Optional.fromNullable(forcedReplacementBundle.get()));
+ if (suppliedKnownBundleMetadata != null) {
+ if (suppliedKnownBundleMetadata.isNameResolved()) {
+ Maybe<VersionedName> forcedReplacementBundle = CatalogUpgrades.tryGetBundleForcedReplaced(mgmt(), suppliedKnownBundleMetadata.getVersionedName());
+ if (forcedReplacementBundle.isPresent()) {
+ return generateForciblyRemovedResult(suppliedKnownBundleMetadata.getVersionedName(), Optional.fromNullable(forcedReplacementBundle.get()));
+ }
+ } else if (suppliedKnownBundleMetadata.getUrl() != null && suppliedKnownBundleMetadata.getUrl().toLowerCase().startsWith("mvn:")) {
+ // This inference is not guaranteed to get the right answer - you can put whatever
+ // you want in the MANIFEST.MF. Also, the maven-bundle-plugin does some surprising
+ // transforms, but we take a simpler approach here.
+ // If folk want it to work for such edge-cases, they should include the
+ // name:version explicitly in the `brooklyn.libraries list`.
+ Optional<VersionedName> inferredName = inferBundleNameFromMvnUrl(suppliedKnownBundleMetadata.getUrl());
+ if (inferredName.isPresent()) {
+ Maybe<VersionedName> forcedReplacementBundle = CatalogUpgrades.tryGetBundleForcedReplaced(mgmt(), inferredName.get());
+ if (forcedReplacementBundle.isPresent()) {
+ return generateForciblyRemovedResult(inferredName.get(), Optional.fromNullable(forcedReplacementBundle.get()));
+ }
+ }
}
}
@@ -717,6 +732,17 @@ class OsgiArchiveInstaller {
}
}
+ @VisibleForTesting
+ static Optional<VersionedName> inferBundleNameFromMvnUrl(String url) {
+ // Assumes format 'mvn:<groupId>/<artifactId>/<version>'
+ // e.g. "mvn:io.brooklyn.etcd/brooklyn-etcd/2.7.0"
+ assert url.startsWith("mvn:") : "url="+url;
+ String[] parts = url.substring(4).split("/");
+ if (parts.length != 3) return Optional.absent();
+ if (parts[0].trim().isEmpty() || parts[1].trim().isEmpty() || parts[2].trim().isEmpty()) return Optional.absent();
+ return Optional.of(new VersionedName(parts[0]+"."+parts[1], parts[2]));
+ }
+
private ReferenceWithError<OsgiBundleInstallationResult> generateForciblyRemovedResult(VersionedName desiredBundle, Optional<VersionedName> replacementBundle) {
if (replacementBundle.isPresent()) {
result.metadata = osgiManager.getManagedBundle(replacementBundle.get());
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/353bc540/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstallerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstallerTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstallerTest.java
index 3a86a3d..57d369a 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstallerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstallerTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.brooklyn.core.mgmt.ha;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -66,6 +67,17 @@ public class OsgiArchiveInstallerTest extends BrooklynMgmtUnitTestSupport {
assertFalse(installer.isBlacklistedForPersistence(newMockManagedBundle("org.apache.brooklyn.core", "1.0.0")));
}
+ @Test
+ public void testInferBundleNameFromMvnUrl() throws Exception {
+ assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:toofewslashes/1.0.0").isPresent());
+ assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:too/many/slashes/1.0.0").isPresent());
+ assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:emptystring//1.0.0").isPresent());
+ assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:/emptystring/1.0.0").isPresent());
+ assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:/emptystring/emptystring/").isPresent());
+ assertEquals(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:mygroupid/myartifactid/1.0.0").get(), new VersionedName("mygroupid.myartifactid", "1.0.0"));
+ assertEquals(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:my.group.id/my.artifact.id/1.0.0").get(), new VersionedName("my.group.id.my.artifact.id", "1.0.0"));
+ }
+
public OsgiManager newMockOsgiManager(ManagementContext mgmt) throws Exception {
OsgiManager result = Mockito.mock(OsgiManager.class);
Mockito.when(result.getManagementContext()).thenReturn(mgmt);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/353bc540/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
index 01c2b68..c7cc83d 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
@@ -363,7 +363,8 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
.catalogBom(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_1_0_0))
.build();
- // A bundle that references the forcibly-replaced bundle via name:version;
+ // A bundle that references the forcibly-replaced bundle via mvn url;
+ // it's not really in mvn repo, we expect it to match the groupId.artifactId with the forcibly removed bundle;
// (add this to persisted state).
BundleFile bundleWithReferenceByNameVersionName = bundleBuilder()
.name("org.example.bundleWithReferenceByName", "1.0.0")
@@ -371,7 +372,7 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
"brooklyn.catalog:",
" version: 1.0.0",
" brooklyn.libraries:",
- " - mvn:org.example/bundleWithReferenceByName/1.0.0"))
+ " - mvn:org.example/bundleBeingUpgraded/1.0.0"))
.build();
newPersistedStateInitializer()