Skip to content

Commit

Permalink
Make the SlotSelector an argument of the Distributor
Browse files Browse the repository at this point in the history
This also provides the indirection needed to get this from the
`DistributorOptions`.
  • Loading branch information
shs96c committed May 4, 2021
1 parent 973ab84 commit 25e848a
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/distributor",
"//java/server/src/org/openqa/selenium/grid/distributor/config",
"//java/server/src/org/openqa/selenium/grid/distributor/local",
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
"//java/server/src/org/openqa/selenium/grid/graphql",
"//java/server/src/org/openqa/selenium/grid/log",
"//java/server/src/org/openqa/selenium/grid/node",
Expand Down
2 changes: 2 additions & 0 deletions java/server/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.openqa.selenium.grid.distributor.Distributor;
import org.openqa.selenium.grid.distributor.config.DistributorOptions;
import org.openqa.selenium.grid.distributor.local.LocalDistributor;
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
import org.openqa.selenium.grid.graphql.GraphqlHandler;
import org.openqa.selenium.grid.log.LoggingOptions;
import org.openqa.selenium.grid.router.ProxyCdpIntoGrid;
Expand Down Expand Up @@ -156,6 +157,7 @@ protected Handlers createHandlers(Config config) {
clientFactory,
sessions,
queue,
distributorOptions.getSlotSelector(),
secret,
distributorOptions.getHealthCheckInterval());
handler.addHandler(distributor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ protected Handlers createHandlers(Config config) {
clientFactory,
sessions,
queue,
distributorOptions.getSlotSelector(),
registrationSecret,
distributorOptions.getHealthCheckInterval());
combinedHandler.addHandler(distributor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ java_library(
"//java:auto-service",
"//java/server/src/org/openqa/selenium/grid/config",
"//java/server/src/org/openqa/selenium/grid/distributor",
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
artifact("com.beust:jcommander"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_DISTRIBUTOR_IMPLEMENTATION;
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_HEALTHCHECK_INTERVAL;
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_SLOT_SELECTOR_IMPLEMENTATION;
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DISTRIBUTOR_SECTION;

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

@Parameter(names = {"--slot-selector"}, description = "Full classname of non-default slot selector implementation")
@ConfigValue(section = DISTRIBUTOR_SECTION, name = "slot-selector", example = DEFAULT_SLOT_SELECTOR_IMPLEMENTATION)
private String slotSelector = DEFAULT_SLOT_SELECTOR_IMPLEMENTATION;

@Parameter(
names = {"--healthcheck-interval"},
description = "How often, in seconds, will the health check run for all Nodes." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.ConfigException;
import org.openqa.selenium.grid.distributor.Distributor;
import org.openqa.selenium.grid.distributor.selector.SlotSelector;

import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -31,6 +32,8 @@ public class DistributorOptions {
static final String DISTRIBUTOR_SECTION = "distributor";
static final String DEFAULT_DISTRIBUTOR_IMPLEMENTATION =
"org.openqa.selenium.grid.distributor.local.LocalDistributor";
static final String DEFAULT_SLOT_SELECTOR_IMPLEMENTATION =
"org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector";

public static final int DEFAULT_HEALTHCHECK_INTERVAL = 300;

Expand Down Expand Up @@ -92,4 +95,12 @@ public Distributor getDistributor() {
Distributor.class,
DEFAULT_DISTRIBUTOR_IMPLEMENTATION);
}

public SlotSelector getSlotSelector() {
return config.getClass(
DISTRIBUTOR_SECTION,
"slot-selector",
SlotSelector.class,
DEFAULT_SLOT_SELECTOR_IMPLEMENTATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.openqa.selenium.grid.distributor.Distributor;
import org.openqa.selenium.grid.distributor.config.DistributorOptions;
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
import org.openqa.selenium.grid.distributor.selector.SlotSelector;
import org.openqa.selenium.grid.log.LoggingOptions;
import org.openqa.selenium.grid.node.HealthCheck;
import org.openqa.selenium.grid.node.Node;
Expand Down Expand Up @@ -119,9 +120,10 @@ public LocalDistributor(
HttpClient.Factory clientFactory,
SessionMap sessions,
NewSessionQueue sessionQueue,
SlotSelector slotSelector,
Secret registrationSecret,
Duration healthcheckInterval) {
super(tracer, clientFactory, new DefaultSlotSelector(), sessions, registrationSecret);
super(tracer, clientFactory, slotSelector, sessions, registrationSecret);
this.tracer = Require.nonNull("Tracer", tracer);
this.bus = Require.nonNull("Event bus", bus);
this.clientFactory = Require.nonNull("HTTP client factory", clientFactory);
Expand Down Expand Up @@ -175,6 +177,7 @@ public static Distributor create(Config config) {
clientFactory,
sessions,
sessionQueue,
distributorOptions.getSlotSelector(),
secretOptions.getRegistrationSecret(),
distributorOptions.getHealthCheckInterval());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ java_library(
],
deps = [
"//java/client/src/org/openqa/selenium:core",
"//java/server/src/org/openqa/selenium/grid/config",
"//java/server/src/org/openqa/selenium/grid/data",
artifact("com.google.guava:guava"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.annotations.VisibleForTesting;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.data.NodeStatus;
import org.openqa.selenium.grid.data.Slot;
import org.openqa.selenium.grid.data.SlotId;
Expand Down Expand Up @@ -65,4 +66,7 @@ long getNumberOfSupportedBrowsers(NodeStatus nodeStatus) {
.count();
}

public static SlotSelector create(Config config) {
return new DefaultSlotSelector();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openqa.selenium.grid.data.SlotId;
import org.openqa.selenium.grid.distributor.local.LocalDistributor;
import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
import org.openqa.selenium.grid.node.CapabilityResponseEncoder;
import org.openqa.selenium.grid.node.HealthCheck;
import org.openqa.selenium.grid.node.Node;
Expand Down Expand Up @@ -117,6 +118,7 @@ public void setUpDistributor() throws MalformedURLException {
clientFactory,
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ java_test_suite(
"//java/server/src/org/openqa/selenium/grid/distributor",
"//java/server/src/org/openqa/selenium/grid/distributor/local",
"//java/server/src/org/openqa/selenium/grid/distributor/remote",
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
"//java/server/src/org/openqa/selenium/grid/node",
"//java/server/src/org/openqa/selenium/grid/node/local",
"//java/server/src/org/openqa/selenium/grid/security",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.openqa.selenium.grid.data.Slot;
import org.openqa.selenium.grid.distributor.local.LocalDistributor;
import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
import org.openqa.selenium.grid.node.HealthCheck;
import org.openqa.selenium.grid.node.Node;
import org.openqa.selenium.grid.node.local.LocalNode;
Expand Down Expand Up @@ -132,6 +133,7 @@ public void setUp() throws URISyntaxException {
HttpClient.Factory.createDefault(),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
stereotype = new ImmutableCapabilities("browserName", "cheese");
Expand Down Expand Up @@ -167,6 +169,7 @@ public void shouldStartHeartBeatOnNodeRegistration() {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -213,6 +216,7 @@ public void shouldBeAbleToAddANodeAndCreateASession() {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -251,6 +255,7 @@ public void creatingASessionAddsItToTheSessionMap() {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -290,6 +295,7 @@ public void shouldBeAbleToRemoveANode() throws MalformedURLException {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
Distributor distributor = new RemoteDistributor(
Expand Down Expand Up @@ -326,6 +332,7 @@ public void testDrainingNodeDoesNotAcceptNewSessions() {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -361,6 +368,7 @@ public void testDrainedNodeShutsDownOnceEmpty() throws InterruptedException {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -403,6 +411,7 @@ public void drainedNodeDoesNotShutDownIfNotEmpty() throws InterruptedException {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -448,6 +457,7 @@ public void drainedNodeShutsDownAfterSessionsFinish() throws InterruptedExceptio
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -518,6 +528,7 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
new PassthroughHttpClient.Factory(handler),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5))
.add(heavy)
Expand Down Expand Up @@ -556,6 +567,7 @@ public void shouldUseLastSessionCreatedTimeAsTieBreaker() {
new PassthroughHttpClient.Factory(handler),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5))
.add(leastRecent);
Expand Down Expand Up @@ -645,6 +657,7 @@ public void shouldIncludeHostsThatAreUpInHostList() {
new PassthroughHttpClient.Factory(handler),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
handler.addHandler(distributor);
Expand Down Expand Up @@ -682,6 +695,7 @@ public void shouldNotScheduleAJobIfAllSlotsAreBeingUsed() {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));

Expand Down Expand Up @@ -719,6 +733,7 @@ public void shouldReleaseSlotOnceSessionEnds() {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -770,6 +785,7 @@ public void shouldNotStartASessionIfTheCapabilitiesAreNotSupported() {
new PassthroughHttpClient.Factory(handler),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
handler.addHandler(distributor);
Expand Down Expand Up @@ -807,6 +823,7 @@ public void attemptingToStartASessionWhichFailsMarksAsTheSlotAsAvailable() {
new PassthroughHttpClient.Factory(node),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
distributor.add(node);
Expand Down Expand Up @@ -849,6 +866,7 @@ public void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthChe
new PassthroughHttpClient.Factory(handler),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
handler.addHandler(distributor);
Expand Down Expand Up @@ -910,6 +928,7 @@ public void shouldPrioritizeHostsWithTheMostSlotsAvailableForASessionType() {
new PassthroughHttpClient.Factory(handler),
sessions,
queue,
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5));
handler.addHandler(distributor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ java_test_suite(
"//java/server/src/org/openqa/selenium/grid/data",
"//java/server/src/org/openqa/selenium/grid/distributor",
"//java/server/src/org/openqa/selenium/grid/distributor/local",
"//java/server/src/org/openqa/selenium/grid/distributor/selector",
"//java/server/src/org/openqa/selenium/grid/node",
"//java/server/src/org/openqa/selenium/grid/node/local",
"//java/server/src/org/openqa/selenium/grid/security",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openqa.selenium.events.EventBus;
import org.openqa.selenium.events.local.GuavaEventBus;
import org.openqa.selenium.grid.distributor.Distributor;
import org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector;
import org.openqa.selenium.grid.security.Secret;
import org.openqa.selenium.grid.sessionmap.SessionMap;
import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class GridModelTest {
clientFactory,
sessions,
queue,
new DefaultSlotSelector(),
secret,
Duration.ofMinutes(5));

Expand Down
Loading

0 comments on commit 25e848a

Please sign in to comment.