diff options
author | Arnstein Ressem <aressem@gmail.com> | 2023-01-09 08:25:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 08:25:27 +0100 |
commit | 170af02d92a5f5e5442c45d6041cd367e46be3ad (patch) | |
tree | 62b7e1e947697ddc92e410a0ed1b951e67302f3d /container-core | |
parent | e704b1b4ae95eabfa30f7fc4ea0f44ac4e7ee177 (diff) |
Revert "More user friendly class resolution"
Diffstat (limited to 'container-core')
6 files changed, 6 insertions, 87 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 |