Skip to content

Commit 25e848a

Browse files
committed
Make the SlotSelector an argument of the Distributor
This also provides the indirection needed to get this from the `DistributorOptions`.
1 parent 973ab84 commit 25e848a

20 files changed

+73
-1
lines changed

java/server/src/org/openqa/selenium/grid/commands/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ java_library(
2525
"//java/server/src/org/openqa/selenium/grid/distributor",
2626
"//java/server/src/org/openqa/selenium/grid/distributor/config",
2727
"//java/server/src/org/openqa/selenium/grid/distributor/local",
28+
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
2829
"//java/server/src/org/openqa/selenium/grid/graphql",
2930
"//java/server/src/org/openqa/selenium/grid/log",
3031
"//java/server/src/org/openqa/selenium/grid/node",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.openqa.selenium.grid.distributor.Distributor;
2929
import org.openqa.selenium.grid.distributor.config.DistributorOptions;
3030
import org.openqa.selenium.grid.distributor.local.LocalDistributor;
31+
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
3132
import org.openqa.selenium.grid.graphql.GraphqlHandler;
3233
import org.openqa.selenium.grid.log.LoggingOptions;
3334
import org.openqa.selenium.grid.router.ProxyCdpIntoGrid;
@@ -156,6 +157,7 @@ protected Handlers createHandlers(Config config) {
156157
clientFactory,
157158
sessions,
158159
queue,
160+
distributorOptions.getSlotSelector(),
159161
secret,
160162
distributorOptions.getHealthCheckInterval());
161163
handler.addHandler(distributor);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ protected Handlers createHandlers(Config config) {
154154
clientFactory,
155155
sessions,
156156
queue,
157+
distributorOptions.getSlotSelector(),
157158
registrationSecret,
158159
distributorOptions.getHealthCheckInterval());
159160
combinedHandler.addHandler(distributor);

java/server/src/org/openqa/selenium/grid/distributor/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ java_library(
1111
"//java:auto-service",
1212
"//java/server/src/org/openqa/selenium/grid/config",
1313
"//java/server/src/org/openqa/selenium/grid/distributor",
14+
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
1415
artifact("com.beust:jcommander"),
1516
],
1617
)

java/server/src/org/openqa/selenium/grid/distributor/config/DistributorFlags.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;
2222
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_DISTRIBUTOR_IMPLEMENTATION;
2323
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_HEALTHCHECK_INTERVAL;
24+
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_SLOT_SELECTOR_IMPLEMENTATION;
2425
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DISTRIBUTOR_SECTION;
2526

2627
import com.google.auto.service.AutoService;
@@ -64,6 +65,10 @@ public class DistributorFlags implements HasRoles {
6465
example = DEFAULT_DISTRIBUTOR_IMPLEMENTATION)
6566
private String implementation = DEFAULT_DISTRIBUTOR_IMPLEMENTATION;
6667

68+
@Parameter(names = {"--slot-selector"}, description = "Full classname of non-default slot selector implementation")
69+
@ConfigValue(section = DISTRIBUTOR_SECTION, name = "slot-selector", example = DEFAULT_SLOT_SELECTOR_IMPLEMENTATION)
70+
private String slotSelector = DEFAULT_SLOT_SELECTOR_IMPLEMENTATION;
71+
6772
@Parameter(
6873
names = {"--healthcheck-interval"},
6974
description = "How often, in seconds, will the health check run for all Nodes." +

java/server/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.openqa.selenium.grid.config.Config;
2121
import org.openqa.selenium.grid.config.ConfigException;
2222
import org.openqa.selenium.grid.distributor.Distributor;
23+
import org.openqa.selenium.grid.distributor.selector.SlotSelector;
2324

2425
import java.net.URI;
2526
import java.net.URISyntaxException;
@@ -31,6 +32,8 @@ public class DistributorOptions {
3132
static final String DISTRIBUTOR_SECTION = "distributor";
3233
static final String DEFAULT_DISTRIBUTOR_IMPLEMENTATION =
3334
"org.openqa.selenium.grid.distributor.local.LocalDistributor";
35+
static final String DEFAULT_SLOT_SELECTOR_IMPLEMENTATION =
36+
"org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector";
3437

3538
public static final int DEFAULT_HEALTHCHECK_INTERVAL = 300;
3639

@@ -92,4 +95,12 @@ public Distributor getDistributor() {
9295
Distributor.class,
9396
DEFAULT_DISTRIBUTOR_IMPLEMENTATION);
9497
}
98+
99+
public SlotSelector getSlotSelector() {
100+
return config.getClass(
101+
DISTRIBUTOR_SECTION,
102+
"slot-selector",
103+
SlotSelector.class,
104+
DEFAULT_SLOT_SELECTOR_IMPLEMENTATION);
105+
}
95106
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.openqa.selenium.grid.distributor.Distributor;
4646
import org.openqa.selenium.grid.distributor.config.DistributorOptions;
4747
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
48+
import org.openqa.selenium.grid.distributor.selector.SlotSelector;
4849
import org.openqa.selenium.grid.log.LoggingOptions;
4950
import org.openqa.selenium.grid.node.HealthCheck;
5051
import org.openqa.selenium.grid.node.Node;
@@ -119,9 +120,10 @@ public LocalDistributor(
119120
HttpClient.Factory clientFactory,
120121
SessionMap sessions,
121122
NewSessionQueue sessionQueue,
123+
SlotSelector slotSelector,
122124
Secret registrationSecret,
123125
Duration healthcheckInterval) {
124-
super(tracer, clientFactory, new DefaultSlotSelector(), sessions, registrationSecret);
126+
super(tracer, clientFactory, slotSelector, sessions, registrationSecret);
125127
this.tracer = Require.nonNull("Tracer", tracer);
126128
this.bus = Require.nonNull("Event bus", bus);
127129
this.clientFactory = Require.nonNull("HTTP client factory", clientFactory);
@@ -175,6 +177,7 @@ public static Distributor create(Config config) {
175177
clientFactory,
176178
sessions,
177179
sessionQueue,
180+
distributorOptions.getSlotSelector(),
178181
secretOptions.getRegistrationSecret(),
179182
distributorOptions.getHealthCheckInterval());
180183
}

java/server/src/org/openqa/selenium/grid/distributor/selector/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ java_library(
1010
],
1111
deps = [
1212
"//java/client/src/org/openqa/selenium:core",
13+
"//java/server/src/org/openqa/selenium/grid/config",
1314
"//java/server/src/org/openqa/selenium/grid/data",
1415
artifact("com.google.guava:guava"),
1516
],

java/server/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.annotations.VisibleForTesting;
2121
import org.openqa.selenium.Capabilities;
22+
import org.openqa.selenium.grid.config.Config;
2223
import org.openqa.selenium.grid.data.NodeStatus;
2324
import org.openqa.selenium.grid.data.Slot;
2425
import org.openqa.selenium.grid.data.SlotId;
@@ -65,4 +66,7 @@ long getNumberOfSupportedBrowsers(NodeStatus nodeStatus) {
6566
.count();
6667
}
6768

69+
public static SlotSelector create(Config config) {
70+
return new DefaultSlotSelector();
71+
}
6872
}

java/server/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.openqa.selenium.grid.data.SlotId;
4040
import org.openqa.selenium.grid.distributor.local.LocalDistributor;
4141
import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;
42+
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
4243
import org.openqa.selenium.grid.node.CapabilityResponseEncoder;
4344
import org.openqa.selenium.grid.node.HealthCheck;
4445
import org.openqa.selenium.grid.node.Node;
@@ -117,6 +118,7 @@ public void setUpDistributor() throws MalformedURLException {
117118
clientFactory,
118119
sessions,
119120
queue,
121+
new DefaultSlotSelector(),
120122
registrationSecret,
121123
Duration.ofMinutes(5));
122124

java/server/test/org/openqa/selenium/grid/distributor/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ java_test_suite(
2222
"//java/server/src/org/openqa/selenium/grid/distributor",
2323
"//java/server/src/org/openqa/selenium/grid/distributor/local",
2424
"//java/server/src/org/openqa/selenium/grid/distributor/remote",
25+
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
2526
"//java/server/src/org/openqa/selenium/grid/node",
2627
"//java/server/src/org/openqa/selenium/grid/node/local",
2728
"//java/server/src/org/openqa/selenium/grid/security",

java/server/test/org/openqa/selenium/grid/distributor/DistributorTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.openqa.selenium.grid.data.Slot;
4444
import org.openqa.selenium.grid.distributor.local.LocalDistributor;
4545
import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;
46+
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
4647
import org.openqa.selenium.grid.node.HealthCheck;
4748
import org.openqa.selenium.grid.node.Node;
4849
import org.openqa.selenium.grid.node.local.LocalNode;
@@ -132,6 +133,7 @@ public void setUp() throws URISyntaxException {
132133
HttpClient.Factory.createDefault(),
133134
sessions,
134135
queue,
136+
new DefaultSlotSelector(),
135137
registrationSecret,
136138
Duration.ofMinutes(5));
137139
stereotype = new ImmutableCapabilities("browserName", "cheese");
@@ -167,6 +169,7 @@ public void shouldStartHeartBeatOnNodeRegistration() {
167169
new PassthroughHttpClient.Factory(node),
168170
sessions,
169171
queue,
172+
new DefaultSlotSelector(),
170173
registrationSecret,
171174
Duration.ofMinutes(5));
172175
distributor.add(node);
@@ -213,6 +216,7 @@ public void shouldBeAbleToAddANodeAndCreateASession() {
213216
new PassthroughHttpClient.Factory(node),
214217
sessions,
215218
queue,
219+
new DefaultSlotSelector(),
216220
registrationSecret,
217221
Duration.ofMinutes(5));
218222
distributor.add(node);
@@ -251,6 +255,7 @@ public void creatingASessionAddsItToTheSessionMap() {
251255
new PassthroughHttpClient.Factory(node),
252256
sessions,
253257
queue,
258+
new DefaultSlotSelector(),
254259
registrationSecret,
255260
Duration.ofMinutes(5));
256261
distributor.add(node);
@@ -290,6 +295,7 @@ public void shouldBeAbleToRemoveANode() throws MalformedURLException {
290295
new PassthroughHttpClient.Factory(node),
291296
sessions,
292297
queue,
298+
new DefaultSlotSelector(),
293299
registrationSecret,
294300
Duration.ofMinutes(5));
295301
Distributor distributor = new RemoteDistributor(
@@ -326,6 +332,7 @@ public void testDrainingNodeDoesNotAcceptNewSessions() {
326332
new PassthroughHttpClient.Factory(node),
327333
sessions,
328334
queue,
335+
new DefaultSlotSelector(),
329336
registrationSecret,
330337
Duration.ofMinutes(5));
331338
distributor.add(node);
@@ -361,6 +368,7 @@ public void testDrainedNodeShutsDownOnceEmpty() throws InterruptedException {
361368
new PassthroughHttpClient.Factory(node),
362369
sessions,
363370
queue,
371+
new DefaultSlotSelector(),
364372
registrationSecret,
365373
Duration.ofMinutes(5));
366374
distributor.add(node);
@@ -403,6 +411,7 @@ public void drainedNodeDoesNotShutDownIfNotEmpty() throws InterruptedException {
403411
new PassthroughHttpClient.Factory(node),
404412
sessions,
405413
queue,
414+
new DefaultSlotSelector(),
406415
registrationSecret,
407416
Duration.ofMinutes(5));
408417
distributor.add(node);
@@ -448,6 +457,7 @@ public void drainedNodeShutsDownAfterSessionsFinish() throws InterruptedExceptio
448457
new PassthroughHttpClient.Factory(node),
449458
sessions,
450459
queue,
460+
new DefaultSlotSelector(),
451461
registrationSecret,
452462
Duration.ofMinutes(5));
453463
distributor.add(node);
@@ -518,6 +528,7 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
518528
new PassthroughHttpClient.Factory(handler),
519529
sessions,
520530
queue,
531+
new DefaultSlotSelector(),
521532
registrationSecret,
522533
Duration.ofMinutes(5))
523534
.add(heavy)
@@ -556,6 +567,7 @@ public void shouldUseLastSessionCreatedTimeAsTieBreaker() {
556567
new PassthroughHttpClient.Factory(handler),
557568
sessions,
558569
queue,
570+
new DefaultSlotSelector(),
559571
registrationSecret,
560572
Duration.ofMinutes(5))
561573
.add(leastRecent);
@@ -645,6 +657,7 @@ public void shouldIncludeHostsThatAreUpInHostList() {
645657
new PassthroughHttpClient.Factory(handler),
646658
sessions,
647659
queue,
660+
new DefaultSlotSelector(),
648661
registrationSecret,
649662
Duration.ofMinutes(5));
650663
handler.addHandler(distributor);
@@ -682,6 +695,7 @@ public void shouldNotScheduleAJobIfAllSlotsAreBeingUsed() {
682695
new PassthroughHttpClient.Factory(node),
683696
sessions,
684697
queue,
698+
new DefaultSlotSelector(),
685699
registrationSecret,
686700
Duration.ofMinutes(5));
687701

@@ -719,6 +733,7 @@ public void shouldReleaseSlotOnceSessionEnds() {
719733
new PassthroughHttpClient.Factory(node),
720734
sessions,
721735
queue,
736+
new DefaultSlotSelector(),
722737
registrationSecret,
723738
Duration.ofMinutes(5));
724739
distributor.add(node);
@@ -770,6 +785,7 @@ public void shouldNotStartASessionIfTheCapabilitiesAreNotSupported() {
770785
new PassthroughHttpClient.Factory(handler),
771786
sessions,
772787
queue,
788+
new DefaultSlotSelector(),
773789
registrationSecret,
774790
Duration.ofMinutes(5));
775791
handler.addHandler(distributor);
@@ -807,6 +823,7 @@ public void attemptingToStartASessionWhichFailsMarksAsTheSlotAsAvailable() {
807823
new PassthroughHttpClient.Factory(node),
808824
sessions,
809825
queue,
826+
new DefaultSlotSelector(),
810827
registrationSecret,
811828
Duration.ofMinutes(5));
812829
distributor.add(node);
@@ -849,6 +866,7 @@ public void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthChe
849866
new PassthroughHttpClient.Factory(handler),
850867
sessions,
851868
queue,
869+
new DefaultSlotSelector(),
852870
registrationSecret,
853871
Duration.ofMinutes(5));
854872
handler.addHandler(distributor);
@@ -910,6 +928,7 @@ public void shouldPrioritizeHostsWithTheMostSlotsAvailableForASessionType() {
910928
new PassthroughHttpClient.Factory(handler),
911929
sessions,
912930
queue,
931+
new DefaultSlotSelector(),
913932
registrationSecret,
914933
Duration.ofMinutes(5));
915934
handler.addHandler(distributor);

java/server/test/org/openqa/selenium/grid/distributor/local/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ java_test_suite(
1717
"//java/server/src/org/openqa/selenium/grid/data",
1818
"//java/server/src/org/openqa/selenium/grid/distributor",
1919
"//java/server/src/org/openqa/selenium/grid/distributor/local",
20+
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
2021
"//java/server/src/org/openqa/selenium/grid/node",
2122
"//java/server/src/org/openqa/selenium/grid/node/local",
2223
"//java/server/src/org/openqa/selenium/grid/security",

java/server/test/org/openqa/selenium/grid/distributor/local/GridModelTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.openqa.selenium.events.EventBus;
2222
import org.openqa.selenium.events.local.GuavaEventBus;
2323
import org.openqa.selenium.grid.distributor.Distributor;
24+
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
2425
import org.openqa.selenium.grid.security.Secret;
2526
import org.openqa.selenium.grid.sessionmap.SessionMap;
2627
import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;
@@ -51,6 +52,7 @@ public class GridModelTest {
5152
clientFactory,
5253
sessions,
5354
queue,
55+
new DefaultSlotSelector(),
5456
secret,
5557
Duration.ofMinutes(5));
5658

0 commit comments

Comments
 (0)