Skip to content

Commit 0720bbd

Browse files
dev-velopujaganidiemol
authored
[java] add ability to disabled UI on grid (#13212)
* add stuff to disabled UI * [java] Picking up disabling UI work --------- Co-authored-by: Puja Jagani <[email protected]> Co-authored-by: Diego Molina <[email protected]> Co-authored-by: Diego Molina <[email protected]>
1 parent 602d015 commit 0720bbd

File tree

5 files changed

+87
-43
lines changed

5 files changed

+87
-43
lines changed

java/src/org/openqa/selenium/grid/commands/Hub.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ protected Handlers createHandlers(Config config) {
182182

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

185-
String subPath = new RouterOptions(config).subPath();
186-
Routable ui = new GridUiRoute(subPath);
185+
RouterOptions routerOptions = new RouterOptions(config);
186+
String subPath = routerOptions.subPath();
187187

188188
Routable appendRoute =
189189
Stream.of(
@@ -192,10 +192,19 @@ protected Handlers createHandlers(Config config) {
192192
graphqlRoute(subPath, () -> graphqlHandler))
193193
.reduce(Route::combine)
194194
.get();
195+
195196
if (!subPath.isEmpty()) {
196197
appendRoute = Route.combine(appendRoute, baseRoute(subPath, combine(routerWithSpecChecks)));
197198
}
198-
Routable httpHandler = combine(ui, appendRoute);
199+
200+
Routable httpHandler;
201+
if (routerOptions.disableUi()) {
202+
LOG.info("Grid UI has been disabled.");
203+
httpHandler = appendRoute;
204+
} else {
205+
Routable ui = new GridUiRoute(subPath);
206+
httpHandler = combine(ui, appendRoute);
207+
}
199208

200209
UsernameAndPassword uap = secretOptions.getServerAuthentication();
201210
if (uap != null) {

java/src/org/openqa/selenium/grid/commands/Standalone.java

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ protected Handlers createHandlers(Config config) {
187187
new GraphqlHandler(
188188
tracer, distributor, queue, serverOptions.getExternalUri(), getFormattedVersion());
189189

190-
String subPath = new RouterOptions(config).subPath();
191-
Routable ui = new GridUiRoute(subPath);
190+
RouterOptions routerOptions = new RouterOptions(config);
191+
String subPath = routerOptions.subPath();
192192

193193
Routable appendRoute =
194194
Stream.of(
@@ -202,7 +202,14 @@ protected Handlers createHandlers(Config config) {
202202
appendRoute = Route.combine(appendRoute, baseRoute(subPath, combine(router)));
203203
}
204204

205-
Routable httpHandler = combine(ui, appendRoute);
205+
Routable httpHandler;
206+
if (routerOptions.disableUi()) {
207+
LOG.info("Grid UI has been disabled.");
208+
httpHandler = appendRoute;
209+
} else {
210+
Routable ui = new GridUiRoute(subPath);
211+
httpHandler = combine(ui, appendRoute);
212+
}
206213

207214
UsernameAndPassword uap = secretOptions.getServerAuthentication();
208215
if (uap != null) {
@@ -213,33 +220,7 @@ protected Handlers createHandlers(Config config) {
213220
// Allow the liveness endpoint to be reached, since k8s doesn't make it easy to authenticate
214221
// these checks
215222
httpHandler = combine(httpHandler, Route.get("/readyz").to(() -> readinessCheck));
216-
217-
Node node = new NodeOptions(config).getNode();
218-
combinedHandler.addHandler(node);
219-
distributor.add(node);
220-
221-
bus.addListener(
222-
NodeDrainComplete.listener(
223-
nodeId -> {
224-
if (!node.getId().equals(nodeId)) {
225-
return;
226-
}
227-
228-
// Wait a beat before shutting down so the final response from the
229-
// node can escape.
230-
new Thread(
231-
() -> {
232-
try {
233-
Thread.sleep(1000);
234-
} catch (InterruptedException e) {
235-
// Swallow, the next thing we're doing is shutting down
236-
}
237-
LOG.info("Shutting down");
238-
System.exit(0);
239-
},
240-
"Standalone shutdown: " + nodeId)
241-
.start();
242-
}));
223+
Node node = createNode(config, bus, distributor, combinedHandler);
243224

244225
return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node));
245226
}
@@ -270,4 +251,35 @@ private String getFormattedVersion() {
270251
BuildInfo info = new BuildInfo();
271252
return String.format("%s (revision %s)", info.getReleaseLabel(), info.getBuildRevision());
272253
}
254+
255+
private Node createNode(
256+
Config config, EventBus bus, Distributor distributor, CombinedHandler combinedHandler) {
257+
Node node = new NodeOptions(config).getNode();
258+
combinedHandler.addHandler(node);
259+
distributor.add(node);
260+
261+
bus.addListener(
262+
NodeDrainComplete.listener(
263+
nodeId -> {
264+
if (!node.getId().equals(nodeId)) {
265+
return;
266+
}
267+
268+
// Wait a beat before shutting down so the final response from the
269+
// node can escape.
270+
new Thread(
271+
() -> {
272+
try {
273+
Thread.sleep(1000);
274+
} catch (InterruptedException e) {
275+
// Swallow, the next thing we're doing is shutting down
276+
}
277+
LOG.info("Shutting down");
278+
System.exit(0);
279+
},
280+
"Standalone shutdown: " + nodeId)
281+
.start();
282+
}));
283+
return node;
284+
}
273285
}

java/src/org/openqa/selenium/grid/router/httpd/RouterFlags.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
package org.openqa.selenium.grid.router.httpd;
1919

2020
import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE;
21-
import static org.openqa.selenium.grid.router.httpd.RouterOptions.NETWORK;
21+
import static org.openqa.selenium.grid.router.httpd.RouterOptions.NETWORK_SECTION;
22+
import static org.openqa.selenium.grid.router.httpd.RouterOptions.ROUTER_SECTION;
2223

2324
import com.beust.jcommander.Parameter;
2425
import com.google.auto.service.AutoService;
@@ -38,23 +39,23 @@ public class RouterFlags implements HasRoles {
3839
"Relax checks on origin header and content type of incoming requests,"
3940
+ " in contravention of strict W3C spec compliance.",
4041
arity = 1)
41-
@ConfigValue(section = "network", name = "relax-checks", example = "true")
42+
@ConfigValue(section = NETWORK_SECTION, name = "relax-checks", example = "true")
4243
private Boolean relaxChecks = false;
4344

4445
@Parameter(
4546
names = "--username",
4647
description =
4748
"User name clients must use to connect to the server. "
4849
+ "Both this and password need to be set in order to be used.")
49-
@ConfigValue(section = "router", name = "username", example = "admin")
50+
@ConfigValue(section = ROUTER_SECTION, name = "username", example = "admin")
5051
private String username;
5152

5253
@Parameter(
5354
names = "--password",
5455
description =
5556
"Password clients must use to connect to the server. "
5657
+ "Both this and the username need to be set in order to be used.")
57-
@ConfigValue(section = "router", name = "password", example = "hunter2")
58+
@ConfigValue(section = ROUTER_SECTION, name = "password", example = "hunter2")
5859
private String password;
5960

6061
@Parameter(
@@ -63,9 +64,16 @@ public class RouterFlags implements HasRoles {
6364
description =
6465
"A sub-path that should be considered for all user facing routes on the"
6566
+ " Hub/Router/Standalone")
66-
@ConfigValue(section = NETWORK, name = "sub-path", example = "my_company/selenium_grid")
67+
@ConfigValue(section = NETWORK_SECTION, name = "sub-path", example = "my_company/selenium_grid")
6768
public String subPath;
6869

70+
@Parameter(
71+
names = {"--disable-ui"},
72+
arity = 1,
73+
description = "Disable the Grid UI")
74+
@ConfigValue(section = ROUTER_SECTION, name = "disable-ui", example = "true")
75+
public boolean disableUi = false;
76+
6977
@Override
7078
public Set<Role> getRoles() {
7179
return Collections.singleton(ROUTER_ROLE);

java/src/org/openqa/selenium/grid/router/httpd/RouterOptions.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
public class RouterOptions {
2323

24-
static final String NETWORK = "network";
24+
static final String NETWORK_SECTION = "network";
25+
static final String ROUTER_SECTION = "router";
2526

2627
private final Config config;
2728

@@ -31,7 +32,7 @@ public RouterOptions(Config config) {
3132

3233
public String subPath() {
3334
return config
34-
.get(NETWORK, "sub-path")
35+
.get(NETWORK_SECTION, "sub-path")
3536
.map(
3637
prefix -> {
3738
prefix = prefix.trim();
@@ -46,4 +47,8 @@ public String subPath() {
4647
})
4748
.orElse("");
4849
}
50+
51+
public boolean disableUi() {
52+
return config.get(ROUTER_SECTION, "disable-ui").map(Boolean::parseBoolean).orElse(false);
53+
}
4954
}

java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ protected Handlers createHandlers(Config config) {
141141
new GraphqlHandler(
142142
tracer, distributor, queue, serverOptions.getExternalUri(), getServerVersion());
143143

144-
String subPath = new RouterOptions(config).subPath();
145-
Routable ui = new GridUiRoute(subPath);
144+
RouterOptions routerOptions = new RouterOptions(config);
145+
String subPath = routerOptions.subPath();
146+
146147
Router router = new Router(tracer, clientFactory, sessions, queue, distributor);
147148
Routable routerWithSpecChecks = router.with(networkOptions.getSpecComplianceChecks());
148149

@@ -153,10 +154,19 @@ protected Handlers createHandlers(Config config) {
153154
graphqlRoute(subPath, () -> graphqlHandler))
154155
.reduce(Route::combine)
155156
.get();
157+
156158
if (!subPath.isEmpty()) {
157159
appendRoute = Route.combine(appendRoute, baseRoute(subPath, combine(routerWithSpecChecks)));
158160
}
159-
Routable route = Route.combine(ui, appendRoute);
161+
162+
Routable route;
163+
if (routerOptions.disableUi()) {
164+
LOG.info("Grid UI has been disabled.");
165+
route = appendRoute;
166+
} else {
167+
Routable ui = new GridUiRoute(subPath);
168+
route = combine(ui, appendRoute);
169+
}
160170

161171
UsernameAndPassword uap = secretOptions.getServerAuthentication();
162172
if (uap != null) {

0 commit comments

Comments
 (0)