dtr 1.0.0 → 1.1.0
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/CHANGES +21 -0
- data/README.rdoc +39 -28
- data/Rakefile +1 -1
- data/TODO +1 -3
- data/bin/dtr +20 -13
- data/dtr.gemspec +3 -3
- data/lib/dtr.rb +2 -2
- data/lib/dtr/agent.rb +12 -5
- data/lib/dtr/agent/brain.rb +45 -19
- data/lib/dtr/agent/herald.rb +8 -10
- data/lib/dtr/agent/process_root.rb +23 -0
- data/lib/dtr/agent/rails_ext.rb +57 -0
- data/lib/dtr/agent/runner.rb +19 -39
- data/lib/dtr/agent/sync_codebase.rb +10 -19
- data/lib/dtr/agent/sync_logger.rb +1 -0
- data/lib/dtr/agent/worker.rb +13 -61
- data/lib/dtr/agent/working_env_ext.rb +51 -17
- data/lib/dtr/agent/working_status.rb +34 -0
- data/lib/dtr/facade.rb +19 -17
- data/lib/dtr/master.rb +2 -0
- data/lib/dtr/monitor.rb +2 -2
- data/lib/dtr/raketasks.rb +14 -19
- data/lib/dtr/shared.rb +1 -0
- data/lib/dtr/shared/adapter.rb +2 -101
- data/lib/dtr/shared/adapter/base.rb +118 -0
- data/lib/dtr/shared/adapter/mortality.rb +41 -0
- data/lib/dtr/shared/configuration.rb +32 -14
- data/lib/dtr/shared/root.rb +20 -0
- data/lib/dtr/shared/sync_codebase/master_ext.rb +2 -2
- data/lib/dtr/shared/sync_codebase/sync_service.rb +7 -4
- data/lib/dtr/shared/utils/cmd.rb +4 -2
- data/lib/dtr/shared/utils/env_store.rb +16 -24
- data/lib/dtr/shared/working_env.rb +8 -0
- data/lib/dtr/test_unit/drb_test_runner.rb +1 -1
- data/lib/dtr/test_unit/thread_safe_test_result.rb +56 -3
- data/test/acceptance/dtr_package_task_test.rb +3 -3
- data/test/acceptance/general_test.rb +3 -3
- data/test/acceptance/rails_ext_test.rb +86 -0
- data/test/acceptance/raketasks_test.rb +14 -0
- data/test/acceptance/sync_codebase_test.rb +8 -31
- data/test/acceptance/sync_logger_test.rb +6 -3
- data/test/agent_helper.rb +24 -16
- data/test/logger_stub.rb +3 -3
- data/test/test_helper.rb +12 -9
- data/test/unit/adapter_test.rb +1 -1
- data/test/unit/configuration_test.rb +36 -4
- data/test/unit/database_initializer_test.rb +36 -0
- data/test/unit/facade_test.rb +11 -1
- data/test/unit/thread_safe_test_result_test.rb +41 -0
- data/test/unit/working_env_test.rb +11 -21
- data/testdata/rails_projects/simple_project/README +256 -0
- data/testdata/rails_projects/simple_project/Rakefile +10 -0
- data/testdata/rails_projects/simple_project/app/controllers/application.rb +15 -0
- data/testdata/rails_projects/simple_project/app/controllers/products_controller.rb +5 -0
- data/testdata/rails_projects/simple_project/app/helpers/application_helper.rb +3 -0
- data/testdata/rails_projects/simple_project/app/helpers/products_helper.rb +2 -0
- data/testdata/rails_projects/simple_project/app/models/product.rb +5 -0
- data/testdata/rails_projects/simple_project/app/views/products/index.rhtml +7 -0
- data/testdata/rails_projects/simple_project/config/boot.rb +109 -0
- data/testdata/rails_projects/simple_project/config/database.yml +19 -0
- data/testdata/rails_projects/simple_project/config/database.yml.mysql +12 -0
- data/testdata/rails_projects/simple_project/config/environment.rb +67 -0
- data/testdata/rails_projects/simple_project/config/environments/development.rb +17 -0
- data/testdata/rails_projects/simple_project/config/environments/production.rb +22 -0
- data/testdata/rails_projects/simple_project/config/environments/test.rb +22 -0
- data/testdata/rails_projects/simple_project/config/initializers/inflections.rb +10 -0
- data/testdata/rails_projects/simple_project/config/initializers/mime_types.rb +5 -0
- data/testdata/rails_projects/simple_project/config/initializers/new_rails_defaults.rb +17 -0
- data/testdata/rails_projects/simple_project/config/routes.rb +43 -0
- data/testdata/rails_projects/simple_project/db/migrate/20081027133744_create_products.rb +13 -0
- data/testdata/rails_projects/simple_project/db/schema.rb +21 -0
- data/testdata/rails_projects/simple_project/doc/README_FOR_APP +2 -0
- data/testdata/rails_projects/simple_project/public/404.html +30 -0
- data/testdata/rails_projects/simple_project/public/422.html +30 -0
- data/testdata/rails_projects/simple_project/public/500.html +30 -0
- data/testdata/rails_projects/simple_project/public/dispatch.cgi +10 -0
- data/testdata/rails_projects/simple_project/public/dispatch.fcgi +24 -0
- data/testdata/rails_projects/simple_project/public/dispatch.rb +10 -0
- data/testdata/rails_projects/simple_project/public/favicon.ico +0 -0
- data/testdata/rails_projects/simple_project/public/images/rails.png +0 -0
- data/testdata/rails_projects/simple_project/public/index.html +274 -0
- data/testdata/rails_projects/simple_project/public/javascripts/application.js +2 -0
- data/testdata/rails_projects/simple_project/public/javascripts/controls.js +963 -0
- data/testdata/rails_projects/simple_project/public/javascripts/dragdrop.js +972 -0
- data/testdata/rails_projects/simple_project/public/javascripts/effects.js +1120 -0
- data/testdata/rails_projects/simple_project/public/javascripts/prototype.js +4225 -0
- data/testdata/rails_projects/simple_project/public/robots.txt +5 -0
- data/testdata/rails_projects/simple_project/script/about +4 -0
- data/testdata/rails_projects/simple_project/script/console +3 -0
- data/testdata/rails_projects/simple_project/script/dbconsole +3 -0
- data/testdata/rails_projects/simple_project/script/destroy +3 -0
- data/testdata/rails_projects/simple_project/script/generate +3 -0
- data/testdata/rails_projects/simple_project/script/performance/benchmarker +3 -0
- data/testdata/rails_projects/simple_project/script/performance/profiler +3 -0
- data/testdata/rails_projects/simple_project/script/performance/request +3 -0
- data/testdata/rails_projects/simple_project/script/plugin +3 -0
- data/testdata/rails_projects/simple_project/script/process/inspector +3 -0
- data/testdata/rails_projects/simple_project/script/process/reaper +3 -0
- data/testdata/rails_projects/simple_project/script/process/spawner +3 -0
- data/testdata/rails_projects/simple_project/script/runner +3 -0
- data/testdata/rails_projects/simple_project/script/server +3 -0
- data/testdata/rails_projects/simple_project/test/fixtures/products.yml +9 -0
- data/testdata/rails_projects/simple_project/test/functional/products_controller_test.rb +11 -0
- data/testdata/rails_projects/simple_project/test/test_helper.rb +38 -0
- data/testdata/rails_projects/simple_project/test/unit/product_test.rb +27 -0
- data/testdata/raketasks/Rakefile +1 -1
- metadata +90 -5
- data/testdata/verify_dir_pwd/Rakefile +0 -6
- data/testdata/verify_dir_pwd/verify_dir_pwd_test_case.rb +0 -10
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
|
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 Agent
|
|
17
|
+
class ProcessRoot
|
|
18
|
+
def initialize(*args)
|
|
19
|
+
DTR.root = Dir.pwd
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
|
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 Agent
|
|
17
|
+
module RailsExt
|
|
18
|
+
module DatabaseInitializer
|
|
19
|
+
def preparing_database_command
|
|
20
|
+
dtr_database_config_exists = File.exist?('config/database.yml.dtr')
|
|
21
|
+
default_database_config_exists = File.exist?('config/database.yml')
|
|
22
|
+
|
|
23
|
+
if !dtr_database_config_exists && !default_database_config_exists
|
|
24
|
+
DTR.info("No config/database.yml.dtr and config/database.yml exists, bypass database initialization.")
|
|
25
|
+
return
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if dtr_database_config_exists
|
|
29
|
+
DTR.info("Found config/database.yml.dtr, use it as database configuration")
|
|
30
|
+
FileUtils.cp('config/database.yml.dtr', 'config/database.yml')
|
|
31
|
+
end
|
|
32
|
+
DTR.info("Clean databases")
|
|
33
|
+
Cmd.execute("rake --trace db:drop DTR_RUNNER_NAME=#{ENV['DTR_RUNNER_NAME']}", :error_output_log_level => :debug)
|
|
34
|
+
|
|
35
|
+
# Counldn't add --trace here, for Test::Unit detected --trace as a invalid option, don't know why
|
|
36
|
+
"rake db:create db:migrate db:test:prepare DTR_RUNNER_NAME=#{ENV['DTR_RUNNER_NAME']}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module WorkingEnvExt
|
|
41
|
+
include DatabaseInitializer
|
|
42
|
+
|
|
43
|
+
def self.included(base)
|
|
44
|
+
base.alias_method_chain :setup_environment, :preparing_database
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def setup_environment_with_preparing_database
|
|
48
|
+
if setup_environment_command.blank? && File.directory?('config')
|
|
49
|
+
DTR.debug("No setup environment command found but found 'config' directory, try default preparing database command")
|
|
50
|
+
self[:agent_env_setup_cmd] = preparing_database_command
|
|
51
|
+
end
|
|
52
|
+
setup_environment_without_preparing_database
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/dtr/agent/runner.rb
CHANGED
|
@@ -14,65 +14,45 @@
|
|
|
14
14
|
|
|
15
15
|
module DTR
|
|
16
16
|
module Agent
|
|
17
|
-
class Runner
|
|
17
|
+
class Runner < ProcessRoot
|
|
18
18
|
include DRbUndumped
|
|
19
19
|
include Service::Runner
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
self.new(name, env).start
|
|
23
|
-
DRb.thread.join if DRb.thread
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
attr_reader :name, :identifier
|
|
21
|
+
attr_reader :name
|
|
27
22
|
|
|
28
|
-
def initialize(name
|
|
23
|
+
def initialize(name)
|
|
24
|
+
super
|
|
29
25
|
@name = name
|
|
30
|
-
@identifier = env[:identifier]
|
|
31
|
-
@env = env
|
|
32
26
|
end
|
|
33
27
|
|
|
34
28
|
def start
|
|
35
29
|
#start service first, so that all logs can be sync with master process
|
|
36
30
|
start_service
|
|
37
|
-
DTR.info("=> Starting runner #{name} at #{Dir.pwd}, pid: #{Process.pid}")
|
|
38
|
-
init_environment
|
|
39
|
-
provide
|
|
40
|
-
DTR.info {"=> Runner #{name} provided"}
|
|
41
|
-
rescue Exception
|
|
42
|
-
DTR.error($!.message)
|
|
43
|
-
DTR.error($!.backtrace.join("\n"))
|
|
44
|
-
end
|
|
45
31
|
|
|
46
|
-
def init_environment
|
|
47
|
-
DTR.info {"#{name}: Initialize working environment..."}
|
|
48
32
|
ENV['DTR_RUNNER_NAME'] = name
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
DTR.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
DTR.debug {"#{name}: $LOAD_PATH: #{$LOAD_PATH.inspect}"}
|
|
56
|
-
|
|
57
|
-
@env[:files].each do |f|
|
|
58
|
-
begin
|
|
59
|
-
load f unless f =~ /^-/
|
|
60
|
-
DTR.debug {"#{name}: loaded #{f}"}
|
|
61
|
-
rescue LoadError => e
|
|
62
|
-
DTR.error {"#{name}: No such file to load -- #{f}"}
|
|
63
|
-
DTR.debug {"Environment: #{@env}"}
|
|
33
|
+
DTR.info "Start #{self} at #{DTR.root}, pid: #{Process.pid}"
|
|
34
|
+
DTR.configuration.working_env.load_environment do
|
|
35
|
+
provide
|
|
36
|
+
DTR.info {"=> Runner provided"}
|
|
37
|
+
while DTR.configuration.runners_should_be_working?
|
|
38
|
+
sleep(1)
|
|
64
39
|
end
|
|
65
40
|
end
|
|
66
|
-
|
|
41
|
+
rescue
|
|
42
|
+
DTR.error($!.message)
|
|
43
|
+
DTR.error($!.backtrace.join("\n"))
|
|
44
|
+
ensure
|
|
45
|
+
#make sure exit process for drb may cause this process hang on
|
|
46
|
+
exit!(0)
|
|
67
47
|
end
|
|
68
48
|
|
|
69
49
|
def run(test, result, &progress_block)
|
|
70
|
-
DTR.debug {"
|
|
50
|
+
DTR.debug {"running #{test}..."}
|
|
71
51
|
Agent::TestCase.new(test, result, &progress_block).run
|
|
72
|
-
DTR.debug {"
|
|
52
|
+
DTR.debug {"done #{test}"}
|
|
73
53
|
ensure
|
|
74
54
|
provide
|
|
75
|
-
DTR.debug {"=> Runner
|
|
55
|
+
DTR.debug {"=> Runner provided"}
|
|
76
56
|
end
|
|
77
57
|
|
|
78
58
|
def provide
|
|
@@ -17,27 +17,18 @@ module DTR
|
|
|
17
17
|
module WorkingEnvExt
|
|
18
18
|
include SyncService
|
|
19
19
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
def synchronize_for(runners)
|
|
21
|
+
Dir.chdir(base_dir) do
|
|
22
|
+
sync_codebase do
|
|
23
|
+
FileUtils.rm_rf(package_name)
|
|
24
|
+
do_work(unpackage_cmd)
|
|
25
|
+
runners.each do |runner_name|
|
|
26
|
+
dir = File.expand_path escape_dir(runner_name)
|
|
27
|
+
FileUtils.rm_rf(dir)
|
|
28
|
+
FileUtils.cp_r(package_name, dir)
|
|
29
|
+
end
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
|
-
setup_env_without_sync_codebase(setup_env_cmd)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def working_dir_with_sync_codebase
|
|
35
|
-
same_working_dir_with_master_process? ? Dir.pwd : File.join(working_dir_without_sync_codebase, package_name)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
def same_working_dir_with_master_process?
|
|
40
|
-
self[:host] == Socket.gethostname && self[:pwd] == Dir.pwd
|
|
41
32
|
end
|
|
42
33
|
end
|
|
43
34
|
end
|
|
@@ -61,6 +61,7 @@ module DTR
|
|
|
61
61
|
private
|
|
62
62
|
def with_decorating_message(level, msg, &block)
|
|
63
63
|
raise 'Should not use block to send log remotely' if block_given?
|
|
64
|
+
msg = "#{ENV['DTR_RUNNER_NAME']}: #{msg}"if ENV['DTR_RUNNER_NAME']
|
|
64
65
|
@logger.send(level, decorate_message(msg))
|
|
65
66
|
end
|
|
66
67
|
end
|
data/lib/dtr/agent/worker.rb
CHANGED
|
@@ -15,74 +15,26 @@
|
|
|
15
15
|
module DTR
|
|
16
16
|
|
|
17
17
|
module Agent
|
|
18
|
-
# Worker
|
|
19
|
-
# Worker manages Herald & Runner processes life cycle.
|
|
18
|
+
# Worker watchs runner processes.
|
|
20
19
|
class Worker
|
|
21
|
-
def initialize
|
|
22
|
-
@
|
|
23
|
-
@agent_env_setup_cmd = agent_env_setup_cmd
|
|
24
|
-
@runner_pids = []
|
|
25
|
-
@herald = nil
|
|
26
|
-
@working_env_key = :working_env
|
|
27
|
-
@env_store = EnvStore.new
|
|
20
|
+
def initialize
|
|
21
|
+
@runners_group = ThreadGroup.new
|
|
28
22
|
end
|
|
29
23
|
|
|
30
|
-
def
|
|
31
|
-
DTR.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
ensure
|
|
36
|
-
teardown
|
|
37
|
-
DTR.info {"Agent worker is dieing"}
|
|
24
|
+
def watch_runners
|
|
25
|
+
DTR.configuration.agent_runners.each do |name|
|
|
26
|
+
runner_thread = Thread.start { DTR.run_script("DTR::Agent::Runner.new(#{name.inspect}).start") }
|
|
27
|
+
runner_thread[:runner_name] = name
|
|
28
|
+
@runners_group.add runner_thread
|
|
38
29
|
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
def setup
|
|
43
|
-
@env_store[@working_env_key] = nil
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def teardown
|
|
47
|
-
unless @runner_pids.blank?
|
|
48
|
-
@runner_pids.each{ |pid| DTR.kill_process pid }
|
|
49
|
-
DTR.info {"=> All runners(#{@runner_pids.join(", ")}) were killed." }
|
|
50
|
-
@runner_pids = []
|
|
51
|
-
end
|
|
52
|
-
if @herald
|
|
53
|
-
DTR.kill_process @herald
|
|
54
|
-
@herald = nil
|
|
55
|
-
DTR.info {"=> Herald is killed."}
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def run
|
|
60
|
-
herald
|
|
61
|
-
runners
|
|
62
|
-
DTR.info {"=> All agent worker sub processes exited."}
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def herald
|
|
66
|
-
@herald = DTR.fork_process { Herald.new @working_env_key, @agent_env_setup_cmd, @runner_names }
|
|
67
|
-
Process.waitpid @herald
|
|
68
|
-
exit(-1) unless $?.exitstatus == 0
|
|
69
|
-
end
|
|
70
30
|
|
|
71
|
-
|
|
72
|
-
working_env = @env_store[@working_env_key]
|
|
31
|
+
yield
|
|
73
32
|
|
|
74
|
-
@
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
exit!
|
|
79
|
-
}
|
|
80
|
-
working_env.within do
|
|
81
|
-
Runner.start name, working_env
|
|
82
|
-
end
|
|
83
|
-
}
|
|
33
|
+
while @runners_group.list.length > 0
|
|
34
|
+
alive_runners = @runners_group.list.collect {|r| r[:runner_name]}
|
|
35
|
+
DTR.info { "Waiting for #{alive_runners.join(', ').downcase} shutdown" }
|
|
36
|
+
sleep 1
|
|
84
37
|
end
|
|
85
|
-
Process.waitall
|
|
86
38
|
end
|
|
87
39
|
end
|
|
88
40
|
end
|
|
@@ -14,33 +14,67 @@
|
|
|
14
14
|
|
|
15
15
|
module DTR
|
|
16
16
|
module Agent
|
|
17
|
-
# Provides working environment setup beheaviours for Herald & Runner process
|
|
18
17
|
module WorkingEnvExt
|
|
19
|
-
def
|
|
20
|
-
|
|
18
|
+
def base_dir
|
|
19
|
+
return @base_dir if defined?(@base_dir)
|
|
20
|
+
project_specific_len = 20
|
|
21
|
+
project_name = self[:pwd].length > project_specific_len ? self[:pwd][-project_specific_len..-1] : self[:pwd]
|
|
22
|
+
@base_dir = File.expand_path FileUtils.mkdir_p(File.join(escape_dir(self[:host]), escape_dir(project_name)))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def load_environment(&block)
|
|
26
|
+
working_dir = FileUtils.mkdir_p(File.join(base_dir, escape_dir(ENV['DTR_RUNNER_NAME'])))
|
|
21
27
|
Dir.chdir(working_dir) do
|
|
22
|
-
|
|
28
|
+
DTR.info "Loading environment at #{Dir.pwd}"
|
|
29
|
+
|
|
30
|
+
ENV['DTR_MASTER_ENV'] = dtr_master_env
|
|
31
|
+
|
|
32
|
+
setup_environment
|
|
33
|
+
|
|
34
|
+
append_libs_to_load_path
|
|
35
|
+
require_files
|
|
36
|
+
|
|
37
|
+
block.call
|
|
23
38
|
end
|
|
24
39
|
end
|
|
25
40
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def setup_environment_command
|
|
44
|
+
DTR.configuration.agent_env_setup_cmd || self.agent_env_setup_cmd
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def setup_environment
|
|
48
|
+
unless Cmd.execute(setup_environment_command)
|
|
49
|
+
raise "Stopped for setup working environment failed."
|
|
29
50
|
end
|
|
30
51
|
end
|
|
31
52
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
str.gsub(/[^a-zA-Z0-9]/, '_')
|
|
53
|
+
def escape_dir(str)
|
|
54
|
+
str.to_s.gsub(/[^a-zA-Z0-9]/, '_')
|
|
35
55
|
end
|
|
36
56
|
|
|
37
|
-
def
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
def append_libs_to_load_path
|
|
58
|
+
libs.select{ |lib| !$LOAD_PATH.include?(lib) && File.exists?(lib) }.each do |lib|
|
|
59
|
+
$LOAD_PATH << lib
|
|
60
|
+
DTR.debug {"appended lib: #{lib}"}
|
|
61
|
+
end
|
|
62
|
+
DTR.info {"libs appended"}
|
|
63
|
+
DTR.debug {"$LOAD_PATH: #{$LOAD_PATH.inspect}"}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def require_files
|
|
67
|
+
files.each do |f|
|
|
68
|
+
begin
|
|
69
|
+
#use require instead of load to avoid load file twice.
|
|
70
|
+
require f unless f =~ /^-/
|
|
71
|
+
DTR.debug {"required #{f}"}
|
|
72
|
+
rescue LoadError => e
|
|
73
|
+
DTR.error {"No such file to load -- #{f}"}
|
|
74
|
+
DTR.debug {"Environment: #{self}"}
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
DTR.info {"test files loaded"}
|
|
44
78
|
end
|
|
45
79
|
end
|
|
46
80
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
|
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 Agent
|
|
17
|
+
module WorkingStatus
|
|
18
|
+
WORKING_STATUS_KEY = :runners_working_status
|
|
19
|
+
def runners_should_be_working
|
|
20
|
+
@store[WORKING_STATUS_KEY] = Time.now
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def runners_should_be_working?
|
|
24
|
+
if time = @store[WORKING_STATUS_KEY]
|
|
25
|
+
(time - Time.now) <= follower_listen_heartbeat_timeout
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def agent_is_going_to_sleep
|
|
30
|
+
@store[WORKING_STATUS_KEY] = nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/dtr/facade.rb
CHANGED
|
@@ -15,13 +15,8 @@
|
|
|
15
15
|
module DTR
|
|
16
16
|
module Facade
|
|
17
17
|
def start_agent
|
|
18
|
-
launch_agent(DTR_AGENT_OPTIONS[:runners], DTR_AGENT_OPTIONS[:agent_env_setup_cmd])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def launch_agent(names, setup=nil)
|
|
22
18
|
require 'dtr/agent'
|
|
23
|
-
|
|
24
|
-
DTR::Agent.start(names, setup)
|
|
19
|
+
DTR::Agent.start
|
|
25
20
|
end
|
|
26
21
|
|
|
27
22
|
def lib_path
|
|
@@ -29,37 +24,44 @@ module DTR
|
|
|
29
24
|
end
|
|
30
25
|
|
|
31
26
|
def broadcast_list=(list)
|
|
32
|
-
require 'dtr/shared'
|
|
33
27
|
DTR.configuration.broadcast_list = list
|
|
34
28
|
DTR.configuration.save
|
|
35
29
|
end
|
|
36
30
|
|
|
37
31
|
def agent_listen_port=(port)
|
|
38
|
-
require 'dtr/shared'
|
|
39
32
|
DTR.configuration.agent_listen_port = port
|
|
40
33
|
DTR.configuration.save
|
|
41
34
|
end
|
|
42
35
|
|
|
43
36
|
def group=(group)
|
|
44
|
-
require 'dtr/shared'
|
|
45
37
|
DTR.configuration.group = group
|
|
46
38
|
DTR.configuration.save
|
|
47
39
|
end
|
|
48
40
|
|
|
41
|
+
def agent_env_setup_cmd=(cmd)
|
|
42
|
+
DTR.configuration.agent_env_setup_cmd = cmd
|
|
43
|
+
DTR.configuration.save
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def agent_runners=(runners)
|
|
47
|
+
DTR.configuration.agent_runners = runners
|
|
48
|
+
DTR.configuration.save
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def agent_runners
|
|
52
|
+
DTR.configuration.agent_runners
|
|
53
|
+
end
|
|
54
|
+
|
|
49
55
|
def monitor
|
|
50
56
|
require 'dtr/monitor'
|
|
51
57
|
DTR.logger('dtr_monitor.log')
|
|
52
58
|
Monitor.new.start
|
|
53
59
|
end
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def fork_process(&block)
|
|
62
|
-
Process.fork(&block)
|
|
61
|
+
DTR_CMD = File.expand_path(File.dirname(__FILE__) + '/../../bin/dtr')
|
|
62
|
+
def run_script(cmd)
|
|
63
|
+
dtr = (RUBY_PLATFORM =~ /java/ || ENV['JRUBY_DTR']) ? "jruby -S #{DTR_CMD.inspect}" : "ruby #{DTR_CMD.inspect}"
|
|
64
|
+
system "#{dtr} -e #{cmd.inspect}"
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
end
|