diff options
9 files changed, 36 insertions, 133 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java b/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java index 7311641b1bd..cf3db91239a 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java @@ -3,7 +3,6 @@ package com.yahoo.container.core.config; import com.yahoo.config.FileReference; import com.yahoo.container.di.Osgi.GenerationStatus; -import com.yahoo.jdisc.application.BsnVersion; import com.yahoo.osgi.Osgi; import org.osgi.framework.Bundle; @@ -15,7 +14,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Logger; -import java.util.stream.Collectors; /** * Manages the set of installed and active/inactive bundles. @@ -51,14 +49,6 @@ public class ApplicationBundleLoader { } /** - * Returns bsn:version for all active bundles. - */ - public synchronized List<BsnVersion> activeBundlesBsnVersion() { - return activeBundles.values().stream().map(BsnVersion::new) - .collect(Collectors.toList()); - } - - /** * Installs the given set of bundles and updates state for which bundles and file references * that are active or should be uninstalled in case of success or failure. */ diff --git a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java index 13c07ffb14b..e2f97c9ad6b 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java @@ -4,7 +4,6 @@ package com.yahoo.container.core.config; import com.google.inject.AbstractModule; import com.google.inject.Injector; import com.yahoo.component.AbstractComponent; -import com.yahoo.component.ComponentSpecification; import com.yahoo.component.annotation.Inject; import com.yahoo.component.provider.ComponentRegistry; import com.yahoo.concurrent.ThreadFactoryFactory; @@ -16,24 +15,20 @@ import com.yahoo.container.di.config.SubscriberFactory; import com.yahoo.container.logging.AccessLog; import com.yahoo.filedistribution.fileacquirer.FileAcquirer; import com.yahoo.jdisc.application.OsgiFramework; -import com.yahoo.jdisc.application.BsnVersion; import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.service.ClientProvider; import com.yahoo.jdisc.service.ServerProvider; import com.yahoo.osgi.OsgiImpl; import com.yahoo.osgi.OsgiWrapper; import org.osgi.framework.Bundle; -import org.osgi.framework.Version; import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; /** * For internal use only. @@ -112,39 +107,6 @@ public class HandlersConfigurerDi { public Set<Bundle> completeBundleGeneration(GenerationStatus status) { return applicationBundleLoader.completeGeneration(status); } - - @Override - protected String bundleResolutionErrorMessage(ComponentSpecification bundleSpec) { - List<BsnVersion> activeBundles = applicationBundleLoader.activeBundlesBsnVersion(); - List<Version> activeVersions = activeVersionsOfBundle(bundleSpec, activeBundles); - - String versionsMessage = ""; - if (activeVersions.size() == 1) { - versionsMessage = "There is an installed bundle with the same name with version: " + activeVersions.get(0); - } else if (activeVersions.size() > 1) { - versionsMessage = "There are installed bundles with the same name with versions: " + activeVersions; - } - if (qualifierIsUsed(bundleSpec, activeVersions)) { - versionsMessage += " Note that qualifier strings must be matched exactly"; - } - return String.format("%s. Installed application bundles: [%s]", - versionsMessage, - activeBundles.stream() - .map(BsnVersion::toReadableString) - .collect(Collectors.joining(", "))); - } - - private static boolean qualifierIsUsed(ComponentSpecification bundleSpec, List<Version> activeVersions) { - return ! bundleSpec.getVersionSpecification().getQualifier().isEmpty() || - activeVersions.stream().anyMatch(version -> ! version.getQualifier().isEmpty()); - } - - private static List<Version> activeVersionsOfBundle(ComponentSpecification bundleSpec, List<BsnVersion> activeBundles) { - return activeBundles.stream() - .filter(bundle -> bundle.symbolicName().equals(bundleSpec.getName())) - .map(BsnVersion::version) - .collect(Collectors.toList()); - } } /** diff --git a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java index 156fa4ab074..2c7a0c2b86b 100644 --- a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java +++ b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java @@ -62,18 +62,13 @@ public class OsgiImpl implements Osgi { if (bundle != null) { return resolveFromBundle(spec, bundle); } else { - if (jdiscOsgi.isFelixFramework() && ! spec.bundle.equals(spec.classId)) { - // Bundle was explicitly specified, but not found. - throw new IllegalArgumentException("Could not find bundle " + spec.bundle + - ". " + bundleResolutionErrorMessage(spec.bundle)); - } return resolveFromThisBundleOrSystemBundle(spec); } } /** - * Tries to resolve the given class from this class' bundle. - * If unsuccessful, resolves the class from the system bundle (jdisc_core). + * Tries to resolve the given class from this class' bundle classloader. + * If unsuccessful, resolves the class from . */ @SuppressWarnings("unchecked") private Class<Object> resolveFromThisBundleOrSystemBundle(BundleInstantiationSpecification spec) { @@ -91,14 +86,9 @@ public class OsgiImpl implements Osgi { } } throw new IllegalArgumentException( - "Could not create a component with class '" + spec.classId.getName() + - "'. Tried to load class directly, since no bundle was found for spec: " + spec.bundle + - ". " + bundleResolutionErrorMessage(spec.bundle)); - } - - protected String bundleResolutionErrorMessage(ComponentSpecification bundleSpec) { - return " If a bundle with the same name is installed, there is a either a version mismatch " + - "or the installed bundle's version contains a qualifier string."; + "Could not create a component with id '" + spec.classId.getName() + "'. Tried to load class directly, " + + "since no bundle was found for spec: " + spec.bundle + ". If a bundle with the same name is installed, " + + "there is a either a version mismatch or the installed bundle's version contains a qualifier string."); } @SuppressWarnings("unchecked") diff --git a/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java b/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java index e973dd28838..e646e916521 100644 --- a/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java +++ b/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java @@ -2,7 +2,6 @@ package com.yahoo.container.core.config; import com.yahoo.container.di.Osgi.GenerationStatus; -import com.yahoo.jdisc.application.BsnVersion; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.osgi.framework.Bundle; @@ -36,7 +35,6 @@ public class ApplicationBundleLoaderTest { @Test void bundles_are_installed_and_started() { bundleLoader.useBundles(List.of(BUNDLE_1_REF)); - bundleLoader.completeGeneration(GenerationStatus.SUCCESS); assertEquals(1, osgi.getInstalledBundles().size()); // The bundle is installed and started @@ -50,16 +48,6 @@ public class ApplicationBundleLoaderTest { } @Test - void current_bundles_metadata_can_be_retrieved() { - bundleLoader.useBundles(List.of(BUNDLE_1_REF, BUNDLE_2_REF)); - bundleLoader.completeGeneration(GenerationStatus.SUCCESS); - - List<BsnVersion> activeBundles = bundleLoader.activeBundlesBsnVersion(); - assertEquals(new BsnVersion(BUNDLE_1), activeBundles.get(0)); - assertEquals(new BsnVersion(BUNDLE_2), activeBundles.get(1)); - } - - @Test void generation_must_be_marked_complete_before_using_new_bundles() { bundleLoader.useBundles(List.of(BUNDLE_1_REF)); assertThrows(IllegalStateException.class, diff --git a/container-core/src/test/java/com/yahoo/container/core/config/BundleTestUtil.java b/container-core/src/test/java/com/yahoo/container/core/config/BundleTestUtil.java index 60ea9009e1e..fddbeaf42be 100644 --- a/container-core/src/test/java/com/yahoo/container/core/config/BundleTestUtil.java +++ b/container-core/src/test/java/com/yahoo/container/core/config/BundleTestUtil.java @@ -4,7 +4,6 @@ import com.yahoo.config.FileReference; import com.yahoo.filedistribution.fileacquirer.FileAcquirer; import com.yahoo.osgi.Osgi; import org.osgi.framework.Bundle; -import org.osgi.framework.Version; import java.util.List; import java.util.Map; @@ -17,7 +16,7 @@ public class BundleTestUtil { public static final FileReference BUNDLE_1_REF = new FileReference("bundle-1"); public static final Bundle BUNDLE_1 = new TestBundle(BUNDLE_1_REF.value()); public static final FileReference BUNDLE_2_REF = new FileReference("bundle-2"); - public static final Bundle BUNDLE_2 = new TestBundle(BUNDLE_2_REF.value(), new Version(2, 0, 0, "SNAPSHOT")); + public static final Bundle BUNDLE_2 = new TestBundle(BUNDLE_2_REF.value()); public static Map<String, Bundle> testBundles() { return Map.of(BUNDLE_1_REF.value(), BUNDLE_1, diff --git a/container-core/src/test/java/com/yahoo/container/core/config/TestBundle.java b/container-core/src/test/java/com/yahoo/container/core/config/TestBundle.java index babc936494e..17709844f99 100644 --- a/container-core/src/test/java/com/yahoo/container/core/config/TestBundle.java +++ b/container-core/src/test/java/com/yahoo/container/core/config/TestBundle.java @@ -21,17 +21,11 @@ public class TestBundle extends MockBundle { private static final BundleRevision revision = new TestBundleRevision(); private final String symbolicName; - private final Version version; boolean started = false; public TestBundle(String symbolicName) { - this(symbolicName, BundleVersion); - } - - public TestBundle(String symbolicName, Version version) { this.symbolicName = symbolicName; - this.version = version; } @Override @@ -44,10 +38,6 @@ public class TestBundle extends MockBundle { return symbolicName; } - @Override - public Version getVersion() { - return version; - } @SuppressWarnings("unchecked") @Override diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java deleted file mode 100644 index 40573eee3b2..00000000000 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.yahoo.jdisc.application; - -import org.osgi.framework.Bundle; -import org.osgi.framework.Version; - -/** - * A bundle's symbolic name and version. - * - * @author gjoranv - */ -public record BsnVersion(String symbolicName, Version version) { - - public BsnVersion(Bundle bundle) { - this(bundle.getSymbolicName(), bundle.getVersion()); - } - - public String toReadableString() { - return symbolicName + " version:" + version; - } - -} diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java index 203c2e975e4..3212bb4e6de 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java @@ -1,11 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.core; -import com.yahoo.jdisc.application.BsnVersion; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.ServiceRegistration; +import org.osgi.framework.Version; import org.osgi.framework.hooks.bundle.CollisionHook; import org.osgi.framework.hooks.bundle.EventHook; import org.osgi.framework.hooks.bundle.FindHook; @@ -15,8 +15,10 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.logging.Logger; +import java.util.stream.Collectors; /** * A bundle {@link CollisionHook} that contains a set of bundles that are allowed to collide with bundles @@ -127,4 +129,31 @@ public class BundleCollisionHook implements CollisionHook, EventHook, FindHook { } } + + static class BsnVersion { + + private final String symbolicName; + private final Version version; + + BsnVersion(Bundle bundle) { + this.symbolicName = bundle.getSymbolicName(); + this.version = bundle.getVersion(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BsnVersion that = (BsnVersion) o; + return Objects.equals(symbolicName, that.symbolicName) && + version.equals(that.version); + } + + @Override + public int hashCode() { + return Objects.hash(symbolicName, version); + } + + } + } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BsnVersionTest.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BsnVersionTest.java deleted file mode 100644 index 484c4c9fb3c..00000000000 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BsnVersionTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.yahoo.jdisc.application; - -import org.junit.jupiter.api.Test; -import org.osgi.framework.Version; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author gjoranv - */ -public class BsnVersionTest { - - @Test - void readable_string_can_be_retrieved() { - BsnVersion bsnVersion = new BsnVersion("com.yahoo.foo", new Version("1.0.0")); - assertEquals("com.yahoo.foo version:1.0.0", bsnVersion.toReadableString()); - } - - @Test - void version_qualifier_can_be_retrieved() { - BsnVersion bsnVersion = new BsnVersion("foo", new Version(1, 2, 3, "SNAPSHOT")); - assertEquals("SNAPSHOT", bsnVersion.version().getQualifier()); - } -} |