From 2d3a028202d04a4edee80da4f4f32131af1d8c87 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Fri, 10 Mar 2023 16:17:53 -0500 Subject: [PATCH] deregister builtin plugins if they are no longer available/selected Signed-off-by: Andrew Azores --- .../cryostat/discovery/BuiltInDiscovery.java | 22 +++++++++++++++---- .../cryostat/discovery/DiscoveryModule.java | 11 ++++++++-- .../io/cryostat/platform/PlatformModule.java | 14 ++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/cryostat/discovery/BuiltInDiscovery.java b/src/main/java/io/cryostat/discovery/BuiltInDiscovery.java index e0aa0a565b..628b297b73 100644 --- a/src/main/java/io/cryostat/discovery/BuiltInDiscovery.java +++ b/src/main/java/io/cryostat/discovery/BuiltInDiscovery.java @@ -41,6 +41,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import java.util.UUID; import java.util.function.Consumer; import java.util.stream.Stream; @@ -62,7 +63,8 @@ public class BuiltInDiscovery extends AbstractVerticle implements Consumer> platformStrategies; + private final Set> selectedStrategies; + private final Set> unselectedStrategies; private final Lazy customTargets; private final Set enabledClients = new HashSet<>(); private final NotificationFactory notificationFactory; @@ -70,12 +72,14 @@ public class BuiltInDiscovery extends AbstractVerticle implements Consumer> platformStrategies, + SortedSet> selectedStrategies, + SortedSet> unselectedStrategies, Lazy customTargets, NotificationFactory notificationFactory, Logger logger) { this.storage = storage; - this.platformStrategies = platformStrategies; + this.selectedStrategies = selectedStrategies; + this.unselectedStrategies = unselectedStrategies; this.customTargets = customTargets; this.notificationFactory = notificationFactory; this.logger = logger; @@ -84,11 +88,21 @@ public class BuiltInDiscovery extends AbstractVerticle implements Consumer start) { storage.addTargetDiscoveryListener(this); + + unselectedStrategies.stream() + .map(PlatformDetectionStrategy::getPlatformClient) + .forEach( + platform -> + storage.getBuiltInPluginByRealm( + platform.getDiscoveryTree().getName()) + .map(PluginInfo::getId) + .ifPresent(storage::deregister)); + Stream.concat( // ensure custom targets is always available regardless of other // configurations Stream.of(customTargets.get()), - platformStrategies.stream() + selectedStrategies.stream() .map(PlatformDetectionStrategy::getPlatformClient)) .distinct() .forEach( diff --git a/src/main/java/io/cryostat/discovery/DiscoveryModule.java b/src/main/java/io/cryostat/discovery/DiscoveryModule.java index e2c5ab1513..8947ec6edc 100644 --- a/src/main/java/io/cryostat/discovery/DiscoveryModule.java +++ b/src/main/java/io/cryostat/discovery/DiscoveryModule.java @@ -119,12 +119,19 @@ static DiscoveryStorage provideDiscoveryStorage( static BuiltInDiscovery provideBuiltInDiscovery( DiscoveryStorage storage, @Named(PlatformModule.SELECTED_PLATFORMS) - SortedSet> platformStrategies, + SortedSet> selectedStrategies, + @Named(PlatformModule.UNSELECTED_PLATFORMS) + SortedSet> unselectedStrategies, Lazy customTargets, NotificationFactory notificationFactory, Logger logger) { return new BuiltInDiscovery( - storage, platformStrategies, customTargets, notificationFactory, logger); + storage, + selectedStrategies, + unselectedStrategies, + customTargets, + notificationFactory, + logger); } @Provides diff --git a/src/main/java/io/cryostat/platform/PlatformModule.java b/src/main/java/io/cryostat/platform/PlatformModule.java index 35c8a1d551..c03526f37f 100644 --- a/src/main/java/io/cryostat/platform/PlatformModule.java +++ b/src/main/java/io/cryostat/platform/PlatformModule.java @@ -64,6 +64,7 @@ public abstract class PlatformModule { public static final String SELECTED_PLATFORMS = "SELECTED_PLATFORMS"; + public static final String UNSELECTED_PLATFORMS = "UNSELECTED_PLATFORMS"; @Provides @Singleton @@ -129,6 +130,19 @@ static SortedSet> provideSelectedPlatformStrategies return selectedStrategies; } + @Provides + @Singleton + @Named(UNSELECTED_PLATFORMS) + static SortedSet> provideUnselectedPlatformStrategies( + @Named(SELECTED_PLATFORMS) SortedSet> selectedStrategies, + Set> platformStrategies) { + SortedSet> unselected = + new TreeSet<>((a, b) -> Integer.compare(b.getPriority(), a.getPriority())); + unselected.addAll(platformStrategies); + unselected.removeAll(selectedStrategies); + return unselected; + } + @Provides @Singleton static PlatformDetectionStrategy providePlatformStrategy(