Permalink
Browse files

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
  • Loading branch information...
ph7
ph7 committed Aug 21, 2008
1 parent e28b4ab commit 9d05140058657ecca7942b0bdfc62d570bca11d2
Showing with 98 additions and 87 deletions.
  1. +14 −13 Selenium Grid.iws
  2. +9 −0 lib/ruby/file_extensions.rb
  3. +28 −0 lib/ruby/java/classpath.rb
  4. +31 −0 lib/ruby/java/vm.rb
  5. +16 −74 src/scripts/Rakefile
View
@@ -69,16 +69,17 @@
<list name="Failed commit: Failed commit: Failed commit: Default" comment="Renamed to com.thoughtworks.selenium.grid" />
<list name="Failed commit: Default (2)" comment="Renamed to com.thoughtworks.selenium.grid" />
<list default="true" name="All Uncommited Changes" comment="">
- <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" />
<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" />
+ <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" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/scripts/Rakefile" afterPath="$PROJECT_DIR$/src/scripts/Rakefile" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManager.java" />
<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" />
- <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" />
<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" />
+ <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" />
<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" />
<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" />
- <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" />
<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" />
+ <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" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/management/LifecyleManagerServletTest.java" />
<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" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/HubServlet.java" />
@@ -541,16 +542,16 @@
</component>
<component name="FileEditorManager">
<leaf>
- <file leaf-file-name="HubServer.java" pinned="false" current="false" current-in-tab="false">
+ <file leaf-file-name="HubServer.java" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="15" column="13" selection-start="708" selection-end="708" vertical-scroll-proportion="0.38709676">
+ <state line="35" column="92" selection-start="1672" selection-end="1672" vertical-scroll-proportion="0.8494624">
<folding />
</state>
</provider>
</entry>
</file>
- <file leaf-file-name="LifecycleManagerServlet.java" pinned="false" current="true" current-in-tab="true">
+ <file leaf-file-name="LifecycleManagerServlet.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/management/LifecycleManagerServlet.java">
<provider selected="true" editor-type-id="text-editor">
<state line="21" column="70" selection-start="775" selection-end="775" vertical-scroll-proportion="0.5419355">
@@ -1885,13 +1886,6 @@
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java">
- <provider selected="true" editor-type-id="text-editor">
- <state line="15" column="13" selection-start="708" selection-end="708" vertical-scroll-proportion="0.38709676">
- <folding />
- </state>
- </provider>
- </entry>
<entry file="file://$PROJECT_DIR$/hub/src/test/unit/java/com/thoughtworks/selenium/grid/hub/HubRegistryTest.java">
<provider selected="true" editor-type-id="text-editor">
<state line="39" column="38" selection-start="1122" selection-end="1122" vertical-scroll-proportion="0.65">
@@ -1955,6 +1949,13 @@
</state>
</provider>
</entry>
+ <entry file="file://$PROJECT_DIR$/hub/src/main/java/com/thoughtworks/selenium/grid/hub/HubServer.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="35" column="92" selection-start="1672" selection-end="1672" vertical-scroll-proportion="0.8494624">
+ <folding />
+ </state>
+ </provider>
+ </entry>
</component>
<component name="ideajad">
<property name="annotate" value="false" />
@@ -0,0 +1,9 @@
+class File
+
+ def self.native_path(path)
+ expanded_path = File.expand_path(path)
+ expanded_path.gsub!('/', '\\') if PLATFORM['win32']
+ expanded_path
+ end
+
+end
View
@@ -0,0 +1,28 @@
+module Java
+
+ class Classpath
+ require 'pathname'
+
+ def initialize(root_dir)
+ @root = root_dir
+ @locations = []
+ self
+ end
+
+ def <<(paths)
+ @locations = (@locations << Dir[@root + '/' + paths]).flatten
+ self
+ end
+
+ def definition
+ @locations.map {|path| File.native_path(path)}.join(self.separator)
+
+ end
+
+ def separator
+ PLATFORM['win32'] ? ";" : ":"
+ end
+
+ end
+
+end
View
@@ -0,0 +1,31 @@
+module Java
+
+ class VM
+
+ def run(classname, options)
+ command = [ "java" ]
+ command << "-cp \"#{options[:classpath]}\""
+ command << classname
+ command << jvm_properties(options[:properties])
+ command << options[:args].join(' ') if options[:args]
+ command << ">\"#{options[:log_file]}\" 2>&1" if options[:log_file]
+
+ if options[:background ]
+ if PLATFORM['win32']
+ command.unshift("start")
+ else
+ command << "&"
+ end
+ end
+
+ sh command.join(' ')
+ end
+
+ def jvm_properties(property_hash)
+ return "" unless property_hash
+ property_hash.inject([]) {|memo, (name, value)| memo << "-D#{name}=#{value}" }.join(' ')
+ end
+
+ end
+
+end
View
@@ -2,6 +2,9 @@
# Rakefile managing Selenium Grid components
#
require File.dirname(__FILE__) + '/lib/ruby/tcp_socket_extensions'
+require File.dirname(__FILE__) + '/lib/ruby/file_extensions'
+require File.dirname(__FILE__) + '/lib/ruby/java/classpath'
+require File.dirname(__FILE__) + '/lib/ruby/java/vm'
desc "Print help"
task :help do
@@ -85,7 +88,8 @@ end
desc "Stop Hub"
task :'hub:stop' do
- sh "kill `lsof -t -i :4444`"
+ http = Net::HTTP.new("localhost", 4444)
+ http.post('/lifecycle-manager', "action=shutdown")
end
desc "Launch Remote Control"
@@ -95,7 +99,8 @@ end
desc "Stop Remote Control"
task :'rc:stop' do
- sh "kill `lsof -t -i :#{ENV['PORT'] || 5555}`"
+ http = Net::HTTP.new("localhost", ENV['PORT'] || 5555)
+ puts http.post('/selenium-server/driver/', "cmd=shutDown")
end
desc "Launch Remote Control"
@@ -110,8 +115,15 @@ end
desc"Stop Remote Controls. Usage rake rc:stop PORTS=5555-5560"
task :'rc:stop_all' do
- port_range = ENV['PORTS'] || "5000-5020"
- sh "kill `lsof -t -i :#{port_range}`"
+ ports = ENV['PORTS'] || "5000-5020"
+ port_range = Range.new(*ports.split("-"))
+ port_range.each do |port|
+ begin
+ http = Net::HTTP.new("localhost", port)
+ http.post('/selenium-server/driver/', "cmd=shutDown")
+ rescue Exception => e
+ STDERR.puts "Could not properly shutdown remote control #{port} : #{e}"
+ end
end
desc "Launch a Xvnc server"
@@ -141,73 +153,3 @@ def rc_args(options)
args << (options[:selenium_args] || ENV['SELENIUM_ARGS'] || "")
args
end
-
-### To be extracted (eventually) ###
-
-
-
-class File
-
- def self.native_path(path)
- expanded_path = File.expand_path(path)
- expanded_path.gsub!('/', '\\') if PLATFORM['win32']
- expanded_path
- end
-end
-
-module Java
-
- class Classpath
- require 'pathname'
-
- def initialize(root_dir)
- @root = root_dir
- @locations = []
- self
- end
-
- def <<(paths)
- @locations = (@locations << Dir[@root + '/' + paths]).flatten
- self
- end
-
- def definition
- @locations.map {|path| File.native_path(path)}.join(self.separator)
-
- end
-
- def separator
- PLATFORM['win32'] ? ";" : ":"
- end
-
- end
-
- class VM
-
- def run(classname, options)
- command = [ "java" ]
- command << "-cp \"#{options[:classpath]}\""
- command << classname
- command << jvm_properties(options[:properties])
- command << options[:args].join(' ') if options[:args]
- command << ">\"#{options[:log_file]}\" 2>&1" if options[:log_file]
-
- if options[:background ]
- if PLATFORM['win32']
- command.unshift("start")
- else
- command << "&"
- end
- end
-
- sh command.join(' ')
- end
-
- def jvm_properties(property_hash)
- return "" unless property_hash
- property_hash.inject([]) {|memo, (name, value)| memo << "-D#{name}=#{value}" }.join(' ')
- end
-
- end
-
-end

0 comments on commit 9d05140

Please sign in to comment.