summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-07-20 00:03:30 +0200
committergjoranv <gv@verizonmedia.com>2020-07-20 00:03:30 +0200
commitb4dfbb30bb4492bf3c6adf9373a8f20d35146886 (patch)
treeedd3f47f487d9721a044fb1494bad7762ff8adb6
parent5deab715167cc3ffbd9ab76726bb6cb7f50397ec (diff)
Let ApplicationBundleLoader take its installer as a ctor argument
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java24
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java6
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java9
-rw-r--r--container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java5
4 files changed, 16 insertions, 28 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 69d7d44773e..f87dd3f42d2 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
@@ -2,8 +2,6 @@
package com.yahoo.container.core.config;
import com.yahoo.config.FileReference;
-import com.yahoo.container.Container;
-import com.yahoo.filedistribution.fileacquirer.FileAcquirer;
import com.yahoo.osgi.Osgi;
import org.osgi.framework.Bundle;
@@ -35,13 +33,11 @@ public class ApplicationBundleLoader {
private final Map<FileReference, Bundle> reference2Bundle = new LinkedHashMap<>();
private final Osgi osgi;
+ private final FileAcquirerBundleInstaller bundleInstaller;
- // TODO: Take the bundle installer as a ctor argument instead. It's safe because the
- // file acquirer in the Container singleton is set up before this is created.
- private FileAcquirerBundleInstaller customBundleInstaller = null;
-
- public ApplicationBundleLoader(Osgi osgi) {
+ public ApplicationBundleLoader(Osgi osgi, FileAcquirerBundleInstaller bundleInstaller) {
this.osgi = osgi;
+ this.bundleInstaller = bundleInstaller;
}
/**
@@ -70,7 +66,6 @@ public class ApplicationBundleLoader {
return obsoleteReferences;
}
-
/**
* Returns the bundles that will not be retained by the new application generation.
*/
@@ -89,12 +84,8 @@ public class ApplicationBundleLoader {
bundlesToInstall.removeAll(reference2Bundle.keySet());
if (!bundlesToInstall.isEmpty()) {
- FileAcquirer fileAcquirer = Container.get().getFileAcquirer();
- boolean hasFileDistribution = (fileAcquirer != null);
- if (hasFileDistribution) {
- installWithFileDistribution(bundlesToInstall, new FileAcquirerBundleInstaller(fileAcquirer));
- } else if (customBundleInstaller != null) {
- installWithFileDistribution(bundlesToInstall, customBundleInstaller);
+ if (bundleInstaller.hasFileDistribution()) {
+ installWithFileDistribution(bundlesToInstall, bundleInstaller);
} else {
log.warning("Can't retrieve bundles since file distribution is disabled.");
}
@@ -134,11 +125,6 @@ public class ApplicationBundleLoader {
}
// Only for testing
- void useCustomBundleInstaller(FileAcquirerBundleInstaller bundleInstaller) {
- customBundleInstaller = bundleInstaller;
- }
-
- // Only for testing
List<FileReference> getActiveFileReferences() {
return new ArrayList<>(reference2Bundle.keySet());
}
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java b/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java
index cbfb8538643..51d77462652 100644
--- a/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java
+++ b/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java
@@ -13,6 +13,8 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
/**
+ * Retrieves bundles with file distribution, and installs them to the OSGi framework.
+ *
* @author gjoranv
*/
public class FileAcquirerBundleInstaller {
@@ -45,6 +47,10 @@ public class FileAcquirerBundleInstaller {
return osgi.install(file.getAbsolutePath());
}
+ public boolean hasFileDistribution() {
+ return fileAcquirer != null;
+ }
+
private static boolean notReadable(File file) {
return ! Files.isReadable(file.toPath());
}
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 a58dff13f09..13d50b9b30f 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
@@ -16,6 +16,7 @@ import com.yahoo.container.di.config.SubscriberFactory;
import com.yahoo.container.di.osgi.BundleClasses;
import com.yahoo.container.di.osgi.OsgiUtil;
import com.yahoo.container.logging.AccessLog;
+import com.yahoo.filedistribution.fileacquirer.FileAcquirer;
import com.yahoo.jdisc.application.OsgiFramework;
import com.yahoo.jdisc.handler.RequestHandler;
import com.yahoo.jdisc.service.ClientProvider;
@@ -68,7 +69,6 @@ public class HandlersConfigurerDi {
}
private final com.yahoo.container.Container vespaContainer;
- private final OsgiWrapper osgiWrapper;
private final Container container;
private volatile ComponentGraph currentGraph = new ComponentGraph(0);
@@ -81,7 +81,7 @@ public class HandlersConfigurerDi {
OsgiFramework osgiFramework) {
this(subscriberFactory, vespaContainer, configId, deconstructor, discInjector,
- new ContainerAndDiOsgi(osgiFramework));
+ new ContainerAndDiOsgi(osgiFramework, vespaContainer.getFileAcquirer()));
}
// Only public for testing
@@ -93,7 +93,6 @@ public class HandlersConfigurerDi {
OsgiWrapper osgiWrapper) {
this.vespaContainer = vespaContainer;
- this.osgiWrapper = osgiWrapper;
container = new Container(subscriberFactory, configId, deconstructor, osgiWrapper);
getNewComponentGraph(discInjector, false);
}
@@ -104,12 +103,12 @@ public class HandlersConfigurerDi {
private final ApplicationBundleLoader applicationBundleLoader;
private final PlatformBundleLoader platformBundleLoader;
- public ContainerAndDiOsgi(OsgiFramework osgiFramework) {
+ public ContainerAndDiOsgi(OsgiFramework osgiFramework, FileAcquirer fileAcquirer) {
super(osgiFramework);
this.osgiFramework = osgiFramework;
OsgiImpl osgi = new OsgiImpl(osgiFramework);
- applicationBundleLoader = new ApplicationBundleLoader(osgi);
+ applicationBundleLoader = new ApplicationBundleLoader(osgi, new FileAcquirerBundleInstaller(fileAcquirer));
platformBundleLoader = new PlatformBundleLoader(osgi);
}
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 6d6db045b73..b56e5d99123 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
@@ -9,11 +9,9 @@ import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
-import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -36,8 +34,7 @@ public class ApplicationBundleLoaderTest {
osgi = new TestOsgi(testBundles());
var bundleInstaller = new TestBundleInstaller(MockFileAcquirer.returnFile(null));
- bundleLoader = new ApplicationBundleLoader(osgi);
- bundleLoader.useCustomBundleInstaller(bundleInstaller);
+ bundleLoader = new ApplicationBundleLoader(osgi, bundleInstaller);
}
@Test