Skip to content

Commit

Permalink
deregister builtin plugins if they are no longer available/selected
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Azores <aazores@redhat.com>
  • Loading branch information
andrewazores committed Mar 11, 2023
1 parent 4af92cb commit 2d3a028
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/main/java/io/cryostat/discovery/BuiltInDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,20 +63,23 @@ public class BuiltInDiscovery extends AbstractVerticle implements Consumer<Targe
static final String NOTIFICATION_CATEGORY = "TargetJvmDiscovery";

private final DiscoveryStorage storage;
private final Set<PlatformDetectionStrategy<?>> platformStrategies;
private final Set<PlatformDetectionStrategy<?>> selectedStrategies;
private final Set<PlatformDetectionStrategy<?>> unselectedStrategies;
private final Lazy<CustomTargetPlatformClient> customTargets;
private final Set<PlatformClient> enabledClients = new HashSet<>();
private final NotificationFactory notificationFactory;
private final Logger logger;

BuiltInDiscovery(
DiscoveryStorage storage,
Set<PlatformDetectionStrategy<?>> platformStrategies,
SortedSet<PlatformDetectionStrategy<?>> selectedStrategies,
SortedSet<PlatformDetectionStrategy<?>> unselectedStrategies,
Lazy<CustomTargetPlatformClient> 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;
Expand All @@ -84,11 +88,21 @@ public class BuiltInDiscovery extends AbstractVerticle implements Consumer<Targe
@Override
public void start(Promise<Void> 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(
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/io/cryostat/discovery/DiscoveryModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,19 @@ static DiscoveryStorage provideDiscoveryStorage(
static BuiltInDiscovery provideBuiltInDiscovery(
DiscoveryStorage storage,
@Named(PlatformModule.SELECTED_PLATFORMS)
SortedSet<PlatformDetectionStrategy<?>> platformStrategies,
SortedSet<PlatformDetectionStrategy<?>> selectedStrategies,
@Named(PlatformModule.UNSELECTED_PLATFORMS)
SortedSet<PlatformDetectionStrategy<?>> unselectedStrategies,
Lazy<CustomTargetPlatformClient> customTargets,
NotificationFactory notificationFactory,
Logger logger) {
return new BuiltInDiscovery(
storage, platformStrategies, customTargets, notificationFactory, logger);
storage,
selectedStrategies,
unselectedStrategies,
customTargets,
notificationFactory,
logger);
}

@Provides
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/cryostat/platform/PlatformModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,6 +130,19 @@ static SortedSet<PlatformDetectionStrategy<?>> provideSelectedPlatformStrategies
return selectedStrategies;
}

@Provides
@Singleton
@Named(UNSELECTED_PLATFORMS)
static SortedSet<PlatformDetectionStrategy<?>> provideUnselectedPlatformStrategies(
@Named(SELECTED_PLATFORMS) SortedSet<PlatformDetectionStrategy<?>> selectedStrategies,
Set<PlatformDetectionStrategy<?>> platformStrategies) {
SortedSet<PlatformDetectionStrategy<?>> unselected =
new TreeSet<>((a, b) -> Integer.compare(b.getPriority(), a.getPriority()));
unselected.addAll(platformStrategies);
unselected.removeAll(selectedStrategies);
return unselected;
}

@Provides
@Singleton
static PlatformDetectionStrategy<?> providePlatformStrategy(
Expand Down

0 comments on commit 2d3a028

Please sign in to comment.