Skip to content
9 changes: 6 additions & 3 deletions java/src/org/openqa/selenium/grid/data/NodeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,20 @@ public static NodeStatus fromJson(JsonInput input) {
}

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

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

// Check if the Node's max session limit is not exceeded and has a free slot that supports the
// capability.
public boolean hasCapacity(Capabilities caps, SlotMatcher slotMatcher) {
return slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount
return this.getAvailability() == Availability.UP
&& slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount
&& slots.stream()
.anyMatch(slot -> slot.getSession() == null && slot.isSupporting(caps, slotMatcher));
}
Expand Down
9 changes: 9 additions & 0 deletions java/src/org/openqa/selenium/grid/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public abstract class Node implements HasReadyState, Routable {
private final Duration sessionTimeout;
private final Route routes;
protected boolean draining;
protected boolean registered;

protected Node(
Tracer tracer, NodeId id, URI uri, Secret registrationSecret, Duration sessionTimeout) {
Expand Down Expand Up @@ -274,6 +275,14 @@ public boolean isDraining() {
return draining;
}

public boolean isRegistered() {
return registered;
}

public void register() {
registered = true;
}

public abstract void drain();

@Override
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/grid/node/StatusHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
status.hasCapacity(),
"message",
status.hasCapacity() ? "Ready" : "No free slots available",
"registered",
node.isRegistered(),
"node",
status));

Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected Handlers createHandlers(Config config) {

HttpHandler readinessCheck =
req -> {
if (node.getStatus().hasCapacity()) {
if (node.isReady() && node.getStatus().hasCapacity()) {
return new HttpResponse()
.setStatus(HTTP_OK)
.setHeader("Content-Type", MediaType.PLAIN_TEXT_UTF_8.toString())
Expand All @@ -148,6 +148,7 @@ protected Handlers createHandlers(Config config) {
nodeId -> {
if (node.getId().equals(nodeId)) {
nodeRegistered.set(true);
node.register();
LOG.info("Node has been added");
}
}));
Expand Down
Loading