xli-dtr 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +6 -115
- data/Rakefile +22 -154
- data/TODO +16 -1
- data/bin/dtr +22 -61
- data/dtr.gemspec +7 -6
- data/lib/dtr/agent/brain.rb +66 -0
- data/lib/dtr/agent/herald.rb +50 -0
- data/lib/dtr/agent/runner.rb +100 -0
- data/lib/dtr/agent/sync_codebase.rb +44 -0
- data/lib/dtr/agent/sync_logger.rb +40 -0
- data/lib/dtr/agent/test_unit.rb +42 -0
- data/lib/dtr/agent/worker.rb +92 -0
- data/lib/dtr/agent/working_env_ext.rb +45 -0
- data/lib/dtr/agent.rb +37 -0
- data/lib/dtr/master.rb +40 -0
- data/lib/dtr/monitor.rb +37 -0
- data/lib/dtr/raketasks.rb +74 -13
- data/lib/dtr/shared/adapter.rb +112 -0
- data/lib/dtr/shared/configuration.rb +76 -0
- data/lib/dtr/shared/message_decorator.rb +28 -0
- data/lib/dtr/shared/ruby_ext.rb +153 -0
- data/lib/dtr/shared/service/agent.rb +33 -0
- data/lib/dtr/shared/service/file.rb +28 -0
- data/lib/dtr/shared/service/rinda.rb +40 -0
- data/lib/dtr/shared/service/runner.rb +33 -0
- data/lib/dtr/shared/service/working_env.rb +28 -0
- data/lib/dtr/shared/service.rb +19 -0
- data/lib/dtr/shared/sync_codebase/codebase.rb +32 -0
- data/lib/dtr/shared/sync_codebase/master_ext.rb +52 -0
- data/lib/dtr/shared/sync_codebase/package.rb +39 -0
- data/lib/dtr/shared/sync_codebase/sync_service.rb +41 -0
- data/lib/dtr/shared/sync_codebase.rb +18 -0
- data/lib/dtr/shared/sync_logger.rb +72 -0
- data/lib/dtr/shared/utils/cmd.rb +30 -0
- data/lib/dtr/shared/utils/env_store.rb +60 -0
- data/lib/dtr/shared/utils/logger.rb +71 -0
- data/lib/dtr/shared/utils.rb +17 -0
- data/lib/dtr/shared/working_env.rb +38 -0
- data/lib/dtr/shared.rb +24 -0
- data/lib/dtr/test_unit/drb_test_runner.rb +57 -0
- data/lib/dtr/test_unit/injection.rb +30 -0
- data/lib/dtr/test_unit/test_case_injection.rb +37 -0
- data/lib/dtr/test_unit/testrunnermediator_injection.rb +72 -0
- data/lib/dtr/test_unit/thread_safe_test_result.rb +40 -0
- data/lib/dtr/test_unit/worker_club.rb +72 -0
- data/lib/dtr/test_unit.rb +8 -275
- data/lib/dtr/test_unit_injection.rb +0 -1
- data/lib/dtr.rb +23 -81
- data/test/acceptance/agent_working_env_test.rb +92 -0
- data/test/acceptance/dtr_package_task_test.rb +26 -0
- data/test/acceptance/general_test.rb +275 -0
- data/test/acceptance/sync_codebase_test.rb +67 -0
- data/test/acceptance/sync_logger_test.rb +41 -0
- data/test/agent_helper.rb +39 -0
- data/test/logger_stub.rb +30 -0
- data/test/test_helper.rb +43 -0
- data/test/unit/adapter_test.rb +107 -0
- data/test/unit/test_unit_test.rb +47 -0
- data/test/unit/working_env_test.rb +71 -0
- data/testdata/Rakefile +15 -0
- data/testdata/a_failed_test_case.rb +8 -0
- data/testdata/a_file_system_test_case.rb +8 -0
- data/testdata/a_test_case.rb +13 -0
- data/testdata/a_test_case2.rb +6 -0
- data/testdata/an_error_test_case.rb +9 -0
- data/testdata/another_project/Rakefile +6 -0
- data/testdata/another_project/passed_test_case.rb +7 -0
- data/testdata/is_required_by_a_test.rb +9 -0
- data/testdata/lib/lib_test_case.rb +7 -0
- data/testdata/package_task_test_rakefile +8 -0
- data/testdata/scenario_test_case.rb +34 -0
- data/testdata/setup_agent_env_test_case.rb +9 -0
- data/testdata/should_not_sync_codebase_and_setup_working_dir_when_agent_is_in_same_dir_with_master_process/Rakefile +6 -0
- data/testdata/should_not_sync_codebase_and_setup_working_dir_when_agent_is_in_same_dir_with_master_process/verify_dir_pwd_test_case.rb +10 -0
- metadata +72 -18
- data/lib/dtr/base.rb +0 -172
- data/lib/dtr/runner.rb +0 -270
- data/lib/dtr/service_provider.rb +0 -160
@@ -0,0 +1,112 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'timeout'
|
16
|
+
|
17
|
+
module DTR
|
18
|
+
module Adapter
|
19
|
+
AGENT_PORT = 7788
|
20
|
+
|
21
|
+
WAKEUP_MESSAGE = 'wakeup'
|
22
|
+
SLEEP_MESSAGE = 'sleep'
|
23
|
+
|
24
|
+
module Follower
|
25
|
+
def wakeup?
|
26
|
+
msg, host = listen
|
27
|
+
if msg == Adapter::WAKEUP_MESSAGE
|
28
|
+
port = host.split(':').last.to_i
|
29
|
+
DTR.configuration.rinda_server_port = port
|
30
|
+
@wakeup_for_host = host
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def sleep?
|
36
|
+
return true unless defined?(@wakeup_for_host)
|
37
|
+
msg, host = Timeout.timeout(DTR.configuration.follower_listen_sleep_timeout) do
|
38
|
+
loop do
|
39
|
+
msg, host = listen
|
40
|
+
break if host == @wakeup_for_host
|
41
|
+
end
|
42
|
+
[msg, host]
|
43
|
+
end
|
44
|
+
DTR.info "Received: #{msg} from #{host}"
|
45
|
+
msg == Adapter::SLEEP_MESSAGE
|
46
|
+
rescue Timeout::Error => e
|
47
|
+
DTR.info "Timeout while listening command"
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def listen
|
53
|
+
unless defined?(@soc)
|
54
|
+
@soc = UDPSocket.open
|
55
|
+
@soc.bind('', Adapter::AGENT_PORT)
|
56
|
+
end
|
57
|
+
@soc.recv(1024).split
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
module Master
|
62
|
+
def hypnotize_agents
|
63
|
+
yell_agents("#{Adapter::SLEEP_MESSAGE} #{host}")
|
64
|
+
end
|
65
|
+
|
66
|
+
def with_wakeup_agents(&block)
|
67
|
+
heartbeat = Thread.new do
|
68
|
+
loop do
|
69
|
+
do_wakeup_agents
|
70
|
+
sleep(DTR.configuration.master_yell_interval)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
#heartbeat thread should have high priority for agent is listening
|
74
|
+
heartbeat.priority = Thread.current.priority + 10
|
75
|
+
block.call
|
76
|
+
ensure
|
77
|
+
#kill heartbeat first, so that agents wouldn't be wakeup after hypnotized
|
78
|
+
Thread.kill heartbeat rescue nil
|
79
|
+
hypnotize_agents rescue nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def do_wakeup_agents
|
83
|
+
yell_agents("#{Adapter::WAKEUP_MESSAGE} #{host}")
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def yell_agents(msg)
|
88
|
+
DTR.info {"yell agents #{msg}: #{DTR.configuration.broadcast_list.inspect}"}
|
89
|
+
DTR.configuration.broadcast_list.each do |it|
|
90
|
+
broadcast(it, msg)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def host
|
95
|
+
"#{Socket.gethostname}:#{DTR.configuration.rinda_server_port}"
|
96
|
+
end
|
97
|
+
|
98
|
+
def broadcast(it, msg)
|
99
|
+
soc = UDPSocket.open
|
100
|
+
begin
|
101
|
+
soc.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
102
|
+
DTR.debug {"broadcast sending #{msg} to #{it}"}
|
103
|
+
soc.send(msg, 0, it, Adapter::AGENT_PORT)
|
104
|
+
rescue
|
105
|
+
nil
|
106
|
+
ensure
|
107
|
+
soc.close
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'singleton'
|
16
|
+
require 'rinda/rinda'
|
17
|
+
require 'rinda/tuplespace'
|
18
|
+
|
19
|
+
module DTR
|
20
|
+
|
21
|
+
def configuration
|
22
|
+
Configuration.instance
|
23
|
+
end
|
24
|
+
|
25
|
+
module_function :configuration
|
26
|
+
|
27
|
+
class Configuration
|
28
|
+
include Singleton
|
29
|
+
include Service::Rinda
|
30
|
+
|
31
|
+
attr_accessor :broadcast_list, :rinda_server_port, :master_yell_interval, :follower_listen_sleep_timeout
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
store = EnvStore.new
|
35
|
+
@broadcast_list = ['localhost'].concat(store[:broadcast_list] || []).uniq
|
36
|
+
@rinda_server_port = store[:port] || 3344
|
37
|
+
@master_yell_interval = store[:master_yell_interval] || 10
|
38
|
+
@follower_listen_sleep_timeout = store[:follower_listen_sleep_timeout] || 15
|
39
|
+
end
|
40
|
+
|
41
|
+
def save
|
42
|
+
store = EnvStore.new
|
43
|
+
store[:broadcast_list] = @broadcast_list
|
44
|
+
store[:port] = @rinda_server_port
|
45
|
+
store[:master_yell_interval] = @master_yell_interval
|
46
|
+
store[:follower_listen_sleep_timeout] = @follower_listen_sleep_timeout
|
47
|
+
end
|
48
|
+
|
49
|
+
def with_rinda_server(&block)
|
50
|
+
start_service
|
51
|
+
DTR.info '-- Booting DTR Rinda server...'
|
52
|
+
loop do
|
53
|
+
begin
|
54
|
+
Rinda::RingServer.new Rinda::TupleSpace.new, @rinda_server_port
|
55
|
+
break
|
56
|
+
rescue Errno::EADDRINUSE
|
57
|
+
@rinda_server_port += 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
DTR.info "-- DTR Rinda server started on port #{@rinda_server_port}"
|
61
|
+
block.call
|
62
|
+
ensure
|
63
|
+
stop_service rescue nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def lookup_ring_any
|
67
|
+
@ring ||= __lookup_ring_any__
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def __lookup_ring_any__
|
72
|
+
DTR.info {"broadcast list: #{@broadcast_list.inspect} on port #{@rinda_server_port}"}
|
73
|
+
::Rinda::TupleSpaceProxy.new(Rinda::RingFinger.new(@broadcast_list, @rinda_server_port).lookup_ring_any)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module MessageDecorator
|
17
|
+
def decorate_message(msg, source=nil)
|
18
|
+
source ? "#{source} from #{Socket.gethostname}: #{msg}" : "From #{Socket.gethostname}: #{msg}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
class RemoteError < StandardError
|
22
|
+
include MessageDecorator
|
23
|
+
def initialize(e)
|
24
|
+
super(decorate_message(e.message, e.class.name))
|
25
|
+
set_backtrace(e.backtrace)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
class Null
|
16
|
+
class << self
|
17
|
+
def instance(overrides = {})
|
18
|
+
self.new.define_overrides(overrides)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#override Object#id for removing the warning
|
23
|
+
def id
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(sym, *args, &block)
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def define_overrides(overrides)
|
32
|
+
overrides.each_pair do |key, value|
|
33
|
+
(class << self; self; end;).send(:define_method, key, lambda { value })
|
34
|
+
end
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# from activesupport-2.1.1
|
40
|
+
class Object
|
41
|
+
def blank?
|
42
|
+
respond_to?(:empty?) ? empty? : !self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class NilClass
|
47
|
+
def blank?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class FalseClass
|
53
|
+
def blank?
|
54
|
+
true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class TrueClass
|
59
|
+
def blank?
|
60
|
+
false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Array
|
65
|
+
alias_method :blank?, :empty?
|
66
|
+
end
|
67
|
+
|
68
|
+
class Hash
|
69
|
+
alias_method :blank?, :empty?
|
70
|
+
end
|
71
|
+
|
72
|
+
class String
|
73
|
+
def blank?
|
74
|
+
self !~ /\S/
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Numeric
|
79
|
+
def blank?
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Module
|
85
|
+
# Encapsulates the common pattern of:
|
86
|
+
#
|
87
|
+
# alias_method :foo_without_feature, :foo
|
88
|
+
# alias_method :foo, :foo_with_feature
|
89
|
+
#
|
90
|
+
# With this, you simply do:
|
91
|
+
#
|
92
|
+
# alias_method_chain :foo, :feature
|
93
|
+
#
|
94
|
+
# And both aliases are set up for you.
|
95
|
+
#
|
96
|
+
# Query and bang methods (foo?, foo!) keep the same punctuation:
|
97
|
+
#
|
98
|
+
# alias_method_chain :foo?, :feature
|
99
|
+
#
|
100
|
+
# is equivalent to
|
101
|
+
#
|
102
|
+
# alias_method :foo_without_feature?, :foo?
|
103
|
+
# alias_method :foo?, :foo_with_feature?
|
104
|
+
#
|
105
|
+
# so you can safely chain foo, foo?, and foo! with the same feature.
|
106
|
+
def alias_method_chain(target, feature)
|
107
|
+
# Strip out punctuation on predicates or bang methods since
|
108
|
+
# e.g. target?_without_feature is not a valid method name.
|
109
|
+
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
110
|
+
yield(aliased_target, punctuation) if block_given?
|
111
|
+
|
112
|
+
with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
|
113
|
+
|
114
|
+
alias_method without_method, target
|
115
|
+
alias_method target, with_method
|
116
|
+
|
117
|
+
case
|
118
|
+
when public_method_defined?(without_method)
|
119
|
+
public target
|
120
|
+
when protected_method_defined?(without_method)
|
121
|
+
protected target
|
122
|
+
when private_method_defined?(without_method)
|
123
|
+
private target
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Allows you to make aliases for attributes, which includes
|
128
|
+
# getter, setter, and query methods.
|
129
|
+
#
|
130
|
+
# Example:
|
131
|
+
#
|
132
|
+
# class Content < ActiveRecord::Base
|
133
|
+
# # has a title attribute
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# class Email < Content
|
137
|
+
# alias_attribute :subject, :title
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# e = Email.find(1)
|
141
|
+
# e.title # => "Superstars"
|
142
|
+
# e.subject # => "Superstars"
|
143
|
+
# e.subject? # => true
|
144
|
+
# e.subject = "Megastars"
|
145
|
+
# e.title # => "Megastars"
|
146
|
+
def alias_attribute(new_name, old_name)
|
147
|
+
module_eval <<-STR, __FILE__, __LINE__+1
|
148
|
+
def #{new_name}; self.#{old_name}; end
|
149
|
+
def #{new_name}?; self.#{old_name}?; end
|
150
|
+
def #{new_name}=(v); self.#{old_name} = v; end
|
151
|
+
STR
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module Service
|
17
|
+
module Agent
|
18
|
+
include Rinda
|
19
|
+
def new_agent_monitor
|
20
|
+
lookup_ring.notify(nil, [:agent, nil])
|
21
|
+
end
|
22
|
+
|
23
|
+
def provide_agent_info(setup_env_cmd, runners)
|
24
|
+
agent = %{
|
25
|
+
- agent(host at #{Socket.gethostname}):
|
26
|
+
default setup environment command: '#{setup_env_cmd}'
|
27
|
+
runners: #{runners.inspect}
|
28
|
+
}
|
29
|
+
lookup_ring.write [:agent, agent]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module Service
|
17
|
+
module File
|
18
|
+
include Rinda
|
19
|
+
def lookup_file
|
20
|
+
lookup(:read, [:file, nil])[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def provide_file(file)
|
24
|
+
lookup_ring.write [:file, file]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'drb'
|
16
|
+
require 'rinda/ring'
|
17
|
+
|
18
|
+
module DTR
|
19
|
+
module Service
|
20
|
+
module Rinda
|
21
|
+
|
22
|
+
def start_service
|
23
|
+
DTR.info "-- Start drb service..."
|
24
|
+
DRb.start_service
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop_service
|
28
|
+
DRb.stop_service
|
29
|
+
end
|
30
|
+
|
31
|
+
def lookup(method, stuff, timeout=nil)
|
32
|
+
lookup_ring.send(method, stuff, timeout)
|
33
|
+
end
|
34
|
+
|
35
|
+
def lookup_ring
|
36
|
+
DTR.configuration.lookup_ring_any
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'rinda/ring'
|
16
|
+
|
17
|
+
module DTR
|
18
|
+
module Service
|
19
|
+
module Runner
|
20
|
+
include Rinda
|
21
|
+
|
22
|
+
def provide_runner(runner)
|
23
|
+
renewer = ::Rinda::SimpleRenewer.new
|
24
|
+
tuple = [:name, 'DTR::Runner'.to_sym, runner, "DTR remote runner #{Process.pid}-#{runner.name}"]
|
25
|
+
lookup_ring.write(tuple, renewer)
|
26
|
+
end
|
27
|
+
|
28
|
+
def lookup_runner
|
29
|
+
lookup(:take, [:name, 'DTR::Runner'.to_sym, nil, nil])[2]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module Service
|
17
|
+
module WorkingEnv
|
18
|
+
include Rinda
|
19
|
+
def lookup_working_env
|
20
|
+
lookup(:read, [:working_env, nil])[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def provide_working_env(env)
|
24
|
+
lookup_ring.write [:working_env, env]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'dtr/shared/service/rinda'
|
16
|
+
require 'dtr/shared/service/file'
|
17
|
+
require 'dtr/shared/service/runner'
|
18
|
+
require 'dtr/shared/service/working_env'
|
19
|
+
require 'dtr/shared/service/agent'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module SyncCodebase
|
17
|
+
class Codebase
|
18
|
+
include DRbUndumped
|
19
|
+
include Package
|
20
|
+
|
21
|
+
CHUNK_SIZE = 1024*1024
|
22
|
+
|
23
|
+
def write(remote_io)
|
24
|
+
File.open(File.join(package_dir, package_file), "rb") do |f|
|
25
|
+
while chunk = f.read(CHUNK_SIZE) and chunk.length > 0
|
26
|
+
remote_io.write(chunk)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'test/unit/testresult'
|
16
|
+
|
17
|
+
module DTR
|
18
|
+
module SyncCodebase
|
19
|
+
module MasterExt
|
20
|
+
include Service::File
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.alias_method_chain :with_dtr_master, :sync_codebase
|
24
|
+
end
|
25
|
+
|
26
|
+
def with_dtr_master_with_sync_codebase(&block)
|
27
|
+
with_dtr_master_without_sync_codebase do
|
28
|
+
unless Cmd.execute('rake dtr_repackage --trace')
|
29
|
+
$stderr.puts %{
|
30
|
+
Execute dtr_repackage rake task failed, see log for details.
|
31
|
+
For running DTR test task, you must define a DTR::PackageTask task in your rakefile for DTR need package and synchronize your codebase within grid.
|
32
|
+
Example:
|
33
|
+
require 'dtr/raketasks'
|
34
|
+
DTR::PackageTask.new do |p|
|
35
|
+
p.package_files.include("**/*")
|
36
|
+
p.package_files.exclude("tmp")
|
37
|
+
p.package_files.exclude("log")
|
38
|
+
end
|
39
|
+
}
|
40
|
+
return Test::Unit::TestResult.new
|
41
|
+
end
|
42
|
+
begin
|
43
|
+
provide_file Codebase.new
|
44
|
+
block.call
|
45
|
+
ensure
|
46
|
+
Cmd.execute('rake dtr_clobber_package --trace')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module SyncCodebase
|
17
|
+
module Package
|
18
|
+
def package_dir
|
19
|
+
'dtr_pkg'
|
20
|
+
end
|
21
|
+
|
22
|
+
def package_name
|
23
|
+
'codebase-dump'
|
24
|
+
end
|
25
|
+
|
26
|
+
def package_dir_path
|
27
|
+
"#{package_dir}/#{package_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def package_file
|
31
|
+
"#{package_name}.tar.bz2"
|
32
|
+
end
|
33
|
+
|
34
|
+
def package_copy_file
|
35
|
+
"copy_#{package_file}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|