Skip to content

Commit

Permalink
Refactoring node registration request initialization, fixup-methods m…
Browse files Browse the repository at this point in the history
…oved to GridNodeConfiguration class, because they fix up objects of this class.
  • Loading branch information
barancev committed Nov 10, 2017
1 parent 8077cc3 commit 39e7e8b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ public static RegistrationRequest build(GridNodeConfiguration configuration, Str
}

// make sure we have a valid host
pendingRequest.fixUpHost();
pendingRequest.configuration.fixUpHost();
// make sure the capabilities are updated with required fields
pendingRequest.fixUpCapabilities();
pendingRequest.configuration.fixUpCapabilities();

return pendingRequest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class SelfRegisteringRemote {

private boolean hasId;

public SelfRegisteringRemote(GridNodeConfiguration configuration) {
this(RegistrationRequest.build(configuration));
}

public SelfRegisteringRemote(RegistrationRequest request) {
this.registrationRequest = request;
this.httpClientFactory = new HttpClientFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@
import com.beust.jcommander.Parameter;

import org.openqa.grid.common.JSONConfigurationUtils;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.common.exception.GridConfigurationException;
import org.openqa.grid.internal.utils.configuration.converters.BrowserDesiredCapabilityConverter;
import org.openqa.grid.internal.utils.configuration.converters.NoOpParameterSplitter;
import org.openqa.grid.internal.utils.configuration.validators.FileExistsValueValidator;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.lang.reflect.Type;
Expand Down Expand Up @@ -501,4 +506,29 @@ public List<MutableCapabilities> deserialize(JsonElement jsonElement, Type type,
throw new JsonParseException("capabilities should be expressed as an array of objects.");
}
}

public void fixUpCapabilities() {
if (capabilities == null) {
return; // assumes the caller set it/wants it this way
}

Platform current = Platform.getCurrent();
for (MutableCapabilities cap : capabilities) {
if (cap.getPlatform() == null) {
cap.setCapability(CapabilityType.PLATFORM, current);
}
if (cap.getCapability(RegistrationRequest.SELENIUM_PROTOCOL) == null) {
cap.setCapability(RegistrationRequest.SELENIUM_PROTOCOL, SeleniumProtocol.WebDriver.toString());
}
}
}

public void fixUpHost() {
NetworkUtils util = new NetworkUtils();
if (host == null || "ip".equalsIgnoreCase(host)) {
host = util.getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
} else if ("host".equalsIgnoreCase(host)) {
host = util.getIp4NonLoopbackAddressOfThisMachine().getHostName();
}
}
}
7 changes: 2 additions & 5 deletions java/server/src/org/openqa/grid/selenium/GridLauncherV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.beust.jcommander.JCommander;

import org.openqa.grid.common.GridRole;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.internal.utils.configuration.CoreRunnerConfiguration;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
Expand Down Expand Up @@ -286,10 +285,8 @@ public void setConfiguration(String[] args) {

public void launch() throws Exception {
log.info("Launching a Selenium Grid node");
RegistrationRequest c =
RegistrationRequest.build(configuration);
SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
remote.setRemoteServer(new SeleniumServer(c.getConfiguration()));
SelfRegisteringRemote remote = new SelfRegisteringRemote(configuration);
remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
remote.startRemoteServer();
log.info("Selenium Grid node is up and ready to register to the hub");
remote.startRegistrationProcess();
Expand Down

0 comments on commit 39e7e8b

Please sign in to comment.