Skip to content

Commit 785981a

Browse files
committed
server: Improving grid node reporting to the console
1 parent 2f48140 commit 785981a

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Diff for: java/server/src/org/openqa/grid/internal/utils/SelfRegisteringRemote.java

+22-14
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@
5353
import java.util.Arrays;
5454
import java.util.List;
5555
import java.util.Map;
56+
import java.util.logging.Level;
5657
import java.util.logging.Logger;
5758

5859
import javax.servlet.Servlet;
5960

6061
public class SelfRegisteringRemote {
6162

62-
private static final Logger log = Logger.getLogger(SelfRegisteringRemote.class.getName());
63+
private static final Logger LOG = Logger.getLogger(SelfRegisteringRemote.class.getName());
6364

6465
private RegistrationRequest nodeConfig;
6566

@@ -105,7 +106,9 @@ public void startRemoteServer() throws Exception {
105106
remoteControlConfiguration.setBrowserTimeoutInMs(browserTimeout);
106107
}
107108
}catch (Exception e) {
108-
log.warning("error getting the parameters from the hub. The node may end up with wrong timeouts."+e.getMessage());
109+
LOG.warning(
110+
"error getting the parameters from the hub. The node may end up with wrong timeouts." + e
111+
.getMessage());
109112
}
110113

111114
server = new SeleniumServer(remoteControlConfiguration);
@@ -128,8 +131,8 @@ public void startRemoteServer() throws Exception {
128131
String path = "/" + servletClass.getSimpleName() + "/*";
129132
String clazz = servletClass.getCanonicalName();
130133
handler.addServlet(path, clazz);
131-
log.info("started extra node servlet visible at : http://xxx:"
132-
+ nodeConfig.getConfiguration().get(RegistrationRequest.PORT) + "/extra" + path);
134+
LOG.info("started extra node servlet visible at : http://xxx:"
135+
+ nodeConfig.getConfiguration().get(RegistrationRequest.PORT) + "/extra" + path);
133136
}
134137
}
135138
extra.addHandler(handler);
@@ -184,20 +187,21 @@ public void sendRegistrationRequest() {
184187
* - register again every X ms is specified in the config of the node.
185188
*/
186189
public void startRegistrationProcess() {
187-
log.info("using the json request : " + nodeConfig.toJSON());
190+
LOG.info("Using the json request : " + nodeConfig.toJSON());
188191

189192
Boolean register = (Boolean) nodeConfig.getConfiguration().get(AUTO_REGISTER);
190193

191194
if (!register) {
192-
log.info("no registration sent ( " + AUTO_REGISTER + " = false )");
195+
LOG.info("No registration sent ( " + AUTO_REGISTER + " = false )");
193196
} else {
194197
final int registerCycleInterval = nodeConfig.getConfigAsInt(RegistrationRequest.REGISTER_CYCLE, 0);
195198
if (registerCycleInterval > 0) {
196199
new Thread(new Runnable() { // Thread safety reviewed
197200

198201
public void run() {
199202
boolean first = true;
200-
log.info("Starting auto register thread. Will try to register every " + registerCycleInterval + " ms.");
203+
LOG.info("Starting auto register thread. Will try to register every "
204+
+ registerCycleInterval + " ms.");
201205
while (true) {
202206
try {
203207
boolean checkForPresence = true;
@@ -207,7 +211,7 @@ public void run() {
207211
}
208212
registerToHub(checkForPresence);
209213
} catch (GridException e) {
210-
log.info("couldn't register this node : " + e.getMessage());
214+
LOG.info("Couldn't register this node: " + e.getMessage());
211215
}
212216
try {
213217
Thread.sleep(registerCycleInterval);
@@ -248,7 +252,7 @@ private void registerToHub(boolean checkPresenceFirst) {
248252
HttpClient client = httpClientFactory.getHttpClient();
249253
try {
250254
URL registration = new URL(tmp);
251-
log.info("Registering the node to hub :" + registration);
255+
LOG.info("Registering the node to hub: " + registration);
252256

253257
BasicHttpEntityEnclosingRequest r =
254258
new BasicHttpEntityEnclosingRequest("POST", registration.toExternalForm());
@@ -258,13 +262,15 @@ private void registerToHub(boolean checkPresenceFirst) {
258262
HttpHost host = new HttpHost(registration.getHost(), registration.getPort());
259263
HttpResponse response = client.execute(host, r);
260264
if (response.getStatusLine().getStatusCode() != 200) {
261-
throw new RuntimeException("Error sending the registration request.");
265+
throw new RuntimeException(String.format("The hub responded with %s:%s",
266+
response.getStatusLine().getStatusCode(),
267+
response.getStatusLine().getReasonPhrase()));
262268
}
263269
} catch (Exception e) {
264-
throw new GridException("Error sending the registration request.", e);
270+
throw new GridException("Error sending the registration request: " + e.getMessage());
265271
}
266272
} else {
267-
log.fine("The node is already present on the hub. Skipping registration.");
273+
LOG.fine("The node is already present on the hub. Skipping registration.");
268274
}
269275

270276
}
@@ -312,12 +318,14 @@ private boolean isAlreadyRegistered(RegistrationRequest node) {
312318

313319
HttpResponse response = client.execute(host, r);
314320
if (response.getStatusLine().getStatusCode() != 200) {
315-
throw new GridException("Hub is down or not responding.");
321+
throw new GridException(String.format("The hub responded with %s:%s",
322+
response.getStatusLine().getStatusCode(),
323+
response.getStatusLine().getReasonPhrase()));
316324
}
317325
JsonObject o = extractObject(response);
318326
return o.get("success").getAsBoolean();
319327
} catch (Exception e) {
320-
throw new GridException("Hub is down or not responding: " + e.getMessage());
328+
throw new GridException("The hub is down or not responding: " + e.getMessage());
321329
}
322330
}
323331

0 commit comments

Comments
 (0)