Skip to content

Commit 1a254fa

Browse files
VietND96sandeepsuryaprasad
authored andcommitted
[grid] Node flag register-shutdown-on-failure (SeleniumHQ#15297)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 13f05cb commit 1a254fa

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

java/src/org/openqa/selenium/grid/node/config/NodeFlags.java

+9
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ public class NodeFlags implements HasRoles {
198198
@ConfigValue(section = NODE_SECTION, name = "register-period", example = "120")
199199
public int registerPeriod = DEFAULT_REGISTER_PERIOD;
200200

201+
@Parameter(
202+
names = "--register-shutdown-on-failure",
203+
description =
204+
"If this flag is enabled, the Node will shut down after the register period is completed."
205+
+ " This is useful for container environments to restart and register again. If"
206+
+ " restarted multiple times, the Node container status will be CrashLoopBackOff.")
207+
@ConfigValue(section = NODE_SECTION, name = "register-shutdown-on-failure", example = "false")
208+
public boolean registerShutdownOnFailure = false;
209+
201210
@Parameter(
202211
names = "--heartbeat-period",
203212
description =

java/src/org/openqa/selenium/grid/node/config/NodeOptions.java

+4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ public Duration getRegisterPeriod() {
205205
return Duration.ofSeconds(seconds);
206206
}
207207

208+
public boolean getRegisterShutdownOnFailure() {
209+
return config.getBool(NODE_SECTION, "register-shutdown-on-failure").orElse(false);
210+
}
211+
208212
public Duration getHeartbeatPeriod() {
209213
// If the user sets 0 or less, we default to 1s.
210214
int seconds =

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

+12
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ public NettyServer start() {
216216
.withMaxDuration(nodeOptions.getRegisterPeriod())
217217
.withDelay(nodeOptions.getRegisterCycle())
218218
.handleResultIf(result -> true)
219+
.onFailure(
220+
event -> {
221+
LOG.severe(
222+
String.format(
223+
"Registration event failed after period of %s seconds. Node will not"
224+
+ " attempt to register again",
225+
nodeOptions.getRegisterPeriod().getSeconds()));
226+
if (nodeOptions.getRegisterShutdownOnFailure()) {
227+
LOG.severe("Shutting down");
228+
System.exit(1);
229+
}
230+
})
219231
.build();
220232

221233
LOG.info("Starting registration process for Node " + node.getUri());

0 commit comments

Comments
 (0)