Skip to content

Commit d097bae

Browse files
committed
[grid] Improving platform matching
This will allow users to match requests that specify a platform family (like WINDOWS) and the Node has WIN10. Fixes partially #9318
1 parent 627c0de commit d097bae

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

java/server/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public boolean matches(Capabilities stereotype, Capabilities capabilities) {
4949
Boolean initialMatch = stereotype.getCapabilityNames().stream()
5050
// Matching of extension capabilities is implementation independent. Skip them
5151
.filter(name -> !name.contains(":"))
52+
// Platform matching is special, we do it below
53+
.filter(name -> !"platform".equalsIgnoreCase(name) && !"platformName".equalsIgnoreCase(name))
5254
.map(name -> {
5355
Object value = capabilities.getCapability(name);
5456
boolean matches;
@@ -75,7 +77,9 @@ public boolean matches(Capabilities stereotype, Capabilities capabilities) {
7577
Objects.equals(stereotype.getBrowserVersion(), capabilities.getBrowserVersion());
7678
boolean platformNameMatch =
7779
capabilities.getPlatformName() == null ||
78-
Objects.equals(stereotype.getPlatformName(), capabilities.getPlatformName());
80+
Objects.equals(stereotype.getPlatformName(), capabilities.getPlatformName()) ||
81+
(stereotype.getPlatformName() != null &&
82+
stereotype.getPlatformName().is(capabilities.getPlatformName()));
7983
return browserNameMatch && browserVersionMatch && platformNameMatch;
8084
}
8185
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@
1717

1818
package org.openqa.selenium.grid.node.local;
1919

20-
import static com.google.common.collect.ImmutableSet.toImmutableSet;
21-
import static org.openqa.selenium.grid.data.Availability.DRAINING;
22-
import static org.openqa.selenium.grid.data.Availability.UP;
23-
import static org.openqa.selenium.grid.node.CapabilityResponseEncoder.getEncoder;
24-
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
25-
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
26-
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
27-
import static org.openqa.selenium.remote.http.Contents.asJson;
28-
import static org.openqa.selenium.remote.http.Contents.string;
29-
import static org.openqa.selenium.remote.http.HttpMethod.DELETE;
30-
3120
import com.google.common.annotations.VisibleForTesting;
3221
import com.google.common.base.Ticker;
3322
import com.google.common.cache.Cache;
@@ -50,9 +39,9 @@
5039
import org.openqa.selenium.grid.data.NodeAddedEvent;
5140
import org.openqa.selenium.grid.data.NodeDrainComplete;
5241
import org.openqa.selenium.grid.data.NodeDrainStarted;
42+
import org.openqa.selenium.grid.data.NodeHeartBeatEvent;
5343
import org.openqa.selenium.grid.data.NodeId;
5444
import org.openqa.selenium.grid.data.NodeStatus;
55-
import org.openqa.selenium.grid.data.NodeHeartBeatEvent;
5645
import org.openqa.selenium.grid.data.Session;
5746
import org.openqa.selenium.grid.data.SessionClosedEvent;
5847
import org.openqa.selenium.grid.data.Slot;
@@ -101,6 +90,17 @@
10190
import java.util.logging.Logger;
10291
import java.util.stream.Collectors;
10392

93+
import static com.google.common.collect.ImmutableSet.toImmutableSet;
94+
import static org.openqa.selenium.grid.data.Availability.DRAINING;
95+
import static org.openqa.selenium.grid.data.Availability.UP;
96+
import static org.openqa.selenium.grid.node.CapabilityResponseEncoder.getEncoder;
97+
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
98+
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
99+
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
100+
import static org.openqa.selenium.remote.http.Contents.asJson;
101+
import static org.openqa.selenium.remote.http.Contents.string;
102+
import static org.openqa.selenium.remote.http.HttpMethod.DELETE;
103+
104104
@ManagedService(objectName = "org.seleniumhq.grid:type=Node,name=LocalNode",
105105
description = "Node running the webdriver sessions.")
106106
public class LocalNode extends Node {
@@ -317,9 +317,9 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
317317
if (slotToUse == null) {
318318
span.setAttribute("error", true);
319319
span.setStatus(Status.NOT_FOUND);
320-
span.addEvent("No slot matched the requested capabilities. All slots are busy.", attributeMap);
320+
span.addEvent("No slot matched the requested capabilities. ", attributeMap);
321321
return Either.left(
322-
new RetrySessionRequestException("No slot matched the requested capabilities. All slots are busy."));
322+
new RetrySessionRequestException("No slot matched the requested capabilities."));
323323
}
324324

325325
Either<WebDriverException, ActiveSession> possibleSession = slotToUse.apply(sessionRequest);

0 commit comments

Comments
 (0)