Skip to content

Commit 40cfd59

Browse files
committed
server: Making selenium server/hub/node start/registration/unregistration messages less noisy and more informative
1 parent 79a755c commit 40cfd59

File tree

6 files changed

+74
-63
lines changed

6 files changed

+74
-63
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public int compareTo(RemoteProxy o) {
479479

480480
@Override
481481
public String toString() {
482-
return "host :" + getRemoteHost();
482+
return getRemoteHost().toString();
483483
}
484484

485485
private final HtmlRenderer renderer = new DefaultHtmlRenderer(this);

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
public class Registry {
5050

5151
public static final String KEY = Registry.class.getName();
52-
private static final Logger log = Logger.getLogger(Registry.class.getName());
52+
private static final Logger LOG = Logger.getLogger(Registry.class.getName());
5353

5454
// lock for anything modifying the tests session currently running on this
5555
// registry.
@@ -173,8 +173,8 @@ public void removeIfPresent(RemoteProxy proxy) {
173173
// an empty TestSlot list, which doesn't figure into the proxy equivalence check. Since we want to free up
174174
// those test sessions, we need to operate on that original object.
175175
if (proxies.contains(proxy)) {
176-
log.warning(String.format(
177-
"Proxy '%s' was previously registered. Cleaning up any stale test sessions.", proxy));
176+
LOG.warning(String.format(
177+
"Cleaning up stale test sessions on the unregistered node %s", proxy));
178178

179179
final RemoteProxy p = proxies.remove(proxy);
180180
for (TestSlot slot : p.getTestSlots()) {
@@ -270,9 +270,9 @@ public boolean apply(RequestHandler input) {
270270
// Just make sure we delete anything that is logged on this thread from memory
271271
LoggingManager.perSessionLogHandler().clearThreadTempLogs();
272272
} catch (InterruptedException e) {
273-
log.info("Shutting down registry.");
273+
LOG.info("Shutting down registry.");
274274
} catch (Throwable t) {
275-
log.log(Level.SEVERE, "Unhandled exception in Matcher thread.", t);
275+
LOG.log(Level.SEVERE, "Unhandled exception in Matcher thread.", t);
276276
}
277277
}
278278

@@ -316,7 +316,7 @@ private void release(String internalKey, SessionTerminationReason reason) {
316316
release(session1, reason);
317317
return;
318318
}
319-
log.warning("Tried to release session with internal key " + internalKey +
319+
LOG.warning("Tried to release session with internal key " + internalKey +
320320
" but couldn't find it.");
321321
}
322322

@@ -330,14 +330,14 @@ public void add(RemoteProxy proxy) {
330330
if (proxy == null) {
331331
return;
332332
}
333-
log.fine("adding " + proxy);
333+
LOG.info("Registered a node " + proxy);
334334
try {
335335
lock.lock();
336336

337337
removeIfPresent(proxy);
338338

339339
if (registeringProxies.contains(proxy)) {
340-
log.warning(String.format("Proxy '%s' is already queued for registration.", proxy));
340+
LOG.warning(String.format("Proxy '%s' is already queued for registration.", proxy));
341341

342342
return;
343343
}
@@ -354,7 +354,7 @@ public void add(RemoteProxy proxy) {
354354
((RegistrationListener) proxy).beforeRegistration();
355355
}
356356
} catch (Throwable t) {
357-
log.severe("Error running the registration listener on " + proxy + ", " + t.getMessage());
357+
LOG.severe("Error running the registration listener on " + proxy + ", " + t.getMessage());
358358
t.printStackTrace();
359359
listenerOk = false;
360360
}
@@ -465,7 +465,7 @@ HttpClientFactory getHttpClientFactory() {
465465
private static class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
466466

467467
public void uncaughtException(Thread t, Throwable e) {
468-
log.log(Level.SEVERE, "Matcher thread dying due to unhandled exception.", e);
468+
LOG.log(Level.SEVERE, "Matcher thread dying due to unhandled exception.", e);
469469
}
470470
}
471471
public CapabilityMatcher getCapabilityMatcher() {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ public void addBrowser(DesiredCapabilities cap, int instances) {
174174
* Use only for testing.
175175
*/
176176
public void sendRegistrationRequest() {
177-
178177
registerToHub(false);
179178
}
180179

@@ -186,7 +185,7 @@ public void sendRegistrationRequest() {
186185
* - register again every X ms is specified in the config of the node.
187186
*/
188187
public void startRegistrationProcess() {
189-
LOG.info("Using the json request : " + nodeConfig.toJSON());
188+
LOG.fine("Using the json request : " + nodeConfig.toJSON());
190189

191190
Boolean register = (Boolean) nodeConfig.getConfiguration().get(AUTO_REGISTER);
192191

@@ -199,7 +198,7 @@ public void startRegistrationProcess() {
199198

200199
public void run() {
201200
boolean first = true;
202-
LOG.info("Starting auto register thread. Will try to register every "
201+
LOG.info("Starting auto registration thread. Will try to register every "
203202
+ registerCycleInterval + " ms.");
204203
while (true) {
205204
try {
@@ -251,7 +250,7 @@ private void registerToHub(boolean checkPresenceFirst) {
251250
HttpClient client = httpClientFactory.getHttpClient();
252251
try {
253252
URL registration = new URL(tmp);
254-
LOG.info("Registering the node to hub: " + registration);
253+
LOG.info("Registering the node to the hub: " + registration);
255254

256255
BasicHttpEntityEnclosingRequest r =
257256
new BasicHttpEntityEnclosingRequest("POST", registration.toExternalForm());
@@ -265,6 +264,7 @@ private void registerToHub(boolean checkPresenceFirst) {
265264
response.getStatusLine().getStatusCode(),
266265
response.getStatusLine().getReasonPhrase()));
267266
}
267+
LOG.info("The node is registered to the hub and ready to use");
268268
} catch (Exception e) {
269269
throw new GridException("Error sending the registration request: " + e.getMessage());
270270
}

Diff for: java/server/src/org/openqa/grid/selenium/GridLauncher.java

+43-35
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,48 @@ public static void main(String[] args) throws Exception {
5252
return;
5353
}
5454

55+
configureLogging(helper);
56+
57+
GridRole role = GridRole.find(args);
58+
59+
switch (role) {
60+
case NOT_GRID:
61+
log.info("Launching a standalone Selenium Server");
62+
SeleniumServer.main(args);
63+
log.info("Selenium Server is up and running");
64+
break;
65+
case HUB:
66+
log.info("Launching Selenium Grid hub");
67+
try {
68+
GridHubConfiguration c = GridHubConfiguration.build(args);
69+
Hub h = new Hub(c);
70+
h.start();
71+
log.info("Nodes should register to " + h.getRegistrationURL());
72+
log.info("Selenium Grid hub is up and running");
73+
} catch (GridConfigurationException e) {
74+
GridDocHelper.printHelp(e.getMessage());
75+
e.printStackTrace();
76+
}
77+
break;
78+
case NODE:
79+
log.info("Launching a Selenium Grid node");
80+
try {
81+
RegistrationRequest c = RegistrationRequest.build(args);
82+
SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
83+
remote.startRemoteServer();
84+
log.info("Selenium Grid node is up and ready to register to the hub");
85+
remote.startRegistrationProcess();
86+
} catch (GridConfigurationException e) {
87+
GridDocHelper.printHelp(e.getMessage());
88+
e.printStackTrace();
89+
}
90+
break;
91+
default:
92+
throw new RuntimeException("NI");
93+
}
94+
}
95+
96+
private static void configureLogging(CommandLineOptionHelper helper) {
5597
Level logLevel =
5698
helper.isParamPresent("-debug")
5799
? Level.FINE
@@ -60,6 +102,7 @@ public static void main(String[] args) throws Exception {
60102
logLevel = Level.INFO;
61103
}
62104
Logger.getLogger("").setLevel(logLevel);
105+
Logger.getLogger("org.openqa.jetty").setLevel(Level.WARNING);
63106

64107
String logFilename =
65108
helper.isParamPresent("-log")
@@ -88,40 +131,5 @@ public static void main(String[] args) throws Exception {
88131
}
89132
}
90133
}
91-
92-
GridRole role = GridRole.find(args);
93-
94-
switch (role) {
95-
case NOT_GRID:
96-
log.info("Launching a standalone server");
97-
SeleniumServer.main(args);
98-
break;
99-
case HUB:
100-
log.info("Launching a selenium grid server");
101-
try {
102-
GridHubConfiguration c = GridHubConfiguration.build(args);
103-
Hub h = new Hub(c);
104-
h.start();
105-
} catch (GridConfigurationException e) {
106-
GridDocHelper.printHelp(e.getMessage());
107-
e.printStackTrace();
108-
}
109-
break;
110-
case NODE:
111-
log.info("Launching a selenium grid node");
112-
try {
113-
RegistrationRequest c = RegistrationRequest.build(args);
114-
SelfRegisteringRemote remote = new SelfRegisteringRemote(c);
115-
remote.startRemoteServer();
116-
remote.startRegistrationProcess();
117-
} catch (GridConfigurationException e) {
118-
GridDocHelper.printHelp(e.getMessage());
119-
e.printStackTrace();
120-
}
121-
break;
122-
default:
123-
throw new RuntimeException("NI");
124-
}
125134
}
126-
127135
}

Diff for: java/server/src/org/openqa/grid/selenium/proxy/DefaultRemoteProxy.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class DefaultRemoteProxy extends BaseRemoteProxy
5555
CommandListener,
5656
TestSessionListener {
5757

58-
private static final Logger log = Logger.getLogger(DefaultRemoteProxy.class.getName());
58+
private static final Logger LOG = Logger.getLogger(DefaultRemoteProxy.class.getName());
5959

6060
public static final int DEFAULT_POLLING_INTERVAL = 10000;
6161
public static final int DEFAULT_UNREGISTER_DELAY = 60000;
@@ -83,7 +83,7 @@ public void beforeRelease(TestSession session) {
8383
}
8484
boolean ok = session.sendDeleteSessionRequest();
8585
if (!ok) {
86-
log.warning("Error releasing the resources on timeout for session " + session);
86+
LOG.warning("Error releasing the resources on timeout for session " + session);
8787
}
8888
}
8989

@@ -119,7 +119,7 @@ public boolean isAlive() {
119119
getStatus();
120120
return true;
121121
} catch (Exception e) {
122-
log.warning("Failed to check status of node: " + e.getMessage());
122+
LOG.fine("Failed to check status of node: " + e.getMessage());
123123
return false;
124124
}
125125
}
@@ -138,14 +138,16 @@ public void run() {
138138
failedPollingTries++;
139139
if (failedPollingTries >= downPollingLimit) {
140140
downSince = System.currentTimeMillis();
141-
addNewEvent(new RemoteNotReachableException("Marking the node as down. " +
142-
"Cannot reach the node for " + failedPollingTries + " tries."));
141+
addNewEvent(new RemoteNotReachableException(String.format(
142+
"Marking the node %s as down: cannot reach the node for %s tries",
143+
DefaultRemoteProxy.this, failedPollingTries)));
143144
}
144145
} else {
145146
long downFor = System.currentTimeMillis() - downSince;
146147
if (downFor > unregisterDelay) {
147-
addNewEvent(new RemoteUnregisterException(
148-
"Unregistering the node. It's been down for " + downFor + " milliseconds."));
148+
addNewEvent(new RemoteUnregisterException(String.format(
149+
"Unregistering the node %s because it's been down for %s milliseconds",
150+
DefaultRemoteProxy.this, downFor)));
149151
}
150152
}
151153
} else {
@@ -176,12 +178,12 @@ public void addNewEvent(RemoteException event) {
176178
public void onEvent(List<RemoteException> events, RemoteException lastInserted) {
177179
for (RemoteException e : events) {
178180
if (e instanceof RemoteNotReachableException) {
179-
log.warning(e.getMessage());
181+
LOG.info(e.getMessage());
180182
down = true;
181183
this.errors.clear();
182184
}
183185
if (e instanceof RemoteUnregisterException) {
184-
log.warning(e.getMessage());
186+
LOG.info(e.getMessage());
185187
Registry registry = this.getRegistry();
186188
registry.removeIfPresent(this);
187189
}

Diff for: java/server/src/org/openqa/selenium/server/SeleniumServer.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ public static void main(String[] args) throws Exception {
243243
// infinite
244244
seleniumProxy = new SeleniumServer(slowResourceProperty(), configuration);
245245
seleniumProxy.boot();
246+
247+
// todo: This is still buggy because it should resolve to external port
248+
seleniumProxy.LOGGER.info(
249+
format("RemoteWebDriver instances should connect to: http://%s:%d/wd/hub",
250+
networkUtils.getPrivateLocalAddress(), seleniumProxy.getPort()));
246251
}
247252

248253
public SeleniumServer() throws Exception {
@@ -397,10 +402,6 @@ private HttpContext createWebDriverRemoteContext(DriverSessions webDriverSession
397402
handler.addServlet("WebDriver remote server", "/hub/*", DriverServlet.class.getName());
398403
webdriverContext.addHandler(handler);
399404

400-
LOGGER.info(format("RemoteWebDriver instances should connect to: http://%s:%d/wd/hub",
401-
networkUtils.getPrivateLocalAddress(), getPort())); // todo: This is still buggy because it
402-
// should resolve to external port
403-
404405
return webdriverContext;
405406
}
406407

0 commit comments

Comments
 (0)