From e81bc1d5d9b1ebd3c17f8ac4487c52c0f9a47c55 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 20 Aug 2025 13:35:09 +0530 Subject: [PATCH 1/2] [grid] Replace Guava set and map ins various Grid packages with Java equivalent --- .../grid/router/GridStatusHandler.java | 40 +++++++++++-------- .../openqa/selenium/grid/router/Router.java | 5 ++- .../grid/router/httpd/RouterServer.java | 7 ++-- .../grid/security/RequiresSecretFilter.java | 4 +- .../selenium/grid/server/EventBusFlags.java | 3 +- .../selenium/grid/server/NetworkOptions.java | 6 +-- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java b/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java index b1fb021cf59a9..5bd7b168f2dce 100644 --- a/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java +++ b/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java @@ -29,12 +29,17 @@ import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE_EVENT; import com.google.common.collect.ImmutableMap; + +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; + import org.openqa.selenium.grid.data.DistributorStatus; import org.openqa.selenium.grid.distributor.Distributor; import org.openqa.selenium.internal.Require; @@ -89,9 +94,9 @@ public HttpResponse execute(HttpRequest req) { new HttpResponse() .setContent( asJson( - ImmutableMap.of( + Map.of( "value", - ImmutableMap.of( + Map.of( "ready", false, "message", "Unable to read distributor status.")))); HTTP_RESPONSE.accept(span, response); @@ -111,9 +116,9 @@ public HttpResponse execute(HttpRequest req) { new HttpResponse() .setContent( asJson( - ImmutableMap.of( + Map.of( "value", - ImmutableMap.of( + Map.of( "ready", false, "message", @@ -136,19 +141,20 @@ public HttpResponse execute(HttpRequest req) { List> nodeResults = status.getNodes().stream() .map( - node -> - new ImmutableMap.Builder() - .put("id", node.getNodeId()) - .put("uri", node.getExternalUri()) - .put("maxSessions", node.getMaxSessionCount()) - .put("sessionTimeout", node.getSessionTimeout().toMillis()) - .put("osInfo", node.getOsInfo()) - .put("heartbeatPeriod", node.getHeartbeatPeriod().toMillis()) - .put("availability", node.getAvailability()) - .put("version", node.getVersion()) - .put("slots", node.getSlots()) - .build()) - .collect(toList()); + node -> { + Map nodeMap = new HashMap<>(); + nodeMap.put("id", node.getNodeId()); + nodeMap.put("uri", node.getExternalUri()); + nodeMap.put("maxSessions", node.getMaxSessionCount()); + nodeMap.put("sessionTimeout", node.getSessionTimeout().toMillis()); + nodeMap.put("osInfo", node.getOsInfo()); + nodeMap.put("heartbeatPeriod", node.getHeartbeatPeriod().toMillis()); + nodeMap.put("availability", node.getAvailability()); + nodeMap.put("version", node.getVersion()); + nodeMap.put("slots", node.getSlots()); + return Collections.unmodifiableMap(nodeMap); + }) + .collect(Collectors.toList()); ImmutableMap.Builder value = ImmutableMap.builder(); value.put("ready", ready); diff --git a/java/src/org/openqa/selenium/grid/router/Router.java b/java/src/org/openqa/selenium/grid/router/Router.java index d0e0ae362208f..2dbd40e59195f 100644 --- a/java/src/org/openqa/selenium/grid/router/Router.java +++ b/java/src/org/openqa/selenium/grid/router/Router.java @@ -21,8 +21,9 @@ import static org.openqa.selenium.remote.http.Route.get; import static org.openqa.selenium.remote.http.Route.matching; -import com.google.common.collect.ImmutableSet; import java.io.Closeable; +import java.util.Set; + import org.openqa.selenium.grid.distributor.Distributor; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionqueue.NewSessionQueue; @@ -71,7 +72,7 @@ public Router( @Override public boolean isReady() { try { - return ImmutableSet.of(distributor, sessions, queue).parallelStream() + return Set.of(distributor, sessions, queue).parallelStream() .map(HasReadyState::isReady) .reduce(true, Boolean::logicalAnd); } catch (RuntimeException e) { diff --git a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java index 7ff73e655cb88..55cef8eda7238 100644 --- a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java +++ b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java @@ -29,14 +29,13 @@ import static org.openqa.selenium.remote.http.Route.get; import com.google.auto.service.AutoService; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import java.io.Closeable; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URL; import java.time.Duration; import java.util.Collections; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -94,7 +93,7 @@ public String getDescription() { @Override public Set getConfigurableRoles() { - return ImmutableSet.of( + return Set.of( DISTRIBUTOR_ROLE, HTTPD_ROLE, ROUTER_ROLE, SESSION_MAP_ROLE, SESSION_QUEUE_ROLE); } @@ -110,7 +109,7 @@ protected String getSystemPropertiesConfigPrefix() { @Override protected Config getDefaultConfig() { - return new MapConfig(ImmutableMap.of("server", ImmutableMap.of("port", 4444))); + return new MapConfig(Map.of("server", Map.of("port", 4444))); } @Override diff --git a/java/src/org/openqa/selenium/grid/security/RequiresSecretFilter.java b/java/src/org/openqa/selenium/grid/security/RequiresSecretFilter.java index 3d6a4a6ec77e6..ec14e602db2a9 100644 --- a/java/src/org/openqa/selenium/grid/security/RequiresSecretFilter.java +++ b/java/src/org/openqa/selenium/grid/security/RequiresSecretFilter.java @@ -21,8 +21,8 @@ import static org.openqa.selenium.grid.security.AddSecretFilter.HEADER_NAME; import static org.openqa.selenium.json.Json.JSON_UTF_8; -import com.google.common.collect.ImmutableMap; import java.util.Collections; +import java.util.Map; import java.util.logging.Logger; import org.openqa.selenium.internal.Require; import org.openqa.selenium.remote.http.Contents; @@ -53,7 +53,7 @@ public HttpHandler apply(HttpHandler httpHandler) { Contents.asJson( Collections.singletonMap( "value", - ImmutableMap.of( + Map.of( "error", "unknown error", "message", "Unauthorized access attempted to ", "stacktrace", "")))); diff --git a/java/src/org/openqa/selenium/grid/server/EventBusFlags.java b/java/src/org/openqa/selenium/grid/server/EventBusFlags.java index cd7a11ff08cb0..b52cebb6a8ce6 100644 --- a/java/src/org/openqa/selenium/grid/server/EventBusFlags.java +++ b/java/src/org/openqa/selenium/grid/server/EventBusFlags.java @@ -22,7 +22,6 @@ import com.beust.jcommander.Parameter; import com.google.auto.service.AutoService; -import com.google.common.collect.ImmutableSet; import java.util.Set; import org.openqa.selenium.grid.config.ConfigValue; import org.openqa.selenium.grid.config.HasRoles; @@ -67,6 +66,6 @@ public class EventBusFlags implements HasRoles { @Override public Set getRoles() { - return ImmutableSet.of(EVENT_BUS_ROLE); + return Set.of(EVENT_BUS_ROLE); } } diff --git a/java/src/org/openqa/selenium/grid/server/NetworkOptions.java b/java/src/org/openqa/selenium/grid/server/NetworkOptions.java index a3dcf9877ea06..e835b5c07cadf 100644 --- a/java/src/org/openqa/selenium/grid/server/NetworkOptions.java +++ b/java/src/org/openqa/selenium/grid/server/NetworkOptions.java @@ -17,8 +17,6 @@ package org.openqa.selenium.grid.server; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import java.util.List; import java.util.Optional; import java.util.Set; @@ -38,7 +36,7 @@ public class NetworkOptions { private final Config config; // These are commonly used by process which can't set various headers. - private final Set SKIP_CHECKS_ON = ImmutableSet.of("/status", "/readyz"); + private final Set SKIP_CHECKS_ON = Set.of("/status", "/readyz"); public NetworkOptions(Config config) { this.config = Require.nonNull("Config", config); @@ -68,7 +66,7 @@ public Filter getSpecComplianceChecks() { if (checkOrigin || allowedOrigins.isPresent()) { toReturn = toReturn.andThen( - new CheckOriginHeader(allowedOrigins.orElse(ImmutableList.of()), SKIP_CHECKS_ON)); + new CheckOriginHeader(allowedOrigins.orElse(List.of()), SKIP_CHECKS_ON)); } return toReturn; From 5061e78f981d6603a4917eba86e9d1c4a07fd10f Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 20 Aug 2025 13:36:18 +0530 Subject: [PATCH 2/2] Fix formatting --- .../src/org/openqa/selenium/grid/router/GridStatusHandler.java | 3 --- java/src/org/openqa/selenium/grid/router/Router.java | 1 - .../org/openqa/selenium/grid/router/httpd/RouterServer.java | 3 +-- java/src/org/openqa/selenium/grid/server/NetworkOptions.java | 3 +-- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java b/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java index 5bd7b168f2dce..cc6b3a1237778 100644 --- a/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java +++ b/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java @@ -18,7 +18,6 @@ package org.openqa.selenium.grid.router; import static java.util.concurrent.TimeUnit.SECONDS; -import static java.util.stream.Collectors.toList; import static org.openqa.selenium.grid.data.Availability.UP; import static org.openqa.selenium.remote.http.Contents.asJson; import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf; @@ -29,7 +28,6 @@ import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE_EVENT; import com.google.common.collect.ImmutableMap; - import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -39,7 +37,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; - import org.openqa.selenium.grid.data.DistributorStatus; import org.openqa.selenium.grid.distributor.Distributor; import org.openqa.selenium.internal.Require; diff --git a/java/src/org/openqa/selenium/grid/router/Router.java b/java/src/org/openqa/selenium/grid/router/Router.java index 2dbd40e59195f..fa41626af8a39 100644 --- a/java/src/org/openqa/selenium/grid/router/Router.java +++ b/java/src/org/openqa/selenium/grid/router/Router.java @@ -23,7 +23,6 @@ import java.io.Closeable; import java.util.Set; - import org.openqa.selenium.grid.distributor.Distributor; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionqueue.NewSessionQueue; diff --git a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java index 55cef8eda7238..6f78c69340a62 100644 --- a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java +++ b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java @@ -93,8 +93,7 @@ public String getDescription() { @Override public Set getConfigurableRoles() { - return Set.of( - DISTRIBUTOR_ROLE, HTTPD_ROLE, ROUTER_ROLE, SESSION_MAP_ROLE, SESSION_QUEUE_ROLE); + return Set.of(DISTRIBUTOR_ROLE, HTTPD_ROLE, ROUTER_ROLE, SESSION_MAP_ROLE, SESSION_QUEUE_ROLE); } @Override diff --git a/java/src/org/openqa/selenium/grid/server/NetworkOptions.java b/java/src/org/openqa/selenium/grid/server/NetworkOptions.java index e835b5c07cadf..e5aba2dfc7620 100644 --- a/java/src/org/openqa/selenium/grid/server/NetworkOptions.java +++ b/java/src/org/openqa/selenium/grid/server/NetworkOptions.java @@ -65,8 +65,7 @@ public Filter getSpecComplianceChecks() { if (checkOrigin || allowedOrigins.isPresent()) { toReturn = - toReturn.andThen( - new CheckOriginHeader(allowedOrigins.orElse(List.of()), SKIP_CHECKS_ON)); + toReturn.andThen(new CheckOriginHeader(allowedOrigins.orElse(List.of()), SKIP_CHECKS_ON)); } return toReturn;