Skip to content

Commit 4f0d18c

Browse files
VietND96sandeepsuryaprasad
authored andcommitted
[grid] Distributor listen and handle the NodeRestartedEvent (SeleniumHQ#14938)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent c4f8b76 commit 4f0d18c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.openqa.selenium.grid.data.NodeHeartBeatEvent;
7878
import org.openqa.selenium.grid.data.NodeId;
7979
import org.openqa.selenium.grid.data.NodeRemovedEvent;
80+
import org.openqa.selenium.grid.data.NodeRestartedEvent;
8081
import org.openqa.selenium.grid.data.NodeStatus;
8182
import org.openqa.selenium.grid.data.NodeStatusEvent;
8283
import org.openqa.selenium.grid.data.RequestId;
@@ -205,6 +206,7 @@ public LocalDistributor(
205206

206207
bus.addListener(NodeStatusEvent.listener(this::register));
207208
bus.addListener(NodeStatusEvent.listener(model::refresh));
209+
bus.addListener(NodeRestartedEvent.listener(this::handleNodeRestarted));
208210
bus.addListener(NodeRemovedEvent.listener(nodeStatus -> remove(nodeStatus.getNodeId())));
209211
bus.addListener(
210212
NodeHeartBeatEvent.listener(
@@ -327,6 +329,25 @@ private void register(NodeStatus status) {
327329
}
328330
}
329331

332+
private void handleNodeRestarted(NodeStatus status) {
333+
Require.nonNull("Node", status);
334+
Lock writeLock = lock.writeLock();
335+
writeLock.lock();
336+
try {
337+
if (!nodes.containsKey(status.getNodeId())) {
338+
return;
339+
}
340+
if (!getNodeFromURI(status.getExternalUri()).isDraining()) {
341+
LOG.info(
342+
String.format(
343+
"Node %s has restarted. Setting availability to DOWN.", status.getNodeId()));
344+
model.setAvailability(status.getNodeId(), DOWN);
345+
}
346+
} finally {
347+
writeLock.unlock();
348+
}
349+
}
350+
330351
@Override
331352
public LocalDistributor add(Node node) {
332353
Require.nonNull("Node", node);

0 commit comments

Comments
 (0)