Skip to content

Commit

Permalink
[grid] Improving platform matching
Browse files Browse the repository at this point in the history
This will allow users to match requests
that specify a platform family (like
WINDOWS) and the Node has WIN10.

Fixes partially #9318
  • Loading branch information
diemol committed Mar 26, 2021
1 parent 627c0de commit d097bae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public boolean matches(Capabilities stereotype, Capabilities capabilities) {
Boolean initialMatch = stereotype.getCapabilityNames().stream()
// Matching of extension capabilities is implementation independent. Skip them
.filter(name -> !name.contains(":"))
// Platform matching is special, we do it below
.filter(name -> !"platform".equalsIgnoreCase(name) && !"platformName".equalsIgnoreCase(name))
.map(name -> {
Object value = capabilities.getCapability(name);
boolean matches;
Expand All @@ -75,7 +77,9 @@ public boolean matches(Capabilities stereotype, Capabilities capabilities) {
Objects.equals(stereotype.getBrowserVersion(), capabilities.getBrowserVersion());
boolean platformNameMatch =
capabilities.getPlatformName() == null ||
Objects.equals(stereotype.getPlatformName(), capabilities.getPlatformName());
Objects.equals(stereotype.getPlatformName(), capabilities.getPlatformName()) ||
(stereotype.getPlatformName() != null &&
stereotype.getPlatformName().is(capabilities.getPlatformName()));
return browserNameMatch && browserVersionMatch && platformNameMatch;
}
}
28 changes: 14 additions & 14 deletions java/server/src/org/openqa/selenium/grid/node/local/LocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@

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

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static org.openqa.selenium.grid.data.Availability.DRAINING;
import static org.openqa.selenium.grid.data.Availability.UP;
import static org.openqa.selenium.grid.node.CapabilityResponseEncoder.getEncoder;
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
import static org.openqa.selenium.remote.http.Contents.asJson;
import static org.openqa.selenium.remote.http.Contents.string;
import static org.openqa.selenium.remote.http.HttpMethod.DELETE;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ticker;
import com.google.common.cache.Cache;
Expand All @@ -50,9 +39,9 @@
import org.openqa.selenium.grid.data.NodeAddedEvent;
import org.openqa.selenium.grid.data.NodeDrainComplete;
import org.openqa.selenium.grid.data.NodeDrainStarted;
import org.openqa.selenium.grid.data.NodeHeartBeatEvent;
import org.openqa.selenium.grid.data.NodeId;
import org.openqa.selenium.grid.data.NodeStatus;
import org.openqa.selenium.grid.data.NodeHeartBeatEvent;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.grid.data.SessionClosedEvent;
import org.openqa.selenium.grid.data.Slot;
Expand Down Expand Up @@ -101,6 +90,17 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static org.openqa.selenium.grid.data.Availability.DRAINING;
import static org.openqa.selenium.grid.data.Availability.UP;
import static org.openqa.selenium.grid.node.CapabilityResponseEncoder.getEncoder;
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
import static org.openqa.selenium.remote.http.Contents.asJson;
import static org.openqa.selenium.remote.http.Contents.string;
import static org.openqa.selenium.remote.http.HttpMethod.DELETE;

@ManagedService(objectName = "org.seleniumhq.grid:type=Node,name=LocalNode",
description = "Node running the webdriver sessions.")
public class LocalNode extends Node {
Expand Down Expand Up @@ -317,9 +317,9 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
if (slotToUse == null) {
span.setAttribute("error", true);
span.setStatus(Status.NOT_FOUND);
span.addEvent("No slot matched the requested capabilities. All slots are busy.", attributeMap);
span.addEvent("No slot matched the requested capabilities. ", attributeMap);
return Either.left(
new RetrySessionRequestException("No slot matched the requested capabilities. All slots are busy."));
new RetrySessionRequestException("No slot matched the requested capabilities."));
}

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

0 comments on commit d097bae

Please sign in to comment.