wakame 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/app_generators/wakame/templates/cluster/resources/markers/http_application_server.rb +3 -0
- data/app_generators/wakame/templates/cluster/resources/markers/http_asset_server.rb +2 -0
- data/app_generators/wakame/templates/cluster/resources/markers/http_server.rb +9 -0
- data/app_generators/wakame/templates/config/cluster.rb +36 -99
- data/app_generators/wakame/templates/config/init.d/wakame-agent +3 -3
- data/app_generators/wakame/templates/config/init.d/wakame-master +3 -3
- data/app_generators/wakame/wakame_generator.rb +5 -1
- data/contrib/imagesetup.sh +9 -5
- data/lib/ext/uri.rb +13 -0
- data/lib/wakame/action.rb +46 -21
- data/lib/wakame/{rule_engine.rb → action_manager.rb} +148 -36
- data/lib/wakame/actions/deploy_config.rb +35 -0
- data/lib/wakame/actions/launch_cluster.rb +8 -10
- data/lib/wakame/actions/launch_vm.rb +26 -20
- data/lib/wakame/actions/migrate_service.rb +30 -19
- data/lib/wakame/actions/notify_child_changed.rb +34 -0
- data/lib/wakame/actions/notify_parent_changed.rb +34 -0
- data/lib/wakame/actions/propagate_resource.rb +27 -0
- data/lib/wakame/actions/propagate_service.rb +27 -0
- data/lib/wakame/actions/reload_service.rb +21 -9
- data/lib/wakame/actions/shutdown_cluster.rb +3 -3
- data/lib/wakame/actions/shutdown_vm.rb +14 -5
- data/lib/wakame/actions/start_service.rb +53 -47
- data/lib/wakame/actions/stop_service.rb +35 -23
- data/lib/wakame/actor/system.rb +6 -3
- data/lib/wakame/agent.rb +29 -7
- data/lib/wakame/amqp_client.rb +26 -5
- data/lib/wakame/command/action_status.rb +7 -7
- data/lib/wakame/command/actor.rb +10 -10
- data/lib/wakame/command/import_cluster_config.rb +10 -0
- data/lib/wakame/command/launch_cluster.rb +2 -2
- data/lib/wakame/command/launch_vm.rb +3 -3
- data/lib/wakame/command/migrate_service.rb +7 -7
- data/lib/wakame/command/propagate_resource.rb +42 -0
- data/lib/wakame/command/propagate_service.rb +21 -19
- data/lib/wakame/command/reload_service.rb +3 -13
- data/lib/wakame/command/shutdown_cluster.rb +2 -2
- data/lib/wakame/command/start_service.rb +14 -0
- data/lib/wakame/command/status.rb +32 -10
- data/lib/wakame/command/stop_service.rb +27 -21
- data/lib/wakame/command.rb +19 -3
- data/lib/wakame/command_queue.rb +87 -67
- data/lib/wakame/configuration.rb +6 -0
- data/lib/wakame/event.rb +17 -0
- data/lib/wakame/event_dispatcher.rb +32 -23
- data/lib/wakame/graph.rb +2 -1
- data/lib/wakame/initializer.rb +11 -8
- data/lib/wakame/master.rb +327 -209
- data/lib/wakame/monitor/agent.rb +5 -1
- data/lib/wakame/monitor/service.rb +6 -5
- data/lib/wakame/packets.rb +13 -21
- data/lib/wakame/runner/administrator_command.rb +383 -264
- data/lib/wakame/runner/agent.rb +1 -5
- data/lib/wakame/runner/master.rb +0 -3
- data/lib/wakame/service.rb +817 -538
- data/lib/wakame/status_db.rb +383 -0
- data/lib/wakame/template.rb +27 -130
- data/lib/wakame/trigger.rb +10 -18
- data/lib/wakame/triggers/instance_count_update.rb +1 -1
- data/lib/wakame/triggers/load_history.rb +1 -1
- data/lib/wakame/triggers/maintain_ssh_known_hosts.rb +8 -5
- data/lib/wakame/triggers/shutdown_unused_vm.rb +1 -1
- data/lib/wakame/util.rb +64 -55
- data/lib/wakame.rb +4 -0
- data/tests/test_action_manager.rb +111 -0
- data/tests/test_service.rb +128 -23
- data/tests/test_status_db.rb +82 -0
- data/tests/test_uri_amqp.rb +10 -0
- data/wakame_generators/resource/templates/apache_app/apache_app.rb +19 -18
- data/wakame_generators/resource/templates/apache_app/conf/apache2.conf +14 -2
- data/wakame_generators/resource/templates/apache_app/conf/system-app.conf +1 -1
- data/wakame_generators/resource/templates/apache_app/conf/vh/aaa.test.conf +9 -0
- data/wakame_generators/resource/templates/apache_lb/apache_lb.rb +21 -20
- data/wakame_generators/resource/templates/apache_lb/conf/apache2.conf +14 -2
- data/wakame_generators/resource/templates/apache_lb/conf/system-lb.conf +17 -2
- data/wakame_generators/resource/templates/apache_lb/conf/vh/aaa.test.conf +37 -0
- data/wakame_generators/resource/templates/apache_www/apache_www.rb +20 -18
- data/wakame_generators/resource/templates/apache_www/conf/apache2.conf +14 -2
- data/wakame_generators/resource/templates/apache_www/conf/system-www.conf +1 -1
- data/wakame_generators/resource/templates/apache_www/conf/vh/aaa.test.conf +9 -0
- data/wakame_generators/resource/templates/ec2_elastic_ip/ec2_elastic_ip.rb +6 -8
- data/wakame_generators/resource/templates/ec2_elb/ec2_elb.rb +7 -6
- data/wakame_generators/resource/templates/memcached/conf/memcached.conf +47 -0
- data/wakame_generators/resource/templates/memcached/init.d/memcached +61 -0
- data/wakame_generators/resource/templates/memcached/memcached.rb +73 -0
- data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +5 -7
- data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +35 -34
- data/wakame_generators/resource/templates/mysql_slave/conf/my.cnf +6 -6
- data/wakame_generators/resource/templates/mysql_slave/mysql_slave.rb +21 -24
- data/wakame_generators/resource/templates/nginx/conf/nginx.conf +17 -27
- data/wakame_generators/resource/templates/nginx/conf/vh/aaa.test.conf +30 -0
- data/wakame_generators/resource/templates/nginx/nginx.rb +18 -18
- metadata +34 -21
- data/lib/wakame/actions/propagate_instances.rb +0 -70
- data/lib/wakame/manager/commands.rb +0 -134
- data/lib/wakame/rule.rb +0 -116
- data/lib/wakame/triggers/process_command.rb +0 -41
- data/tests/test_rule_engine.rb +0 -127
- data/wakame_generators/resource/templates/apache_app/conf/sites-app.conf +0 -23
- data/wakame_generators/resource/templates/apache_lb/conf/sites-lb.conf +0 -54
- data/wakame_generators/resource/templates/apache_www/conf/sites-www.conf +0 -23
@@ -1,4 +1,5 @@
|
|
1
1
|
|
2
|
+
require 'thread'
|
2
3
|
require 'timeout'
|
3
4
|
|
4
5
|
module Wakame
|
@@ -6,14 +7,12 @@ module Wakame
|
|
6
7
|
class CancelBroadcast < StandardError; end
|
7
8
|
class GlobalLockError < StandardError; end
|
8
9
|
|
9
|
-
class
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
attr_reader :triggers, :active_jobs
|
10
|
+
class ActionManager
|
11
|
+
include Manager
|
12
|
+
attr_reader :active_jobs, :lock_queue
|
14
13
|
|
15
14
|
def master
|
16
|
-
|
15
|
+
Wakame::Master.instance
|
17
16
|
end
|
18
17
|
|
19
18
|
def command_queue
|
@@ -24,38 +23,16 @@ module Wakame
|
|
24
23
|
master.agent_monitor
|
25
24
|
end
|
26
25
|
|
27
|
-
def
|
28
|
-
@service_cluster
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize(service_cluster, &blk)
|
32
|
-
@service_cluster = service_cluster
|
33
|
-
@triggers = []
|
34
|
-
|
26
|
+
def initialize()
|
35
27
|
@active_jobs = {}
|
36
28
|
@job_history = []
|
37
|
-
|
29
|
+
@lock_queue = LockQueue.new
|
38
30
|
end
|
39
31
|
|
40
|
-
def
|
41
|
-
Wakame.log.debug("Registering trigger #{trigger.class}")
|
42
|
-
trigger.bind_engine(self)
|
43
|
-
trigger.register_hooks
|
44
|
-
@triggers << trigger
|
32
|
+
def init
|
45
33
|
end
|
46
34
|
|
47
|
-
def
|
48
|
-
root_action.job_id = job_id = Wakame.gen_id
|
49
|
-
|
50
|
-
@active_jobs[job_id] = {
|
51
|
-
:job_id=>job_id,
|
52
|
-
:src_trigger=>trigger,
|
53
|
-
:create_at=>Time.now,
|
54
|
-
:start_at=>nil,
|
55
|
-
:complete_at=>nil,
|
56
|
-
:root_action=>root_action,
|
57
|
-
:notes=>{}
|
58
|
-
}
|
35
|
+
def terminate
|
59
36
|
end
|
60
37
|
|
61
38
|
def cancel_action(job_id)
|
@@ -92,7 +69,19 @@ module Wakame
|
|
92
69
|
end
|
93
70
|
end
|
94
71
|
|
72
|
+
def trigger_action(action)
|
73
|
+
raise ArguemntError unless action.is_a?(Action)
|
74
|
+
context = create_job_context(action)
|
75
|
+
action.action_manager = self
|
76
|
+
action.job_id = context[:job_id]
|
77
|
+
|
78
|
+
run_action(action)
|
79
|
+
action.job_id
|
80
|
+
end
|
81
|
+
|
82
|
+
|
95
83
|
def run_action(action)
|
84
|
+
raise ArguemntError unless action.is_a?(Action)
|
96
85
|
job_context = @active_jobs[action.job_id]
|
97
86
|
raise "The job session is killed.: job_id=#{action.job_id}" if job_context.nil?
|
98
87
|
|
@@ -110,7 +99,7 @@ module Wakame
|
|
110
99
|
begin
|
111
100
|
action.bind_thread(Thread.current)
|
112
101
|
action.status = :running
|
113
|
-
Wakame.log.debug("Start action : #{action.class.to_s}
|
102
|
+
Wakame.log.debug("Start action : #{action.class.to_s} #{action.parent_action.nil? ? '' : ('sub-action of ' + action.parent_action.class.to_s)}")
|
114
103
|
ED.fire_event(Event::ActionStart.new(action))
|
115
104
|
begin
|
116
105
|
action.run
|
@@ -129,7 +118,7 @@ module Wakame
|
|
129
118
|
ED.fire_event(Event::ActionFailed.new(action, e))
|
130
119
|
res = e
|
131
120
|
rescue => e
|
132
|
-
Wakame.log.
|
121
|
+
Wakame.log.error("Failed action : #{action.class.to_s} due to #{e}")
|
133
122
|
Wakame.log.error(e)
|
134
123
|
action.completion_status = :failed
|
135
124
|
begin
|
@@ -161,7 +150,7 @@ module Wakame
|
|
161
150
|
|
162
151
|
actary = []
|
163
152
|
job_context[:root_action].walk_subactions {|a| actary << a }
|
164
|
-
Wakame.log.debug(actary.collect{|a| {a.class.to_s=>a.status}}.inspect)
|
153
|
+
#Wakame.log.debug(actary.collect{|a| {a.class.to_s=>a.status}}.inspect)
|
165
154
|
|
166
155
|
if res.is_a?(Exception)
|
167
156
|
job_context[:exception]=res
|
@@ -178,7 +167,7 @@ module Wakame
|
|
178
167
|
job_context[:complete_at]=Time.now
|
179
168
|
@job_history << job_context
|
180
169
|
@active_jobs.delete(job_context[:job_id])
|
181
|
-
|
170
|
+
@lock_queue.quit(job_context[:job_id])
|
182
171
|
end
|
183
172
|
}
|
184
173
|
rescue => e
|
@@ -187,5 +176,128 @@ module Wakame
|
|
187
176
|
}
|
188
177
|
end
|
189
178
|
|
179
|
+
private
|
180
|
+
def create_job_context(root_action)
|
181
|
+
raise ArguemntError unless root_action.is_a?(Action)
|
182
|
+
root_action.job_id = job_id = Wakame.gen_id
|
183
|
+
|
184
|
+
@active_jobs[job_id] = {
|
185
|
+
:job_id=>job_id,
|
186
|
+
:create_at=>Time.now,
|
187
|
+
:start_at=>nil,
|
188
|
+
:complete_at=>nil,
|
189
|
+
:root_action=>root_action,
|
190
|
+
:notes=>{}
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
190
194
|
end
|
195
|
+
|
196
|
+
class LockQueue
|
197
|
+
def initialize()
|
198
|
+
@locks = {}
|
199
|
+
@id2res = {}
|
200
|
+
|
201
|
+
@queue_by_thread = {}
|
202
|
+
@qbt_m = ::Mutex.new
|
203
|
+
end
|
204
|
+
|
205
|
+
def set(resource, id)
|
206
|
+
# Ths Job ID already holds/reserves the lock regarding the resource.
|
207
|
+
return if @id2res.has_key?(id) && @id2res[id].has_key?(resource.to_s)
|
208
|
+
|
209
|
+
# Need to use EM.barrier while RuleEngine is using EventMachine's threads.
|
210
|
+
#StatusDB.barrier {
|
211
|
+
EM.barrier {
|
212
|
+
@locks[resource.to_s] ||= []
|
213
|
+
@id2res[id] ||= {}
|
214
|
+
|
215
|
+
@id2res[id][resource.to_s]=1
|
216
|
+
@locks[resource.to_s] << id
|
217
|
+
}
|
218
|
+
Wakame.log.debug("#{self.class}: set(#{resource.to_s}, #{id})" + "\n#{self.inspect}")
|
219
|
+
end
|
220
|
+
|
221
|
+
def reset()
|
222
|
+
@locks.keys { |k|
|
223
|
+
@locks[k].clear
|
224
|
+
}
|
225
|
+
@id2res.clear
|
226
|
+
end
|
227
|
+
|
228
|
+
def test(id)
|
229
|
+
reslist = @id2res[id]
|
230
|
+
return :pass if reslist.nil? || reslist.empty?
|
231
|
+
|
232
|
+
#
|
233
|
+
if reslist.keys.all? { |r| id == @locks[r.to_s][0] }
|
234
|
+
return :runnable
|
235
|
+
else
|
236
|
+
return :wait
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def wait(id, tout=60*30)
|
241
|
+
@qbt_m.synchronize { @queue_by_thread[Thread.current] = ::Queue.new }
|
242
|
+
|
243
|
+
timeout(tout) {
|
244
|
+
while test(id) == :wait
|
245
|
+
Wakame.log.debug("#{self.class}: Job #{id} waits for locked resouces: #{@id2res[id].keys.join(', ')}")
|
246
|
+
break if id == @queue_by_thread[Thread.current].deq
|
247
|
+
end
|
248
|
+
}
|
249
|
+
ensure
|
250
|
+
@qbt_m.synchronize { @queue_by_thread.delete(Thread.current) }
|
251
|
+
end
|
252
|
+
|
253
|
+
def quit(id)
|
254
|
+
# Need to use EM.barrier while RuleEngine is using EventMachine's threads.
|
255
|
+
#StatusDB.barrier {
|
256
|
+
EM.barrier {
|
257
|
+
case test(id)
|
258
|
+
when :runnable, :wait
|
259
|
+
@id2res[id].keys.each { |r| @locks[r.to_s].delete_if{ |i| i == id } }
|
260
|
+
@locks.delete_if{ |k,v| v.nil? || v.empty? }
|
261
|
+
|
262
|
+
@qbt_m.synchronize {
|
263
|
+
@queue_by_thread.each {|t, q| q.enq(id) }
|
264
|
+
}
|
265
|
+
end
|
266
|
+
|
267
|
+
@id2res.delete(id)
|
268
|
+
}
|
269
|
+
Wakame.log.debug("#{self.class}: quit(#{id})" + "\n#{self.inspect}")
|
270
|
+
end
|
271
|
+
|
272
|
+
def clear_resource(resource)
|
273
|
+
end
|
274
|
+
|
275
|
+
def inspect
|
276
|
+
output = @locks.collect { |k, lst|
|
277
|
+
[k, lst].flatten
|
278
|
+
}
|
279
|
+
return "" if output.empty?
|
280
|
+
|
281
|
+
# Table display
|
282
|
+
maxcolws = (0..(output.size)).zip(*output).collect { |i| i.shift; i.map!{|i| (i.nil? ? "" : i).length }.max }
|
283
|
+
maxcol = maxcolws.size
|
284
|
+
maxcolws.reverse.each { |i|
|
285
|
+
break if i > 0
|
286
|
+
maxcol -= 1
|
287
|
+
}
|
288
|
+
|
289
|
+
textrows = output.collect { |x|
|
290
|
+
buf=""
|
291
|
+
maxcol.times { |n|
|
292
|
+
buf << "|" + (x[n] || "").ljust(maxcolws[n])
|
293
|
+
}
|
294
|
+
buf << "|"
|
295
|
+
}
|
296
|
+
|
297
|
+
"+" + (["-"] * (textrows[0].length - 2)).join('') + "+\n" + \
|
298
|
+
textrows.join("\n") + \
|
299
|
+
"\n+" + (["-"] * (textrows[0].length - 2)).join('')+ "+"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
191
303
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Wakame
|
2
|
+
module Actions
|
3
|
+
class DeployConfig < Action
|
4
|
+
def initialize(svc)
|
5
|
+
@svc = svc
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
Wakame.log.debug("#{self.class}: run() Begin: #{@svc.resource.class}")
|
10
|
+
raise "CloudHost is not mapped Agent: CloudHost.id=#{@svc.cloud_host.id}" unless @svc.cloud_host.mapped?
|
11
|
+
|
12
|
+
acquire_lock { |lst|
|
13
|
+
lst << @svc.resource.class.to_s
|
14
|
+
}
|
15
|
+
|
16
|
+
begin
|
17
|
+
tmpl = Wakame::Template.new(@svc)
|
18
|
+
tmpl.render_config
|
19
|
+
|
20
|
+
src_path = tmpl.tmp_basedir.dup
|
21
|
+
src_path.sub!('/$', '') if File.directory? src_path
|
22
|
+
|
23
|
+
dest_path = File.expand_path("tmp/config/" + File.basename(tmpl.basedir), @svc.cloud_host.root_path)
|
24
|
+
#Wakame::Util.exec("rsync -e 'ssh -i #{Wakame.config.ssh_private_key} -o \"UserKnownHostsFile #{Wakame.config.ssh_known_hosts}\"' -au #{src_path}/ root@#{@svc.cloud_host.agent_ip}:#{dest_path}")
|
25
|
+
Wakame::Util.exec("rsync -e 'ssh -i #{Wakame.config.ssh_private_key} -o \"StrictHostKeyChecking no\"' -au #{src_path}/ root@#{@svc.cloud_host.agent_ip}:#{dest_path}")
|
26
|
+
|
27
|
+
ensure
|
28
|
+
tmpl.cleanup if tmpl
|
29
|
+
end
|
30
|
+
|
31
|
+
Wakame.log.debug("#{self.class}: run() End: #{@svc.resource.class}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,30 +2,28 @@ module Wakame
|
|
2
2
|
module Actions
|
3
3
|
class LaunchCluster < Action
|
4
4
|
def initialize
|
5
|
-
@acquire_lock = true
|
6
5
|
end
|
7
6
|
|
8
7
|
def run
|
9
8
|
if service_cluster.status == Service::ServiceCluster::STATUS_ONLINE
|
10
|
-
Wakame.log.info("
|
11
|
-
|
9
|
+
Wakame.log.info("Ignore to launch the cluster as is already ONLINE: #{service_cluster.name}")
|
10
|
+
return
|
12
11
|
end
|
13
12
|
|
14
|
-
EM.barrier {
|
15
|
-
service_cluster.launch
|
16
|
-
}
|
17
13
|
levels = service_cluster.dg.levels
|
18
|
-
Wakame.log.debug("#{self.class}:
|
14
|
+
Wakame.log.debug("#{self.class}: Scheduled resource launch order: " + levels.collect {|lv| '['+ lv.collect{|prop| "#{prop.class}" }.join(', ') + ']' }.join(', '))
|
19
15
|
acquire_lock { |list|
|
20
16
|
levels.each {|lv| list << lv.collect{|res| res.class } }
|
21
17
|
}
|
22
18
|
|
23
19
|
levels.each { |lv|
|
24
|
-
lv.
|
25
|
-
|
20
|
+
Wakame.log.info("#{self.class}: Launching resources: #{lv.collect{|prop| "#{prop.class}" }.join(', ')}")
|
21
|
+
lv.each { |resource|
|
22
|
+
cluster.each_instance(resource) { |svc|
|
23
|
+
trigger_action(StartService.new(svc))
|
24
|
+
}
|
26
25
|
}
|
27
26
|
flush_subactions
|
28
|
-
Wakame.log.debug("#{self.class}: DG level next")
|
29
27
|
}
|
30
28
|
end
|
31
29
|
|
@@ -1,51 +1,57 @@
|
|
1
1
|
module Wakame
|
2
2
|
module Actions
|
3
3
|
class LaunchVM < Action
|
4
|
-
def initialize(notes_key,
|
5
|
-
@ref_agent = ref_agent
|
4
|
+
def initialize(notes_key, vm_spec)
|
6
5
|
@notes_key = notes_key
|
6
|
+
@vm_spec = vm_spec
|
7
7
|
end
|
8
8
|
|
9
9
|
USER_DATA_TMPL=<<__END__
|
10
10
|
node=agent
|
11
|
-
amqp_server
|
12
|
-
agent_id=%s
|
11
|
+
amqp_server=%s
|
13
12
|
__END__
|
14
13
|
|
15
14
|
def run
|
16
15
|
require 'right_aws'
|
17
16
|
ec2 = RightAws::Ec2.new(Wakame.config.aws_access_key, Wakame.config.aws_secret_key, {:cache=>false})
|
18
17
|
|
19
|
-
|
20
|
-
@ref_agent ||= master.agent_monitor.master_local
|
21
|
-
ref_attr = ec2.describe_instances([@ref_agent.attr[:instance_id]])
|
22
|
-
ref_attr = ref_attr[0]
|
23
|
-
|
18
|
+
ref_attr = @vm_spec.merge(cluster.template_vm_attr)
|
24
19
|
|
25
|
-
user_data = sprintf(USER_DATA_TMPL,
|
20
|
+
user_data = sprintf(USER_DATA_TMPL, cluster.advertised_amqp_servers)
|
26
21
|
Wakame.log.debug("#{self.class}: Lauching VM: #{ref_attr.inspect}\nuser_data: #{user_data}")
|
27
|
-
res = ec2.run_instances(ref_attr[:
|
28
|
-
ref_attr[:
|
29
|
-
ref_attr[:
|
22
|
+
res = ec2.run_instances(ref_attr[:image_id], 1, 1,
|
23
|
+
ref_attr[:security_groups],
|
24
|
+
ref_attr[:key_name],
|
30
25
|
user_data,
|
31
26
|
'public', # addressing_type
|
32
|
-
ref_attr[:
|
27
|
+
ref_attr[:instance_type], # instance_type
|
33
28
|
nil, # kernel_id
|
34
29
|
nil, # ramdisk_id
|
35
|
-
ref_attr[:
|
30
|
+
ref_attr[:availability_zone], # availability_zone
|
36
31
|
nil # block_device_mappings
|
37
32
|
)[0]
|
38
33
|
inst_id = res[:aws_instance_id]
|
39
34
|
|
40
35
|
ConditionalWait.wait { | cond |
|
41
36
|
cond.wait_event(Event::AgentMonitored) { |event|
|
42
|
-
event.agent.
|
37
|
+
event.agent.vm_attr[:instance_id] == inst_id
|
43
38
|
}
|
44
39
|
|
45
|
-
cond.poll(5,
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
cond.poll(5, 360) {
|
41
|
+
begin
|
42
|
+
d = ec2.describe_instances([inst_id])[0]
|
43
|
+
Wakame.log.debug("#{self.class}: Polling describe_instances(#{inst_id}): #{d[:aws_state]} ")
|
44
|
+
d[:aws_state] == "running"
|
45
|
+
rescue RightAws::AwsError => e
|
46
|
+
if e.include?(%r'InvalidInstanceID.NotFound')
|
47
|
+
# describe_instances() sometime fails due to this error when it is called just after sending run_instances().
|
48
|
+
# This is the timing issue in AWS so that continues the polling check.
|
49
|
+
Wakame.log.warn("Polling to describe_instances() got InvalidInstanceID.NotFound error with #{inst_id}. Retry again.")
|
50
|
+
next
|
51
|
+
else
|
52
|
+
raise e
|
53
|
+
end
|
54
|
+
end
|
49
55
|
}
|
50
56
|
}
|
51
57
|
|
@@ -2,44 +2,55 @@
|
|
2
2
|
module Wakame
|
3
3
|
module Actions
|
4
4
|
class MigrateService < Action
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
@
|
5
|
+
def initialize(svc, dest_cloud_host=nil)
|
6
|
+
raise ArgumentError unless svc.is_a?(Service::ServiceInstance)
|
7
|
+
@svc = svc
|
8
|
+
@dest_cloud_host = dest_cloud_host
|
8
9
|
end
|
9
10
|
|
10
11
|
def run
|
11
12
|
acquire_lock { |list|
|
12
|
-
list << @
|
13
|
+
list << @svc.resource.class
|
13
14
|
}
|
14
15
|
|
15
|
-
|
16
|
+
if @svc.status == Service::STATUS_MIGRATING
|
17
|
+
Wakame.log.info("Ignore to migrate the service as is already MIGRATING: #{@svc.resource.class}")
|
18
|
+
return
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
@
|
21
|
+
StatusDB.barrier {
|
22
|
+
@svc.update_status(Service::STATUS_MIGRATING)
|
19
23
|
}
|
20
|
-
|
21
|
-
|
22
|
-
clone_service(prop)
|
24
|
+
if @svc.resource.duplicable
|
25
|
+
clone_service()
|
23
26
|
flush_subactions
|
24
|
-
trigger_action(StopService.new(@
|
27
|
+
trigger_action(StopService.new(@svc))
|
25
28
|
else
|
26
|
-
|
27
|
-
trigger_action(StopService.new(@service_instance))
|
29
|
+
trigger_action(StopService.new(@svc))
|
28
30
|
flush_subactions
|
29
|
-
clone_service(
|
31
|
+
clone_service()
|
30
32
|
end
|
31
33
|
flush_subactions
|
32
34
|
end
|
33
35
|
|
36
|
+
def on_failed
|
37
|
+
StatusDB.barrier {
|
38
|
+
@svc.update_status(Service::STATUS_FAIL)
|
39
|
+
if @new_svc
|
40
|
+
@new_svc.update_status(Service::STATUS_FAIL)
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
34
45
|
private
|
35
|
-
def clone_service(
|
46
|
+
def clone_service()
|
36
47
|
new_svc = nil
|
37
|
-
|
38
|
-
new_svc = service_cluster.
|
48
|
+
StatusDB.barrier {
|
49
|
+
new_svc = service_cluster.propagate_service(@svc.id, @dest_cloud_host, true)
|
39
50
|
}
|
40
51
|
|
41
|
-
trigger_action(StartService.new(new_svc
|
42
|
-
new_svc
|
52
|
+
trigger_action(StartService.new(new_svc))
|
53
|
+
@new_svc = new_svc
|
43
54
|
end
|
44
55
|
end
|
45
56
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Wakame
|
2
|
+
module Actions
|
3
|
+
class NotifyChildChanged < Action
|
4
|
+
def initialize(svc)
|
5
|
+
@child_svc = svc
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
parents = []
|
10
|
+
StatusDB.barrier {
|
11
|
+
parents = @child_svc.parent_instances
|
12
|
+
}
|
13
|
+
|
14
|
+
acquire_lock { |lst|
|
15
|
+
lst << parents.map{|c| c.resource.class.to_s }.uniq
|
16
|
+
}
|
17
|
+
|
18
|
+
Wakame.log.debug("#{self.class}: Parent nodes for #{@child_svc.resource.class}: " + parents.map{|c| c.resource.class }.uniq.inspect )
|
19
|
+
|
20
|
+
parents.each { |svc|
|
21
|
+
if svc.status != Service::STATUS_ONLINE
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
trigger_action { |proc_action|
|
26
|
+
svc.resource.on_child_changed(svc, proc_action)
|
27
|
+
}
|
28
|
+
}
|
29
|
+
flush_subactions
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Wakame
|
2
|
+
module Actions
|
3
|
+
class NotifyParentChanged < Action
|
4
|
+
def initialize(svc)
|
5
|
+
@parent_svc = svc
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
children = []
|
10
|
+
StatusDB.barrier {
|
11
|
+
children = @parent_svc.child_instances
|
12
|
+
}
|
13
|
+
|
14
|
+
acquire_lock { |lst|
|
15
|
+
lst << children.map{|c| c.resource.class.to_s }.uniq
|
16
|
+
}
|
17
|
+
|
18
|
+
Wakame.log.debug("#{self.class}: Child nodes for #{@parent_svc.resource.class}: " + children.map{|c| c.resource.class }.uniq.inspect )
|
19
|
+
|
20
|
+
children.each { |svc|
|
21
|
+
if svc.status != Service::STATUS_ONLINE
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
trigger_action { |proc_action|
|
26
|
+
svc.resource.on_parent_changed(svc, proc_action)
|
27
|
+
}
|
28
|
+
}
|
29
|
+
flush_subactions
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Wakame
|
2
|
+
module Actions
|
3
|
+
class PropagateResource < Action
|
4
|
+
|
5
|
+
def initialize(resource, cloud_host_id)
|
6
|
+
raise ArgumentError unless resource.is_a?(Wakame::Service::Resource)
|
7
|
+
@resource = resource
|
8
|
+
@cloud_host_id = cloud_host_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
acquire_lock { |ary|
|
13
|
+
ary << @resource.class.to_s
|
14
|
+
}
|
15
|
+
|
16
|
+
newsvc=nil
|
17
|
+
StatusDB.barrier {
|
18
|
+
newsvc = service_cluster.propagate_resource(@resource, @cloud_host_id)
|
19
|
+
}
|
20
|
+
|
21
|
+
trigger_action(StartService.new(newsvc))
|
22
|
+
flush_subactions
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Wakame
|
2
|
+
module Actions
|
3
|
+
class PropagateService < Action
|
4
|
+
|
5
|
+
def initialize(svc, cloud_host_id=nil)
|
6
|
+
raise ArgumentError unless svc.is_a?(Wakame::Service::ServiceInstance)
|
7
|
+
@svc = svc
|
8
|
+
@cloud_host_id = cloud_host_id
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def run
|
13
|
+
acquire_lock { |ary|
|
14
|
+
ary << @svc.resource.class.to_s
|
15
|
+
}
|
16
|
+
|
17
|
+
newsvc = nil
|
18
|
+
StatusDB.barrier {
|
19
|
+
newsvc = cluster.propagate_service(@svc.id, @cloud_host_id)
|
20
|
+
}
|
21
|
+
trigger_action(StartService.new(newsvc))
|
22
|
+
flush_subactions
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,21 +1,33 @@
|
|
1
1
|
module Wakame
|
2
2
|
module Actions
|
3
3
|
class ReloadService < Action
|
4
|
-
def initialize(
|
5
|
-
@
|
4
|
+
def initialize(svc)
|
5
|
+
@svc = svc
|
6
6
|
end
|
7
7
|
|
8
8
|
def run
|
9
|
-
raise "Agent is not bound on this service : #{@service_instance}" if @service_instance.agent.nil?
|
10
|
-
raise "The assigned agent for the service instance #{@service_instance.instance_id} is not online." unless @service_instance.agent.status == Service::Agent::STATUS_ONLINE
|
11
|
-
|
12
9
|
# Skip to act when the service is having below status.
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
if @svc.status != Service::STATUS_ONLINE
|
11
|
+
raise "Canceled as the service is being or already ONLINE: #{@svc.resource.class}"
|
12
|
+
end
|
13
|
+
|
14
|
+
StatusDB.barrier {
|
15
|
+
@svc.update_status(Service::STATUS_RELOADING)
|
16
|
+
}
|
17
|
+
|
18
|
+
@svc.resource.reload(@svc, self)
|
19
|
+
|
20
|
+
StatusDB.barrier {
|
21
|
+
@svc.update_status(Service::STATUS_ONLINE)
|
22
|
+
}
|
23
|
+
end
|
16
24
|
|
17
|
-
|
25
|
+
def on_failed
|
26
|
+
StatusDB.barrier {
|
27
|
+
@svc.update_status(Service::STATUS_FAIL)
|
28
|
+
}
|
18
29
|
end
|
30
|
+
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
@@ -2,7 +2,7 @@ module Wakame
|
|
2
2
|
module Actions
|
3
3
|
class ShutdownCluster < Action
|
4
4
|
def run
|
5
|
-
levels =
|
5
|
+
levels = cluster.dg.levels
|
6
6
|
Wakame.log.debug("#{self.class}: Resource shutdown order: " + levels.collect {|lv| '['+ lv.collect{|prop| "#{prop.class}" }.join(', ') + ']' }.join(', '))
|
7
7
|
acquire_lock { |list|
|
8
8
|
levels.each {|lv| list << lv.collect{|res| res.class } }
|
@@ -17,8 +17,8 @@ module Wakame
|
|
17
17
|
flush_subactions
|
18
18
|
}
|
19
19
|
|
20
|
-
agent_monitor.
|
21
|
-
trigger_action(ShutdownVM.new(
|
20
|
+
agent_monitor.agent_pool.group_active.keys.each { |agent_id|
|
21
|
+
trigger_action(ShutdownVM.new(Service::Agent.find(agent_id)))
|
22
22
|
}
|
23
23
|
end
|
24
24
|
end
|