tengine_job 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +23 -0
  4. data/Gemfile.lock +109 -0
  5. data/README.rdoc +20 -0
  6. data/Rakefile +42 -0
  7. data/VERSION +1 -0
  8. data/examples/0004_retry_one_layer.rb +24 -0
  9. data/examples/0004_retry_one_layer.sh +38 -0
  10. data/examples/0005_retry_two_layer.rb +54 -0
  11. data/examples/0005_retry_two_layer.sh +80 -0
  12. data/examples/0006_retry_three_layer.rb +58 -0
  13. data/examples/0006_retry_three_layer.sh +74 -0
  14. data/examples/0007_simple_jobnet.rb +7 -0
  15. data/examples/0021_dynamic_env.rb +20 -0
  16. data/examples/VERSION +1 -0
  17. data/examples/tengine_job_test.sh +10 -0
  18. data/lib/tengine/job.rb +94 -0
  19. data/lib/tengine/job/category.rb +54 -0
  20. data/lib/tengine/job/connectable.rb +43 -0
  21. data/lib/tengine/job/drivers/job_control_driver.rb +82 -0
  22. data/lib/tengine/job/drivers/job_execution_driver.rb +30 -0
  23. data/lib/tengine/job/drivers/jobnet_control_driver.rb +117 -0
  24. data/lib/tengine/job/drivers/schedule_driver.rb +30 -0
  25. data/lib/tengine/job/dsl_binder.rb +12 -0
  26. data/lib/tengine/job/dsl_evaluator.rb +18 -0
  27. data/lib/tengine/job/dsl_loader.rb +180 -0
  28. data/lib/tengine/job/edge.rb +150 -0
  29. data/lib/tengine/job/element_selector_notation.rb +169 -0
  30. data/lib/tengine/job/end.rb +32 -0
  31. data/lib/tengine/job/executable.rb +74 -0
  32. data/lib/tengine/job/execution.rb +141 -0
  33. data/lib/tengine/job/expansion.rb +37 -0
  34. data/lib/tengine/job/fork.rb +6 -0
  35. data/lib/tengine/job/job.rb +23 -0
  36. data/lib/tengine/job/jobnet.rb +173 -0
  37. data/lib/tengine/job/jobnet/builder.rb +150 -0
  38. data/lib/tengine/job/jobnet/job_state_transition.rb +167 -0
  39. data/lib/tengine/job/jobnet/jobnet_state_transition.rb +110 -0
  40. data/lib/tengine/job/jobnet/state_transition.rb +37 -0
  41. data/lib/tengine/job/jobnet_actual.rb +55 -0
  42. data/lib/tengine/job/jobnet_template.rb +10 -0
  43. data/lib/tengine/job/join.rb +6 -0
  44. data/lib/tengine/job/junction.rb +29 -0
  45. data/lib/tengine/job/killing.rb +30 -0
  46. data/lib/tengine/job/mm_compatibility.rb +6 -0
  47. data/lib/tengine/job/mm_compatibility/connectable.rb +13 -0
  48. data/lib/tengine/job/name_path.rb +31 -0
  49. data/lib/tengine/job/root.rb +16 -0
  50. data/lib/tengine/job/root_jobnet_actual.rb +39 -0
  51. data/lib/tengine/job/root_jobnet_template.rb +49 -0
  52. data/lib/tengine/job/script_executable.rb +235 -0
  53. data/lib/tengine/job/signal.rb +121 -0
  54. data/lib/tengine/job/start.rb +20 -0
  55. data/lib/tengine/job/stoppable.rb +15 -0
  56. data/lib/tengine/job/vertex.rb +172 -0
  57. data/lib/tengine_job.rb +3 -0
  58. data/spec/fixtures/rjn_0001_simple_jobnet_builder.rb +42 -0
  59. data/spec/fixtures/rjn_0002_simple_parallel_jobnet_builder.rb +42 -0
  60. data/spec/fixtures/rjn_0003_fork_join_jobnet_builder.rb +61 -0
  61. data/spec/fixtures/rjn_0004_parallel_jobnet_with_finally_fixture.rb +62 -0
  62. data/spec/fixtures/rjn_0005_retry_two_layer_fixture.rb +153 -0
  63. data/spec/fixtures/rjn_0008_expansion_fixture.rb +32 -0
  64. data/spec/fixtures/rjn_0009_tree_sequential_jobnet_builder.rb +174 -0
  65. data/spec/fixtures/rjn_0010_2jobs_and_1job_parallel_jobnet_builder.rb +39 -0
  66. data/spec/fixtures/rjn_0011_nested_fork_jobnet_builder.rb +96 -0
  67. data/spec/fixtures/rjn_0012_nested_and_finally_builder.rb +157 -0
  68. data/spec/fixtures/rjn_1004_hadoop_job_in_jobnet_fixture.rb +105 -0
  69. data/spec/fixtures/rjn_means_root_jobnet +0 -0
  70. data/spec/fixtures/test_credential_fixture.rb +12 -0
  71. data/spec/fixtures/test_server_fixture.rb +28 -0
  72. data/spec/mongoid.yml +35 -0
  73. data/spec/spec_helper.rb +56 -0
  74. data/spec/sshd/.gitignore +1 -0
  75. data/spec/sshd/id_rsa +51 -0
  76. data/spec/sshd/id_rsa.pub +1 -0
  77. data/spec/sshd/ssh_host_rsa_key +51 -0
  78. data/spec/sshd/ssh_host_rsa_key.pub +1 -0
  79. data/spec/sshd/sshd_config +10 -0
  80. data/spec/sshd/sshd_config.erb +11 -0
  81. data/spec/sshd/tengine_job_test.sh +6 -0
  82. data/spec/support/jobnet_fixture_builder.rb +145 -0
  83. data/spec/support/mongo_index_key_log.rb +91 -0
  84. data/spec/tengine/job/category_spec.rb +193 -0
  85. data/spec/tengine/job/connectable_spec.rb +94 -0
  86. data/spec/tengine/job/drivers/job_controll_driver/connection_error_spec.rb +236 -0
  87. data/spec/tengine/job/drivers/job_controll_driver/duplicated_job_start_spec.rb +302 -0
  88. data/spec/tengine/job/drivers/job_controll_driver/expansion_spec.rb +120 -0
  89. data/spec/tengine/job/drivers/job_controll_driver/stop_spec.rb +159 -0
  90. data/spec/tengine/job/drivers/job_controll_driver_spec.rb +623 -0
  91. data/spec/tengine/job/drivers/job_execution_driver_spec.rb +88 -0
  92. data/spec/tengine/job/drivers/jobnet_control_driver/nested_and_finally_spec.rb +472 -0
  93. data/spec/tengine/job/drivers/jobnet_control_driver/nested_jobnet_spec.rb +231 -0
  94. data/spec/tengine/job/drivers/jobnet_control_driver/stop_jobnet_spec.rb +202 -0
  95. data/spec/tengine/job/drivers/jobnet_control_driver_spec.rb +446 -0
  96. data/spec/tengine/job/drivers/schedule_driver_spec.rb +202 -0
  97. data/spec/tengine/job/dsl_binder_spec.rb +36 -0
  98. data/spec/tengine/job/dsl_loader_spec.rb +403 -0
  99. data/spec/tengine/job/dsls/0013_hadoop_job_run.rb +29 -0
  100. data/spec/tengine/job/dsls/0014_join_and_join.rb +19 -0
  101. data/spec/tengine/job/dsls/0015_fork_and_fork.rb +18 -0
  102. data/spec/tengine/job/dsls/0016_complex_fork_and_join.rb +20 -0
  103. data/spec/tengine/job/dsls/0017_finally.rb +15 -0
  104. data/spec/tengine/job/dsls/0018_expansion.rb +23 -0
  105. data/spec/tengine/job/dsls/0019_execute_job_on_event.rb +16 -0
  106. data/spec/tengine/job/dsls/0020_duplicated_jobnet_name.rb +16 -0
  107. data/spec/tengine/job/dsls/1060_test_dir1/1060_test_dir2/0013_hadoop_job_run.rb +29 -0
  108. data/spec/tengine/job/dsls/2003_expansion/expansion_5.rb +11 -0
  109. data/spec/tengine/job/dsls/VERSION +1 -0
  110. data/spec/tengine/job/dynamic_env_spec.rb +95 -0
  111. data/spec/tengine/job/edge_spec.rb +241 -0
  112. data/spec/tengine/job/element_selector_notation_spec.rb +354 -0
  113. data/spec/tengine/job/examples_spec.rb +62 -0
  114. data/spec/tengine/job/execution_spec.rb +100 -0
  115. data/spec/tengine/job/expansion_spec.rb +116 -0
  116. data/spec/tengine/job/hadoop_job_run_spec.rb +65 -0
  117. data/spec/tengine/job/job_spec.rb +4 -0
  118. data/spec/tengine/job/jobnet/1015_complecated_jobnet_spec.rb +72 -0
  119. data/spec/tengine/job/jobnet_actual_spec.rb +175 -0
  120. data/spec/tengine/job/jobnet_spec.rb +399 -0
  121. data/spec/tengine/job/jobnet_template_spec.rb +240 -0
  122. data/spec/tengine/job/killing_spec.rb +91 -0
  123. data/spec/tengine/job/reset_spec.rb +958 -0
  124. data/spec/tengine/job/reset_spec/4056_1_dump.txt +1 -0
  125. data/spec/tengine/job/root_jobnet_actual_spec.rb +89 -0
  126. data/spec/tengine/job/root_jobnet_template_spec.rb +248 -0
  127. data/spec/tengine/job/script_executable_spec.rb +132 -0
  128. data/spec/tengine/job/stoppable_spec.rb +176 -0
  129. data/spec/tengine/job/vertex_spec.rb +25 -0
  130. data/spec/tengine_job_spec.rb +4 -0
  131. data/tengine_job.gemspec +197 -0
  132. data/tmp/log/.gitignore +1 -0
  133. metadata +296 -0
@@ -0,0 +1,88 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'tengine/rspec'
4
+
5
+ describe 'job_execution_driver' do
6
+ include Tengine::RSpec::Extension
7
+
8
+ target_dsl File.expand_path("../../../../lib/tengine/job/drivers/job_execution_driver.rb", File.dirname(__FILE__))
9
+ driver :job_execution_driver
10
+
11
+ # in [rjn0001]
12
+ # (S1) --e1-->(j11)--e2-->(j12)--e3-->(E1)
13
+ context "rjn0001" do
14
+ before do
15
+ Tengine::Job::Vertex.delete_all
16
+ builder = Rjn0001SimpleJobnetBuilder.new
17
+ @root = builder.create_actual
18
+ @ctx = builder.context
19
+ @execution = Tengine::Job::Execution.create!({
20
+ :root_jobnet_id => @root.id,
21
+ })
22
+ end
23
+
24
+ it "ジョブの起動イベントを受け取ったら" do
25
+ @execution.phase_key = :initialized
26
+ @execution.save!
27
+ @root.phase_key = :initialized
28
+ @root.save!
29
+ tengine.should_fire(:"start.jobnet.job.tengine",
30
+ :source_name => @root.name_as_resource,
31
+ :properties => {
32
+ :execution_id => @execution.id.to_s,
33
+ :root_jobnet_id => @root.id.to_s,
34
+ :root_jobnet_name_path => @root.name_path,
35
+ :target_jobnet_id => @root.id.to_s,
36
+ :target_jobnet_name_path => @root.name_path,
37
+ })
38
+ tengine.receive("start.execution.job.tengine", :properties => {
39
+ :execution_id => @execution.id.to_s,
40
+ :root_jobnet_id => @root.id.to_s,
41
+ :root_jobnet_name_path => @root.name_path,
42
+ :target_jobnet_id => @root.id.to_s,
43
+ :target_jobnet_name_path => @root.name_path,
44
+ })
45
+ @execution.reload
46
+ @execution.phase_key.should == :starting
47
+ @root.reload
48
+ @root.phase_key.should == :ready
49
+ end
50
+
51
+ %w[user_stop timeout].each do |stop_reason|
52
+ context stop_reason do
53
+ it "強制停止イベントを受け取ったら" do
54
+ @execution.phase_key = :running
55
+ @execution.save!
56
+ @root.phase_key = :running
57
+ @root.save!
58
+ tengine.should_fire(:"stop.jobnet.job.tengine",
59
+ :source_name => @root.name_as_resource,
60
+ :properties => {
61
+ :execution_id => @execution.id.to_s,
62
+ :root_jobnet_id => @root.id.to_s,
63
+ :root_jobnet_name_path => @root.name_path,
64
+ :target_jobnet_id => @root.id.to_s,
65
+ :target_jobnet_name_path => @root.name_path,
66
+ :stop_reason => stop_reason
67
+ })
68
+ tengine.receive("stop.execution.job.tengine",
69
+ :source_name => @execution.name_as_resource,
70
+ :properties => {
71
+ :execution_id => @execution.id.to_s,
72
+ :root_jobnet_id => @root.id.to_s,
73
+ :root_jobnet_name_path => @root.name_path,
74
+ :target_jobnet_id => @root.id.to_s,
75
+ :target_jobnet_name_path => @root.name_path,
76
+ :stop_reason => stop_reason
77
+ })
78
+ @execution.reload
79
+ @execution.phase_key.should == :dying
80
+ @root.reload
81
+ @root.phase_key.should == :running
82
+ end
83
+ end
84
+ end
85
+ # jobnet_control_driverでexecution起動後の処理を行っています
86
+ end
87
+
88
+ end
@@ -0,0 +1,472 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'tengine/rspec'
4
+
5
+ describe 'jobnet_control_driver' do
6
+ include Tengine::RSpec::Extension
7
+
8
+ target_dsl File.expand_path("../../../../../lib/tengine/job/drivers/jobnet_control_driver.rb", File.dirname(__FILE__))
9
+ driver :jobnet_control_driver
10
+
11
+ # in [rjn0012]
12
+ # (S1)--e1-->[j1000]--e2-->[j2000]--e3-->(E1)
13
+ #
14
+ # in [j1000]
15
+ # (S2)--e4-->[j1100]--e5-->[j1200]--e6-->(E2)
16
+ #
17
+ # in [j1100]
18
+ # (S3)--e7-->(j1110)--e8-->(E3)
19
+ #
20
+ # in [j1200]
21
+ # (S4)--e9-->(j1210)--e10-->(E4)
22
+ #
23
+ # in [j1000:finally (=j1f00)]
24
+ # (S5)--e11-->[j1f10]--e12-->(E5)
25
+ #
26
+ # in [j1f10]
27
+ # (S6)--e13-->(j1f11)--e14-->(E6)
28
+ #
29
+ # in [j1000:finally:finally (=j1ff0)]
30
+ # (S7)--e15-->(j1ff1)--e16-->(E7)
31
+ #
32
+ # in [j2000]
33
+ # (S8)--e17-->(j2100)--e18-->(E8)
34
+ #
35
+ # in [jf000:finally (=jf000)]
36
+ # (S9)--e19-->(jf100)--e20-->(E9)
37
+ #
38
+ context "rjn0012" do
39
+ before do
40
+ Tengine::Job::Vertex.delete_all
41
+ builder = Rjn0012NestedAndFinallyBuilder.new
42
+ @root = builder.create_actual
43
+ @ctx = builder.context
44
+ @execution = Tengine::Job::Execution.create!({
45
+ :root_jobnet_id => @root.id,
46
+ })
47
+ @base_props = {
48
+ :execution_id => @execution.id.to_s,
49
+ :root_jobnet_id => @root.id.to_s,
50
+ :root_jobnet_name_path => @root.name_path,
51
+ :target_jobnet_id => @root.id.to_s,
52
+ :target_jobnet_name_path => @root.name_path,
53
+ }
54
+ end
55
+
56
+ context "j1100が終了して" do
57
+ it "j1100が成功した場合、j1200を実行するイベントが発火される" do
58
+ @root.phase_key = :running
59
+ @ctx.vertex(:j1000).phase_key = :running
60
+ @ctx.vertex(:j1100).phase_key = :success
61
+ @ctx.vertex(:j1110).phase_key = :success
62
+ @ctx.vertex(:j1200).phase_key = :initialized
63
+ @ctx.vertex(:j1000).finally_vertex.phase_key = :initialized
64
+ [:e1, :e4, :e7, :e8].each{|name| @ctx.edge(name).phase_key = :transmitted}
65
+ @root.save!
66
+ tengine.should_fire(:"start.jobnet.job.tengine",
67
+ :source_name => @ctx[:j1200].name_as_resource,
68
+ :properties => @base_props.merge({
69
+ :target_jobnet_id => @ctx[:j1200].id.to_s,
70
+ :target_jobnet_name_path => @ctx[:j1200].name_path,
71
+ }))
72
+ tengine.receive(:"success.jobnet.job.tengine",
73
+ :properties => @base_props.merge({
74
+ :target_jobnet_id => @ctx[:j1100].id.to_s,
75
+ :target_jobnet_name_path => @ctx[:j1100].name_path,
76
+ }))
77
+ @root.reload
78
+ [:e1, :e4, :e5, :e7, :e8].each{|name| @ctx.edge(name).phase_key = :transmitted}
79
+ [:e2, :e3, :e6 ].each{|name| @ctx.edge(name).phase_key = :active }
80
+ @ctx.vertex(:j1100).phase_key.should == :success
81
+ @ctx.vertex(:j1200).phase_key.should == :ready
82
+ @ctx.vertex(:j1000).finally_vertex.phase_key.should == :initialized
83
+ end
84
+
85
+ it "j1100が失敗した場合、j1200ではなく、j1f00が実行するイベントが発火される" do
86
+ @root.phase_key = :running
87
+ @ctx.vertex(:j1000).phase_key = :running
88
+ @ctx.vertex(:j1100).phase_key = :error
89
+ @ctx.vertex(:j1110).phase_key = :error
90
+ @ctx.vertex(:j1200).phase_key = :initialized
91
+ @ctx.vertex(:j1000).finally_vertex.phase_key = :initialized
92
+ [:e1, :e4, :e7].each{ |name| @ctx.edge(name).phase_key = :transmitted}
93
+ [:e8 ].each{ |name| @ctx.edge(name).phase_key = :closed }
94
+ [:e5, :e6 ].each{ |name| @ctx.edge(name).phase_key = :active }
95
+ @root.save!
96
+ tengine.should_fire(:"start.jobnet.job.tengine",
97
+ :source_name => @ctx[:j1000].finally_vertex.name_as_resource,
98
+ :properties => @base_props.merge({
99
+ :target_jobnet_id => @ctx[:j1000].finally_vertex.id.to_s,
100
+ :target_jobnet_name_path => @ctx[:j1000].finally_vertex.name_path,
101
+ }))
102
+ tengine.receive(:"error.jobnet.job.tengine",
103
+ :properties => @base_props.merge({
104
+ :target_jobnet_id => @ctx[:j1100].id.to_s,
105
+ :target_jobnet_name_path => @ctx[:j1100].name_path,
106
+ }))
107
+ @root.reload
108
+ [:e1, :e4, :e7].each{ |name| [name, @ctx.edge(name).phase_key].should == [name, :transmitted]}
109
+ [:e5, :e6, :e8].each{ |name| [name, @ctx.edge(name).phase_key].should == [name, :closed ]}
110
+ [:e2, :e3 ].each{ |name| [name, @ctx.edge(name).phase_key].should == [name, :closing ]}
111
+ @ctx.vertex(:j1100).phase_key.should == :error
112
+ @ctx.vertex(:j1200).phase_key.should == :initialized
113
+ @ctx.vertex(:j1000).finally_vertex.phase_key.should == :ready
114
+ end
115
+ end
116
+
117
+ context "j1200が終了して、j1f00が実行される" do
118
+ it "j1200が成功した場合、j1f00が実行するイベントが発火される" do
119
+ @root.phase_key = :running
120
+ @ctx.vertex(:j1000).phase_key = :running
121
+ @ctx.vertex(:j1100).phase_key = :success
122
+ @ctx.vertex(:j1110).phase_key = :success
123
+ @ctx.vertex(:j1200).phase_key = :success
124
+ @ctx.vertex(:j1210).phase_key = :success
125
+ @ctx.vertex(:j1000).finally_vertex.phase_key = :initialized
126
+ [:e1, :e4, :e5, :e7, :e8, :e9, :e10].each{|name| @ctx.edge(name).phase_key = :transmitted}
127
+ [:e2, :e3, :e6, ].each{|name| @ctx.edge(name).phase_key = :active }
128
+ @root.save!
129
+ tengine.should_fire(:"start.jobnet.job.tengine",
130
+ :source_name => @ctx[:j1000].finally_vertex.name_as_resource,
131
+ :properties => @base_props.merge({
132
+ :target_jobnet_id => @ctx[:j1000].finally_vertex.id.to_s,
133
+ :target_jobnet_name_path => @ctx[:j1000].finally_vertex.name_path,
134
+ }))
135
+ tengine.receive(:"success.jobnet.job.tengine", :properties => @base_props.merge({
136
+ :target_jobnet_id => @ctx[:j1200].id.to_s,
137
+ :target_jobnet_name_path => @ctx[:j1200].name_path,
138
+ }))
139
+ @root.reload
140
+ [:e1, :e4, :e5, :e6, :e7, :e8, :e9, :e10].each{|name| @ctx.edge(name).phase_key = :transmitted}
141
+ [:e2, :e3 ].each{|name| @ctx.edge(name).phase_key = :active }
142
+ @ctx.vertex(:j1100).phase_key.should == :success
143
+ @ctx.vertex(:j1110).phase_key.should == :success
144
+ @ctx.vertex(:j1200).phase_key.should == :success
145
+ @ctx.vertex(:j1210).phase_key.should == :success
146
+ @ctx.vertex(:j1000).finally_vertex.phase_key.should == :ready
147
+ end
148
+
149
+ it "j1200が失敗した場合、j1f00が実行するイベントが発火される" do
150
+ @root.phase_key = :running
151
+ @ctx.vertex(:j1000).phase_key = :running
152
+ @ctx.vertex(:j1100).phase_key = :success
153
+ @ctx.vertex(:j1110).phase_key = :success
154
+ @ctx.vertex(:j1200).phase_key = :error
155
+ @ctx.vertex(:j1210).phase_key = :error
156
+ @ctx.vertex(:j1000).finally_vertex.phase_key = :initialized
157
+ [:e1, :e4, :e5, :e7, :e8, :e9].each{|name| @ctx.edge(name).phase_key = :transmitted}
158
+ [:e10 ].each{|name| @ctx.edge(name).phase_key = :closed }
159
+ @root.save!
160
+ tengine.should_fire(:"start.jobnet.job.tengine",
161
+ :source_name => @ctx[:j1000].finally_vertex.name_as_resource,
162
+ :properties => @base_props.merge({
163
+ :target_jobnet_id => @ctx[:j1000].finally_vertex.id.to_s,
164
+ :target_jobnet_name_path => @ctx[:j1000].finally_vertex.name_path,
165
+ }))
166
+ tengine.receive(:"error.jobnet.job.tengine",
167
+ :properties => @base_props.merge({
168
+ :target_jobnet_id => @ctx[:j1200].id.to_s,
169
+ :target_jobnet_name_path => @ctx[:j1200].name_path,
170
+ }))
171
+ @root.reload
172
+ [:e1, :e4, :e5, :e7, :e8].each{|name| @ctx.edge(name).phase_key = :transmitted}
173
+ [:e6, :e10 ].each{|name| @ctx.edge(name).phase_key = :closed }
174
+ [:e2, :e3 ].each{|name| @ctx.edge(name).phase_key = :active }
175
+ @ctx.vertex(:j1100).phase_key.should == :success
176
+ @ctx.vertex(:j1110).phase_key.should == :success
177
+ @ctx.vertex(:j1200).phase_key.should == :error
178
+ @ctx.vertex(:j1210).phase_key.should == :error
179
+ @ctx.vertex(:j1000).finally_vertex.phase_key.should == :ready
180
+ end
181
+ end
182
+
183
+ context "j1f00が終了" do
184
+ it "j1f00が成功した場合" do
185
+ @root.phase_key = :running
186
+ @ctx.vertex(:j1000).phase_key = :running
187
+ @ctx.vertex(:j1100).phase_key = :success
188
+ @ctx.vertex(:j1110).phase_key = :success
189
+ @ctx.vertex(:j1200).phase_key = :success
190
+ @ctx.vertex(:j1210).phase_key = :success
191
+ @ctx.vertex(:j1000).finally_vertex.phase_key = :success
192
+ @ctx.vertex(:j1000).finally_vertex.finally_vertex.phase_key = :success
193
+ @ctx.vertex(:j1ff1).phase_key = :success
194
+ [:e2, :e3, :e17, :e18, :e19, :e20].each{|name| @ctx.edge(name).phase_key = :active }
195
+ [:e1, :e4, :e5, :e6, :e7, :e8, :e9, :e10, :e11, :e12, :e13, :e14, :e15, :e16].
196
+ each{|name| @ctx.edge(name).phase_key = :transmitted}
197
+ @root.save!
198
+ tengine.should_fire(:"success.jobnet.job.tengine",
199
+ :source_name => @ctx[:j1000].name_as_resource,
200
+ :properties => @base_props.merge({
201
+ :target_jobnet_id => @ctx[:j1000].id.to_s,
202
+ :target_jobnet_name_path => @ctx[:j1000].name_path,
203
+ }))
204
+ tengine.receive(:"success.jobnet.job.tengine",
205
+ :properties => @base_props.merge({
206
+ :target_jobnet_id => @ctx.vertex(:j1000).finally_vertex.id.to_s,
207
+ :target_jobnet_name_path => @ctx.vertex(:j1000).finally_vertex.name_path,
208
+ }))
209
+ @root.reload
210
+ [:e2, :e3, :e17, :e18, :e19, :e20].each{|name| @ctx.edge(name).phase_key.should == :active }
211
+ [:e1, :e4, :e5, :e6, :e7, :e8, :e9, :e10, :e11, :e12, :e13, :e14, :e15, :e16].
212
+ each{|name| @ctx.edge(name).phase_key.should == :transmitted}
213
+ @ctx.vertex(:j1100).phase_key.should == :success
214
+ @ctx.vertex(:j1110).phase_key.should == :success
215
+ @ctx.vertex(:j1200).phase_key.should == :success
216
+ @ctx.vertex(:j1210).phase_key.should == :success
217
+ @ctx.vertex(:j1000).finally_vertex.phase_key.should == :success
218
+ @ctx.vertex(:j2000).phase_key.should == :initialized
219
+ end
220
+
221
+ it "j1000が成功した場合" do
222
+ @root.phase_key = :running
223
+ @ctx[:j1000].phase_key = :success
224
+ @ctx[:j1100].phase_key = :success
225
+ @ctx[:j1110].phase_key = :success
226
+ @ctx[:j1200].phase_key = :success
227
+ @ctx[:j1210].phase_key = :success
228
+ @ctx[:j1000].finally_vertex.phase_key = :success
229
+ @ctx[:j1000].finally_vertex.finally_vertex.phase_key = :success
230
+ @ctx[:j1ff1].phase_key = :success
231
+ [:e2, :e3, :e17, :e18, :e19, :e20].each{|name| @ctx[name].phase_key = :active }
232
+ [:e1, :e4, :e5, :e6, :e7, :e8, :e9, :e10, :e11, :e12, :e13, :e14, :e15, :e16].
233
+ each{|name| @ctx[name].phase_key = :transmitted}
234
+ @root.save!
235
+ tengine.should_fire(:"start.jobnet.job.tengine",
236
+ :source_name => @ctx[:j2000].name_as_resource,
237
+ :properties => @base_props.merge({
238
+ :target_jobnet_id => @ctx.vertex(:j2000).id.to_s,
239
+ :target_jobnet_name_path => @ctx.vertex(:j2000).name_path,
240
+ }))
241
+ tengine.receive(:"success.jobnet.job.tengine",
242
+ :properties => @base_props.merge({
243
+ :target_jobnet_id => @ctx.vertex(:j1000).id.to_s,
244
+ :target_jobnet_name_path => @ctx.vertex(:j1000).name_path,
245
+ }))
246
+ @root.reload
247
+ [:e3, :e17, :e18, :e19, :e20].each{|name| @ctx.edge(name).phase_key.should == :active }
248
+ [:e2 ].each{|name| @ctx.edge(name).phase_key.should == :transmitting }
249
+ [:e1, :e4, :e5, :e6, :e7, :e8, :e9, :e10, :e11, :e12, :e13, :e14, :e15, :e16].
250
+ each{|name| @ctx.edge(name).phase_key.should == :transmitted}
251
+ @ctx.vertex(:j1100).phase_key.should == :success
252
+ @ctx.vertex(:j1110).phase_key.should == :success
253
+ @ctx.vertex(:j1200).phase_key.should == :success
254
+ @ctx.vertex(:j1210).phase_key.should == :success
255
+ @ctx.vertex(:j1000).finally_vertex.phase_key.should == :success
256
+ @ctx.vertex(:j2000).phase_key.should == :ready
257
+ end
258
+
259
+ it "j1f00が失敗した場合" do
260
+ @root.phase_key = :running
261
+ @ctx.vertex(:j1000).phase_key = :running
262
+ @ctx.vertex(:j1100).phase_key = :success
263
+ @ctx.vertex(:j1110).phase_key = :success
264
+ @ctx.vertex(:j1200).phase_key = :success
265
+ @ctx.vertex(:j1210).phase_key = :success
266
+ @ctx.vertex(:j1000).finally_vertex.phase_key = :error
267
+ @ctx.vertex(:j1000).finally_vertex.finally_vertex.phase_key = :error
268
+ @ctx.vertex(:j1ff1).phase_key = :error
269
+ [:e2, :e3, :e17, :e18, :e19, :e20].each{|name| @ctx.edge(name).phase_key = :active }
270
+ [:e12, :e16].each{|name| @ctx.edge(name).phase_key = :closed}
271
+ [:e1, :e4, :e5, :e6, :e7, :e8, :e9, :e10, :e11, :e13, :e14, :e15].
272
+ each{|name| @ctx.edge(name).phase_key = :transmitted}
273
+ @root.save!
274
+ tengine.should_fire(:"error.jobnet.job.tengine",
275
+ :source_name => @ctx[:j1000].name_as_resource,
276
+ :properties => @base_props.merge({
277
+ :target_jobnet_id => @ctx[:j1000].id.to_s,
278
+ :target_jobnet_name_path => @ctx[:j1000].name_path,
279
+ }))
280
+ tengine.receive(:"error.jobnet.job.tengine",
281
+ :properties => @base_props.merge({
282
+ :target_jobnet_id => @ctx.vertex(:j1000).finally_vertex.id.to_s,
283
+ :target_jobnet_name_path => @ctx.vertex(:j1000).finally_vertex.name_path,
284
+ }))
285
+ @root.reload
286
+ [:e2, :e3, :e17, :e18, :e19, :e20].each{|name| @ctx.edge(name).phase_key.should == :active }
287
+ [:e12, :e16].each{|name| @ctx.edge(name).phase_key.should == :closed}
288
+ [:e1, :e4, :e5, :e6, :e7, :e8, :e9, :e10, :e11, :e13, :e14, :e15].
289
+ each{|name| @ctx.edge(name).phase_key.should == :transmitted}
290
+ @ctx.vertex(:j1100).phase_key.should == :success
291
+ @ctx.vertex(:j1110).phase_key.should == :success
292
+ @ctx.vertex(:j1200).phase_key.should == :success
293
+ @ctx.vertex(:j1210).phase_key.should == :success
294
+ @ctx.vertex(:j1000).finally_vertex.phase_key.should == :error
295
+ @ctx.vertex(:j1000).finally_vertex.finally_vertex.phase_key.should == :error
296
+ @ctx.vertex(:j1ff1).phase_key.should == :error
297
+ @root.finally_vertex.phase_key.should == :initialized
298
+ end
299
+ end
300
+
301
+ end
302
+
303
+
304
+ context "rjn0005" do
305
+ before do
306
+ Tengine::Job::Vertex.delete_all
307
+ builder = Rjn0005RetryTwoLayerFixture.new
308
+ @root = builder.create_actual
309
+ @ctx = builder.context
310
+ @execution = Tengine::Job::Execution.create!({
311
+ :root_jobnet_id => @root.id,
312
+ })
313
+ @base_props = {
314
+ :execution_id => @execution.id.to_s,
315
+ :root_jobnet_id => @root.id.to_s,
316
+ :root_jobnet_name_path => @root.name_path,
317
+ :target_jobnet_id => @root.id.to_s,
318
+ :target_jobnet_name_path => @root.name_path,
319
+ }
320
+ end
321
+
322
+ all_edge_names = (1..26).map{|idx| :"e#{idx}"}
323
+
324
+ context "j41がエラーになったことをjn4で受けた場合" do
325
+ it "以降のvertexがclosedになる" do
326
+ @root.phase_key = :running
327
+ @ctx[:j1].phase_key = :success
328
+ @ctx[:j2].phase_key = :success
329
+ @ctx[:j4].phase_key = :initialized
330
+ @ctx[:jn4].phase_key = :running
331
+ @ctx[:j41].phase_key = :error
332
+ [
333
+ :j42, :j43, :j44,
334
+ :jn4f, :jn4_f,
335
+ :finally, :jn0005_fjn, :jn0005_f, :jn0005_fjn,
336
+ :jn0005_f1, :jn0005_f2, :jn0005_fjn_f, :jn0005_fif
337
+ ].each do |key|
338
+ @ctx[key].phase_key = :initialized
339
+ end
340
+ transmitted_edges = [:e1, :e2, :e3, :e4, :e9]
341
+ transmitted_edges.each{|name| @ctx[name].phase_key = :transmitted}
342
+ (all_edge_names - transmitted_edges).each{|name| @ctx[name].phase_key = :active}
343
+ @root.save!
344
+ tengine.should_fire(:"start.jobnet.job.tengine",
345
+ :source_name => @ctx[:jn4f].name_as_resource,
346
+ :properties => @base_props.merge({
347
+ :target_jobnet_id => @ctx[:jn4f].id.to_s,
348
+ :target_jobnet_name_path => @ctx[:jn4f].name_path,
349
+ }))
350
+ tengine.receive(:"error.job.job.tengine",
351
+ :properties => @base_props.merge({
352
+ :target_jobnet_id => @ctx[:jn4].id.to_s,
353
+ :target_jobnet_name_path => @ctx[:jn4].name_path,
354
+ :target_job_id => @ctx[:j41].id.to_s,
355
+ :target_job_name_path => @ctx[:j41].name_path,
356
+ }))
357
+
358
+ @root.reload
359
+ [
360
+ :j42, :j43, :j44,
361
+ :jn4_f,
362
+ :finally, :jn0005_fjn, :jn0005_f, :jn0005_fjn,
363
+ :jn0005_f1, :jn0005_f2, :jn0005_fjn_f, :jn0005_fif
364
+ ].each do |key|
365
+ @ctx[key].phase_key.should == :initialized
366
+ end
367
+ transmitted_edges = [:e1, :e2, :e3, :e4, :e9]
368
+ transmitted_edges.each{|name| @ctx.edge(name).phase_key.should == :transmitted}
369
+ closed_edges = [
370
+ :e10, :e11, :e12, :e13, :e14, :e15, :e16, # jn4のedge
371
+ ]
372
+ closing_edges = [
373
+ :e6, :e7, :e8, # rootのedge
374
+ ]
375
+ closed_edges.each{|name| [name, @ctx.edge(name).phase_key].should == [name, :closed]}
376
+ (all_edge_names - transmitted_edges - closed_edges - closing_edges).
377
+ each{|name| [name, @ctx.edge(name).phase_key].should == [name, :active]}
378
+ @root.phase_key.should == :running
379
+
380
+ expected_job_phases = {
381
+ :j1 => :success,
382
+ :j2 => :success,
383
+ :j4 => :initialized,
384
+ :jn4 => :running,
385
+ :j41 => :error,
386
+ :jn4f => :initialized,
387
+ }
388
+
389
+ actual_job_phases = expected_job_phases.keys.inject({}) do |d, key|
390
+ d[key] = @ctx[key].phase_key
391
+ d
392
+ end
393
+
394
+ actual_job_phases.should == expected_job_phases
395
+ end
396
+ end
397
+
398
+ context "j41がエラーになって、jn4_fを実行中に、j2が失敗した場合" do
399
+ it "jn4の終了を待ってからfinallyが実行される" do
400
+ @root.phase_key = :running
401
+ @ctx[:j1].phase_key = :success
402
+ @ctx[:j2].phase_key = :error
403
+ @ctx[:j4].phase_key = :initialized
404
+ @ctx[:jn4].phase_key = :running
405
+ @ctx[:jn4f].phase_key = :running
406
+ @ctx[:jn4_f].phase_key = :running
407
+ @ctx[:j41].phase_key = :error
408
+ [
409
+ :j42, :j43, :j44,
410
+ :finally, :jn0005_fjn, :jn0005_f, :jn0005_fjn,
411
+ :jn0005_f1, :jn0005_f2, :jn0005_fjn_f, :jn0005_fif
412
+ ].each do |key|
413
+ @ctx[key].phase_key = :initialized
414
+ end
415
+ transmitted_edges = [:e1, :e2, :e3, :e4, :e9, :e17]
416
+ transmitted_edges.each{|name| @ctx[name].phase_key = :transmitted}
417
+ closed_edges = [:e10, :e11, :e12, :e13, :e14, :e15, :e16] # jn4のedge
418
+ closed_edges.each{|name| @ctx.edge(name).phase_key = :closed}
419
+ closing_edges = [:e6, :e7, :e8] # rootのedge
420
+ closing_edges.each{|name| @ctx.edge(name).phase_key = :closing}
421
+ (all_edge_names - transmitted_edges - closed_edges - closing_edges).
422
+ each{|name| @ctx[name].phase_key = :active}
423
+ @root.save!
424
+ tengine.should_not_fire
425
+ tengine.receive(:"error.job.job.tengine",
426
+ :properties => @base_props.merge({
427
+ :target_jobnet_id => @root.id.to_s,
428
+ :target_jobnet_name_path => @root.name_path,
429
+ :target_job_id => @ctx[:j2].id.to_s,
430
+ :target_job_name_path => @ctx[:j2].name_path,
431
+ }))
432
+
433
+ @root.reload
434
+ [
435
+ :j42, :j43, :j44,
436
+ :finally, :jn0005_fjn, :jn0005_f, :jn0005_fjn,
437
+ :jn0005_f1, :jn0005_f2, :jn0005_fjn_f, :jn0005_fif
438
+ ].each do |key|
439
+ @ctx[key].phase_key.should == :initialized
440
+ end
441
+ transmitted_edges = [:e1, :e2, :e3, :e4, :e9, :e17]
442
+ transmitted_edges.each{|name| @ctx.edge(name).phase_key.should == :transmitted}
443
+ closed_edges = [:e10, :e11, :e12, :e13, :e14, :e15, :e16, :e5, ] # jn4のedge + j2の後
444
+ closed_edges.each{|name| [name, @ctx.edge(name).phase_key].should == [name, :closed]}
445
+ closing_edges = [:e6, :e7, :e8] # rootのedge
446
+ closing_edges.each{|name| [name, @ctx.edge(name).phase_key].should == [name, :closing]}
447
+ (all_edge_names - transmitted_edges - closed_edges - closing_edges).
448
+ each{|name| [name, @ctx.edge(name).phase_key].should == [name, :active]}
449
+ @root.phase_key.should == :running
450
+
451
+ expected_job_phases = {
452
+ :j1 => :success,
453
+ :j2 => :error,
454
+ :j4 => :initialized,
455
+ :jn4 => :running,
456
+ :jn4f => :running,
457
+ :jn4_f => :running,
458
+ :j41 => :error,
459
+ }
460
+
461
+ actual_job_phases = expected_job_phases.keys.inject({}) do |d, key|
462
+ d[key] = @ctx[key].phase_key
463
+ d
464
+ end
465
+
466
+ actual_job_phases.should == expected_job_phases
467
+ end
468
+
469
+ end
470
+ end
471
+
472
+ end