From 600e63f1298b5b54eef5ff66302bb48b054ea5a8 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Fri, 11 Oct 2024 06:55:57 +0000 Subject: [PATCH] [grid]: Node sessionTimeout include in Grid status Signed-off-by: Viet Nguyen Duc --- java/src/org/openqa/selenium/grid/data/NodeStatus.java | 3 ++- java/src/org/openqa/selenium/grid/graphql/Grid.java | 1 + java/src/org/openqa/selenium/grid/graphql/Node.java | 8 ++++++++ .../selenium/grid/graphql/selenium-grid-schema.graphqls | 1 + .../openqa/selenium/grid/router/GridStatusHandler.java | 9 +-------- .../grid/distributor/local/LocalDistributorTest.java | 2 ++ 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/data/NodeStatus.java b/java/src/org/openqa/selenium/grid/data/NodeStatus.java index 47753585ec989d..0b2f63752954a6 100644 --- a/java/src/org/openqa/selenium/grid/data/NodeStatus.java +++ b/java/src/org/openqa/selenium/grid/data/NodeStatus.java @@ -214,6 +214,7 @@ public boolean equals(Object o) { return Objects.equals(this.nodeId, that.nodeId) && Objects.equals(this.externalUri, that.externalUri) && this.maxSessionCount == that.maxSessionCount + && this.sessionTimeout == that.sessionTimeout && Objects.equals(this.slots, that.slots) && Objects.equals(this.availability, that.availability) && Objects.equals(this.version, that.version); @@ -224,7 +225,7 @@ public int hashCode() { return Objects.hash(nodeId, externalUri, maxSessionCount, slots, version); } - private Map toJson() { + public Map toJson() { Map toReturn = new TreeMap<>(); toReturn.put("nodeId", nodeId); toReturn.put("externalUri", externalUri); diff --git a/java/src/org/openqa/selenium/grid/graphql/Grid.java b/java/src/org/openqa/selenium/grid/graphql/Grid.java index da67f9f6e586f3..a6eb03cb6e35dd 100644 --- a/java/src/org/openqa/selenium/grid/graphql/Grid.java +++ b/java/src/org/openqa/selenium/grid/graphql/Grid.java @@ -97,6 +97,7 @@ public List getNodes() { status.getExternalUri(), status.getAvailability(), status.getMaxSessionCount(), + status.getSessionTimeout(), status.getSlots().size(), stereotypes, sessions, diff --git a/java/src/org/openqa/selenium/grid/graphql/Node.java b/java/src/org/openqa/selenium/grid/graphql/Node.java index 564ef6e8eef957..267789c5a8fd3d 100644 --- a/java/src/org/openqa/selenium/grid/graphql/Node.java +++ b/java/src/org/openqa/selenium/grid/graphql/Node.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import java.net.URI; +import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -38,6 +39,7 @@ public class Node { private final URI uri; private final Availability status; private final int maxSession; + private final Duration sessionTimeout; private final Map stereotypes; private final Map activeSessions; private final String version; @@ -49,6 +51,7 @@ public Node( URI uri, Availability status, int maxSession, + Duration sessionTimeout, int slotCount, Map stereotypes, Map activeSessions, @@ -63,6 +66,7 @@ public Node( this.activeSessions = Require.nonNull("Active sessions", activeSessions); this.version = Require.nonNull("Grid Node version", version); this.osInfo = Require.nonNull("Grid Node OS info", osInfo); + this.sessionTimeout = Require.positive("Node session timeout", sessionTimeout); } public List getSessions() { @@ -122,6 +126,10 @@ public OsInfo getOsInfo() { return osInfo; } + public Duration getSessionTimeout() { + return sessionTimeout; + } + private org.openqa.selenium.grid.graphql.Session createGraphqlSession( Map.Entry entry) { Session session = entry.getKey(); diff --git a/java/src/org/openqa/selenium/grid/graphql/selenium-grid-schema.graphqls b/java/src/org/openqa/selenium/grid/graphql/selenium-grid-schema.graphqls index 96c5b9e29f6cc6..9278611699c883 100644 --- a/java/src/org/openqa/selenium/grid/graphql/selenium-grid-schema.graphqls +++ b/java/src/org/openqa/selenium/grid/graphql/selenium-grid-schema.graphqls @@ -38,6 +38,7 @@ type Node { uri: Uri! status: Status! maxSession: Int! + sessionTimeout: String! slotCount: Int! sessions: [Session]! sessionCount: Int! diff --git a/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java b/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java index c873ecaeb003d9..270bc5c2408715 100644 --- a/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java +++ b/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java @@ -138,14 +138,7 @@ public HttpResponse execute(HttpRequest req) { .map( node -> new ImmutableMap.Builder() - .put("id", node.getNodeId()) - .put("uri", node.getExternalUri()) - .put("maxSessions", node.getMaxSessionCount()) - .put("osInfo", node.getOsInfo()) - .put("heartbeatPeriod", node.getHeartbeatPeriod().toMillis()) - .put("availability", node.getAvailability()) - .put("version", node.getVersion()) - .put("slots", node.getSlots()) + .putAll(node.toJson()) .build()) .collect(toList()); diff --git a/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java b/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java index eaba9689faa80b..41b0beeffb41a4 100644 --- a/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java +++ b/java/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java @@ -102,6 +102,7 @@ public void setUp() throws URISyntaxException { LocalNode.builder(tracer, bus, uri, uri, registrationSecret) .add(caps, new TestSessionFactory((id, c) -> new Handler(c))) .maximumConcurrentSessions(2) + .sessionTimeout(Duration.ofSeconds(30)) .build(); wait = @@ -143,6 +144,7 @@ void testAddNodeToDistributor() { NodeStatus distributorNode = nodes.iterator().next(); assertThat(distributorNode.getNodeId()).isEqualByComparingTo(localNode.getId()); assertThat(distributorNode.getExternalUri()).isEqualTo(uri); + assertThat(distributorNode.getSessionTimeout()).isEqualTo(Duration.ofSeconds(30)); } @Test