diff --git a/java/src/org/openqa/selenium/grid/data/NodeStatus.java b/java/src/org/openqa/selenium/grid/data/NodeStatus.java index 47753585ec989..0b2f63752954a 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 da67f9f6e586f..a6eb03cb6e35d 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 564ef6e8eef95..267789c5a8fd3 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 96c5b9e29f6cc..9278611699c88 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 c873ecaeb003d..1bd9dd1614ad3 100644 --- a/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java +++ b/java/src/org/openqa/selenium/grid/router/GridStatusHandler.java @@ -135,18 +135,7 @@ 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("osInfo", node.getOsInfo()) - .put("heartbeatPeriod", node.getHeartbeatPeriod().toMillis()) - .put("availability", node.getAvailability()) - .put("version", node.getVersion()) - .put("slots", node.getSlots()) - .build()) + .map(node -> new ImmutableMap.Builder().putAll(node.toJson()).build()) .collect(toList()); ImmutableMap.Builder value = ImmutableMap.builder(); 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 eaba9689faa80..41b0beeffb41a 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