Skip to content

Commit

Permalink
[grid]: Add node sessionTimeout to Grid status (#14582)
Browse files Browse the repository at this point in the history
[grid]: Node sessionTimeout include in Grid status

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Oct 13, 2024
1 parent f4e414b commit f9ffaa2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/grid/data/NodeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -224,7 +225,7 @@ public int hashCode() {
return Objects.hash(nodeId, externalUri, maxSessionCount, slots, version);
}

private Map<String, Object> toJson() {
public Map<String, Object> toJson() {
Map<String, Object> toReturn = new TreeMap<>();
toReturn.put("nodeId", nodeId);
toReturn.put("externalUri", externalUri);
Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/grid/graphql/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public List<Node> getNodes() {
status.getExternalUri(),
status.getAvailability(),
status.getMaxSessionCount(),
status.getSessionTimeout(),
status.getSlots().size(),
stereotypes,
sessions,
Expand Down
8 changes: 8 additions & 0 deletions java/src/org/openqa/selenium/grid/graphql/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Capabilities, Integer> stereotypes;
private final Map<Session, Slot> activeSessions;
private final String version;
Expand All @@ -49,6 +51,7 @@ public Node(
URI uri,
Availability status,
int maxSession,
Duration sessionTimeout,
int slotCount,
Map<Capabilities, Integer> stereotypes,
Map<Session, Slot> activeSessions,
Expand All @@ -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<org.openqa.selenium.grid.graphql.Session> getSessions() {
Expand Down Expand Up @@ -122,6 +126,10 @@ public OsInfo getOsInfo() {
return osInfo;
}

public Duration getSessionTimeout() {
return sessionTimeout;
}

private org.openqa.selenium.grid.graphql.Session createGraphqlSession(
Map.Entry<Session, Slot> entry) {
Session session = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Node {
uri: Uri!
status: Status!
maxSession: Int!
sessionTimeout: String!
slotCount: Int!
sessions: [Session]!
sessionCount: Int!
Expand Down
13 changes: 1 addition & 12 deletions java/src/org/openqa/selenium/grid/router/GridStatusHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,7 @@ public HttpResponse execute(HttpRequest req) {

List<Map<String, Object>> nodeResults =
status.getNodes().stream()
.map(
node ->
new ImmutableMap.Builder<String, Object>()
.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<String, Object>().putAll(node.toJson()).build())
.collect(toList());

ImmutableMap.Builder<String, Object> value = ImmutableMap.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down

3 comments on commit f9ffaa2

@pujagani
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! There are some failing tests, probably due to this PR. Can you please help take a look? We typically check if all RBE tests are passing or if failures are due to changes before merging the request.

@VietND96
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pujagani, I am just aware, the Grid status response json schema changed due to using node.toJson(). I am fixing it

@pujagani
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No rush. I appreciate your time here. Thank you so much!

Please sign in to comment.