Skip to content

Commit

Permalink
Use the Node's configuration to set up the Pipeline
Browse files Browse the repository at this point in the history
This means a 3.7 Grid Node now no longer needs the Hub to
rewrite the incoming capabilities.
  • Loading branch information
shs96c committed Nov 2, 2017
1 parent 84af205 commit e66d995
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 35 deletions.
5 changes: 2 additions & 3 deletions java/server/src/org/openqa/grid/selenium/GridLauncherV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ public void setConfiguration(String[] args) {

public void launch() throws Exception {
log.info("Launching a Selenium Grid node");
RegistrationRequest
c =
RegistrationRequest.build((GridNodeConfiguration) configuration);
RegistrationRequest c =
RegistrationRequest.build((GridNodeConfiguration) configuration);
SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
remote.setRemoteServer(new SeleniumServer(c.getConfiguration()));
remote.startRemoteServer();
Expand Down
1 change: 1 addition & 0 deletions java/server/src/org/openqa/grid/selenium/node/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ java_library(
],
visibility = [
"//java/server/src/org/openqa/grid/selenium:classes",
"//java/server/src/org/openqa/selenium/remote/server:standalone-server-lib",
"//java/server/test/org/openqa/grid/selenium/node:",
],
)
2 changes: 2 additions & 0 deletions java/server/src/org/openqa/selenium/remote/server/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ java_library(
'ActiveSessions.java',
'AllHandlers.java',
'CommandHandler.java',
'DefaultPipeline.java',
'InMemorySession.java',
'NewSessionPipeline.java',
'Passthrough.java',
Expand Down Expand Up @@ -135,6 +136,7 @@ java_library(name = 'standalone-server-lib',
'//java/client/src/org/openqa/selenium/remote:remote',
'//java/client/src/org/openqa/selenium/safari:safari',
'//java/server/src/org/openqa/grid:grid',
'//java/server/src/org/openqa/grid/selenium/node:node',
'//third_party/java/beust:jcommander',
'//third_party/java/jetty:jetty',
'//third_party/java/phantomjs-driver:phantomjs-driver',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;

import org.openqa.selenium.remote.service.DriverService;

import java.util.Optional;
import java.util.logging.Logger;
import java.util.stream.Stream;

/**
* Used to represent the {@link NewSessionPipeline} that is typically used in the
* {@link SeleniumServer}}.
*/
public class DefaultPipeline {

private static final Logger LOG = Logger.getLogger(DefaultPipeline.class.getName());

private DefaultPipeline() {
// Utility class
}

public static NewSessionPipeline.Builder createPipelineWithDefaultFallbacks() {
// Set up the pipeline to inject
SessionFactory fallback = Stream.of(
"org.openqa.selenium.chrome.ChromeDriverService",
"org.openqa.selenium.firefox.GeckoDriverService",
"org.openqa.selenium.edge.EdgeDriverService",
"org.openqa.selenium.ie.InternetExplorerDriverService",
"org.openqa.selenium.safari.SafariDriverService")
.filter(name -> {
try {
Class.forName(name).asSubclass(DriverService.class);
return true;
} catch (ReflectiveOperationException e) {
return false;
}
})
.findFirst()
.map(serviceName -> {
SessionFactory factory = new ServicedSession.Factory(serviceName);
return (SessionFactory) (dialects, caps) -> {
LOG.info("Using default factory: " + serviceName);
return factory.apply(dialects, caps);
};
})
.orElse((dialects, caps) -> Optional.empty());

return NewSessionPipeline.builder()
.add(new ActiveSessionFactory())
.fallback(fallback);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@

package org.openqa.selenium.remote.server;

import static org.openqa.selenium.remote.server.WebDriverServlet.NEW_SESSION_PIPELINE_KEY;

import com.beust.jcommander.JCommander;

import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;
import org.openqa.grid.internal.utils.configuration.StandaloneConfiguration;
import org.openqa.grid.selenium.node.ChromeMutator;
import org.openqa.grid.selenium.node.FirefoxMutator;
import org.openqa.grid.shared.GridNodeServer;
import org.openqa.grid.web.servlet.DisplayHelpServlet;
import org.openqa.grid.web.servlet.beta.ConsoleServlet;
Expand Down Expand Up @@ -134,6 +139,10 @@ public void boot() {
new DefaultDriverFactory(Platform.getCurrent()),
TimeUnit.SECONDS.toMillis(inactiveSessionTimeoutSeconds));
handler.setAttribute(DriverServlet.SESSIONS_KEY, driverSessions);

NewSessionPipeline pipeline = createPipeline(configuration);
handler.setAttribute(NEW_SESSION_PIPELINE_KEY, pipeline);

handler.setContextPath("/");
if (configuration.enablePassThrough) {
LOG.info("Using the passthrough mode handler");
Expand Down Expand Up @@ -183,6 +192,22 @@ public void boot() {
}
}

private NewSessionPipeline createPipeline(StandaloneConfiguration configuration) {
NewSessionPipeline.Builder builder = DefaultPipeline.createPipelineWithDefaultFallbacks();

if (configuration instanceof GridNodeConfiguration) {
((GridNodeConfiguration) configuration).capabilities.forEach(
caps -> {
Map<String, Object> mapified = caps.asMap();
builder.addCapabilitiesMutator(new ChromeMutator(mapified));
builder.addCapabilitiesMutator(new FirefoxMutator(mapified));
}
);
}

return builder.create();
}

/**
* Stops the Jetty server
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,17 @@
import org.openqa.selenium.remote.server.log.PerSessionLogHandler;
import org.openqa.selenium.remote.server.xdrpc.CrossDomainRpc;
import org.openqa.selenium.remote.server.xdrpc.CrossDomainRpcLoader;
import org.openqa.selenium.remote.service.DriverService;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.stream.Stream;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
Expand Down Expand Up @@ -88,35 +85,7 @@ public void init() throws ServletException {
NewSessionPipeline pipeline =
(NewSessionPipeline) getServletContext().getAttribute(NEW_SESSION_PIPELINE_KEY);
if (pipeline == null) {
// Set up the pipeline to inject
SessionFactory fallback = Stream.of(
"org.openqa.selenium.chrome.ChromeDriverService",
"org.openqa.selenium.firefox.GeckoDriverService",
"org.openqa.selenium.edge.EdgeDriverService",
"org.openqa.selenium.ie.InternetExplorerDriverService",
"org.openqa.selenium.safari.SafariDriverService")
.filter(name -> {
try {
Class.forName(name).asSubclass(DriverService.class);
return true;
} catch (ReflectiveOperationException e) {
return false;
}
})
.findFirst()
.map(serviceName -> {
SessionFactory factory = new ServicedSession.Factory(serviceName);
return (SessionFactory) (dialects, caps) -> {
LOG.info("Using default factory: " + serviceName);
return factory.apply(dialects, caps);
};
})
.orElse((dialects, caps) -> Optional.empty());

pipeline = NewSessionPipeline.builder()
.add(new ActiveSessionFactory())
.fallback(fallback)
.create();
pipeline = DefaultPipeline.createPipelineWithDefaultFallbacks().create();
getServletContext().setAttribute(NEW_SESSION_PIPELINE_KEY, pipeline);
}

Expand Down

0 comments on commit e66d995

Please sign in to comment.