tengine_job 0.6.13 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/Gemfile +1 -20
  2. data/Gemfile.lock +70 -72
  3. data/README.rdoc +2 -2
  4. data/bin/create_indexes_for_tengine_job +18 -0
  5. data/lib/tengine/job/connectable.rb +4 -4
  6. data/lib/tengine/job/drivers/job_execution_driver.rb +2 -2
  7. data/lib/tengine/job/drivers/jobnet_control_driver.rb +3 -3
  8. data/lib/tengine/job/drivers/schedule_driver.rb +12 -12
  9. data/lib/tengine/job/edge.rb +2 -2
  10. data/lib/tengine/job/expansion.rb +1 -1
  11. data/lib/tengine/job/jobnet.rb +12 -2
  12. data/lib/tengine/job/jobnet_actual.rb +29 -0
  13. data/lib/tengine/job/root_jobnet_actual.rb +20 -1
  14. data/lib/tengine/job/root_jobnet_template.rb +4 -4
  15. data/lib/tengine/job/signal.rb +1 -1
  16. data/lib/tengine/job/vertex.rb +10 -1
  17. metadata +130 -126
  18. data/.document +0 -5
  19. data/.rspec +0 -1
  20. data/Rakefile +0 -42
  21. data/VERSION +0 -1
  22. data/spec/fixtures/rjn_0001_simple_jobnet_builder.rb +0 -42
  23. data/spec/fixtures/rjn_0002_simple_parallel_jobnet_builder.rb +0 -42
  24. data/spec/fixtures/rjn_0003_fork_join_jobnet_builder.rb +0 -61
  25. data/spec/fixtures/rjn_0004_parallel_jobnet_with_finally_fixture.rb +0 -62
  26. data/spec/fixtures/rjn_0005_retry_two_layer_fixture.rb +0 -153
  27. data/spec/fixtures/rjn_0008_expansion_fixture.rb +0 -32
  28. data/spec/fixtures/rjn_0009_tree_sequential_jobnet_builder.rb +0 -174
  29. data/spec/fixtures/rjn_0010_2jobs_and_1job_parallel_jobnet_builder.rb +0 -39
  30. data/spec/fixtures/rjn_0011_nested_fork_jobnet_builder.rb +0 -96
  31. data/spec/fixtures/rjn_0012_nested_and_finally_builder.rb +0 -157
  32. data/spec/fixtures/rjn_1004_hadoop_job_in_jobnet_fixture.rb +0 -105
  33. data/spec/fixtures/rjn_means_root_jobnet +0 -0
  34. data/spec/fixtures/test_credential_fixture.rb +0 -12
  35. data/spec/fixtures/test_server_fixture.rb +0 -28
  36. data/spec/mongoid.yml +0 -35
  37. data/spec/spec_helper.rb +0 -58
  38. data/spec/sshd/.gitignore +0 -1
  39. data/spec/sshd/id_rsa +0 -51
  40. data/spec/sshd/id_rsa.pub +0 -1
  41. data/spec/sshd/ssh_host_rsa_key +0 -51
  42. data/spec/sshd/ssh_host_rsa_key.pub +0 -1
  43. data/spec/sshd/sshd_config +0 -10
  44. data/spec/sshd/sshd_config.erb +0 -11
  45. data/spec/sshd/tengine_job_test.sh +0 -6
  46. data/spec/support/jobnet_fixture_builder.rb +0 -145
  47. data/spec/support/mongo_index_key_log.rb +0 -91
  48. data/spec/tengine/job/category_spec.rb +0 -193
  49. data/spec/tengine/job/connectable_spec.rb +0 -94
  50. data/spec/tengine/job/drivers/job_controll_driver/connection_error_spec.rb +0 -236
  51. data/spec/tengine/job/drivers/job_controll_driver/duplicated_job_start_spec.rb +0 -302
  52. data/spec/tengine/job/drivers/job_controll_driver/expansion_spec.rb +0 -120
  53. data/spec/tengine/job/drivers/job_controll_driver/stop_spec.rb +0 -159
  54. data/spec/tengine/job/drivers/job_controll_driver_spec.rb +0 -740
  55. data/spec/tengine/job/drivers/job_execution_driver_spec.rb +0 -138
  56. data/spec/tengine/job/drivers/jobnet_control_driver/nested_and_finally_spec.rb +0 -472
  57. data/spec/tengine/job/drivers/jobnet_control_driver/nested_jobnet_spec.rb +0 -231
  58. data/spec/tengine/job/drivers/jobnet_control_driver/stop_jobnet_spec.rb +0 -202
  59. data/spec/tengine/job/drivers/jobnet_control_driver_spec.rb +0 -608
  60. data/spec/tengine/job/drivers/schedule_driver_spec.rb +0 -241
  61. data/spec/tengine/job/dsl_binder_spec.rb +0 -36
  62. data/spec/tengine/job/dsl_loader_spec.rb +0 -437
  63. data/spec/tengine/job/dsls/0013_hadoop_job_run.rb +0 -29
  64. data/spec/tengine/job/dsls/0014_join_and_join.rb +0 -19
  65. data/spec/tengine/job/dsls/0015_fork_and_fork.rb +0 -18
  66. data/spec/tengine/job/dsls/0016_complex_fork_and_join.rb +0 -20
  67. data/spec/tengine/job/dsls/0017_finally.rb +0 -15
  68. data/spec/tengine/job/dsls/0018_expansion.rb +0 -23
  69. data/spec/tengine/job/dsls/0019_execute_job_on_event.rb +0 -16
  70. data/spec/tengine/job/dsls/0020_duplicated_jobnet_name.rb +0 -16
  71. data/spec/tengine/job/dsls/0021_caption.rb +0 -13
  72. data/spec/tengine/job/dsls/1060_test_dir1/1060_test_dir2/0013_hadoop_job_run.rb +0 -29
  73. data/spec/tengine/job/dsls/2003_expansion/expansion_5.rb +0 -11
  74. data/spec/tengine/job/dsls/VERSION +0 -1
  75. data/spec/tengine/job/dynamic_env_spec.rb +0 -95
  76. data/spec/tengine/job/edge_spec.rb +0 -241
  77. data/spec/tengine/job/element_selector_notation_spec.rb +0 -354
  78. data/spec/tengine/job/examples_spec.rb +0 -62
  79. data/spec/tengine/job/execution_spec.rb +0 -100
  80. data/spec/tengine/job/expansion_spec.rb +0 -116
  81. data/spec/tengine/job/hadoop_job_run_spec.rb +0 -65
  82. data/spec/tengine/job/job_spec.rb +0 -4
  83. data/spec/tengine/job/jobnet/1015_complecated_jobnet_spec.rb +0 -72
  84. data/spec/tengine/job/jobnet_actual_spec.rb +0 -175
  85. data/spec/tengine/job/jobnet_spec.rb +0 -399
  86. data/spec/tengine/job/jobnet_template_spec.rb +0 -240
  87. data/spec/tengine/job/killing_spec.rb +0 -91
  88. data/spec/tengine/job/reset_spec.rb +0 -958
  89. data/spec/tengine/job/reset_spec/4056_1_dump.txt +0 -1
  90. data/spec/tengine/job/root_jobnet_actual_spec.rb +0 -89
  91. data/spec/tengine/job/root_jobnet_template_spec.rb +0 -248
  92. data/spec/tengine/job/script_executable_spec.rb +0 -132
  93. data/spec/tengine/job/stoppable_spec.rb +0 -176
  94. data/spec/tengine/job/vertex_spec.rb +0 -25
  95. data/spec/tengine_job_spec.rb +0 -4
  96. data/tengine_job.gemspec +0 -198
  97. data/tmp/log/.gitignore +0 -1
@@ -1,91 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # 使い方
3
- # テスト実行時に 環境変数MONGO_INDEX_KEY_LOGにログの出力先のファイル名を指定しておくと、
4
- # そこにmongoに対してどんな検索条件やソート、ヒントなどをどのように指定しているのかを出力できます
5
- #
6
- # この出力された結果のファイルに対して sort と uniq をかけることにより、どんなインデックスを
7
- # 作れば良いのか判断する材料となります。
8
- #
9
- # export MONGO_INDEX_KEY_LOG=$HOME/tmp/mongo_index_key.log
10
- # cd tenigne_core && rake spec
11
- # cd tenigne_resource && rake spec
12
- # cd tenigne_job && rake spec
13
- # cd tenigne_console && rake spec
14
- # cd $HOME/tmp
15
- # cat mongo_index_key.log | sort | uniq > mongo_index_key_summary.log
16
- #
17
- # これで $HOME/tmp/mongo_index_key_summary.log にどのようなキーが使われているのかがまとめられます
18
- #
19
- if ENV['MONGO_INDEX_KEY_LOG']
20
- file_path = File.expand_path(ENV['MONGO_INDEX_KEY_LOG'])
21
- STDOUT.puts("MONGO_INDEX_KEY_LOG enable logging key infomation for index to #{file_path}")
22
-
23
- Mongo::Collection.class_eval do
24
- def index_key_log_file
25
- unless defined?(@@index_key_log_file)
26
- file_path = File.expand_path(ENV['MONGO_INDEX_KEY_LOG'])
27
- @@index_key_log_file = File.open(file_path, "a")
28
- end
29
- @@index_key_log_file
30
- end
31
-
32
- def find_with_index_key_log(selector={}, opts={}, &block)
33
- result = find_without_index_key_log(selector, opts, &block)
34
- index_key_log_file.puts("#{self.name}.find({#{_hash_keys_(selector)}}, {#{_hash_keys_(opts.dup)}}): #{_explain_summary_(result.explain)}")
35
- result
36
- end
37
- alias_method :find_without_index_key_log, :find
38
- alias_method :find, :find_with_index_key_log
39
-
40
-
41
- def find_and_modify_with_index_key_log(opts={}, &block)
42
- o = opts.dup
43
- query = o.delete(:query)
44
- index_key_log_file.puts("#{self.name}.find_and_modify({#{_hash_keys_(query)}}, {#{_hash_keys_(o)}})")
45
- find_and_modify_without_index_key_log(opts, &block)
46
- end
47
- alias_method :find_and_modify_without_index_key_log, :find_and_modify
48
- alias_method :find_and_modify, :find_and_modify_with_index_key_log
49
-
50
- def _hash_keys_(hash)
51
- res = []
52
- [:sort, :hint, :limit].each do |key|
53
- if value = hash.delete(key)
54
- res << "#{key.inspect} => #{value.inspect}"
55
- end
56
- end
57
- res += hash.keys.map(&:inspect)
58
- res.join(',')
59
- end
60
-
61
- def _explain_summary_(hash)
62
- case cursor = hash['cursor']
63
- when /^BtreeCursor/ then
64
- res = []
65
- %w[cursor].each do |key|
66
- if value = hash.delete(key)
67
- res << "#{key.inspect} => #{value.inspect}"
68
- end
69
- end
70
- res += hash.keys.map(&:inspect)
71
- "{" << res.join(',') << "}"
72
- else
73
- res = []
74
- res << "'cursor' => #{hash.delete('cursor').inspect}"
75
- {"nscanned" => 1, "nscannedObjects" => 1, "n" => 1, "millis" => 0, "nYields"=>0, "nChunkSkips"=>0 }.each do |key, border|
76
- if value = hash.delete(key)
77
- if value > border
78
- res << "#{key.inspect} => '>#{border.inspect}'"
79
- else
80
- res << "#{key.inspect} => #{value.inspect}"
81
- end
82
- end
83
- end
84
- res += hash.keys.map(&:inspect)
85
- "{" << res.join(',') << "}"
86
- end
87
- end
88
-
89
- end
90
-
91
- end
@@ -1,193 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
- require 'tmpdir'
4
- require 'fileutils'
5
-
6
- describe Tengine::Job::Category do
7
-
8
- describe :update_for do
9
-
10
- context "RootJobnetTemplateのdsl_filepathからCategoryを登録します" do
11
-
12
- before do
13
- Tengine::Job::Vertex.delete_all
14
- Tengine::Job::Category.delete_all
15
- @root1 = Tengine::Job::RootJobnetTemplate.create!({
16
- :name => "root_jobnet_template01",
17
- :dsl_filepath => "foo/bar1/jobnet01.rb",
18
- :dsl_lineno => 4,
19
- :dsl_version => "1"
20
- })
21
- @root2 = Tengine::Job::RootJobnetTemplate.create!({
22
- :name => "root_jobnet_template01",
23
- :dsl_filepath => "foo/bar2/jobnet01.rb",
24
- :dsl_lineno => 4,
25
- :dsl_version => "2"
26
- })
27
- @root3 = Tengine::Job::RootJobnetTemplate.create!({
28
- :name => "root_jobnet_template01",
29
- :dsl_filepath => "foo/bar3/jobnet2.rb",
30
- :dsl_lineno => 4,
31
- :dsl_version => "2"
32
- })
33
- @root4 = Tengine::Job::RootJobnetTemplate.create!({
34
- :name => "root_jobnet_template04",
35
- :dsl_filepath => "jobnet4.rb",
36
- :dsl_lineno => 4,
37
- :dsl_version => "2"
38
- })
39
- @tmp_dir = Dir.tmpdir
40
- @base_dir = File.expand_path("root", @tmp_dir)
41
- FileUtils.mkdir_p(File.expand_path("foo/bar2", @base_dir))
42
- FileUtils.mkdir_p(File.expand_path("foo/bar3", @base_dir))
43
- File.open(File.expand_path("dictionary.yml", @tmp_dir), "w"){|f| YAML.dump({"root" => "ルート"}, f)}
44
- File.open(File.expand_path("dictionary.yml", @base_dir), "w"){|f| YAML.dump({"foo" => "ほげ"}, f)}
45
- File.open(File.expand_path("foo/dictionary.yml", @base_dir), "w"){|f|
46
- YAML.dump({"bar1" => "ばー1", "bar2" => "ばー2"}, f)}
47
- end
48
-
49
- context "指定されたバージョンのRootJobneTTemplateからカテゴリを生成します" do
50
- it "全ドキュメントを対象にしています・・・" do
51
- expect{
52
- Tengine::Job::Category.update_for(@base_dir)
53
- }.to change(Tengine::Job::Category, :count).by(5)
54
- root = Tengine::Job::Category.first(:conditions => {:parent_id => nil})
55
- root.name.should == "root"
56
- root.caption.should == "ルート"
57
- root.children.count.should == 1
58
- foo = root.children[0]
59
- foo.name.should == "foo"
60
- foo.caption.should == "ほげ"
61
- foo.children.count.should == 3
62
- foo.children[0].tap do |c|
63
- c.name.should == "bar1"
64
- c.caption.should == "ばー1"
65
- c.parent_id.should == foo.id
66
- @root1.reload
67
- @root1.category_id.should == c.id
68
- end
69
- foo.children[1].tap do |c|
70
- c.name.should == "bar2"
71
- c.caption.should == "ばー2"
72
- c.parent_id.should == foo.id
73
- @root2.reload
74
- @root2.category_id.should == c.id
75
- end
76
- foo.children[2].tap do |c|
77
- c.name.should == "bar3"
78
- c.caption.should == "bar3"
79
- c.parent_id.should == foo.id
80
- @root3.reload
81
- @root3.category_id.should == c.id
82
- end
83
- end
84
- end
85
-
86
- it "後から追加された場合" do
87
- expect{
88
- Tengine::Job::Category.update_for(@base_dir)
89
- }.to change(Tengine::Job::Category, :count).by(5)
90
- @root4 = Tengine::Job::RootJobnetTemplate.create!({
91
- :name => "root_jobnet_template01",
92
- :dsl_filepath => "foo/bar3/baz1/jobnet2.rb",
93
- :dsl_lineno => 4,
94
- :dsl_version => "3"
95
- })
96
- expect{
97
- Tengine::Job::Category.update_for(@base_dir)
98
- }.to change(Tengine::Job::Category, :count).by(1)
99
- root = Tengine::Job::Category.first(:conditions => {:parent_id => nil})
100
- foo = root.children[0]
101
- foo.children[2].tap do |bar3|
102
- bar3.name.should == "bar3"
103
- bar3.caption.should == "bar3"
104
- bar3.parent_id.should == foo.id
105
- bar3.children.first.tap do |baz1|
106
- baz1.name.should == "baz1"
107
- baz1.caption.should == "baz1"
108
- baz1.parent_id.should == bar3.id
109
- @root4.reload
110
- @root4.category_id.should == baz1.id
111
- end
112
- end
113
- end
114
-
115
- it "Tengine::Job.notifyでジョブDSLのロード終了を通知された場合" do
116
- mock_config = mock(:config)
117
- mock_config.should_receive(:dsl_dir_path).and_return(@base_dir)
118
- mock_sender = mock(:sender)
119
- mock_sender.should_receive(:respond_to?).with(:config).and_return(true)
120
- mock_sender.should_receive(:config).and_return(mock_config)
121
- expect{
122
- Tengine::Job.notify(mock_sender, :after_load_dsl)
123
- }.to change(Tengine::Job::Category, :count).by(5)
124
- root = Tengine::Job::Category.first(:conditions => {:parent_id => nil})
125
- root.name.should == "root"
126
- root.caption.should == "ルート"
127
- root.children.count.should == 1
128
- foo = root.children[0]
129
- foo.name.should == "foo"
130
- foo.caption.should == "ほげ"
131
- foo.should_not be_nil
132
- foo.children.count.should == 3
133
- foo.children[0].tap do |c|
134
- c.name.should == "bar1"
135
- c.caption.should == "ばー1"
136
- c.parent_id.should == foo.id
137
- @root1.reload
138
- @root1.category_id.should == c.id
139
- end
140
- foo.children[1].tap do |c|
141
- c.name.should == "bar2"
142
- c.caption.should == "ばー2"
143
- c.parent_id.should == foo.id
144
- @root2.reload
145
- @root2.category_id.should == c.id
146
- end
147
- foo.children[2].tap do |c|
148
- c.name.should == "bar3"
149
- c.caption.should == "bar3"
150
- c.parent_id.should == foo.id
151
- @root3.reload
152
- @root3.category_id.should == c.id
153
- end
154
- end
155
-
156
- end
157
-
158
- end
159
-
160
-
161
- describe "名前で検索" do
162
- before do
163
- Tengine::Job::Category.delete_all
164
- Tengine::Job::Category.create!(:name => "category1", :caption => "ONE")
165
- Tengine::Job::Category.create!(:name => "category2", :caption => "TWO")
166
- end
167
-
168
- [:find_by_name, :find_by_name!].each do |method_name|
169
- it "存在する場合はそれを返す" do
170
- driver = Tengine::Job::Category.send(method_name, "category1")
171
- driver.should be_a(Tengine::Job::Category)
172
- driver.name.should == "category1"
173
- driver.caption.should == "ONE"
174
- end
175
- end
176
-
177
- it ":find_by_nameは見つからなかった場合はnilを返す" do
178
- Tengine::Job::Category.find_by_name("unexist_category").should == nil
179
- end
180
-
181
- it ":find_by_name!は見つからなかった場合はTengine::Core::FindByName::Errorをraiseする" do
182
- begin
183
- Tengine::Job::Category.find_by_name!("unexist_category")
184
- rescue Tengine::Errors::NotFound => e
185
- e.message.should == "Tengine::Job::Category named \"unexist_category\" not found"
186
- end
187
- end
188
-
189
- end
190
-
191
-
192
-
193
- end
@@ -1,94 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Tengine::Job::Connectable do
5
-
6
- context "Rjn0001SimpleJobnetBuilderを使う場合" do
7
- [:actual, :template].each do |jobnet_type|
8
- context "#{jobnet_type}の場合" do
9
-
10
- before(:all) do
11
- builder = Rjn0009TreeSequentialJobnetBuilder.new
12
- builder.send(:"create_#{jobnet_type}")
13
- @ctx = builder.context
14
- end
15
-
16
- {
17
- "rjn0009" => [nil, nil],
18
- "j1100" => ["test_credential1" , "test_server1"],
19
- "j1110" => ["test_credential1" , "test_server1"],
20
- "j1120" => ["test_credential1" , "test_server1"],
21
- "j1200" => ["test_credential1" , nil ],
22
- "j1210" => ["test_credential1" , "mysql_master"],
23
- "j1300" => [nil , "mysql_master"],
24
- "j1310" => ["test_credential1" , "mysql_master"],
25
- "j1400" => [nil , nil ],
26
- "j1410" => ["test_credential1" , "mysql_master"],
27
- "j1500" => ["test_credential1" , "mysql_master"],
28
- "j1510" => ["test_credential1" , "mysql_master"],
29
- "j1511" => ["test_credential1" , "mysql_master"],
30
- "j1600" => ["test_credential1" , "mysql_master"],
31
- "j1610" => ["test_credential1" , "mysql_master"],
32
- "j1611" => ["test_credential1" , "test_server1"],
33
- "j1612" => ["gohan_ssh_pk" , "mysql_master"],
34
- "j1620" => ["test_credential1" , "test_server1"],
35
- "j1621" => ["test_credential1" , "test_server1"],
36
- "j1630" => ["gohan_ssh_pk", "mysql_master" ],
37
- "j1631" => ["gohan_ssh_pk", "mysql_master" ],
38
- }.each do |job_name, (credential_name, server_name)|
39
- context job_name do
40
- subject{ @ctx[job_name.to_sym] }
41
- its(:actual_credential_name){ should == credential_name }
42
- its(:actual_server_name){ should == server_name }
43
- end
44
- end
45
-
46
- end
47
- end
48
-
49
- end
50
-
51
- describe :actual_credential do
52
- before do
53
- resource_fixture = GokuAtEc2ApNortheast.new
54
- resource_fixture.goku_ssh_pw
55
- end
56
-
57
- it "存在するCredentialの場合" do
58
- jobnet = Tengine::Job::JobnetTemplate.new(:credential_name => "test_credential1")
59
- credential = jobnet.actual_credential
60
- credential.should be_a(Tengine::Resource::Credential)
61
- credential.name.should == "test_credential1"
62
- end
63
-
64
- it "存在しないCredentialの場合" do
65
- jobnet = Tengine::Job::JobnetTemplate.new(:credential_name => "unexist_credential")
66
- expect{
67
- jobnet.actual_credential
68
- }.to raise_error(Mongoid::Errors::DocumentNotFound)
69
- end
70
- end
71
-
72
-
73
- describe :actual_server do
74
- before do
75
- resource_fixture = GokuAtEc2ApNortheast.new
76
- resource_fixture.hadoop_master_node
77
- end
78
-
79
- it "存在するServerの場合" do
80
- jobnet = Tengine::Job::JobnetTemplate.new(:server_name => "test_server1")
81
- server = jobnet.actual_server
82
- server.should be_a(Tengine::Resource::Server)
83
- server.name.should == "test_server1"
84
- end
85
-
86
- it "存在しないServerの場合" do
87
- jobnet = Tengine::Job::JobnetTemplate.new(:server_name => "unexist_server")
88
- expect{
89
- jobnet.actual_server
90
- }.to raise_error(Mongoid::Errors::DocumentNotFound)
91
- end
92
- end
93
-
94
- end
@@ -1,236 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
- require 'tengine/rspec'
4
-
5
- describe 'connection error' do
6
- include Tengine::RSpec::Extension
7
-
8
- target_dsl File.expand_path("../../../../../lib/tengine/job/drivers/job_control_driver.rb", File.dirname(__FILE__))
9
- driver :job_control_driver
10
-
11
- let :ssh_dir do
12
- File.expand_path("../../../../../sshd", __FILE__)
13
- end
14
-
15
- before :all do
16
- raise "WRONG" if $_pid
17
-
18
- uid = Etc.getlogin
19
- case uid
20
- when "root"
21
- pending "rootは危険なのでこのテストを実行できません"
22
- when NilClass
23
- raise "who am i?"
24
- end
25
-
26
- # 1. sshdをさがす
27
- sshd = nil
28
- ENV["PATH"].split(/:/).find do |dir|
29
- Dir.glob("#{dir}/sshd") do |path|
30
- if File.executable?(path)
31
- sshd = path
32
- break
33
- end
34
- end
35
- end
36
-
37
- raise "sshd not found" unless sshd
38
-
39
- # 2. sshd_configの生成
40
- template = File.expand_path("sshd_config.erb", ssh_dir)
41
- hostkey = File.expand_path("ssh_host_rsa_key", ssh_dir)
42
- clientkey = File.expand_path("id_rsa", ssh_dir)
43
- File.chmod(0400, hostkey, clientkey)
44
- File.chmod(0700, ssh_dir)
45
- $_port = nil
46
-
47
- # 指定したポートはもう使われているかもしれないので、その際は
48
- # sshdが起動に失敗するので、何回かポートを変えて試す。
49
- catch(:return) do
50
- n = 0
51
- @port = rand(32768)
52
- begin
53
- Tempfile.open("sshd_config", ssh_dir) do |conf|
54
- File.open(template, "rb") do |tmpl|
55
- conf.write ERB.new(tmpl.read).result(binding)
56
- end
57
- conf.flush
58
- conf.close(false) # no unlink
59
- argv = [sshd, "-Def", conf.path, "-h", hostkey]
60
- $_pid = Process.spawn(*argv)
61
- x = Time.now
62
- while Time.now < x + 16.0 do # まあこんくらい待てばいいでしょ
63
- sleep 0.1
64
- Process.waitpid2($_pid, Process::WNOHANG)
65
- Process.kill 0, $_pid
66
- # netstat -an は Linux / BSD ともに有効
67
- # どちらかに限ればもう少し効率的な探し方はある。たとえば Linux 限定でよければ netstat -lnt ...
68
- y = `netstat -an | fgrep LISTEN | fgrep #{@port}`
69
- if y.lines.to_a.size > 1
70
- $_port = @port
71
- throw :return
72
- end
73
- end
74
- pending "failed to invoke sshd in 16 secs."
75
- end
76
- rescue Errno::ECHILD, Errno::ESRCH
77
- if (n += 1) > 10
78
- pending "10 attempts to invoke sshd failed."
79
- else
80
- @port = rand(32768)
81
- retry
82
- end
83
- end
84
- end
85
- end
86
-
87
- after :all do
88
- if $_pid
89
- begin
90
- Process.kill "INT", $_pid
91
- Process.waitpid $_pid
92
- rescue Errno::ECHILD
93
- end
94
- end
95
- end
96
-
97
- # in [rjn0001]
98
- # (S1) --e1-->(j11)--e2-->(j12)--e3-->(E1)
99
- #
100
- context "rjn0001" do
101
- before do
102
- Tengine::Job::Vertex.delete_all
103
- builder = Rjn0001SimpleJobnetBuilder.new
104
- @root = builder.create_actual
105
- @ctx = builder.context
106
- @execution = Tengine::Job::Execution.create!({
107
- :root_jobnet_id => @root.id,
108
- })
109
- @base_props = {
110
- :execution_id => @execution.id.to_s,
111
- :root_jobnet_id => @root.id.to_s,
112
- :target_jobnet_id => @root.id.to_s,
113
- }
114
- Tengine::Resource::Server.find_by_name("test_server1").update_attributes :properties => { :ssh_port => $_port }
115
- end
116
-
117
- after do
118
- # 中身を書き換えてしまうので他のテストに影響しないように削除します
119
- Tengine::Resource::Credential.delete_all
120
- Tengine::Resource::Server.delete_all
121
- end
122
-
123
- context "credential not found" do
124
- it "対象のジョブはerrorになりエラーイベントが発火される" do
125
- Tengine::Resource::Credential.delete_all
126
- @root.phase_key = :starting
127
- @ctx.edge(:e1).phase_key = :transmitting
128
- @ctx.vertex(:j11).phase_key = :ready
129
- @root.save!
130
- @root.reload
131
- tengine.should_fire(:"error.job.job.tengine", an_instance_of(Hash))
132
- tengine.receive("start.job.job.tengine", :properties => {
133
- :execution_id => @execution.id.to_s,
134
- :root_jobnet_id => @root.id.to_s,
135
- :root_jobnet_name_path => @root.name_path,
136
- :target_jobnet_id => @root.id.to_s,
137
- :target_jobnet_name_path => @root.name_path,
138
- :target_job_id => @ctx.vertex(:j11).id.to_s,
139
- :target_job_name_path => @ctx.vertex(:j11).name_path,
140
- })
141
- @root.reload
142
- @ctx.edge(:e1).phase_key.should == :transmitted
143
- @ctx.edge(:e2).phase_key.should == :active
144
- @ctx.vertex(:j11).phase_key.should == :error
145
- end
146
- end
147
-
148
-
149
- context "wrong credential" do
150
- it "対象のジョブはerrorになりエラーイベントが発火される" do
151
- credential = Tengine::Resource::Credential.find_by_name("test_credential1")
152
- hash = credential.auth_values.dup
153
- hash['username'] = "piccolo"
154
- credential.auth_values = hash
155
- credential.save!
156
- @root.phase_key = :starting
157
- @ctx.edge(:e1).phase_key = :transmitting
158
- @ctx.vertex(:j11).phase_key = :ready
159
- @root.save!
160
- @root.reload
161
- tengine.should_fire(:"error.job.job.tengine", an_instance_of(Hash))
162
- tengine.receive("start.job.job.tengine", :properties => {
163
- :execution_id => @execution.id.to_s,
164
- :root_jobnet_id => @root.id.to_s,
165
- :root_jobnet_name_path => @root.name_path,
166
- :target_jobnet_id => @root.id.to_s,
167
- :target_jobnet_name_path => @root.name_path,
168
- :target_job_id => @ctx.vertex(:j11).id.to_s,
169
- :target_job_name_path => @ctx.vertex(:j11).name_path,
170
- })
171
- @root.reload
172
- @ctx.edge(:e1).phase_key.should == :transmitted
173
- @ctx.edge(:e2).phase_key.should == :active
174
- @ctx.vertex(:j11).phase_key.should == :error
175
- end
176
- end
177
-
178
- context "server not found" do
179
- it "対象のジョブはerrorになりエラーイベントが発火される" do
180
- Tengine::Resource::Server.delete_all
181
- @root.phase_key = :starting
182
- @ctx.edge(:e1).phase_key = :transmitting
183
- @ctx.vertex(:j11).phase_key = :ready
184
- @root.save!
185
- @root.reload
186
- tengine.should_fire(:"error.job.job.tengine", an_instance_of(Hash))
187
- tengine.receive("start.job.job.tengine", :properties => {
188
- :execution_id => @execution.id.to_s,
189
- :root_jobnet_id => @root.id.to_s,
190
- :root_jobnet_name_path => @root.name_path,
191
- :target_jobnet_id => @root.id.to_s,
192
- :target_jobnet_name_path => @root.name_path,
193
- :target_job_id => @ctx.vertex(:j11).id.to_s,
194
- :target_job_name_path => @ctx.vertex(:j11).name_path,
195
- })
196
- @root.reload
197
- @ctx.edge(:e1).phase_key.should == :transmitted
198
- @ctx.edge(:e2).phase_key.should == :active
199
- @ctx.vertex(:j11).phase_key.should == :error
200
- end
201
- end
202
-
203
-
204
- context "wrong server IP" do
205
- it "対象のジョブはerrorになりエラーイベントが発火される" do
206
- server = Tengine::Resource::Server.find_by_name("test_server1")
207
- server.addresses = {'private_ip_address' => "unexist_ip"}
208
- server.save!
209
- @root.phase_key = :starting
210
- @ctx.edge(:e1).phase_key = :transmitting
211
- @ctx.vertex(:j11).phase_key = :ready
212
- @root.save!
213
- @root.reload
214
- tengine.should_fire(:"error.job.job.tengine", an_instance_of(Hash))
215
- tengine.receive("start.job.job.tengine", :properties => {
216
- :execution_id => @execution.id.to_s,
217
- :root_jobnet_id => @root.id.to_s,
218
- :root_jobnet_name_path => @root.name_path,
219
- :target_jobnet_id => @root.id.to_s,
220
- :target_jobnet_name_path => @root.name_path,
221
- :target_job_id => @ctx.vertex(:j11).id.to_s,
222
- :target_job_name_path => @ctx.vertex(:j11).name_path,
223
- })
224
- @root.reload
225
- @ctx.edge(:e1).phase_key.should == :transmitted
226
- @ctx.edge(:e2).phase_key.should == :active
227
- @ctx.vertex(:j11).phase_key.should == :error
228
- end
229
- end
230
-
231
-
232
- end
233
-
234
- end
235
-
236
-