Skip to content

Commit 9d05140

Browse files
author
ph7
committed
Rakefile: Less brutal shutdown tasks for Hub and RCs
git-svn-id: https://svn.openqa.org/svn/selenium-grid/trunk@362 22590ab4-ef3b-0410-9bef-a9f5a1089f47
1 parent e28b4ab commit 9d05140

5 files changed

Lines changed: 98 additions & 87 deletions

File tree

Selenium Grid.iws

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@
6969
<list name="Failed commit: Failed commit: Failed commit: Default" comment="Renamed to com.thoughtworks.selenium.grid" />
7070
<list name="Failed commit: Default (2)" comment="Renamed to com.thoughtworks.selenium.grid" />
7171
<list default="true" name="All Uncommited Changes" comment="">
72-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/LifecyleManagerServletTest.java" afterPath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/LifecyleManagerServletTest.java" />
7372
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/RegistrationServlet.java" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/RegistrationServlet.java" />
73+
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/LifecyleManagerServletTest.java" afterPath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/LifecyleManagerServletTest.java" />
74+
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/scripts/Rakefile" afterPath="$PROJECT_DIR$/src/scripts/Rakefile" />
7475
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManager.java" />
7576
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/RegistrationServletTest.java" afterPath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/RegistrationServletTest.java" />
76-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/UnregistrationServletTest.java" afterPath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/UnregistrationServletTest.java" />
7777
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/HubServlet.java" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/HubServlet.java" />
78+
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/UnregistrationServletTest.java" afterPath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/UnregistrationServletTest.java" />
7879
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/RegistrationManagementServlet.java" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/RegistrationManagementServlet.java" />
7980
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubRegistry.java" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubRegistry.java" />
80-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManager.java" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManager.java" />
8181
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/remote-control/lib/selenium-server-1.0-SNAPSHOT.jar" afterPath="$PROJECT_DIR$/remote-control/lib/selenium-server-1.0-SNAPSHOT.jar" />
82+
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManager.java" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManager.java" />
8283
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/LifecyleManagerServletTest.java" />
8384
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java" />
8485
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/HubServlet.java" />
@@ -541,16 +542,16 @@
541542
</component>
542543
<component name="FileEditorManager">
543544
<leaf>
544-
<file leaf-file-name="HubServer.java" pinned="false" current="false" current-in-tab="false">
545+
<file leaf-file-name="HubServer.java" pinned="false" current="true" current-in-tab="true">
545546
<entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java">
546547
<provider selected="true" editor-type-id="text-editor">
547-
<state line="15" column="13" selection-start="708" selection-end="708" vertical-scroll-proportion="0.38709676">
548+
<state line="35" column="92" selection-start="1672" selection-end="1672" vertical-scroll-proportion="0.8494624">
548549
<folding />
549550
</state>
550551
</provider>
551552
</entry>
552553
</file>
553-
<file leaf-file-name="LifecycleManagerServlet.java" pinned="false" current="true" current-in-tab="true">
554+
<file leaf-file-name="LifecycleManagerServlet.java" pinned="false" current="false" current-in-tab="false">
554555
<entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManagerServlet.java">
555556
<provider selected="true" editor-type-id="text-editor">
556557
<state line="21" column="70" selection-start="775" selection-end="775" vertical-scroll-proportion="0.5419355">
@@ -1885,13 +1886,6 @@
18851886
</state>
18861887
</provider>
18871888
</entry>
1888-
<entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java">
1889-
<provider selected="true" editor-type-id="text-editor">
1890-
<state line="15" column="13" selection-start="708" selection-end="708" vertical-scroll-proportion="0.38709676">
1891-
<folding />
1892-
</state>
1893-
</provider>
1894-
</entry>
18951889
<entry file="file://$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/HubRegistryTest.java">
18961890
<provider selected="true" editor-type-id="text-editor">
18971891
<state line="39" column="38" selection-start="1122" selection-end="1122" vertical-scroll-proportion="0.65">
@@ -1955,6 +1949,13 @@
19551949
</state>
19561950
</provider>
19571951
</entry>
1952+
<entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java">
1953+
<provider selected="true" editor-type-id="text-editor">
1954+
<state line="35" column="92" selection-start="1672" selection-end="1672" vertical-scroll-proportion="0.8494624">
1955+
<folding />
1956+
</state>
1957+
</provider>
1958+
</entry>
19581959
</component>
19591960
<component name="ideajad">
19601961
<property name="annotate" value="false" />

lib/ruby/file_extensions.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class File
2+
3+
def self.native_path(path)
4+
expanded_path = File.expand_path(path)
5+
expanded_path.gsub!('/', '\\') if PLATFORM['win32']
6+
expanded_path
7+
end
8+
9+
end

lib/ruby/java/classpath.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Java
2+
3+
class Classpath
4+
require 'pathname'
5+
6+
def initialize(root_dir)
7+
@root = root_dir
8+
@locations = []
9+
self
10+
end
11+
12+
def <<(paths)
13+
@locations = (@locations << Dir[@root + '/' + paths]).flatten
14+
self
15+
end
16+
17+
def definition
18+
@locations.map {|path| File.native_path(path)}.join(self.separator)
19+
20+
end
21+
22+
def separator
23+
PLATFORM['win32'] ? ";" : ":"
24+
end
25+
26+
end
27+
28+
end

lib/ruby/java/vm.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Java
2+
3+
class VM
4+
5+
def run(classname, options)
6+
command = [ "java" ]
7+
command << "-cp \"#{options[:classpath]}\""
8+
command << classname
9+
command << jvm_properties(options[:properties])
10+
command << options[:args].join(' ') if options[:args]
11+
command << ">\"#{options[:log_file]}\" 2>&1" if options[:log_file]
12+
13+
if options[:background ]
14+
if PLATFORM['win32']
15+
command.unshift("start")
16+
else
17+
command << "&"
18+
end
19+
end
20+
21+
sh command.join(' ')
22+
end
23+
24+
def jvm_properties(property_hash)
25+
return "" unless property_hash
26+
property_hash.inject([]) {|memo, (name, value)| memo << "-D#{name}=#{value}" }.join(' ')
27+
end
28+
29+
end
30+
31+
end

src/scripts/Rakefile

Lines changed: 16 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Rakefile managing Selenium Grid components
33
#
44
require File.dirname(__FILE__) + '/lib/ruby/tcp_socket_extensions'
5+
require File.dirname(__FILE__) + '/lib/ruby/file_extensions'
6+
require File.dirname(__FILE__) + '/lib/ruby/java/classpath'
7+
require File.dirname(__FILE__) + '/lib/ruby/java/vm'
58

69
desc "Print help"
710
task :help do
@@ -85,7 +88,8 @@ end
8588

8689
desc "Stop Hub"
8790
task :'hub:stop' do
88-
sh "kill `lsof -t -i :4444`"
91+
http = Net::HTTP.new("localhost", 4444)
92+
http.post('/lifecycle-manager', "action=shutdown")
8993
end
9094

9195
desc "Launch Remote Control"
@@ -95,7 +99,8 @@ end
9599

96100
desc "Stop Remote Control"
97101
task :'rc:stop' do
98-
sh "kill `lsof -t -i :#{ENV['PORT'] || 5555}`"
102+
http = Net::HTTP.new("localhost", ENV['PORT'] || 5555)
103+
puts http.post('/selenium-server/driver/', "cmd=shutDown")
99104
end
100105

101106
desc "Launch Remote Control"
@@ -110,8 +115,15 @@ end
110115

111116
desc"Stop Remote Controls. Usage rake rc:stop PORTS=5555-5560"
112117
task :'rc:stop_all' do
113-
port_range = ENV['PORTS'] || "5000-5020"
114-
sh "kill `lsof -t -i :#{port_range}`"
118+
ports = ENV['PORTS'] || "5000-5020"
119+
port_range = Range.new(*ports.split("-"))
120+
port_range.each do |port|
121+
begin
122+
http = Net::HTTP.new("localhost", port)
123+
http.post('/selenium-server/driver/', "cmd=shutDown")
124+
rescue Exception => e
125+
STDERR.puts "Could not properly shutdown remote control #{port} : #{e}"
126+
end
115127
end
116128

117129
desc "Launch a Xvnc server"
@@ -141,73 +153,3 @@ def rc_args(options)
141153
args << (options[:selenium_args] || ENV['SELENIUM_ARGS'] || "")
142154
args
143155
end
144-
145-
### To be extracted (eventually) ###
146-
147-
148-
149-
class File
150-
151-
def self.native_path(path)
152-
expanded_path = File.expand_path(path)
153-
expanded_path.gsub!('/', '\\') if PLATFORM['win32']
154-
expanded_path
155-
end
156-
end
157-
158-
module Java
159-
160-
class Classpath
161-
require 'pathname'
162-
163-
def initialize(root_dir)
164-
@root = root_dir
165-
@locations = []
166-
self
167-
end
168-
169-
def <<(paths)
170-
@locations = (@locations << Dir[@root + '/' + paths]).flatten
171-
self
172-
end
173-
174-
def definition
175-
@locations.map {|path| File.native_path(path)}.join(self.separator)
176-
177-
end
178-
179-
def separator
180-
PLATFORM['win32'] ? ";" : ":"
181-
end
182-
183-
end
184-
185-
class VM
186-
187-
def run(classname, options)
188-
command = [ "java" ]
189-
command << "-cp \"#{options[:classpath]}\""
190-
command << classname
191-
command << jvm_properties(options[:properties])
192-
command << options[:args].join(' ') if options[:args]
193-
command << ">\"#{options[:log_file]}\" 2>&1" if options[:log_file]
194-
195-
if options[:background ]
196-
if PLATFORM['win32']
197-
command.unshift("start")
198-
else
199-
command << "&"
200-
end
201-
end
202-
203-
sh command.join(' ')
204-
end
205-
206-
def jvm_properties(property_hash)
207-
return "" unless property_hash
208-
property_hash.inject([]) {|memo, (name, value)| memo << "-D#{name}=#{value}" }.join(' ')
209-
end
210-
211-
end
212-
213-
end

0 commit comments

Comments
 (0)