Skip to content

Commit e28b4ab

Browse files
author
ph7
committed
Hub shutdown action + upgraded Selenium Remote Control.
git-svn-id: https://svn.openqa.org/svn/selenium-grid/trunk@361 22590ab4-ef3b-0410-9bef-a9f5a1089f47
1 parent 37667f7 commit e28b4ab

15 files changed

Lines changed: 484 additions & 174 deletions

Selenium Grid.iws

Lines changed: 308 additions & 155 deletions
Large diffs are not rendered by default.

hub/Hub.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
77
<sourceFolder url="file://$MODULE_DIR$/src/main/ruby" isTestSource="false" />
88
<sourceFolder url="file://$MODULE_DIR$/src/test/integration" isTestSource="true" />
9-
<sourceFolder url="file://$MODULE_DIR$/src/test/unit" isTestSource="true" />
10-
<sourceFolder url="file://$MODULE_DIR$/src/test/unit/java" isTestSource="false" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/unit/java" isTestSource="true" />
1110
<excludeFolder url="file://$MODULE_DIR$/src/test/integration" />
1211
</content>
1312
<orderEntry type="inheritedJdk" />

hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubRegistry.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.thoughtworks.selenium.grid.configuration.ResourceLocator;
66
import com.thoughtworks.selenium.grid.hub.remotecontrol.DynamicRemoteControlPool;
77
import com.thoughtworks.selenium.grid.hub.remotecontrol.GlobalRemoteControlPool;
8+
import com.thoughtworks.selenium.grid.hub.management.LifecycleManager;
89
import org.apache.commons.logging.Log;
910
import org.apache.commons.logging.LogFactory;
1011

@@ -20,6 +21,7 @@ public class HubRegistry {
2021
private DynamicRemoteControlPool pool;
2122
private EnvironmentManager environmentManager;
2223
private GridConfiguration gridConfiguration;
24+
private LifecycleManager lifecycleManager;
2325

2426
public static synchronized HubRegistry registry() {
2527
if (null == singleton) {
@@ -55,4 +57,12 @@ public synchronized GridConfiguration gridConfiguration() {
5557
}
5658
return gridConfiguration;
5759
}
60+
61+
public synchronized LifecycleManager lifecycleManager() {
62+
if (null == lifecycleManager) {
63+
lifecycleManager = new LifecycleManager();
64+
}
65+
return lifecycleManager;
66+
}
67+
5868
}

hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.thoughtworks.selenium.grid.configuration.HubConfiguration;
44
import com.thoughtworks.selenium.grid.hub.management.RegistrationServlet;
55
import com.thoughtworks.selenium.grid.hub.management.UnregistrationServlet;
6+
import com.thoughtworks.selenium.grid.hub.management.LifecycleManagerServlet;
67
import com.thoughtworks.selenium.grid.hub.management.console.ConsoleServlet;
78
import org.mortbay.jetty.Server;
89
import org.mortbay.jetty.handler.ContextHandlerCollection;
@@ -33,6 +34,7 @@ public static void main(String[] args) throws Exception {
3334
root.addServlet(new ServletHolder(new ConsoleServlet()), "/console");
3435
root.addServlet(new ServletHolder(new RegistrationServlet()), "/registration-manager/register");
3536
root.addServlet(new ServletHolder(new UnregistrationServlet()), "/registration-manager/unregister");
37+
root.addServlet(new ServletHolder(new LifecycleManagerServlet()), "/lifecycle-manager");
3638

3739
server.start();
3840
server.join();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.thoughtworks.selenium.grid.hub.management;
2+
3+
import com.thoughtworks.selenium.grid.hub.HubRegistry;
4+
5+
import javax.servlet.http.HttpServlet;
6+
7+
/**
8+
* Base class for all servlets exposed by Selenium Grid Hub.
9+
*
10+
*
11+
* Provides access to the global application registry via a method
12+
* that can easily be overriden in unit tests.
13+
*/
14+
public class HubServlet extends HttpServlet {
15+
16+
/**
17+
* Application Registry (singleton)
18+
*
19+
* @return A valid application registry. Never null.
20+
*/
21+
protected HubRegistry registry() {
22+
return HubRegistry.registry();
23+
}
24+
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.thoughtworks.selenium.grid.hub.management;
2+
3+
import org.apache.commons.logging.Log;
4+
import org.apache.commons.logging.LogFactory;
5+
6+
/**
7+
* Manages lifecyle of Hub components
8+
*/
9+
public class LifecycleManager {
10+
11+
private static final Log LOGGER = LogFactory.getLog(LifecycleManager.class);
12+
13+
public void shutdown() {
14+
LOGGER.info("Shutting down Hub...");
15+
System.exit(0);
16+
}
17+
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.thoughtworks.selenium.grid.hub.management;
2+
3+
import org.apache.commons.logging.Log;
4+
import org.apache.commons.logging.LogFactory;
5+
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
import javax.servlet.ServletException;
9+
import java.io.IOException;
10+
11+
/**
12+
* Servlet in charge of shutting down the Hub.
13+
*/
14+
public class LifecycleManagerServlet extends HubServlet {
15+
16+
private static final Log LOGGER = LogFactory.getLog(LifecycleManagerServlet.class);
17+
18+
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
19+
final String action;
20+
21+
action = request.getParameter("action");
22+
LOGGER.info("Requesting life cycle manager action : '" + action + "'");
23+
if ("shutdown".equals(action)) {
24+
registry().lifecycleManager().shutdown();
25+
}
26+
}
27+
28+
}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package com.thoughtworks.selenium.grid.hub.management;
22

3-
import com.thoughtworks.selenium.grid.hub.HubRegistry;
4-
5-
import javax.servlet.http.HttpServlet;
3+
import javax.servlet.ServletException;
64
import javax.servlet.http.HttpServletRequest;
75
import javax.servlet.http.HttpServletResponse;
8-
import javax.servlet.ServletException;
96
import java.io.IOException;
107

118

12-
public abstract class RegistrationManagementServlet extends HttpServlet {
9+
public abstract class RegistrationManagementServlet extends HubServlet {
1310

1411
protected void doGet(HttpServletRequest request, HttpServletResponse response)
1512
throws ServletException, IOException {
@@ -23,15 +20,11 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
2320

2421
protected abstract void process(HttpServletRequest request, HttpServletResponse response) throws IOException;
2522

26-
protected void witeSuccessfulResponse(HttpServletResponse response) throws IOException {
23+
protected void writeSuccessfulResponse(HttpServletResponse response) throws IOException {
2724
response.setContentType("text/plain");
2825
response.setCharacterEncoding("UTF-8");
2926
response.setStatus(HttpServletResponse.SC_OK);
3027
response.getWriter().print("OK");
3128
}
3229

33-
protected HubRegistry registry() {
34-
return HubRegistry.registry();
35-
}
36-
3730
}

hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/RegistrationServlet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
*/
1717
public class RegistrationServlet extends RegistrationManagementServlet {
1818

19-
private static final Log logger = LogFactory.getLog(RegistrationServlet.class);
19+
private static final Log LOGGER = LogFactory.getLog(RegistrationServlet.class);
2020

2121
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
2222

2323
final RemoteControlProxy newRemoteControl;
2424
final DynamicRemoteControlPool pool;
2525

26-
logger.info("Registering new remote control...");
26+
LOGGER.info("Registering new remote control...");
2727
newRemoteControl = RemoteControlParser.parse(request);
2828
pool = registry().remoteControlPool();
2929
pool.register(newRemoteControl);
30-
logger.info("Registered " + newRemoteControl);
31-
witeSuccessfulResponse(response);
30+
LOGGER.info("Registered " + newRemoteControl);
31+
writeSuccessfulResponse(response);
3232
}
3333

3434

hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/UnregistrationServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected void process(HttpServletRequest request, HttpServletResponse response)
2525
pool = registry().remoteControlPool();
2626
pool.unregister(newRemoteControl);
2727
logger.info("Unregistered " + newRemoteControl);
28-
witeSuccessfulResponse(response);
28+
writeSuccessfulResponse(response);
2929
}
3030

3131
}

0 commit comments

Comments
 (0)