diff options
author | gjoranv <gv@verizonmedia.com> | 2020-07-08 23:22:02 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2020-07-15 12:51:54 +0200 |
commit | 72eb7a8938f60b6c3c7a562673514414bcb1b106 (patch) | |
tree | d8ea219e9bf4d63179c213491afd5a8b7bac9f2b | |
parent | f832e4330d5452e228659d7d2b55cf992e6550d0 (diff) |
Separate installation for platform and application bundles.
7 files changed, 82 insertions, 10 deletions
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 b983cbcfe37..1011e4ef719 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 @@ -102,11 +102,15 @@ public class HandlersConfigurerDi { private final OsgiFramework osgiFramework; private final BundleManager bundleManager; + private final PlatformBundleInstaller platformBundleInstaller; public ContainerAndDiOsgi(OsgiFramework osgiFramework) { super(osgiFramework); this.osgiFramework = osgiFramework; - bundleManager = new BundleManager(new OsgiImpl(osgiFramework)); + + OsgiImpl osgi = new OsgiImpl(osgiFramework); + bundleManager = new BundleManager(osgi); + platformBundleInstaller = new PlatformBundleInstaller(osgi); } @@ -131,6 +135,12 @@ public class HandlersConfigurerDi { } @Override + public void installPlatformBundles(Collection<FileReference> bundles) { + log.fine("Installing platform bundles."); + platformBundleInstaller.install(bundles); + } + + @Override public Set<Bundle> useBundles(Collection<FileReference> bundles) { log.info("Installing bundles from the latest application"); return bundleManager.use(new ArrayList<>(bundles)); diff --git a/container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleInstaller.java b/container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleInstaller.java new file mode 100644 index 00000000000..848930932fd --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleInstaller.java @@ -0,0 +1,47 @@ +package com.yahoo.container.core.config; + +import com.yahoo.config.FileReference; +import com.yahoo.osgi.Osgi; +import org.osgi.framework.Bundle; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Logger; + +/** + * Installs all platform bundles, using the {@link DiskBundleInstaller}. + * All platform bundles reside on disk, and they are never uninstalled. + * + * @author gjoranv + */ +// TODO: rename to ...Loader or ...Manager +public class PlatformBundleInstaller { + private static final Logger log = Logger.getLogger(PlatformBundleInstaller.class.getName()); + + private final Osgi osgi; + private final DiskBundleInstaller installer; + + public PlatformBundleInstaller(Osgi osgi) { + this.osgi = osgi; + installer = new DiskBundleInstaller(); + } + + public void install(Collection<FileReference> bundlesToInstall) { + for (FileReference reference : bundlesToInstall) { + try { + installBundleFromDisk(reference); + } + catch(Exception e) { + throw new RuntimeException("Could not install bundle '" + reference + "'", e); + } + } + } + + private void installBundleFromDisk(FileReference reference) { + log.info("Installing bundle from disk with reference '" + reference.value() + "'"); + List<Bundle> bundles = installer.installBundles(reference, osgi); + log.fine("Installed " + bundles.size() + " bundles for file reference " + reference); + } + +} diff --git a/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java b/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java index 9f49b016b68..503bf2f2db1 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java @@ -41,7 +41,8 @@ public class HandlersConfigurerTestWrapper { private final static String testFiles[] = { "components.cfg", "handlers.cfg", - "bundles.cfg", + "platform-bundles.cfg", + "application-bundles.cfg", "string.cfg", "int.cfg", "renderers.cfg", diff --git a/container-di/src/main/java/com/yahoo/container/di/Container.java b/container-di/src/main/java/com/yahoo/container/di/Container.java index ef7813ce368..bb3634983a9 100644 --- a/container-di/src/main/java/com/yahoo/container/di/Container.java +++ b/container-di/src/main/java/com/yahoo/container/di/Container.java @@ -40,7 +40,8 @@ public class Container { private static final Logger log = Logger.getLogger(Container.class.getName()); private final SubscriberFactory subscriberFactory; - private ConfigKey<BundlesConfig> bundlesConfigKey; + private ConfigKey<ApplicationBundlesConfig> applicationBundlesConfigKey; + private ConfigKey<PlatformBundlesConfig> platformBundlesConfigKey; private ConfigKey<ComponentsConfig> componentsConfigKey; private final ComponentDeconstructor componentDeconstructor; private final Osgi osgi; @@ -54,9 +55,10 @@ public class Container { this.componentDeconstructor = componentDeconstructor; this.osgi = osgi; - bundlesConfigKey = new ConfigKey<>(BundlesConfig.class, configId); + applicationBundlesConfigKey = new ConfigKey<>(ApplicationBundlesConfig.class, configId); + platformBundlesConfigKey = new ConfigKey<>(PlatformBundlesConfig.class, configId); componentsConfigKey = new ConfigKey<>(ComponentsConfig.class, configId); - var bootstrapKeys = Set.of(bundlesConfigKey, componentsConfigKey); + var bootstrapKeys = Set.of(applicationBundlesConfigKey, platformBundlesConfigKey, componentsConfigKey); this.configurer = new ConfigRetriever(bootstrapKeys, subscriberFactory::getSubscriber); } @@ -74,7 +76,6 @@ public class Container { deconstructObsoleteComponents(oldGraph, newGraph, obsoleteBundles); return newGraph; } catch (Throwable t) { - // TODO: Wrap ComponentConstructorException in an Error when generation==0 (+ unit test that Error is thrown) invalidateGeneration(oldGraph.generation(), t); throw t; } @@ -104,6 +105,9 @@ public class Container { + "previous generation: %d\n", getBootstrapGeneration(), getComponentsGeneration(), previousConfigGeneration)); + if (graph.generation() == 0) { + installPlatformBundles(getConfig(platformBundlesConfigKey, snapshot.configs())); + } Collection<Bundle> bundlesToRemove = installBundles(snapshot.configs()); obsoleteBundles.addAll(bundlesToRemove); @@ -151,9 +155,13 @@ public class Container { componentDeconstructor.deconstruct(oldComponents.keySet(), obsoleteBundles); } + private void installPlatformBundles(PlatformBundlesConfig platformBundlesConfig) { + osgi.installPlatformBundles(platformBundlesConfig.bundles()); + } + private Set<Bundle> installBundles(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs) { - BundlesConfig bundlesConfig = getConfig(bundlesConfigKey, configsIncludingBootstrapConfigs); - return osgi.useBundles(bundlesConfig.bundle()); + ApplicationBundlesConfig applicationBundlesConfig = getConfig(applicationBundlesConfigKey, configsIncludingBootstrapConfigs); + return osgi.useBundles(applicationBundlesConfig.bundles()); } private ComponentGraph createComponentsGraph(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs, diff --git a/container-di/src/main/java/com/yahoo/container/di/Osgi.java b/container-di/src/main/java/com/yahoo/container/di/Osgi.java index ab7da7665b6..563efd5f65e 100644 --- a/container-di/src/main/java/com/yahoo/container/di/Osgi.java +++ b/container-di/src/main/java/com/yahoo/container/di/Osgi.java @@ -25,6 +25,10 @@ public interface Osgi { return new BundleClasses(new MockBundle(), Collections.emptySet()); } + default void installPlatformBundles(Collection<FileReference> bundles) { + System.out.println("installPlatformBundles " + bundles.stream().map(Object::toString).collect(Collectors.joining(", "))); + } + /** * Returns the set of bundles that is not used by the current application generation, * and therefore should be scheduled for uninstalling. diff --git a/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java b/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java index eac64c20274..19f277ff8fb 100644 --- a/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java +++ b/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java @@ -267,7 +267,8 @@ public class ContainerTest extends ContainerTestBase { "inject[0].forClass \"" + injectedClass.getName() + "\"\n"; dirConfigSource.writeConfig("components", componentsConfig); - dirConfigSource.writeConfig("bundles", ""); + dirConfigSource.writeConfig("platform-bundles", ""); + dirConfigSource.writeConfig("application-bundles", ""); dirConfigSource.writeConfig("jersey-bundles", "bundles[0].spec \"mock-entry-to-enforce-a-MockBundle\""); dirConfigSource.writeConfig("jersey-injection", injectionConfig); diff --git a/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java b/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java index 18236a6bde9..4578a173c3b 100644 --- a/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java +++ b/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java @@ -81,7 +81,8 @@ public class ContainerTestBase { } protected void writeBootstrapConfigs(ComponentEntry... componentEntries) { - dirConfigSource.writeConfig("bundles", ""); + dirConfigSource.writeConfig("platform-bundles", ""); + dirConfigSource.writeConfig("application-bundles", ""); StringBuilder components = new StringBuilder(); for (int i = 0; i < componentEntries.length; i++) { components.append(componentEntries[i].asConfig(i)); |