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
@@ -0,0 +1,383 @@
|
|
1
|
+
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
module Wakame
|
5
|
+
module StatusDB
|
6
|
+
|
7
|
+
def self.pass(&blk)
|
8
|
+
if Thread.current == WorkerThread.worker_thread
|
9
|
+
blk.call
|
10
|
+
else
|
11
|
+
WorkerThread.queue.enq(blk)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.barrier(&blk)
|
16
|
+
abort "Cant use barrier() in side of the EventMachine thread." if Kernel.const_defined?(:EventMachine) && ::EventMachine.reactor_thread?
|
17
|
+
|
18
|
+
if Thread.current == WorkerThread.worker_thread
|
19
|
+
return blk.call
|
20
|
+
end
|
21
|
+
|
22
|
+
@q ||= ::Queue.new
|
23
|
+
time_start = ::Time.now
|
24
|
+
|
25
|
+
self.pass {
|
26
|
+
begin
|
27
|
+
res = blk.call
|
28
|
+
@q << [true, res]
|
29
|
+
rescue => e
|
30
|
+
@q << [false, e]
|
31
|
+
end
|
32
|
+
}
|
33
|
+
|
34
|
+
res = @q.shift
|
35
|
+
time_elapsed = ::Time.now - time_start
|
36
|
+
Wakame.log.debug("#{self}.barrier: Elapsed time for #{blk}: #{time_elapsed} sec") if time_elapsed > 0.05
|
37
|
+
if res[0] == false && res[1].is_a?(Exception)
|
38
|
+
raise res[1]
|
39
|
+
end
|
40
|
+
res[1]
|
41
|
+
end
|
42
|
+
|
43
|
+
class WorkerThread
|
44
|
+
|
45
|
+
def self.queue
|
46
|
+
@queue ||= ::Queue.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.worker_thread
|
50
|
+
@thread
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.init
|
54
|
+
@proceed_reqs = 0
|
55
|
+
|
56
|
+
if @thread.nil?
|
57
|
+
@thread = Thread.new {
|
58
|
+
while blk = queue.deq
|
59
|
+
begin
|
60
|
+
blk.call
|
61
|
+
rescue => e
|
62
|
+
Wakame.log.error("#{self.class}: #{e}")
|
63
|
+
Wakame.log.error(e)
|
64
|
+
end
|
65
|
+
@proceed_reqs += 1
|
66
|
+
end
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.terminate
|
72
|
+
if self.queue.size > 0
|
73
|
+
Wakame.log.warn("#{self.class}: #{self.class.queue.size} of non-processed reqs are going to be ignored to shutdown the worker thread.")
|
74
|
+
self.queue.clear
|
75
|
+
end
|
76
|
+
self.worker_thread.kill if !self.worker_thread.nil? && self.worker_thread.alive?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def self.adapter
|
82
|
+
@adapter ||= SequelAdapter.new
|
83
|
+
end
|
84
|
+
|
85
|
+
class SequelAdapter
|
86
|
+
DATA_FORMAT_VERSION='0.4'
|
87
|
+
|
88
|
+
def initialize
|
89
|
+
require 'sequel/core'
|
90
|
+
require 'sequel/model'
|
91
|
+
|
92
|
+
#@db = Sequel.connect(Wakame.config.status_db_dsn, {:logger=>Wakame.log})
|
93
|
+
@db = Sequel.connect(Wakame.config.status_db_dsn)
|
94
|
+
|
95
|
+
if [:metadata, :model_stores].all?{ |i| @db.table_exists?(i) }
|
96
|
+
m = @db[:metadata].where(:id=>1).first
|
97
|
+
|
98
|
+
unless m && m[:version] == DATA_FORMAT_VERSION
|
99
|
+
setup_store
|
100
|
+
end
|
101
|
+
|
102
|
+
else
|
103
|
+
setup_store
|
104
|
+
end
|
105
|
+
|
106
|
+
# Generate Sequel::Model class dynamically.
|
107
|
+
# This is same as below:
|
108
|
+
# class ModelStore < Sequel::Model
|
109
|
+
# unrestrict_primary_key
|
110
|
+
# end
|
111
|
+
@model_class = Class.new(Sequel::Model(:model_stores)) { |klass|
|
112
|
+
klass.unrestrict_primary_key
|
113
|
+
}
|
114
|
+
@model_class.plugin :schema
|
115
|
+
@model_class.plugin :hook_class_methods
|
116
|
+
@model_class.class_eval {
|
117
|
+
before_create(:set_created_at) do
|
118
|
+
self.updated_at = self.created_at = Time.now
|
119
|
+
end
|
120
|
+
before_update(:set_updated_at) do
|
121
|
+
self.updated_at = Time.now
|
122
|
+
end
|
123
|
+
}
|
124
|
+
# @model_class.plugin :caching, store
|
125
|
+
end
|
126
|
+
|
127
|
+
def setup_store
|
128
|
+
@db.drop_table :metadata rescue nil
|
129
|
+
@db.create_table? :metadata do
|
130
|
+
primary_key :id
|
131
|
+
column :version, :string
|
132
|
+
column :created_at, :datetime
|
133
|
+
end
|
134
|
+
|
135
|
+
@db[:metadata].insert(:version=>DATA_FORMAT_VERSION, :created_at=>Time.now)
|
136
|
+
|
137
|
+
@db.drop_table :model_stores rescue nil
|
138
|
+
@db.create_table? :model_stores do
|
139
|
+
primary_key :id, :string, :size=>50, :auto_increment=>false
|
140
|
+
column :class_type, :string
|
141
|
+
column :dump, :text
|
142
|
+
column :created_at, :datetime
|
143
|
+
column :updated_at, :datetime
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def find(id, &blk)
|
148
|
+
m = @model_class[id]
|
149
|
+
if m
|
150
|
+
hash = eval(m[:dump])
|
151
|
+
blk.call(id, hash)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Find all rows belong to given klass name.
|
156
|
+
# Returns id list which matches class_type == klass
|
157
|
+
def find_all(klass)
|
158
|
+
ds = @model_class.where(:class_type=>klass.to_s)
|
159
|
+
ds.all.map {|r| r[:id] }
|
160
|
+
end
|
161
|
+
|
162
|
+
def exists?(id)
|
163
|
+
!@model_class[id].nil?
|
164
|
+
end
|
165
|
+
|
166
|
+
def save(id, hash)
|
167
|
+
m = @model_class[id]
|
168
|
+
if m.nil?
|
169
|
+
m = @model_class.new
|
170
|
+
m.id = id
|
171
|
+
m.class_type = hash[AttributeHelper::CLASS_TYPE_KEY]
|
172
|
+
end
|
173
|
+
m.dump = hash.inspect
|
174
|
+
m.save
|
175
|
+
end
|
176
|
+
|
177
|
+
def delete(id)
|
178
|
+
@model_class[id].destroy
|
179
|
+
end
|
180
|
+
|
181
|
+
def clear_store
|
182
|
+
setup_store
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
class Model
|
189
|
+
include ::AttributeHelper
|
190
|
+
|
191
|
+
module ClassMethods
|
192
|
+
def enable_cache
|
193
|
+
unless @enable_cache
|
194
|
+
@enable_cache = true
|
195
|
+
@_instance_cache = {}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def disable_cache
|
200
|
+
if @enable_cache
|
201
|
+
@enable_cache = false
|
202
|
+
@_instance_cache = {}
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def _instance_cache
|
207
|
+
return {} unless @enable_cache
|
208
|
+
|
209
|
+
@_instance_cache ||= {}
|
210
|
+
end
|
211
|
+
|
212
|
+
def find(id)
|
213
|
+
raise "Can not retrieve the data with nil." if id.nil?
|
214
|
+
obj = _instance_cache[id]
|
215
|
+
return obj unless obj.nil?
|
216
|
+
|
217
|
+
StatusDB.adapter.find(id) { |id, hash|
|
218
|
+
if hash[AttributeHelper::CLASS_TYPE_KEY]
|
219
|
+
klass_const = Util.build_const(hash[AttributeHelper::CLASS_TYPE_KEY])
|
220
|
+
else
|
221
|
+
klass_const = self.class
|
222
|
+
end
|
223
|
+
|
224
|
+
# klass_const class is equal to self class or child of self class
|
225
|
+
if klass_const <= self
|
226
|
+
obj = klass_const.new
|
227
|
+
else
|
228
|
+
raise "Can not instanciate the object #{klass_const.to_s} from #{self}"
|
229
|
+
end
|
230
|
+
|
231
|
+
obj.on_before_load
|
232
|
+
|
233
|
+
obj.instance_variable_set(:@id, id)
|
234
|
+
obj.instance_variable_set(:@_orig, hash.dup.freeze)
|
235
|
+
obj.instance_variable_set(:@load_at, Time.now)
|
236
|
+
|
237
|
+
hash.each { |k,v|
|
238
|
+
obj.instance_variable_set("@#{k}", v)
|
239
|
+
}
|
240
|
+
|
241
|
+
obj.on_after_load
|
242
|
+
}
|
243
|
+
|
244
|
+
_instance_cache[id] = obj
|
245
|
+
obj
|
246
|
+
end
|
247
|
+
|
248
|
+
|
249
|
+
def find_all
|
250
|
+
StatusDB.adapter.find_all(self.to_s).map { |id|
|
251
|
+
find(id)
|
252
|
+
}
|
253
|
+
end
|
254
|
+
|
255
|
+
def exists?(id)
|
256
|
+
_instance_cache.has_key?(id) || StatusDB.adapter.exists?(id)
|
257
|
+
end
|
258
|
+
|
259
|
+
# A helper method to define an accessor with persistent flag.
|
260
|
+
def property(key, opts={})
|
261
|
+
case opts
|
262
|
+
when Hash
|
263
|
+
opts.merge!({:persistent=>true})
|
264
|
+
else
|
265
|
+
opts = {:persistent=>true}
|
266
|
+
end
|
267
|
+
def_attribute(key.to_sym, opts)
|
268
|
+
end
|
269
|
+
|
270
|
+
def delete(id)
|
271
|
+
obj = find(id)
|
272
|
+
if obj
|
273
|
+
obj.on_before_delete
|
274
|
+
|
275
|
+
StatusDB.adapter.delete(id)
|
276
|
+
_instance_cache.delete(id)
|
277
|
+
|
278
|
+
obj.on_after_delete
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
def self.inherited(klass)
|
285
|
+
klass.extend(ClassMethods)
|
286
|
+
klass.class_eval {
|
287
|
+
#include(::AttributeHelper)
|
288
|
+
#enable_cache
|
289
|
+
|
290
|
+
# Manually set attr option to get :id appeared in dump_attrs.
|
291
|
+
attr_attributes[:id]={:persistent=>false}
|
292
|
+
}
|
293
|
+
end
|
294
|
+
|
295
|
+
def id
|
296
|
+
@id ||= Wakame::Util.gen_id
|
297
|
+
end
|
298
|
+
|
299
|
+
def new_record?
|
300
|
+
@load_at.nil?
|
301
|
+
end
|
302
|
+
|
303
|
+
def dirty?(key=nil)
|
304
|
+
return true if new_record?
|
305
|
+
|
306
|
+
if key
|
307
|
+
attr_attr = self.class.get_attr_attribute(key.to_sym)
|
308
|
+
raise "#{key} is not the key to be saved" if attr_attr.nil? || !attr_attr[:persistent]
|
309
|
+
return @_orig[key.to_sym] != self.__send__(key.to_sym)
|
310
|
+
else
|
311
|
+
self.class.merged_attr_attributes.each { |k,v|
|
312
|
+
next unless v[:persistent]
|
313
|
+
#p "@_orig[#{k.to_sym}]=#{@_orig[k.to_sym].inspect}"
|
314
|
+
#p "@self.__send__(#{k.to_sym})=#{self.__send__(k.to_sym).inspect}"
|
315
|
+
return true if @_orig[k.to_sym] != self.__send__(k.to_sym)
|
316
|
+
}
|
317
|
+
return false
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def save
|
322
|
+
# return unless dirty?
|
323
|
+
# raise "No change" unless dirty?
|
324
|
+
|
325
|
+
validate_on_save
|
326
|
+
|
327
|
+
self.class.merged_attr_attributes.each { |k,v|
|
328
|
+
next unless v[:persistent]
|
329
|
+
if dirty?(k) && v[:call_after_changed]
|
330
|
+
case v[:call_after_changed]
|
331
|
+
when Symbol
|
332
|
+
self.__send__(v[:call_after_changed].to_sym) # if self.respond_to?(v[:call_after_changed].to_sym)
|
333
|
+
when Proc
|
334
|
+
v[:call_after_changed].call(self)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
}
|
338
|
+
|
339
|
+
hash_saved = self.dump_attrs { |k,v,dumper|
|
340
|
+
if v[:persistent] == true
|
341
|
+
dumper.call(k)
|
342
|
+
end
|
343
|
+
}
|
344
|
+
@_orig = hash_saved.dup.freeze
|
345
|
+
|
346
|
+
StatusDB.adapter.save(self.id, hash_saved)
|
347
|
+
end
|
348
|
+
|
349
|
+
def delete
|
350
|
+
self.class.delete(self.id)
|
351
|
+
end
|
352
|
+
|
353
|
+
def reload
|
354
|
+
self.class._instance_cache.delete(self.id)
|
355
|
+
self.class.find(self.id)
|
356
|
+
end
|
357
|
+
|
358
|
+
# Callback methods
|
359
|
+
|
360
|
+
# Called prior to copying data from database in self.find().
|
361
|
+
def on_before_load
|
362
|
+
end
|
363
|
+
# Called after copying data from database in self.find().
|
364
|
+
def on_after_load
|
365
|
+
end
|
366
|
+
|
367
|
+
def on_before_delete
|
368
|
+
end
|
369
|
+
|
370
|
+
def on_after_delete
|
371
|
+
end
|
372
|
+
|
373
|
+
protected
|
374
|
+
|
375
|
+
def validate_on_save
|
376
|
+
end
|
377
|
+
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
382
|
+
|
383
|
+
end
|
data/lib/wakame/template.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'erb'
|
4
|
+
require 'pathname'
|
4
5
|
|
5
6
|
module Wakame
|
6
7
|
class Template
|
@@ -17,40 +18,44 @@ module Wakame
|
|
17
18
|
@service_instance.resource.basedir
|
18
19
|
end
|
19
20
|
|
21
|
+
def glob_basedir(glob_patterns, &blk)
|
22
|
+
glob_patterns = [glob_patterns] if glob_patterns.is_a? String
|
23
|
+
|
24
|
+
basedir_obj = Pathname.new(basedir)
|
25
|
+
paths = glob_patterns.collect {|pattern| Pathname.glob(File.join(basedir, pattern)).collect {|path| path.relative_path_from(basedir_obj) } }
|
26
|
+
paths = paths.flatten.uniq
|
27
|
+
|
28
|
+
paths.each &blk if blk
|
29
|
+
|
30
|
+
paths
|
31
|
+
end
|
32
|
+
|
20
33
|
def render_config
|
21
|
-
service_instance.
|
34
|
+
service_instance.resource.render_config(self)
|
22
35
|
end
|
23
36
|
|
24
37
|
def cleanup
|
25
38
|
FileUtils.rm_r( @tmp_basedir, :force=>true)
|
26
39
|
end
|
27
40
|
|
28
|
-
def render(
|
29
|
-
|
30
|
-
|
31
|
-
args.each { |path|
|
32
|
-
update(path) { |buf|
|
33
|
-
ERB.new(buf, nil, '-').result(service_instance.export_binding)
|
34
|
-
}
|
41
|
+
def render(path)
|
42
|
+
update(path) { |buf|
|
43
|
+
ERB.new(buf, nil, '-').result(service_instance.export_binding)
|
35
44
|
}
|
36
45
|
end
|
37
46
|
|
38
|
-
def cp(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
destpath,
|
47
|
-
{:preserve=>true}
|
48
|
-
)
|
49
|
-
}
|
47
|
+
def cp(path)
|
48
|
+
destpath = File.expand_path(path, @tmp_basedir)
|
49
|
+
FileUtils.mkpath(File.dirname(destpath)) unless File.directory?(File.dirname(destpath))
|
50
|
+
|
51
|
+
FileUtils.cp_r(File.join(basedir, path),
|
52
|
+
destpath,
|
53
|
+
{:preserve=>true}
|
54
|
+
)
|
50
55
|
end
|
51
56
|
|
52
|
-
def chmod(
|
53
|
-
File.chmod(mode, File.join(@tmp_basedir,
|
57
|
+
def chmod(path, mode)
|
58
|
+
File.chmod(mode, File.join(@tmp_basedir, path))
|
54
59
|
end
|
55
60
|
|
56
61
|
def load(path)
|
@@ -77,113 +82,5 @@ module Wakame
|
|
77
82
|
end
|
78
83
|
|
79
84
|
end
|
80
|
-
|
81
|
-
module Template2
|
82
|
-
class Base
|
83
|
-
attr_reader :tmp_output_basedir
|
84
|
-
|
85
|
-
def initialize()
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
def pre_render
|
90
|
-
@tmp_output_basedir = File.expand_path(Util.gen_id, Wakame.config.config_tmp_root)
|
91
|
-
FileUtils.mkdir_p @tmp_output_basedir
|
92
|
-
end
|
93
|
-
|
94
|
-
def render(service_instance)
|
95
|
-
end
|
96
|
-
|
97
|
-
def post_render
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
# Returns source path which to be synced to the agent host
|
102
|
-
def sync_src
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
def load(path)
|
107
|
-
path = path.sub(/^\//, '')
|
108
|
-
|
109
|
-
return File.readlines(File.expand_path(path, Wakame.config.config_template_root), "r").join('')
|
110
|
-
end
|
111
|
-
|
112
|
-
def save(path, buf)
|
113
|
-
path = path.sub(/^\//, '')
|
114
|
-
|
115
|
-
destpath = File.expand_path(path, @tmp_output_basedir)
|
116
|
-
FileUtils.mkpath(File.dirname(destpath)) unless File.directory?(File.dirname(destpath))
|
117
|
-
|
118
|
-
File.open(destpath, "w", 0644) {|f|
|
119
|
-
f.write(buf)
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
def update(path, &blk)
|
124
|
-
buf = load(path)
|
125
|
-
buf = yield buf if block_given?
|
126
|
-
save(path, buf)
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
class MySQLTemplate < Base
|
133
|
-
def render(service_instance)
|
134
|
-
require 'erb'
|
135
|
-
|
136
|
-
FileUtils.mkpath File.expand_path('mysql', tmp_output_basedir)
|
137
|
-
|
138
|
-
["mysql/my.cnf"].each { |path|
|
139
|
-
update(path) { |buf|
|
140
|
-
ERB.new(buf, nil, '-').result service_instance.export_binding
|
141
|
-
}
|
142
|
-
}
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
def sync_src
|
147
|
-
File.join(@tmp_output_basedir, 'mysql')
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
class ApacheTemplate < Base
|
152
|
-
attr_accessor :suffix
|
153
|
-
|
154
|
-
def initialize(suffix)
|
155
|
-
super()
|
156
|
-
@suffix = suffix
|
157
|
-
end
|
158
|
-
|
159
|
-
def render(service_instance)
|
160
|
-
#p service_instance.service_cluster.virtual_hosts
|
161
|
-
require 'erb'
|
162
|
-
|
163
|
-
FileUtils.mkpath File.expand_path('apache2', tmp_output_basedir)
|
164
|
-
|
165
|
-
["envvars-#{@suffix}", "apache2.conf"].each { |fname|
|
166
|
-
FileUtils.cp_r(File.join(Wakame.config.config_template_root, "apache2/#{fname}"),
|
167
|
-
File.join(tmp_output_basedir, "apache2/#{fname}"),
|
168
|
-
{:preserve=>true})
|
169
|
-
}
|
170
|
-
|
171
|
-
["apache2/system-#{@suffix}.conf", "apache2/sites-#{@suffix}.conf"].each { |path|
|
172
|
-
update(path) { |buf|
|
173
|
-
ERB.new(buf, nil, '-').result service_instance.export_binding
|
174
|
-
}
|
175
|
-
}
|
176
|
-
end
|
177
|
-
|
178
|
-
|
179
|
-
def sync_src
|
180
|
-
File.join(@tmp_output_basedir, 'apache2')
|
181
|
-
end
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
end
|
187
|
-
|
188
85
|
|
189
86
|
end
|
data/lib/wakame/trigger.rb
CHANGED
@@ -5,36 +5,28 @@ module Wakame
|
|
5
5
|
|
6
6
|
def_attribute :enabled, true
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def service_cluster
|
14
|
-
@rule_engine.service_cluster
|
15
|
-
end
|
8
|
+
#def service_cluster
|
9
|
+
# action_manager.service_cluster
|
10
|
+
#end
|
11
|
+
#alias :cluster :service_cluster
|
16
12
|
|
17
13
|
def master
|
18
|
-
|
14
|
+
Master.instance
|
19
15
|
end
|
20
16
|
|
21
17
|
def agent_monitor
|
22
|
-
|
18
|
+
master.agent_monitor
|
23
19
|
end
|
24
20
|
|
25
|
-
def
|
26
|
-
|
21
|
+
def command_queue
|
22
|
+
master.command_queue
|
27
23
|
end
|
28
24
|
|
29
25
|
def trigger_action(action)
|
30
|
-
|
31
|
-
action.bind_trigger(self)
|
32
|
-
|
33
|
-
rule_engine.run_action(action)
|
34
|
-
action.job_id
|
26
|
+
job_id = master.action_manager.trigger_action(action)
|
35
27
|
end
|
36
28
|
|
37
|
-
def register_hooks
|
29
|
+
def register_hooks(service_cluster_id)
|
38
30
|
end
|
39
31
|
|
40
32
|
def cleanup
|
@@ -42,7 +42,7 @@ module Wakame
|
|
42
42
|
@history_period = 3
|
43
43
|
end
|
44
44
|
|
45
|
-
def register_hooks
|
45
|
+
def register_hooks(cluster_id)
|
46
46
|
event_subscribe(Event::AgentMonitored) { |event|
|
47
47
|
@agent_data[event.agent.agent_id]={:load_history=>[], :last_event=>:normal}
|
48
48
|
service_cluster.properties.each { |klass, prop|
|
@@ -17,11 +17,14 @@ module Wakame
|
|
17
17
|
|
18
18
|
tmpfile = File.expand_path(File.basename(Wakame.config.ssh_known_hosts) + '.tmp', basedir)
|
19
19
|
File.open(tmpfile, 'w') { |f|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
StatusDB.barrier do
|
21
|
+
agent_monitor.agent_pool.group_active.keys.each { |agent_id|
|
22
|
+
agent = Service::Agent.find(agent_id)
|
23
|
+
host_keys.each { |k|
|
24
|
+
f << "#{Wakame::Util.ssh_known_hosts_hash(agent.agent_ip)} #{k}\n"
|
25
|
+
}
|
23
26
|
}
|
24
|
-
|
27
|
+
end
|
25
28
|
}
|
26
29
|
|
27
30
|
FileUtils.move(tmpfile, Wakame.config.ssh_known_hosts, {:force=>true})
|
@@ -29,7 +32,7 @@ module Wakame
|
|
29
32
|
end
|
30
33
|
|
31
34
|
|
32
|
-
def register_hooks
|
35
|
+
def register_hooks(cluster_id)
|
33
36
|
event_subscribe(Event::AgentMonitored) { |event|
|
34
37
|
trigger_action(UpdateKnownHosts.new)
|
35
38
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Wakame
|
2
2
|
module Triggers
|
3
3
|
class ShutdownUnusedVM < Trigger
|
4
|
-
def register_hooks
|
4
|
+
def register_hooks(cluster_id)
|
5
5
|
event_subscribe(Event::AgentPong) { |event|
|
6
6
|
if event.agent.services.empty? &&
|
7
7
|
Time.now - event.agent.last_service_assigned_at > Wakame.config.unused_vm_live_period &&
|