Skip to content

Commit

Permalink
[Grid] Add support for customizing the Grid Registry
Browse files Browse the repository at this point in the history
- Make the grid registry an interface -- GridRegistry.
- Introduce BaseGridRegistry which is intended to be extended by
  GridRegistry implementations.
- Introduce DefaultGridRegistry which replaces the pre-existing
  (now deprecated) Registry class. Most of the _real_ code from Registry
  was moved to DefaultGridRegistry.
- Deprecated Registry. Replaced underlying implementation of new
  DefaultGridRegistry. Also make Registry implement GridRegistry.
  Changes here intended to ease migration and allow old
  code paths to continue to compile/work in the interim.
- Change the return type to T extends GridRegistry for some methods.
- Increase visibility of some additional methods and/or types which the
  existing DefaultGridRegistry takes advantage of -- allowing reuse.
- Add 'registryClass' arugment to '-role hub' for specifying custom
  registry implmentation on the CLASSPATH
- Update test code to use DefaultGridRegistry and GridRegistry
  • Loading branch information
mach6 committed Nov 2, 2017
1 parent 24ac288 commit 6a19886
Show file tree
Hide file tree
Showing 76 changed files with 1,118 additions and 553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"withoutServlets": [],
"custom": {},
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"registryClass": "org.openqa.grid.internal.DefaultGridRegistry",
"throwOnCapabilityNotPresent": true,
"cleanUpCycle": 5000,
"role": "hub",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* The set of active test sessions.
*/
@ThreadSafe
class ActiveTestSessions {
public class ActiveTestSessions {

private static final Logger log = Logger.getLogger(ActiveTestSessions.class.getName());

Expand Down
73 changes: 73 additions & 0 deletions java/server/src/org/openqa/grid/internal/BaseGridRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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.grid.internal;

import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.remote.internal.HttpClientFactory;

public abstract class BaseGridRegistry implements GridRegistry {
protected final HttpClientFactory httpClientFactory;
@Deprecated
protected GridHubConfiguration configuration;

// The following needs to be volatile because we expose a public setters
protected volatile Hub hub;

public BaseGridRegistry(Hub hub) {
this.httpClientFactory = new HttpClientFactory();
this.hub = hub;

this.configuration = (hub != null) ?
hub.getConfiguration() : new GridHubConfiguration();
}

/**
* @see GridRegistry#getConfiguration()
*/
@Deprecated
public GridHubConfiguration getConfiguration() {
return (hub != null) ? hub.getConfiguration() :
(configuration != null) ? configuration : new GridHubConfiguration();
}

/**
* @see GridRegistry#getHub()
*/
public Hub getHub() {
return hub;
}

/**
* @see GridRegistry#setHub(Hub)
*/
public void setHub(Hub hub) {
this.hub = hub;
if (hub != null) {
this.configuration = hub.getConfiguration();
}
}

/**
* @see GridRegistry#getHttpClientFactory()
*/
public HttpClientFactory getHttpClientFactory() {
return httpClientFactory;
}

}
27 changes: 16 additions & 11 deletions java/server/src/org/openqa/grid/internal/BaseRemoteProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import org.openqa.grid.common.exception.GridException;
import org.openqa.grid.internal.listeners.TimeoutListener;
import org.openqa.grid.internal.utils.CapabilityMatcher;
import org.openqa.grid.internal.utils.DefaultCapabilityMatcher;
import org.openqa.grid.internal.utils.DefaultHtmlRenderer;
import org.openqa.grid.internal.utils.HtmlRenderer;
import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.internal.HttpClientFactory;

import java.io.BufferedReader;
Expand Down Expand Up @@ -69,8 +69,9 @@ public class BaseRemoteProxy implements RemoteProxy {
// list of the type of test the remote can run.
private final List<TestSlot> testSlots;

private final Registry registry;
private final GridRegistry registry;

private CapabilityMatcher capabilityMatcher;

private final String id;

Expand All @@ -81,12 +82,12 @@ public List<TestSlot> getTestSlots() {
return testSlots;
}

public Registry getRegistry() {
return registry;
public <T extends GridRegistry> T getRegistry() {
return (T) registry;
}

public CapabilityMatcher getCapabilityHelper() {
return registry.getConfiguration().capabilityMatcher;
return capabilityMatcher;
}


Expand All @@ -99,12 +100,16 @@ public CapabilityMatcher getCapabilityHelper() {
* @param request The request
* @param registry The registry to use
*/
public BaseRemoteProxy(RegistrationRequest request, Registry registry) {
public BaseRemoteProxy(RegistrationRequest request, GridRegistry registry) {
this.request = request;
this.registry = registry;
this.config = new GridNodeConfiguration();
// the registry is the 'hub' configuration, which is used as a seed.
this.config.merge(registry.getConfiguration());
this.capabilityMatcher = new DefaultCapabilityMatcher();
// the registry is the 'hub' configuration, which is used as a seed for this proxy configuration
if (registry.getHub() != null) {
this.config.merge(registry.getHub().getConfiguration());
this.capabilityMatcher = registry.getHub().getConfiguration().capabilityMatcher;
}
// the proxy values must override any that the hub specify where an overlap occurs.
// merging last causes the values to be overridden.
this.config.merge(request.getConfiguration());
Expand Down Expand Up @@ -137,7 +142,7 @@ public BaseRemoteProxy(RegistrationRequest request, Registry registry) {
this.id = remoteHost.toExternalForm();
}

List<MutableCapabilities>capabilities = request.getConfiguration().capabilities;
List<MutableCapabilities> capabilities = request.getConfiguration().capabilities;

List<TestSlot> slots = new ArrayList<>();
for (MutableCapabilities capability : capabilities) {
Expand Down Expand Up @@ -336,7 +341,7 @@ public boolean isBusy() {
*/
@SuppressWarnings("unchecked")
public static <T extends RemoteProxy> T getNewInstance(
RegistrationRequest request, Registry registry) {
RegistrationRequest request, GridRegistry registry) {
try {
String proxyClass = request.getConfiguration().proxy;
if (proxyClass == null) {
Expand All @@ -346,7 +351,7 @@ public static <T extends RemoteProxy> T getNewInstance(
Class<?> clazz = Class.forName(proxyClass);
log.fine("Using class " + clazz.getName());
Object[] args = new Object[]{request, registry};
Class<?>[] argsClass = new Class[]{RegistrationRequest.class, Registry.class};
Class<?>[] argsClass = new Class[]{RegistrationRequest.class, GridRegistry.class};
Constructor<?> c = clazz.getConstructor(argsClass);
Object proxy = c.newInstance(args);
if (proxy instanceof RemoteProxy) {
Expand Down
Loading

0 comments on commit 6a19886

Please sign in to comment.