Skip to content

Commit e66d995

Browse files
committed
Use the Node's configuration to set up the Pipeline
This means a 3.7 Grid Node now no longer needs the Hub to rewrite the incoming capabilities.
1 parent 84af205 commit e66d995

File tree

6 files changed

+99
-35
lines changed

6 files changed

+99
-35
lines changed

java/server/src/org/openqa/grid/selenium/GridLauncherV3.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,8 @@ public void setConfiguration(String[] args) {
280280

281281
public void launch() throws Exception {
282282
log.info("Launching a Selenium Grid node");
283-
RegistrationRequest
284-
c =
285-
RegistrationRequest.build((GridNodeConfiguration) configuration);
283+
RegistrationRequest c =
284+
RegistrationRequest.build((GridNodeConfiguration) configuration);
286285
SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
287286
remote.setRemoteServer(new SeleniumServer(c.getConfiguration()));
288287
remote.startRemoteServer();

java/server/src/org/openqa/grid/selenium/node/BUCK

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ java_library(
99
],
1010
visibility = [
1111
"//java/server/src/org/openqa/grid/selenium:classes",
12+
"//java/server/src/org/openqa/selenium/remote/server:standalone-server-lib",
1213
"//java/server/test/org/openqa/grid/selenium/node:",
1314
],
1415
)

java/server/src/org/openqa/selenium/remote/server/BUCK

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ java_library(
7474
'ActiveSessions.java',
7575
'AllHandlers.java',
7676
'CommandHandler.java',
77+
'DefaultPipeline.java',
7778
'InMemorySession.java',
7879
'NewSessionPipeline.java',
7980
'Passthrough.java',
@@ -135,6 +136,7 @@ java_library(name = 'standalone-server-lib',
135136
'//java/client/src/org/openqa/selenium/remote:remote',
136137
'//java/client/src/org/openqa/selenium/safari:safari',
137138
'//java/server/src/org/openqa/grid:grid',
139+
'//java/server/src/org/openqa/grid/selenium/node:node',
138140
'//third_party/java/beust:jcommander',
139141
'//third_party/java/jetty:jetty',
140142
'//third_party/java/phantomjs-driver:phantomjs-driver',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.remote.server;
19+
20+
import org.openqa.selenium.remote.service.DriverService;
21+
22+
import java.util.Optional;
23+
import java.util.logging.Logger;
24+
import java.util.stream.Stream;
25+
26+
/**
27+
* Used to represent the {@link NewSessionPipeline} that is typically used in the
28+
* {@link SeleniumServer}}.
29+
*/
30+
public class DefaultPipeline {
31+
32+
private static final Logger LOG = Logger.getLogger(DefaultPipeline.class.getName());
33+
34+
private DefaultPipeline() {
35+
// Utility class
36+
}
37+
38+
public static NewSessionPipeline.Builder createPipelineWithDefaultFallbacks() {
39+
// Set up the pipeline to inject
40+
SessionFactory fallback = Stream.of(
41+
"org.openqa.selenium.chrome.ChromeDriverService",
42+
"org.openqa.selenium.firefox.GeckoDriverService",
43+
"org.openqa.selenium.edge.EdgeDriverService",
44+
"org.openqa.selenium.ie.InternetExplorerDriverService",
45+
"org.openqa.selenium.safari.SafariDriverService")
46+
.filter(name -> {
47+
try {
48+
Class.forName(name).asSubclass(DriverService.class);
49+
return true;
50+
} catch (ReflectiveOperationException e) {
51+
return false;
52+
}
53+
})
54+
.findFirst()
55+
.map(serviceName -> {
56+
SessionFactory factory = new ServicedSession.Factory(serviceName);
57+
return (SessionFactory) (dialects, caps) -> {
58+
LOG.info("Using default factory: " + serviceName);
59+
return factory.apply(dialects, caps);
60+
};
61+
})
62+
.orElse((dialects, caps) -> Optional.empty());
63+
64+
return NewSessionPipeline.builder()
65+
.add(new ActiveSessionFactory())
66+
.fallback(fallback);
67+
}
68+
}

java/server/src/org/openqa/selenium/remote/server/SeleniumServer.java

+25
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
package org.openqa.selenium.remote.server;
1919

20+
import static org.openqa.selenium.remote.server.WebDriverServlet.NEW_SESSION_PIPELINE_KEY;
21+
2022
import com.beust.jcommander.JCommander;
2123

24+
import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;
2225
import org.openqa.grid.internal.utils.configuration.StandaloneConfiguration;
26+
import org.openqa.grid.selenium.node.ChromeMutator;
27+
import org.openqa.grid.selenium.node.FirefoxMutator;
2328
import org.openqa.grid.shared.GridNodeServer;
2429
import org.openqa.grid.web.servlet.DisplayHelpServlet;
2530
import org.openqa.grid.web.servlet.beta.ConsoleServlet;
@@ -134,6 +139,10 @@ public void boot() {
134139
new DefaultDriverFactory(Platform.getCurrent()),
135140
TimeUnit.SECONDS.toMillis(inactiveSessionTimeoutSeconds));
136141
handler.setAttribute(DriverServlet.SESSIONS_KEY, driverSessions);
142+
143+
NewSessionPipeline pipeline = createPipeline(configuration);
144+
handler.setAttribute(NEW_SESSION_PIPELINE_KEY, pipeline);
145+
137146
handler.setContextPath("/");
138147
if (configuration.enablePassThrough) {
139148
LOG.info("Using the passthrough mode handler");
@@ -183,6 +192,22 @@ public void boot() {
183192
}
184193
}
185194

195+
private NewSessionPipeline createPipeline(StandaloneConfiguration configuration) {
196+
NewSessionPipeline.Builder builder = DefaultPipeline.createPipelineWithDefaultFallbacks();
197+
198+
if (configuration instanceof GridNodeConfiguration) {
199+
((GridNodeConfiguration) configuration).capabilities.forEach(
200+
caps -> {
201+
Map<String, Object> mapified = caps.asMap();
202+
builder.addCapabilitiesMutator(new ChromeMutator(mapified));
203+
builder.addCapabilitiesMutator(new FirefoxMutator(mapified));
204+
}
205+
);
206+
}
207+
208+
return builder.create();
209+
}
210+
186211
/**
187212
* Stops the Jetty server
188213
*/

java/server/src/org/openqa/selenium/remote/server/WebDriverServlet.java

+1-32
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,17 @@
3434
import org.openqa.selenium.remote.server.log.PerSessionLogHandler;
3535
import org.openqa.selenium.remote.server.xdrpc.CrossDomainRpc;
3636
import org.openqa.selenium.remote.server.xdrpc.CrossDomainRpcLoader;
37-
import org.openqa.selenium.remote.service.DriverService;
3837

3938
import java.io.ByteArrayInputStream;
4039
import java.io.IOException;
4140
import java.util.List;
42-
import java.util.Optional;
4341
import java.util.concurrent.ExecutionException;
4442
import java.util.concurrent.ExecutorService;
4543
import java.util.concurrent.Executors;
4644
import java.util.concurrent.Future;
4745
import java.util.concurrent.TimeoutException;
4846
import java.util.logging.Handler;
4947
import java.util.logging.Logger;
50-
import java.util.stream.Stream;
5148

5249
import javax.servlet.ServletException;
5350
import javax.servlet.ServletInputStream;
@@ -88,35 +85,7 @@ public void init() throws ServletException {
8885
NewSessionPipeline pipeline =
8986
(NewSessionPipeline) getServletContext().getAttribute(NEW_SESSION_PIPELINE_KEY);
9087
if (pipeline == null) {
91-
// Set up the pipeline to inject
92-
SessionFactory fallback = Stream.of(
93-
"org.openqa.selenium.chrome.ChromeDriverService",
94-
"org.openqa.selenium.firefox.GeckoDriverService",
95-
"org.openqa.selenium.edge.EdgeDriverService",
96-
"org.openqa.selenium.ie.InternetExplorerDriverService",
97-
"org.openqa.selenium.safari.SafariDriverService")
98-
.filter(name -> {
99-
try {
100-
Class.forName(name).asSubclass(DriverService.class);
101-
return true;
102-
} catch (ReflectiveOperationException e) {
103-
return false;
104-
}
105-
})
106-
.findFirst()
107-
.map(serviceName -> {
108-
SessionFactory factory = new ServicedSession.Factory(serviceName);
109-
return (SessionFactory) (dialects, caps) -> {
110-
LOG.info("Using default factory: " + serviceName);
111-
return factory.apply(dialects, caps);
112-
};
113-
})
114-
.orElse((dialects, caps) -> Optional.empty());
115-
116-
pipeline = NewSessionPipeline.builder()
117-
.add(new ActiveSessionFactory())
118-
.fallback(fallback)
119-
.create();
88+
pipeline = DefaultPipeline.createPipelineWithDefaultFallbacks().create();
12089
getServletContext().setAttribute(NEW_SESSION_PIPELINE_KEY, pipeline);
12190
}
12291

0 commit comments

Comments
 (0)