wakame 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +18 -0
- data/README.rdoc +2 -4
- data/Rakefile +4 -1
- data/VERSION +1 -1
- data/app_generators/wakame/templates/config/cluster.rb +36 -0
- data/app_generators/wakame/wakame_generator.rb +1 -0
- data/lib/wakame/action.rb +19 -34
- data/lib/wakame/actions/launch_cluster.rb +6 -3
- data/lib/wakame/actions/launch_vm.rb +57 -0
- data/lib/wakame/actions/migrate_service.rb +6 -25
- data/lib/wakame/actions/propagate_instances.rb +16 -41
- data/lib/wakame/actions/reload_service.rb +2 -2
- data/lib/wakame/actions/shutdown_cluster.rb +4 -0
- data/lib/wakame/actions/start_service.rb +30 -9
- data/lib/wakame/actions/stop_service.rb +1 -4
- data/lib/wakame/actions/util.rb +0 -24
- data/lib/wakame/actor/mysql.rb +106 -0
- data/lib/wakame/actor/service_monitor.rb +10 -0
- data/lib/wakame/actor/system.rb +19 -9
- data/lib/wakame/actor.rb +1 -1
- data/lib/wakame/agent.rb +23 -17
- data/lib/wakame/command/action_status.rb +7 -38
- data/lib/wakame/command/agent_status.rb +18 -0
- data/lib/wakame/command/launch_cluster.rb +0 -4
- data/lib/wakame/command/launch_vm.rb +11 -0
- data/lib/wakame/command/migrate_service.rb +12 -9
- data/lib/wakame/command/propagate_service.rb +15 -7
- data/lib/wakame/command/reload_service.rb +21 -0
- data/lib/wakame/command/shutdown_cluster.rb +0 -5
- data/lib/wakame/command/shutdown_vm.rb +20 -0
- data/lib/wakame/command/status.rb +6 -66
- data/lib/wakame/command/stop_service.rb +31 -0
- data/lib/wakame/command.rb +3 -0
- data/lib/wakame/command_queue.rb +76 -5
- data/lib/wakame/configuration.rb +6 -1
- data/lib/wakame/event.rb +6 -5
- data/lib/wakame/event_dispatcher.rb +5 -3
- data/lib/wakame/initializer.rb +1 -1
- data/lib/wakame/master.rb +14 -10
- data/lib/wakame/monitor/agent.rb +1 -6
- data/lib/wakame/monitor/service.rb +13 -1
- data/lib/wakame/packets.rb +51 -13
- data/lib/wakame/rule_engine.rb +7 -18
- data/lib/wakame/runner/administrator_command.rb +517 -46
- data/lib/wakame/service.rb +104 -173
- data/lib/wakame/trigger.rb +1 -10
- data/lib/wakame/triggers/process_command.rb +9 -2
- data/lib/wakame/util.rb +21 -21
- data/lib/wakame/vm_manipulator.rb +1 -0
- data/tests/test_service.rb +30 -6
- data/wakame_generators/resource/templates/ec2_elb/ec2_elb.rb +80 -0
- data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +3 -1
- data/wakame_generators/resource/templates/mysql_master/init.d/mysql +3 -3
- data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +11 -12
- data/{app_generators/wakame/templates/cluster/resources/mysql_master → wakame_generators/resource/templates/mysql_slave}/conf/my.cnf +19 -9
- data/{app_generators/wakame/templates/cluster/resources/mysql_master/init.d/mysql → wakame_generators/resource/templates/mysql_slave/init.d/mysql-slave} +4 -4
- data/wakame_generators/resource/templates/mysql_slave/mysql_slave.rb +123 -0
- data/wakame_generators/resource/templates/nginx/conf/nginx.conf +166 -0
- data/wakame_generators/resource/templates/nginx/init.d/nginx +70 -0
- data/{app_generators/wakame/templates/cluster/resources/apache_lb/apache_lb.rb → wakame_generators/resource/templates/nginx/nginx.rb} +28 -17
- metadata +46 -27
- data/app_generators/wakame/templates/cluster/resources/apache_app/apache_app.rb +0 -54
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/apache2.conf +0 -46
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/envvars-app +0 -7
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/sites-app.conf +0 -23
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/system-app.conf +0 -67
- data/app_generators/wakame/templates/cluster/resources/apache_app/init.d/apache2-app +0 -192
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/apache2.conf +0 -46
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/envvars-lb +0 -6
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/sites-lb.conf +0 -54
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/system-lb.conf +0 -75
- data/app_generators/wakame/templates/cluster/resources/apache_lb/init.d/apache2-lb +0 -192
- data/app_generators/wakame/templates/cluster/resources/apache_www/apache_www.rb +0 -50
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/apache2.conf +0 -47
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/envvars-www +0 -7
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/sites-www.conf +0 -23
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/system-www.conf +0 -63
- data/app_generators/wakame/templates/cluster/resources/apache_www/init.d/apache2-www +0 -192
- data/app_generators/wakame/templates/cluster/resources/ec2_elastic_ip/ec2_elastic_ip.rb +0 -39
- data/app_generators/wakame/templates/cluster/resources/mysql_master/mysql_master.rb +0 -174
- data/tests/conf/a +0 -1
- data/tests/conf/b +0 -1
- data/tests/conf/c +0 -1
@@ -86,12 +86,14 @@ module Wakame
|
|
86
86
|
}
|
87
87
|
end
|
88
88
|
|
89
|
+
FIRE_EVENT_LOG_IGNORE_EVENTS = [Wakame::Event::AgentPong]
|
90
|
+
|
89
91
|
def fire_event(event_obj)
|
90
92
|
raise ArgumentError unless event_obj.is_a?(Event::Base)
|
91
|
-
log_msg = ""
|
92
|
-
log_msg = " #{event_obj.log_message}" unless event_obj.log_message.nil?
|
93
93
|
|
94
|
-
Wakame.log.
|
94
|
+
if Wakame.log.level == 'DEBUG' && !FIRE_EVENT_LOG_IGNORE_EVENTS.member?(event_obj.class)
|
95
|
+
Wakame.log.debug("Event #{event_obj.class} has been fired:" + (event_obj.log_message.nil? ? "" : event_obj.log_message) )
|
96
|
+
end
|
95
97
|
tlist = @event_handlers[event_obj.class]
|
96
98
|
return if tlist.nil?
|
97
99
|
|
data/lib/wakame/initializer.rb
CHANGED
@@ -47,7 +47,7 @@ module Wakame
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def setup_load_paths
|
50
|
-
load_paths = configuration.load_paths + configuration.framework_paths
|
50
|
+
load_paths = configuration.load_paths + configuration.project_paths + configuration.framework_paths
|
51
51
|
load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
|
52
52
|
$LOAD_PATH.uniq!
|
53
53
|
|
data/lib/wakame/master.rb
CHANGED
@@ -42,7 +42,7 @@ module Wakame
|
|
42
42
|
}
|
43
43
|
|
44
44
|
kill_list.each { |agent_id|
|
45
|
-
agent = @
|
45
|
+
agent = @registered_agents.delete(agent_id)
|
46
46
|
ED.fire_event(Event::AgentUnMonitored.new(agent)) unless agent.nil?
|
47
47
|
}
|
48
48
|
#Wakame.log.debug("Finished agent GC")
|
@@ -129,7 +129,7 @@ module Wakame
|
|
129
129
|
when Actor::STATUS_RUNNING
|
130
130
|
ED.fire_event(Event::ActorProgress.new(response[:agent_id], response[:token], 0))
|
131
131
|
else
|
132
|
-
ED.fire_event(Event::ActorComplete.new(response[:agent_id], response[:token], response[:status]))
|
132
|
+
ED.fire_event(Event::ActorComplete.new(response[:agent_id], response[:token], response[:status], response[:opts][:return_value]))
|
133
133
|
end
|
134
134
|
else
|
135
135
|
Wakame.log.warn("#{self.class}: Unhandled agent response: #{response[:type]}")
|
@@ -162,6 +162,7 @@ module Wakame
|
|
162
162
|
ED.fire_event(Event::AgentMonitored.new(agent))
|
163
163
|
end
|
164
164
|
agent.root_path = data[:root_path]
|
165
|
+
agent.attr = data[:attrs]
|
165
166
|
end
|
166
167
|
|
167
168
|
def unregister_agent(agent_id)
|
@@ -299,7 +300,7 @@ module Wakame
|
|
299
300
|
|
300
301
|
|
301
302
|
class ActorRequest
|
302
|
-
attr_reader :master
|
303
|
+
attr_reader :master, :return_value
|
303
304
|
|
304
305
|
def initialize(master, packet)
|
305
306
|
raise TypeError unless packet.is_a?(Wakame::Packets::ActorRequest)
|
@@ -308,6 +309,7 @@ module Wakame
|
|
308
309
|
@packet = packet
|
309
310
|
@requested = false
|
310
311
|
@event_ticket = nil
|
312
|
+
@return_value = nil
|
311
313
|
@wait_lock = ::Queue.new
|
312
314
|
end
|
313
315
|
|
@@ -316,13 +318,14 @@ module Wakame
|
|
316
318
|
raise "The request has already been sent." if @requested
|
317
319
|
|
318
320
|
@event_ticket = ED.subscribe(Event::ActorComplete) { |event|
|
319
|
-
|
321
|
+
if event.token == @packet.token
|
320
322
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
323
|
+
# Any of status except RUNNING are accomplishment of the actor request.
|
324
|
+
Wakame.log.debug("#{self.class}: The actor request has been completed: token=#{self.token}, status=#{event.status}, return_value=#{event.return_value}")
|
325
|
+
ED.unsubscribe(@event_ticket)
|
326
|
+
@return_value = event.return_value
|
327
|
+
@wait_lock.enq([event.status, event.return_value])
|
328
|
+
end
|
326
329
|
}
|
327
330
|
Wakame.log.debug("#{self.class}: Send the actor request: #{@packet.path}@#{@packet.agent_id}, token=#{self.token}")
|
328
331
|
master.publish_to('agent_command', "agent_id.#{@packet.agent_id}", @packet.marshal)
|
@@ -352,11 +355,12 @@ module Wakame
|
|
352
355
|
check_requested?
|
353
356
|
timeout(tout) {
|
354
357
|
Wakame.log.debug("#{self.class}: Waiting a response from the actor: #{@packet.path}@#{@packet.agent_id}, token=#{@packet.token}")
|
355
|
-
ret_status = @wait_lock.deq
|
358
|
+
ret_status, ret_val = @wait_lock.deq
|
356
359
|
Wakame.log.debug("#{self.class}: A response (status=#{ret_status}) back from the actor: #{@packet.path}@#{@packet.agent_id}, token=#{@packet.token}")
|
357
360
|
if ret_status == Actor::STATUS_FAILED
|
358
361
|
raise RuntimeError, "Failed status has been returned: Actor Request #{token}"
|
359
362
|
end
|
363
|
+
ret_val
|
360
364
|
}
|
361
365
|
end
|
362
366
|
alias :wait :wait_completion
|
data/lib/wakame/monitor/agent.rb
CHANGED
@@ -23,12 +23,7 @@ class Wakame::Monitor::Agent
|
|
23
23
|
|
24
24
|
|
25
25
|
def check
|
26
|
-
|
27
|
-
require 'wakame/vm_manipulator'
|
28
|
-
attrs = Wakame::VmManipulator::EC2::MetadataService.fetch_local_attrs
|
29
|
-
else
|
30
|
-
attrs = Wakame::VmManipulator::StandAlone.fetch_local_attrs
|
31
|
-
end
|
26
|
+
attrs = Wakame::VmManipulator.create.fetch_local_attrs
|
32
27
|
|
33
28
|
res = {:attrs=>attrs, :monitors=>[], :actors=>[], :services=>{}}
|
34
29
|
EM.barrier {
|
@@ -21,6 +21,9 @@ class Wakame::Monitor::Service
|
|
21
21
|
|
22
22
|
def start
|
23
23
|
if !@timer.running?
|
24
|
+
# Runs checker once for immediate status update.
|
25
|
+
signal_checker
|
26
|
+
|
24
27
|
@timer.start
|
25
28
|
@service_monitor.send_event(Wakame::Packets::MonitoringStarted.new(@service_monitor.agent, self.svc_id))
|
26
29
|
Wakame.log.debug("#{self.class}: Started the checker")
|
@@ -174,10 +177,19 @@ class Wakame::Monitor::Service
|
|
174
177
|
def unregister(svc_id)
|
175
178
|
chk = @checkers[svc_id]
|
176
179
|
if chk
|
177
|
-
chk.
|
180
|
+
chk.stop
|
178
181
|
@checkers.delete(svc_id)
|
179
182
|
Wakame.log.info("#{self.class}: Unregistered service checker for #{svc_id}")
|
180
183
|
end
|
181
184
|
end
|
182
185
|
|
186
|
+
def check_status(svc_id)
|
187
|
+
chk = @checkers[svc_id]
|
188
|
+
if chk
|
189
|
+
chk.status
|
190
|
+
else
|
191
|
+
raise RuntimeError, "#{self.class}: Specified service id was not found: #{svc_id}"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
183
195
|
end
|
data/lib/wakame/packets.rb
CHANGED
@@ -10,7 +10,9 @@ module Wakame
|
|
10
10
|
class ResponseBase
|
11
11
|
include AttributeHelper
|
12
12
|
|
13
|
-
attr_reader :agent_id, :responded_at
|
13
|
+
#attr_reader :agent_id, :responded_at
|
14
|
+
def_attribute :agent_id
|
15
|
+
def_attribute :responded_at
|
14
16
|
|
15
17
|
def initialize(agent)
|
16
18
|
raise TypeError unless agent.respond_to?(:agent_id)
|
@@ -29,7 +31,9 @@ module Wakame
|
|
29
31
|
class RequestBase
|
30
32
|
include AttributeHelper
|
31
33
|
|
32
|
-
attr_reader :token, :requested_at
|
34
|
+
#attr_reader :token, :requested_at
|
35
|
+
def_attribute :token
|
36
|
+
def_attribute :requested_at
|
33
37
|
|
34
38
|
def initialize(token=nil)
|
35
39
|
@token = token || Util.gen_id
|
@@ -43,7 +47,12 @@ module Wakame
|
|
43
47
|
end
|
44
48
|
|
45
49
|
class Ping < ResponseBase
|
46
|
-
attr_reader :attrs, :monitors, :actors, :services
|
50
|
+
#attr_reader :attrs, :monitors, :actors, :services
|
51
|
+
def_attribute :attrs
|
52
|
+
def_attribute :monitors
|
53
|
+
def_attribute :actors
|
54
|
+
def_attribute :services
|
55
|
+
|
47
56
|
def initialize(agent, attrs, actors, monitors, services)
|
48
57
|
super(agent)
|
49
58
|
@attrs = attrs
|
@@ -55,10 +64,14 @@ module Wakame
|
|
55
64
|
|
56
65
|
|
57
66
|
class Register < ResponseBase
|
58
|
-
attr_reader :root_path
|
59
|
-
|
67
|
+
#attr_reader :root_path, :attrs
|
68
|
+
def_attribute :root_path
|
69
|
+
def_attribute :attrs
|
70
|
+
|
71
|
+
def initialize(agent, root_path, attrs)
|
60
72
|
super(agent)
|
61
73
|
@root_path = root_path
|
74
|
+
@attrs = attrs
|
62
75
|
end
|
63
76
|
end
|
64
77
|
|
@@ -69,7 +82,9 @@ module Wakame
|
|
69
82
|
end
|
70
83
|
|
71
84
|
class MonitoringStarted < ResponseBase
|
72
|
-
attr_reader :svc_id
|
85
|
+
#attr_reader :svc_id
|
86
|
+
def_attribute :svc_id
|
87
|
+
|
73
88
|
def initialize(agent, svc_id)
|
74
89
|
super(agent)
|
75
90
|
@svc_id = svc_id
|
@@ -77,14 +92,19 @@ module Wakame
|
|
77
92
|
end
|
78
93
|
|
79
94
|
class MonitoringStopped < ResponseBase
|
80
|
-
attr_reader :svc_id
|
95
|
+
#attr_reader :svc_id
|
96
|
+
def_attribute :svc_id
|
97
|
+
|
81
98
|
def initialize(agent, svc_id)
|
82
99
|
super(agent)
|
83
100
|
@svc_id = svc_id
|
84
101
|
end
|
85
102
|
end
|
86
103
|
class MonitoringOutput < ResponseBase
|
87
|
-
attr_reader :svc_id, :outputs
|
104
|
+
#attr_reader :svc_id, :outputs
|
105
|
+
def_attribute :svc_id
|
106
|
+
def_attribute :outputs
|
107
|
+
|
88
108
|
def initialize(agent, svc_id, outputs)
|
89
109
|
super(agent)
|
90
110
|
@svc_id = svc_id
|
@@ -93,7 +113,9 @@ module Wakame
|
|
93
113
|
end
|
94
114
|
|
95
115
|
class EventResponse < ResponseBase
|
96
|
-
attr_reader :event
|
116
|
+
#attr_reader :event
|
117
|
+
def_attribute :event
|
118
|
+
|
97
119
|
def initialize(agent, event)
|
98
120
|
super(agent)
|
99
121
|
@event = event
|
@@ -126,7 +148,12 @@ module Wakame
|
|
126
148
|
# end
|
127
149
|
|
128
150
|
class ServiceStatusChanged < ResponseBase
|
129
|
-
attr_accessor :svc_id, :prev_status, :new_status, :fail_message
|
151
|
+
#attr_accessor :svc_id, :prev_status, :new_status, :fail_message
|
152
|
+
def_attribute :svc_id
|
153
|
+
def_attribute :prev_status
|
154
|
+
def_attribute :new_status
|
155
|
+
def_attribute :fail_message
|
156
|
+
|
130
157
|
def initialize(agent, svc_id, prev_status, new_status, fail_message=nil)
|
131
158
|
super(agent)
|
132
159
|
@svc_id = svc_id
|
@@ -137,7 +164,12 @@ module Wakame
|
|
137
164
|
end
|
138
165
|
|
139
166
|
class ActorRequest < RequestBase
|
140
|
-
attr_reader :agent_id, :token, :path, :args
|
167
|
+
#attr_reader :agent_id, :token, :path, :args
|
168
|
+
def_attribute :agent_id
|
169
|
+
def_attribute :token
|
170
|
+
def_attribute :path
|
171
|
+
def_attribute :args
|
172
|
+
|
141
173
|
def initialize(agent_id, token, path, *args)
|
142
174
|
super()
|
143
175
|
@agent_id = agent_id
|
@@ -148,11 +180,17 @@ module Wakame
|
|
148
180
|
end
|
149
181
|
|
150
182
|
class ActorResponse < ResponseBase
|
151
|
-
attr_reader :agent_id, :token, :status
|
152
|
-
|
183
|
+
#attr_reader :agent_id, :token, :status, :opts
|
184
|
+
def_attribute :agent_id
|
185
|
+
def_attribute :token
|
186
|
+
def_attribute :status
|
187
|
+
def_attribute :opts
|
188
|
+
|
189
|
+
def initialize(agent, token, status, opts={})
|
153
190
|
super(agent)
|
154
191
|
@token = token
|
155
192
|
@status = status
|
193
|
+
@opts = opts
|
156
194
|
end
|
157
195
|
end
|
158
196
|
|
data/lib/wakame/rule_engine.rb
CHANGED
@@ -34,7 +34,6 @@ module Wakame
|
|
34
34
|
|
35
35
|
@active_jobs = {}
|
36
36
|
@job_history = []
|
37
|
-
@global_lock = nil
|
38
37
|
instance_eval(&blk) if blk
|
39
38
|
end
|
40
39
|
|
@@ -52,7 +51,7 @@ module Wakame
|
|
52
51
|
:job_id=>job_id,
|
53
52
|
:src_trigger=>trigger,
|
54
53
|
:create_at=>Time.now,
|
55
|
-
:start_at=>nil,
|
54
|
+
:start_at=>nil,
|
56
55
|
:complete_at=>nil,
|
57
56
|
:root_action=>root_action,
|
58
57
|
:notes=>{}
|
@@ -97,16 +96,6 @@ module Wakame
|
|
97
96
|
job_context = @active_jobs[action.job_id]
|
98
97
|
raise "The job session is killed.: job_id=#{action.job_id}" if job_context.nil?
|
99
98
|
|
100
|
-
if action.acquire_lock
|
101
|
-
if @global_lock.nil?
|
102
|
-
@global_lock = action.job_id
|
103
|
-
else
|
104
|
-
unless @global_lock == action.job_id
|
105
|
-
raise GlobalLockError, "Global Lock is already acquired by the JobID: #{@global_lock}"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
99
|
EM.next_tick {
|
111
100
|
|
112
101
|
begin
|
@@ -170,17 +159,17 @@ module Wakame
|
|
170
159
|
next
|
171
160
|
end
|
172
161
|
|
173
|
-
|
174
|
-
job_context[:root_action].walk_subactions {|a|
|
175
|
-
Wakame.log.debug(
|
162
|
+
actary = []
|
163
|
+
job_context[:root_action].walk_subactions {|a| actary << a }
|
164
|
+
Wakame.log.debug(actary.collect{|a| {a.class.to_s=>a.status}}.inspect)
|
176
165
|
|
177
166
|
if res.is_a?(Exception)
|
178
167
|
job_context[:exception]=res
|
179
168
|
end
|
180
169
|
|
181
|
-
if
|
170
|
+
if actary.all? { |act| act.status == :complete }
|
182
171
|
|
183
|
-
if
|
172
|
+
if actary.all? { |act| act.completion_status == :succeeded }
|
184
173
|
ED.fire_event(Event::JobComplete.new(action.job_id))
|
185
174
|
else
|
186
175
|
ED.fire_event(Event::JobFailed.new(action.job_id, res))
|
@@ -189,7 +178,7 @@ module Wakame
|
|
189
178
|
job_context[:complete_at]=Time.now
|
190
179
|
@job_history << job_context
|
191
180
|
@active_jobs.delete(job_context[:job_id])
|
192
|
-
|
181
|
+
service_cluster.lock_queue.quit(job_context[:job_id])
|
193
182
|
end
|
194
183
|
}
|
195
184
|
rescue => e
|