diff options
author | gjoranv <gv@verizonmedia.com> | 2020-04-16 16:33:47 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2020-04-16 23:09:18 +0200 |
commit | ba655e034f212024d6c992a86410d4715a7fea5f (patch) | |
tree | b627be245e0a08dcbefe97a4417b80485741be18 /container-core | |
parent | bdb570a9e21410108bbb56f183bad1603c45c1fc (diff) |
Extract interface for a bundle installer
.. and add implementations for file acquirer and disk bundles.
- This is a step to allow unit testing of BundleLoader.
Diffstat (limited to 'container-core')
4 files changed, 83 insertions, 15 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/BundleInstaller.java b/container-core/src/main/java/com/yahoo/container/core/config/BundleInstaller.java new file mode 100644 index 00000000000..dd21478447c --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/core/config/BundleInstaller.java @@ -0,0 +1,20 @@ +package com.yahoo.container.core.config; + +import com.yahoo.config.FileReference; +import com.yahoo.osgi.Osgi; +import org.osgi.framework.Bundle; + +import java.util.List; + +/** + * @author gjoranv + */ +public interface BundleInstaller { + + /** + * Installs the bundle with the given file reference, plus all bundles in its X-JDisc-Preinstall-Bundle directive. + * Returns all bundles installed to the given OSGi framework as a result of this call. + */ + List<Bundle> installBundles(FileReference reference, Osgi osgi) throws InterruptedException; + +} diff --git a/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java b/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java index ca11ad387ee..ca1549784c6 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java @@ -89,17 +89,10 @@ public class BundleLoader { } private void installBundleFromDisk(FileReference reference) { - assert(reference.value().startsWith(DISK_BUNDLE_PREFIX)); - String referenceFileName = reference.value().substring(DISK_BUNDLE_PREFIX.length()); log.info("Installing bundle from disk with reference '" + reference.value() + "'"); - File file = new File(referenceFileName); - if ( ! file.exists()) { - throw new IllegalArgumentException("Reference '" + reference.value() + "' not found on disk."); - } - - List<Bundle> bundles = osgi.install(file.getAbsolutePath()); - + var bundleInstaller = new DiskBundleInstaller(); + List<Bundle> bundles = bundleInstaller.installBundles(reference, osgi); reference2Bundles.put(reference, bundles); } @@ -107,7 +100,8 @@ public class BundleLoader { for (FileReference reference : bundlesToInstall) { try { log.info("Installing bundle with reference '" + reference.value() + "'"); - List<Bundle> bundles = obtainBundles(reference, fileAcquirer); + var bundleInstaller = new FileAcquirerBundleInstaller(fileAcquirer); + List<Bundle> bundles = bundleInstaller.installBundles(reference, osgi); reference2Bundles.put(reference, bundles); } catch(Exception e) { @@ -116,11 +110,6 @@ public class BundleLoader { } } - private List<Bundle> obtainBundles(FileReference reference, FileAcquirer fileAcquirer) throws InterruptedException { - File file = fileAcquirer.waitFor(reference, 7, TimeUnit.DAYS); - return osgi.install(file.getAbsolutePath()); - } - /** * Resolves and starts (calls the Bundles BundleActivator) all bundles. Bundle resolution must take place * after all bundles are installed to ensure that the framework can resolve dependencies between bundles. diff --git a/container-core/src/main/java/com/yahoo/container/core/config/DiskBundleInstaller.java b/container-core/src/main/java/com/yahoo/container/core/config/DiskBundleInstaller.java new file mode 100644 index 00000000000..1ada4449a6e --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/core/config/DiskBundleInstaller.java @@ -0,0 +1,30 @@ +package com.yahoo.container.core.config; + +import com.yahoo.config.FileReference; +import com.yahoo.osgi.Osgi; +import org.osgi.framework.Bundle; + +import java.io.File; +import java.util.List; + +import static com.yahoo.container.core.BundleLoaderProperties.DISK_BUNDLE_PREFIX; + +/** + * @author gjoranv + */ +public class DiskBundleInstaller implements BundleInstaller { + + @Override + public List<Bundle> installBundles(FileReference reference, Osgi osgi) { + assert(reference.value().startsWith(DISK_BUNDLE_PREFIX)); + String referenceFileName = reference.value().substring(DISK_BUNDLE_PREFIX.length()); + + File file = new File(referenceFileName); + if ( ! file.exists()) { + throw new IllegalArgumentException("Reference '" + reference.value() + "' not found on disk."); + } + + return osgi.install(file.getAbsolutePath()); + } + +} 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 new file mode 100644 index 00000000000..96cc77ca7b2 --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/core/config/FileAcquirerBundleInstaller.java @@ -0,0 +1,29 @@ +package com.yahoo.container.core.config; + +import com.yahoo.config.FileReference; +import com.yahoo.filedistribution.fileacquirer.FileAcquirer; +import com.yahoo.osgi.Osgi; +import org.osgi.framework.Bundle; + +import java.io.File; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * @author gjoranv + */ +public class FileAcquirerBundleInstaller implements BundleInstaller { + + private final FileAcquirer fileAcquirer; + + public FileAcquirerBundleInstaller(FileAcquirer fileAcquirer) { + this.fileAcquirer = fileAcquirer; + } + + @Override + public List<Bundle> installBundles(FileReference reference, Osgi osgi) throws InterruptedException { + File file = fileAcquirer.waitFor(reference, 7, TimeUnit.DAYS); + return osgi.install(file.getAbsolutePath()); + } + +} |