summaryrefslogtreecommitdiffstats
path: root/container-di
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-07-16 07:27:49 +0200
committerGitHub <noreply@github.com>2020-07-16 07:27:49 +0200
commit0355cb740fe498abc03861bcb64de5e418c2fa88 (patch)
treea456fc74ed740d6c5c5fb6ed61f100c09c951c24 /container-di
parent14c65de9b6b0d7a5dac17aa96109e125c14762b5 (diff)
Revert "Load platform bundles separately"
Diffstat (limited to 'container-di')
-rw-r--r--container-di/src/main/java/com/yahoo/container/di/Container.java50
-rw-r--r--container-di/src/main/java/com/yahoo/container/di/Osgi.java6
-rw-r--r--container-di/src/main/resources/configdefinitions/application-bundles.def5
-rw-r--r--container-di/src/main/resources/configdefinitions/bundles.def2
-rw-r--r--container-di/src/main/resources/configdefinitions/platform-bundles.def5
-rw-r--r--container-di/src/test/java/com/yahoo/container/di/ContainerTest.java3
-rw-r--r--container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java5
7 files changed, 24 insertions, 52 deletions
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 d85591386fd..ef7813ce368 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
@@ -4,8 +4,8 @@ package com.yahoo.container.di;
import com.google.inject.Injector;
import com.yahoo.config.ConfigInstance;
import com.yahoo.config.ConfigurationRuntimeException;
-import com.yahoo.config.FileReference;
import com.yahoo.config.subscription.ConfigInterruptedException;
+import com.yahoo.container.BundlesConfig;
import com.yahoo.container.ComponentsConfig;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.di.ConfigRetriever.BootstrapConfigs;
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.IdentityHashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
@@ -41,14 +40,12 @@ public class Container {
private static final Logger log = Logger.getLogger(Container.class.getName());
private final SubscriberFactory subscriberFactory;
- private ConfigKey<ApplicationBundlesConfig> applicationBundlesConfigKey;
- private ConfigKey<PlatformBundlesConfig> platformBundlesConfigKey;
+ private ConfigKey<BundlesConfig> bundlesConfigKey;
private ConfigKey<ComponentsConfig> componentsConfigKey;
private final ComponentDeconstructor componentDeconstructor;
private final Osgi osgi;
private final ConfigRetriever configurer;
- private List<FileReference> platformBundles; // Used to verify that platform bundles don't change.
private long previousConfigGeneration = -1L;
private long leastGeneration = -1L;
@@ -57,10 +54,9 @@ public class Container {
this.componentDeconstructor = componentDeconstructor;
this.osgi = osgi;
- applicationBundlesConfigKey = new ConfigKey<>(ApplicationBundlesConfig.class, configId);
- platformBundlesConfigKey = new ConfigKey<>(PlatformBundlesConfig.class, configId);
+ bundlesConfigKey = new ConfigKey<>(BundlesConfig.class, configId);
componentsConfigKey = new ConfigKey<>(ComponentsConfig.class, configId);
- var bootstrapKeys = Set.of(applicationBundlesConfigKey, platformBundlesConfigKey, componentsConfigKey);
+ var bootstrapKeys = Set.of(bundlesConfigKey, componentsConfigKey);
this.configurer = new ConfigRetriever(bootstrapKeys, subscriberFactory::getSubscriber);
}
@@ -78,6 +74,7 @@ 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;
}
@@ -101,15 +98,13 @@ public class Container {
"Got bootstrap configs out of sequence for old config generation %d.\n" + "Previous config generation is %d",
getBootstrapGeneration(), previousConfigGeneration));
}
- log.log(FINE, "Got new bootstrap generation\n" + configGenerationsString());
+ log.log(FINE,
+ String.format(
+ "Got new bootstrap generation\n" + "bootstrap generation = %d\n" + "components generation: %d\n"
+ + "previous generation: %d\n",
+ getBootstrapGeneration(), getComponentsGeneration(), previousConfigGeneration));
- if (graph.generation() == 0) {
- platformBundles = getConfig(platformBundlesConfigKey, snapshot.configs()).bundles();
- osgi.installPlatformBundles(platformBundles);
- } else {
- throwIfPlatformBundlesChanged(snapshot);
- }
- Collection<Bundle> bundlesToRemove = installApplicationBundles(snapshot.configs());
+ Collection<Bundle> bundlesToRemove = installBundles(snapshot.configs());
obsoleteBundles.addAll(bundlesToRemove);
graph = createComponentsGraph(snapshot.configs(), getBootstrapGeneration(), fallbackInjector);
@@ -120,7 +115,11 @@ public class Container {
break;
}
}
- log.log(FINE, "Got components configs,\n" + configGenerationsString());
+ log.log(FINE,
+ String.format(
+ "Got components configs,\n" + "bootstrap generation = %d\n" + "components generation: %d\n"
+ + "previous generation: %d",
+ getBootstrapGeneration(), getComponentsGeneration(), previousConfigGeneration));
return createAndConfigureComponentsGraph(snapshot.configs(), fallbackInjector);
}
@@ -132,17 +131,6 @@ public class Container {
return configurer.getComponentsGeneration();
}
- private String configGenerationsString() {
- return String.format("bootstrap generation = %d\n" + "components generation: %d\n" + "previous generation: %d",
- getBootstrapGeneration(), getComponentsGeneration(), previousConfigGeneration);
- }
-
- private void throwIfPlatformBundlesChanged(ConfigSnapshot snapshot) {
- var checkPlatformBundles = getConfig(platformBundlesConfigKey, snapshot.configs()).bundles();
- if (! checkPlatformBundles.equals(platformBundles))
- throw new RuntimeException("Platform bundles are not allowed to change!\nOld: " + platformBundles + "\nNew: " + checkPlatformBundles);
- }
-
private ComponentGraph createAndConfigureComponentsGraph(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> componentsConfigs,
Injector fallbackInjector) {
ComponentGraph componentGraph = createComponentsGraph(componentsConfigs, getComponentsGeneration(), fallbackInjector);
@@ -163,9 +151,9 @@ public class Container {
componentDeconstructor.deconstruct(oldComponents.keySet(), obsoleteBundles);
}
- private Set<Bundle> installApplicationBundles(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs) {
- ApplicationBundlesConfig applicationBundlesConfig = getConfig(applicationBundlesConfigKey, configsIncludingBootstrapConfigs);
- return osgi.useApplicationBundles(applicationBundlesConfig.bundles());
+ private Set<Bundle> installBundles(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs) {
+ BundlesConfig bundlesConfig = getConfig(bundlesConfigKey, configsIncludingBootstrapConfigs);
+ return osgi.useBundles(bundlesConfig.bundle());
}
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 c9ca256b5e0..ab7da7665b6 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,15 +25,11 @@ 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.
*/
- default Set<Bundle> useApplicationBundles(Collection<FileReference> bundles) {
+ default Set<Bundle> useBundles(Collection<FileReference> bundles) {
System.out.println("useBundles " + bundles.stream().map(Object::toString).collect(Collectors.joining(", ")));
return emptySet();
}
diff --git a/container-di/src/main/resources/configdefinitions/application-bundles.def b/container-di/src/main/resources/configdefinitions/application-bundles.def
deleted file mode 100644
index e883e4f47ae..00000000000
--- a/container-di/src/main/resources/configdefinitions/application-bundles.def
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package=com.yahoo.container.di
-
-# References to user bundles to install.
-bundles[] file
diff --git a/container-di/src/main/resources/configdefinitions/bundles.def b/container-di/src/main/resources/configdefinitions/bundles.def
index 79e24742398..9e10d863106 100644
--- a/container-di/src/main/resources/configdefinitions/bundles.def
+++ b/container-di/src/main/resources/configdefinitions/bundles.def
@@ -1,5 +1,5 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
namespace=container
-# References to both application and platform bundles to install.
+# References to all 3rd-party bundles to be installed.
bundle[] file
diff --git a/container-di/src/main/resources/configdefinitions/platform-bundles.def b/container-di/src/main/resources/configdefinitions/platform-bundles.def
deleted file mode 100644
index 70b78fab074..00000000000
--- a/container-di/src/main/resources/configdefinitions/platform-bundles.def
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package=com.yahoo.container.di
-
-# References to platform bundles to install.
-bundles[] file
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 19f277ff8fb..eac64c20274 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,8 +267,7 @@ public class ContainerTest extends ContainerTestBase {
"inject[0].forClass \"" + injectedClass.getName() + "\"\n";
dirConfigSource.writeConfig("components", componentsConfig);
- dirConfigSource.writeConfig("platform-bundles", "");
- dirConfigSource.writeConfig("application-bundles", "");
+ dirConfigSource.writeConfig("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 f1f3c4a2ae4..18236a6bde9 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
@@ -61,7 +61,7 @@ public class ContainerTestBase {
}
@Override
- public Set<Bundle> useApplicationBundles(Collection<FileReference> bundles) {
+ public Set<Bundle> useBundles(Collection<FileReference> bundles) {
return emptySet();
}
@@ -81,8 +81,7 @@ public class ContainerTestBase {
}
protected void writeBootstrapConfigs(ComponentEntry... componentEntries) {
- dirConfigSource.writeConfig("platform-bundles", "");
- dirConfigSource.writeConfig("application-bundles", "");
+ dirConfigSource.writeConfig("bundles", "");
StringBuilder components = new StringBuilder();
for (int i = 0; i < componentEntries.length; i++) {
components.append(componentEntries[i].asConfig(i));