Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 47824b3

Browse files
committedApr 27, 2021
Bring SessionRequest and CreateSessionRequest into alignment
1 parent 7e20289 commit 47824b3

File tree

12 files changed

+23
-23
lines changed

12 files changed

+23
-23
lines changed
 

‎java/server/src/org/openqa/selenium/grid/data/CreateSessionRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Set<Dialect> getDownstreamDialects() {
5353
return downstreamDialects;
5454
}
5555

56-
public Capabilities getCapabilities() {
56+
public Capabilities getDesiredCapabilities() {
5757
return capabilities;
5858
}
5959

@@ -69,7 +69,7 @@ private static CreateSessionRequest fromJson(JsonInput input) {
6969
input.beginObject();
7070
while (input.hasNext()) {
7171
switch (input.nextName()) {
72-
case "capabilities":
72+
case "desiredCapabilities":
7373
capabilities = input.read(Capabilities.class);
7474
break;
7575

‎java/server/src/org/openqa/selenium/grid/distributor/Distributor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Sess
195195

196196
// Reject new session immediately if no node has the required capabilities
197197
boolean hostsWithCaps = model.stream()
198-
.anyMatch(nodeStatus -> nodeStatus.hasCapability(firstRequest.getCapabilities()));
198+
.anyMatch(nodeStatus -> nodeStatus.hasCapability(firstRequest.getDesiredCapabilities()));
199199

200200
if (!hostsWithCaps) {
201201
String errorMessage = String.format(
@@ -214,7 +214,7 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Sess
214214
}
215215

216216
// Find a Node that supports the capabilities present in the new session
217-
Set<SlotId> slotIds = slotSelector.selectSlot(firstRequest.getCapabilities(), model);
217+
Set<SlotId> slotIds = slotSelector.selectSlot(firstRequest.getDesiredCapabilities(), model);
218218
if (!slotIds.isEmpty()) {
219219
selected = reserve(slotIds.iterator().next(), firstRequest);
220220
} else {

‎java/server/src/org/openqa/selenium/grid/docker/DockerSessionFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public boolean test(Capabilities capabilities) {
133133

134134
@Override
135135
public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sessionRequest) {
136-
LOG.info("Starting session for " + sessionRequest.getCapabilities());
136+
LOG.info("Starting session for " + sessionRequest.getDesiredCapabilities());
137137

138138
int port = runningInDocker ? 4444 : PortProber.findFreePort();
139139
try (Span span = tracer.getCurrentContext().createSpan("docker_session_factory.apply")) {
@@ -143,7 +143,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
143143
String logMessage = runningInDocker ? "Creating container..." :
144144
"Creating container, mapping container port 4444 to " + port;
145145
LOG.info(logMessage);
146-
Container container = createBrowserContainer(port, sessionRequest.getCapabilities());
146+
Container container = createBrowserContainer(port, sessionRequest.getDesiredCapabilities());
147147
container.start();
148148
ContainerInfo containerInfo = container.inspect();
149149

@@ -184,7 +184,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
184184

185185
Command command = new Command(
186186
null,
187-
DriverCommand.NEW_SESSION(sessionRequest.getCapabilities()));
187+
DriverCommand.NEW_SESSION(sessionRequest.getDesiredCapabilities()));
188188
ProtocolHandshake.Result result;
189189
Response response;
190190
try {
@@ -211,7 +211,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
211211

212212
SessionId id = new SessionId(response.getSessionId());
213213
Capabilities capabilities = new ImmutableCapabilities((Map<?, ?>) response.getValue());
214-
Capabilities mergedCapabilities = capabilities.merge(sessionRequest.getCapabilities());
214+
Capabilities mergedCapabilities = capabilities.merge(sessionRequest.getDesiredCapabilities());
215215

216216
Container videoContainer = null;
217217
Optional<DockerAssetsPath> path = ofNullable(this.assetsPath);

‎java/server/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
9494
return Either.left(new SessionNotCreatedException("No downstream dialects were found."));
9595
}
9696

97-
if (!test(sessionRequest.getCapabilities())) {
97+
if (!test(sessionRequest.getDesiredCapabilities())) {
9898
return Either.left(new SessionNotCreatedException("New session request capabilities do not "
9999
+ "match the stereotype."));
100100
}
101101

102102
try (Span span = tracer.getCurrentContext().createSpan("driver_service_factory.apply")) {
103103

104-
Capabilities capabilities = browserOptionsMutator.apply(sessionRequest.getCapabilities());
104+
Capabilities capabilities = browserOptionsMutator.apply(sessionRequest.getDesiredCapabilities());
105105

106106
Optional<Platform> platformName = Optional.ofNullable(capabilities.getPlatformName());
107107
if (platformName.isPresent()) {

‎java/server/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
163163
throw new IllegalStateException("Only expected one session at a time");
164164
}
165165

166-
Optional<WebDriver> driver = driverInfo.createDriver(sessionRequest.getCapabilities());
166+
Optional<WebDriver> driver = driverInfo.createDriver(sessionRequest.getDesiredCapabilities());
167167
if (!driver.isPresent()) {
168168
return Either.left(new WebDriverException("Unable to create a driver instance"));
169169
}

‎java/server/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
279279
attributeMap
280280
.put(AttributeKey.LOGGER_CLASS.getKey(), EventAttribute.setValue(getClass().getName()));
281281
attributeMap.put("session.request.capabilities",
282-
EventAttribute.setValue(sessionRequest.getCapabilities().toString()));
282+
EventAttribute.setValue(sessionRequest.getDesiredCapabilities().toString()));
283283
attributeMap.put("session.request.downstreamdialect",
284284
EventAttribute.setValue(sessionRequest.getDownstreamDialects().toString()));
285285

@@ -304,7 +304,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
304304
SessionSlot slotToUse = null;
305305
synchronized (factories) {
306306
for (SessionSlot factory : factories) {
307-
if (!factory.isAvailable() || !factory.test(sessionRequest.getCapabilities())) {
307+
if (!factory.isAvailable() || !factory.test(sessionRequest.getDesiredCapabilities())) {
308308
continue;
309309
}
310310

‎java/server/src/org/openqa/selenium/grid/node/local/SessionSlot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
134134
return Either.left(new RetrySessionRequestException("Slot is busy. Try another slot."));
135135
}
136136

137-
if (!test(sessionRequest.getCapabilities())) {
137+
if (!test(sessionRequest.getDesiredCapabilities())) {
138138
return Either.left(new SessionNotCreatedException("New session request capabilities do not "
139139
+ "match the stereotype."));
140140
}

‎java/server/src/org/openqa/selenium/grid/session/remote/ServicedSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public boolean test(Capabilities capabilities) {
154154
@Override
155155
public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
156156
Require.nonNull("Session creation request", sessionRequest);
157-
DriverService service = createService.apply(sessionRequest.getCapabilities());
157+
DriverService service = createService.apply(sessionRequest.getDesiredCapabilities());
158158

159159
try {
160160
service.start();
@@ -168,7 +168,7 @@ public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
168168
service,
169169
url,
170170
sessionRequest.getDownstreamDialects(),
171-
sessionRequest.getCapabilities());
171+
sessionRequest.getDesiredCapabilities());
172172
} catch (IOException | IllegalStateException | NullPointerException | InvalidArgumentException e) {
173173
LOG.log(Level.INFO, e.getMessage(), e);
174174
service.stop();

‎java/server/src/org/openqa/selenium/remote/server/ActiveSessionFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ public boolean test(Capabilities capabilities) {
170170

171171
@Override
172172
public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
173-
LOG.finest("Capabilities are: " + new Json().toJson(sessionRequest.getCapabilities()));
173+
LOG.finest("Capabilities are: " + new Json().toJson(sessionRequest.getDesiredCapabilities()));
174174
return factories.stream()
175-
.filter(factory -> factory.test(sessionRequest.getCapabilities()))
175+
.filter(factory -> factory.test(sessionRequest.getDesiredCapabilities()))
176176
.peek(factory -> LOG.finest(String.format("Matched factory %s", factory)))
177177
.map(factory -> factory.apply(sessionRequest))
178178
.filter(Optional::isPresent)

‎java/server/src/org/openqa/selenium/remote/server/InMemorySession.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
141141

142142
// Assume the blob fits in the available memory.
143143
try {
144-
if (!provider.canCreateDriverInstanceFor(sessionRequest.getCapabilities())) {
144+
if (!provider.canCreateDriverInstanceFor(sessionRequest.getDesiredCapabilities())) {
145145
return Optional.empty();
146146
}
147147

148-
WebDriver driver = provider.newInstance(sessionRequest.getCapabilities());
148+
WebDriver driver = provider.newInstance(sessionRequest.getDesiredCapabilities());
149149

150150
// Prefer the OSS dialect.
151151
Set<Dialect> downstreamDialects = sessionRequest.getDownstreamDialects();
152152
Dialect downstream = downstreamDialects.contains(Dialect.OSS) || downstreamDialects.isEmpty() ?
153153
Dialect.OSS :
154154
downstreamDialects.iterator().next();
155155
return Optional.of(
156-
new InMemorySession(driver, sessionRequest.getCapabilities(), downstream));
156+
new InMemorySession(driver, sessionRequest.getDesiredCapabilities(), downstream));
157157
} catch (IllegalStateException e) {
158158
return Optional.empty();
159159
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
305305
if (running != null) {
306306
return Either.left(new SessionNotCreatedException("Session already exists"));
307307
}
308-
Session session = factory.apply(sessionRequest.getCapabilities());
308+
Session session = factory.apply(sessionRequest.getDesiredCapabilities());
309309
running = session;
310310
return Either.right(
311311
new CreateSessionResponse(

‎java/server/test/org/openqa/selenium/grid/testing/TestSessionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public TestSessionFactory(Capabilities stereotype, BiFunction<SessionId, Capabil
6060
@Override
6161
public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sessionRequest) {
6262
SessionId id = new SessionId(UUID.randomUUID());
63-
Session session = sessionGenerator.apply(id, sessionRequest.getCapabilities());
63+
Session session = sessionGenerator.apply(id, sessionRequest.getDesiredCapabilities());
6464

6565
URL url;
6666
try {

0 commit comments

Comments
 (0)
Please sign in to comment.