diff --git a/src/main/java/io/cryostat/platform/internal/PodmanPlatformClient.java b/src/main/java/io/cryostat/platform/internal/PodmanPlatformClient.java index 04401710c9..a6307672fc 100644 --- a/src/main/java/io/cryostat/platform/internal/PodmanPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/PodmanPlatformClient.java @@ -79,7 +79,6 @@ import io.vertx.core.Vertx; import io.vertx.core.http.HttpMethod; import io.vertx.core.net.SocketAddress; -import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.codec.BodyCodec; import org.apache.commons.lang3.StringUtils; @@ -168,53 +167,38 @@ private void queryContainers() { containers.removeAll(removed); removed.stream() + .map(this::convert) .filter(Objects::nonNull) - .forEach( - spec -> - notifyAsyncTargetDiscovery( - EventKind.LOST, convert(spec))); + .forEach(spec -> notifyAsyncTargetDiscovery(EventKind.LOST, spec)); containers.addAll(added); added.stream() + .map(this::convert) .filter(Objects::nonNull) - .forEach( - spec -> - notifyAsyncTargetDiscovery( - EventKind.FOUND, convert(spec))); + .forEach(spec -> notifyAsyncTargetDiscovery(EventKind.FOUND, spec)); }); } private void doPodmanListRequest(Consumer> successHandler) { URI requestPath = URI.create("http://d/v3.0.0/libpod/containers/json"); - executor.submit( - () -> - webClient - .get() - .request( - HttpMethod.GET, - podmanSocket, - 80, - "localhost", - requestPath.toString()) - .addQueryParam( - "filters", - gson.toJson(Map.of("label", List.of(DISCOVERY_LABEL)))) - .timeout(2_000L) - .as(BodyCodec.string()) - .send( - ar -> { - if (ar.failed()) { - Throwable t = ar.cause(); - logger.error("Podman API request failed", t); - return; - } - HttpResponse response = ar.result(); - successHandler.accept( - gson.fromJson( - response.body(), - new TypeToken< - List>() {})); - })); + webClient + .get() + .request(HttpMethod.GET, podmanSocket, 80, "localhost", requestPath.toString()) + .addQueryParam("filters", gson.toJson(Map.of("label", List.of(DISCOVERY_LABEL)))) + .timeout(2_000L) + .as(BodyCodec.string()) + .send( + ar -> { + if (ar.failed()) { + Throwable t = ar.cause(); + logger.error("Podman API request failed", t); + return; + } + successHandler.accept( + gson.fromJson( + ar.result().body(), + new TypeToken>() {})); + }); } private CompletableFuture doPodmanInspectRequest(ContainerSpec container) { @@ -232,9 +216,6 @@ private CompletableFuture doPodmanInspectRequest(ContainerSpec 80, "localhost", requestPath.toString()) - .addQueryParam( - "filters", - gson.toJson(Map.of("label", List.of(JMX_PORT_LABEL)))) .timeout(2_000L) .as(BodyCodec.string()) .send( @@ -245,10 +226,10 @@ private CompletableFuture doPodmanInspectRequest(ContainerSpec result.completeExceptionally(t); return; } - HttpResponse response = ar.result(); result.complete( gson.fromJson( - response.body(), ContainerDetails.class)); + ar.result().body(), + ContainerDetails.class)); }); }); return result; @@ -280,6 +261,7 @@ private ServiceRef convert(ContainerSpec desc) { .Config .Hostname; } catch (InterruptedException | TimeoutException | ExecutionException e) { + containers.remove(desc); logger.warn(e); return null; } @@ -306,6 +288,7 @@ private ServiceRef convert(ContainerSpec desc) { return serviceRef; } catch (NumberFormatException | URISyntaxException | MalformedURLException e) { + containers.remove(desc); logger.warn(e); return null; } diff --git a/src/main/java/io/cryostat/platform/internal/PodmanPlatformStrategy.java b/src/main/java/io/cryostat/platform/internal/PodmanPlatformStrategy.java index dd529ba2d1..1031d83801 100644 --- a/src/main/java/io/cryostat/platform/internal/PodmanPlatformStrategy.java +++ b/src/main/java/io/cryostat/platform/internal/PodmanPlatformStrategy.java @@ -40,7 +40,7 @@ import java.net.URI; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -111,7 +111,7 @@ public boolean isAvailable() { private boolean testPodmanApi() { CompletableFuture result = new CompletableFuture<>(); URI requestPath = URI.create("http://d/info"); - Executors.newSingleThreadExecutor() + ForkJoinPool.commonPool() .submit( () -> { webClient @@ -147,7 +147,7 @@ private boolean testPodmanApi() { public PodmanPlatformClient getPlatformClient() { logger.info("Selected {} Strategy", getClass().getSimpleName()); return new PodmanPlatformClient( - Executors.newSingleThreadExecutor(), + ForkJoinPool.commonPool(), webClient, vertx, getSocket(),