Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grid]: Add node sessionTimeout to Grid status #14582

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading