Skip to content

Commit 28fbf40

Browse files
committed
[grid] Expose register status via Node status response
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent f5cfd43 commit 28fbf40

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

java/src/org/openqa/selenium/grid/data/NodeStatus.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,20 @@ public static NodeStatus fromJson(JsonInput input) {
139139
}
140140

141141
public boolean hasCapability(Capabilities caps, SlotMatcher slotMatcher) {
142-
return slots.stream().anyMatch(slot -> slot.isSupporting(caps, slotMatcher));
142+
return this.getAvailability() == Availability.UP
143+
&& slots.stream().anyMatch(slot -> slot.isSupporting(caps, slotMatcher));
143144
}
144145

145146
public boolean hasCapacity() {
146-
return slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount;
147+
return this.getAvailability() == Availability.UP
148+
&& slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount;
147149
}
148150

149151
// Check if the Node's max session limit is not exceeded and has a free slot that supports the
150152
// capability.
151153
public boolean hasCapacity(Capabilities caps, SlotMatcher slotMatcher) {
152-
return slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount
154+
return this.getAvailability() == Availability.UP
155+
&& slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount
153156
&& slots.stream()
154157
.anyMatch(slot -> slot.getSession() == null && slot.isSupporting(caps, slotMatcher));
155158
}

java/src/org/openqa/selenium/grid/node/Node.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public abstract class Node implements HasReadyState, Routable {
131131
private final Duration sessionTimeout;
132132
private final Route routes;
133133
protected boolean draining;
134+
protected boolean registered;
134135

135136
protected Node(
136137
Tracer tracer, NodeId id, URI uri, Secret registrationSecret, Duration sessionTimeout) {
@@ -274,6 +275,14 @@ public boolean isDraining() {
274275
return draining;
275276
}
276277

278+
public boolean isRegistered() {
279+
return registered;
280+
}
281+
282+
public void register() {
283+
registered = true;
284+
}
285+
277286
public abstract void drain();
278287

279288
@Override

java/src/org/openqa/selenium/grid/node/StatusHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
4747
status.hasCapacity(),
4848
"message",
4949
status.hasCapacity() ? "Ready" : "No free slots available",
50+
"registered",
51+
node.isRegistered(),
5052
"node",
5153
status));
5254

java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected Handlers createHandlers(Config config) {
130130

131131
HttpHandler readinessCheck =
132132
req -> {
133-
if (node.getStatus().hasCapacity()) {
133+
if (node.isReady() && node.getStatus().hasCapacity()) {
134134
return new HttpResponse()
135135
.setStatus(HTTP_OK)
136136
.setHeader("Content-Type", MediaType.PLAIN_TEXT_UTF_8.toString())
@@ -148,6 +148,7 @@ protected Handlers createHandlers(Config config) {
148148
nodeId -> {
149149
if (node.getId().equals(nodeId)) {
150150
nodeRegistered.set(true);
151+
node.register();
151152
LOG.info("Node has been added");
152153
}
153154
}));

0 commit comments

Comments
 (0)