-
-
Save freynaud/1357735 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Eclipse Workspace Patch 1.0 | |
#P selenium | |
Index: java/server/src/org/openqa/grid/common/RegistrationRequest.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/RegistrationRequest.java (revision 14688) | |
+++ java/server/src/org/openqa/grid/common/RegistrationRequest.java (working copy) | |
@@ -33,6 +33,7 @@ | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import org.openqa.grid.common.exception.GridConfigurationException; | |
+import org.openqa.grid.common.exception.GridException; | |
import org.openqa.selenium.net.NetworkUtils; | |
import org.openqa.selenium.remote.CapabilityType; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
@@ -57,8 +58,7 @@ | |
private String[] args; | |
private String nodeJSON; | |
- private static final Logger log = Logger | |
- .getLogger(RegistrationRequest.class.getName()); | |
+ private static final Logger log = Logger.getLogger(RegistrationRequest.class.getName()); | |
// some special param for capability | |
public static final String APP = "applicationName"; | |
@@ -167,8 +167,7 @@ | |
} | |
res.put("capabilities", caps); | |
} catch (JSONException e) { | |
- throw new RuntimeException("Error encoding to JSON " | |
- + e.getMessage(), e); | |
+ throw new RuntimeException("Error encoding to JSON " + e.getMessage(), e); | |
} | |
return res; | |
@@ -191,9 +190,7 @@ | |
try { | |
return Integer.parseInt(o.toString()); | |
} catch (Throwable t) { | |
- log.warning("Error." + name | |
- + " is supposed to be an int. Keeping default of " | |
- + defaultValue); | |
+ log.warning("Error." + name + " is supposed to be an int. Keeping default of " + defaultValue); | |
return defaultValue; | |
} | |
@@ -212,12 +209,9 @@ | |
try { | |
JSONObject o = new JSONObject(json); | |
- if (o.has("id")) | |
- request.setId(o.getString("id")); | |
- if (o.has("name")) | |
- request.setName(o.getString("name")); | |
- if (o.has("description")) | |
- request.setDescription(o.getString("description")); | |
+ if (o.has("id")) request.setId(o.getString("id")); | |
+ if (o.has("name")) request.setName(o.getString("name")); | |
+ if (o.has("description")) request.setDescription(o.getString("description")); | |
JSONObject config = o.getJSONObject("configuration"); | |
Map<String, Object> configuration = Maps.newHashMap(); | |
@@ -232,13 +226,13 @@ | |
for (int i = 0; i < capabilities.length(); i++) { | |
JSONObject capability = capabilities.getJSONObject(i); | |
DesiredCapabilities cap = new DesiredCapabilities(); | |
- for (Iterator<String> iterator = capability.keys(); iterator | |
- .hasNext();) { | |
+ for (Iterator<String> iterator = capability.keys(); iterator.hasNext();) { | |
String key = iterator.next(); | |
cap.setCapability(key, capability.get(key)); | |
} | |
request.capabilities.add(cap); | |
} | |
+ request.ensureBackwardCompatibility(); | |
return request; | |
} catch (JSONException e) { | |
// Check if it was a Selenium Grid 1.0 request. | |
@@ -278,32 +272,28 @@ | |
registrationInfo.put(URLDecoder.decode(configItem[0], "UTF-8"), | |
URLDecoder.decode(configItem[1], "UTF-8")); | |
} catch (UnsupportedEncodingException e) { | |
- log.warning(String.format( | |
- "Unable to decode registration request portion: %s", | |
- part)); | |
+ log.warning(String.format("Unable to decode registration request portion: %s", part)); | |
} | |
} | |
// Now validate the query string. | |
- if ((registrationInfo.get("port") != null) | |
- && (registrationInfo.get("environment") != null)) { | |
+ if ((registrationInfo.get("port") != null) && (registrationInfo.get("environment") != null)) { | |
RegistrationRequest request = new RegistrationRequest(); | |
Map<String, Object> configuration = Maps.newHashMap(); | |
- configuration.put(SELENIUM_PROTOCOL,SeleniumProtocol.Selenium.toString()); | |
+ configuration.put(SELENIUM_PROTOCOL, SeleniumProtocol.Selenium.toString()); | |
configuration | |
- .put(REMOTE_HOST, String.format( | |
- "http://%s:%s", | |
- registrationInfo.get("host"), | |
- registrationInfo.get("port"))); | |
+ .put( | |
+ REMOTE_HOST, | |
+ String.format("http://%s:%s", registrationInfo.get("host"), | |
+ registrationInfo.get("port"))); | |
request.setConfiguration(configuration); | |
DesiredCapabilities cap = new DesiredCapabilities(); | |
// cap.put(CapabilityType.PLATFORM, "LINUX"); | |
// TODO freynaud envt or browser ? | |
cap.setCapability(BROWSER, registrationInfo.get("environment")); | |
- cap.setCapability("environment", | |
- registrationInfo.get("environment")); | |
+ cap.setCapability("environment", registrationInfo.get("environment")); | |
request.capabilities.add(cap); | |
return request; | |
@@ -318,6 +308,52 @@ | |
return res; | |
} | |
+ /** | |
+ * fixing a backward compatibility issue causing #2738 After 2.9 release, the remoteProxy for a | |
+ * node changed for 2 type of nodes to single node answering both sel1 and webdriver protocol. | |
+ * <p> | |
+ * That means the hub now need to handle registration request containing | |
+ * "url":"http://ip:port/selenium-server/driver" ( 2.9- , RC ),"url":"http://ip:port/wd/hub" | |
+ * (2.9-, wb) | |
+ * <p> | |
+ * and "remoteHost":"http://ip:port" ( 2.9 ). | |
+ * | |
+ * The pre 2.9 registration requests need to be updated and take the "url" config param and | |
+ * generate the "remoteHost" out of it. | |
+ */ | |
+ | |
+ // TODO freynaud : remove that when 2.9- nodes are history. | |
+ | |
+ private void ensureBackwardCompatibility() { | |
+ // new param after 2.9 | |
+ String url = (String) configuration.get(REMOTE_HOST); | |
+ | |
+ if (url != null) { | |
+ return; | |
+ } else { | |
+ // could be a pre 2.9 node | |
+ url = (String) configuration.get("url"); | |
+ if (url == null) { | |
+ return; | |
+ } else { | |
+ // was a legacy RC node. Needs to set that on the capabilities, as webdriver is the default. | |
+ if (url.contains("selenium-server/driver")) { | |
+ for (DesiredCapabilities capability : capabilities) { | |
+ capability.setCapability(SELENIUM_PROTOCOL, SeleniumProtocol.Selenium); | |
+ } | |
+ } | |
+ URL tmp; | |
+ try { | |
+ tmp = new URL(url); | |
+ } catch (MalformedURLException e) { | |
+ throw new GridException("specified URL for the node isn't valid :" + url); | |
+ } | |
+ configuration.put(REMOTE_HOST, "http://" + tmp.getHost() + ":" + tmp.getPort()); | |
+ } | |
+ } | |
+ } | |
+ | |
+ | |
public static RegistrationRequest build(String... args) { | |
RegistrationRequest res = new RegistrationRequest(); | |
res.args = args; | |
@@ -325,27 +361,27 @@ | |
CommandLineOptionHelper helper = new CommandLineOptionHelper(args); | |
res.role = GridRole.find(args); | |
- | |
- | |
+ | |
+ | |
String defaultConfig = "defaults/DefaultNode.json"; | |
String nodeType = helper.getParamValue("-role"); | |
- if (GridRole.RCAliases().contains(nodeType)){ | |
+ if (GridRole.RCAliases().contains(nodeType)) { | |
defaultConfig = "defaults/DefaultNodeSelenium.json"; | |
} | |
- if (GridRole.WDAliases().contains(nodeType)){ | |
+ if (GridRole.WDAliases().contains(nodeType)) { | |
defaultConfig = "defaults/DefaultNodeWebDriver.json"; | |
} | |
- | |
- | |
+ | |
+ | |
res.loadFromJSON(defaultConfig); | |
- // -file *.json ? | |
+ // -file *.json ? | |
if (helper.isParamPresent("-nodeConfig")) { | |
String value = helper.getParamValue("-nodeConfig"); | |
res.nodeJSON = value; | |
res.loadFromJSON(value); | |
} | |
- | |
+ | |
// from command line | |
res.loadFromCommandLine(args); | |
@@ -360,8 +396,8 @@ | |
res.configuration.put(HOST, guessedHost); | |
} | |
- | |
+ | |
// some values can be calculated. | |
if (res.configuration.get(REMOTE_HOST) == null) { | |
String url = "http://" + res.configuration.get(HOST) + ":" + res.configuration.get(PORT); | |
@@ -401,33 +437,26 @@ | |
configuration.put(HUB_HOST, helper.getParamValue("-hubHost")); | |
} | |
if (helper.isParamPresent("-" + HUB_PORT)) { | |
- configuration.put(HUB_PORT, | |
- Integer.parseInt(helper.getParamValue("-" + HUB_PORT))); | |
+ configuration.put(HUB_PORT, Integer.parseInt(helper.getParamValue("-" + HUB_PORT))); | |
} | |
if (helper.isParamPresent("-host")) { | |
configuration.put(HOST, helper.getParamValue("-host")); | |
} | |
if (helper.isParamPresent("-port")) { | |
- configuration.put(PORT, | |
- Integer.parseInt(helper.getParamValue("-port"))); | |
+ configuration.put(PORT, Integer.parseInt(helper.getParamValue("-port"))); | |
} | |
if (helper.isParamPresent("-cleanUpCycle")) { | |
- configuration.put(CLEAN_UP_CYCLE, | |
- Integer.parseInt(helper.getParamValue("-cleanUpCycle"))); | |
+ configuration.put(CLEAN_UP_CYCLE, Integer.parseInt(helper.getParamValue("-cleanUpCycle"))); | |
} | |
if (helper.isParamPresent("-timeout")) { | |
- configuration.put(TIME_OUT, | |
- Integer.parseInt(helper.getParamValue("-timeout"))); | |
+ configuration.put(TIME_OUT, Integer.parseInt(helper.getParamValue("-timeout"))); | |
} | |
if (helper.isParamPresent("-maxSession")) { | |
- configuration.put(MAX_SESSION, | |
- Integer.parseInt(helper.getParamValue("-maxSession"))); | |
+ configuration.put(MAX_SESSION, Integer.parseInt(helper.getParamValue("-maxSession"))); | |
} | |
if (helper.isParamPresent("-" + AUTO_REGISTER)) { | |
- configuration.put( | |
- AUTO_REGISTER, | |
- Boolean.parseBoolean(helper.getParamValue("-" | |
- + AUTO_REGISTER))); | |
+ configuration.put(AUTO_REGISTER, | |
+ Boolean.parseBoolean(helper.getParamValue("-" + AUTO_REGISTER))); | |
} | |
if (helper.isParamPresent("-servlets")) { | |
@@ -451,16 +480,13 @@ | |
System.out.println("adding " + capability); | |
String[] s = capability.split(","); | |
if (s.length == 0) { | |
- throw new GridConfigurationException( | |
- "-browser must be followed by a browser description"); | |
+ throw new GridConfigurationException("-browser must be followed by a browser description"); | |
} | |
DesiredCapabilities res = new DesiredCapabilities(); | |
for (String capabilityPair : s) { | |
if (capabilityPair.split("=").length != 2) { | |
- throw new GridConfigurationException( | |
- "-browser format is key1=value1,key2=value2 " | |
- + capabilityPair | |
- + " deosn't follow that format."); | |
+ throw new GridConfigurationException("-browser format is key1=value1,key2=value2 " | |
+ + capabilityPair + " deosn't follow that format."); | |
} | |
String key = capabilityPair.split("=")[0]; | |
String value = capabilityPair.split("=")[1]; | |
@@ -487,8 +513,7 @@ | |
res.put("configuration", new JSONObject(configuration)); | |
return res; | |
} catch (JSONException e) { | |
- throw new GridConfigurationException( | |
- "error generating the node config : " + e.getMessage()); | |
+ throw new GridConfigurationException("error generating the node config : " + e.getMessage()); | |
} | |
} | |
@@ -533,8 +558,8 @@ | |
} | |
} catch (Throwable e) { | |
- throw new GridConfigurationException( | |
- "Error with the JSON of the config : " + e.getMessage(), e); | |
+ throw new GridConfigurationException("Error with the JSON of the config : " + e.getMessage(), | |
+ e); | |
} | |
} | |
@@ -551,12 +576,11 @@ | |
for (String key : configuration.keySet()) { | |
params.add("-" + key); | |
- if (! configuration.get(key).toString().trim().isEmpty()) { | |
+ if (!configuration.get(key).toString().trim().isEmpty()) { | |
params.add("" + configuration.get(key)); | |
} | |
} | |
- return RemoteControlLauncher.parseLauncherOptions(params | |
- .toArray(new String[params.size()])); | |
+ return RemoteControlLauncher.parseLauncherOptions(params.toArray(new String[params.size()])); | |
} | |
public String[] getArgs() { | |
@@ -572,11 +596,9 @@ | |
String hub = (String) configuration.get(HUB_HOST); | |
Integer port = (Integer) configuration.get(HUB_PORT); | |
if (hub == null || port == null) { | |
- throw new GridConfigurationException( | |
- "You need to specify a hub to register to using -" | |
- + HUB_HOST + " X -" + HUB_PORT | |
- + " 5555. The specified config was -" + HUB_HOST | |
- + " " + hub + " -" + HUB_PORT + " " + port); | |
+ throw new GridConfigurationException("You need to specify a hub to register to using -" | |
+ + HUB_HOST + " X -" + HUB_PORT + " 5555. The specified config was -" + HUB_HOST + " " | |
+ + hub + " -" + HUB_PORT + " " + port); | |
} | |
} | |
Index: java/server/src/org/openqa/grid/web/servlet/ProxyStatusServlet.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/web/servlet/ProxyStatusServlet.java (revision 14628) | |
+++ java/server/src/org/openqa/grid/web/servlet/ProxyStatusServlet.java (working copy) | |
@@ -17,16 +17,12 @@ | |
package org.openqa.grid.web.servlet; | |
-import org.json.JSONException; | |
-import org.json.JSONObject; | |
-import org.openqa.grid.common.exception.GridException; | |
-import org.openqa.grid.internal.Registry; | |
-import org.openqa.grid.internal.RemoteProxy; | |
- | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.lang.reflect.Method; | |
+import java.net.MalformedURLException; | |
+import java.net.URL; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
@@ -35,6 +31,12 @@ | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
+import org.json.JSONException; | |
+import org.json.JSONObject; | |
+import org.openqa.grid.common.exception.GridException; | |
+import org.openqa.grid.internal.Registry; | |
+import org.openqa.grid.internal.RemoteProxy; | |
+ | |
public class ProxyStatusServlet extends RegistryBasedServlet { | |
private static final long serialVersionUID = 7653463271803124556L; | |
@@ -107,6 +109,11 @@ | |
id = requestJSON.getString("id"); | |
} | |
} | |
+ // see RegistrationRequest.ensureBackwardCompatibility() | |
+ try { | |
+ URL u = new URL(id); | |
+ id = "http://" + u.getHost() + ":" + u.getPort(); | |
+ } catch (MalformedURLException ignore) {} | |
// id is defined from here. | |
RemoteProxy proxy = getRegistry().getProxyById(id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment