Skip to content

Commit

Permalink
Merge f86f2b5 into ebf9de9
Browse files Browse the repository at this point in the history
  • Loading branch information
LogicOscar authored Dec 6, 2023
2 parents ebf9de9 + f86f2b5 commit 6e6dae4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 27 deletions.
6 changes: 6 additions & 0 deletions java/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ protected Handlers createHandlers(Config config) {

Routable routerWithSpecChecks = router.with(networkOptions.getSpecComplianceChecks());

Boolean disableUi = new RouterOptions(config).disableUi();
if (disableUi) {
LOG.info("UI disabled");
return new Handlers(routerWithSpecChecks, new ProxyWebsocketsIntoGrid(clientFactory, sessions));
}

String subPath = new RouterOptions(config).subPath();
Routable ui = new GridUiRoute(subPath);

Expand Down
64 changes: 37 additions & 27 deletions java/src/org/openqa/selenium/grid/commands/Standalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ protected Handlers createHandlers(Config config) {
new GraphqlHandler(
tracer, distributor, queue, serverOptions.getExternalUri(), getFormattedVersion());

Boolean disableUi = new RouterOptions(config).disableUi();
if (disableUi) {
Node node = createNode(config, bus, distributor, combinedHandler);
return new Handlers(graphqlRoute("", () -> graphqlHandler), new ProxyNodeWebsockets(clientFactory, node));
}

String subPath = new RouterOptions(config).subPath();
Routable ui = new GridUiRoute(subPath);

Expand All @@ -213,33 +219,7 @@ protected Handlers createHandlers(Config config) {
// Allow the liveness endpoint to be reached, since k8s doesn't make it easy to authenticate
// these checks
httpHandler = combine(httpHandler, Route.get("/readyz").to(() -> readinessCheck));

Node node = new NodeOptions(config).getNode();
combinedHandler.addHandler(node);
distributor.add(node);

bus.addListener(
NodeDrainComplete.listener(
nodeId -> {
if (!node.getId().equals(nodeId)) {
return;
}

// Wait a beat before shutting down so the final response from the
// node can escape.
new Thread(
() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Swallow, the next thing we're doing is shutting down
}
LOG.info("Shutting down");
System.exit(0);
},
"Standalone shutdown: " + nodeId)
.start();
}));
Node node = createNode(config, bus, distributor, combinedHandler);

return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node));
}
Expand Down Expand Up @@ -270,4 +250,34 @@ private String getFormattedVersion() {
BuildInfo info = new BuildInfo();
return String.format("%s (revision %s)", info.getReleaseLabel(), info.getBuildRevision());
}

private Node createNode(Config config, EventBus bus, Distributor distributor, CombinedHandler combinedHandler) {
Node node = new NodeOptions(config).getNode();
combinedHandler.addHandler(node);
distributor.add(node);

bus.addListener(
NodeDrainComplete.listener(
nodeId -> {
if (!node.getId().equals(nodeId)) {
return;
}

// Wait a beat before shutting down so the final response from the
// node can escape.
new Thread(
() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Swallow, the next thing we're doing is shutting down
}
LOG.info("Shutting down");
System.exit(0);
},
"Standalone shutdown: " + nodeId)
.start();
}));
return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public class RouterFlags implements HasRoles {
@ConfigValue(section = NETWORK, name = "sub-path", example = "my_company/selenium_grid")
public String subPath;

@Parameter(
names = {"--disable-ui"},
arity = 1,
description = "Disable the UI on the Hub/Router/Standalone")
@ConfigValue(section = NETWORK, name = "disable-ui", example = "true")
public boolean disableUi = false;

@Override
public Set<Role> getRoles() {
return Collections.singleton(ROUTER_ROLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public String subPath() {
})
.orElse("");
}

public boolean disableUi() {
return config.get(NETWORK,"disable-ui").map(Boolean::parseBoolean).orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ protected Handlers createHandlers(Config config) {
new GraphqlHandler(
tracer, distributor, queue, serverOptions.getExternalUri(), getServerVersion());

Boolean disableUi = new RouterOptions(config).disableUi();
if (disableUi) {
return new Handlers(graphqlRoute("", () -> graphqlHandler), new ProxyWebsocketsIntoGrid(clientFactory, sessions));
}
String subPath = new RouterOptions(config).subPath();
Routable ui = new GridUiRoute(subPath);
Router router = new Router(tracer, clientFactory, sessions, queue, distributor);
Expand Down

0 comments on commit 6e6dae4

Please sign in to comment.