aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2023-01-03 14:49:54 +0100
committergjoranv <gv@verizonmedia.com>2023-01-09 12:59:59 +0100
commitbe55b80e2c1af8ce7e1d640c7de6cb642281fb9a (patch)
treef5c4ce59f779ff6f1e51762f0a22290a7dc6e367 /container-core/src
parented9092b7fd04633a4d0f92c6901facf75fbceb79 (diff)
Add method for listing bsnVersion for active application bundles.
Diffstat (limited to 'container-core/src')
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java10
-rw-r--r--container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java12
-rw-r--r--container-core/src/test/java/com/yahoo/container/core/config/BundleTestUtil.java3
-rw-r--r--container-core/src/test/java/com/yahoo/container/core/config/TestBundle.java10
4 files changed, 34 insertions, 1 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 cf3db91239a..0717ca51dc5 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,6 +3,7 @@ package com.yahoo.container.core.config;
import com.yahoo.config.FileReference;
import com.yahoo.container.di.Osgi.GenerationStatus;
+import com.yahoo.jdisc.core.BsnVersion;
import com.yahoo.osgi.Osgi;
import org.osgi.framework.Bundle;
@@ -14,6 +15,7 @@ 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.
@@ -49,6 +51,14 @@ 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/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java b/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java
index e646e916521..764771bc285 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,6 +2,7 @@
package com.yahoo.container.core.config;
import com.yahoo.container.di.Osgi.GenerationStatus;
+import com.yahoo.jdisc.core.BsnVersion;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.osgi.framework.Bundle;
@@ -35,6 +36,7 @@ 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
@@ -48,6 +50,16 @@ 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 fddbeaf42be..60ea9009e1e 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,6 +4,7 @@ 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;
@@ -16,7 +17,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());
+ public static final Bundle BUNDLE_2 = new TestBundle(BUNDLE_2_REF.value(), new Version(2, 0, 0, "SNAPSHOT"));
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 17709844f99..babc936494e 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,11 +21,17 @@ 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
@@ -38,6 +44,10 @@ public class TestBundle extends MockBundle {
return symbolicName;
}
+ @Override
+ public Version getVersion() {
+ return version;
+ }
@SuppressWarnings("unchecked")
@Override