wakame 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/History.txt +8 -0
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/app_generators/wakame/templates/cluster/resources/markers/http_application_server.rb +3 -0
  5. data/app_generators/wakame/templates/cluster/resources/markers/http_asset_server.rb +2 -0
  6. data/app_generators/wakame/templates/cluster/resources/markers/http_server.rb +9 -0
  7. data/app_generators/wakame/templates/config/cluster.rb +36 -99
  8. data/app_generators/wakame/templates/config/init.d/wakame-agent +3 -3
  9. data/app_generators/wakame/templates/config/init.d/wakame-master +3 -3
  10. data/app_generators/wakame/wakame_generator.rb +5 -1
  11. data/contrib/imagesetup.sh +9 -5
  12. data/lib/ext/uri.rb +13 -0
  13. data/lib/wakame/action.rb +46 -21
  14. data/lib/wakame/{rule_engine.rb → action_manager.rb} +148 -36
  15. data/lib/wakame/actions/deploy_config.rb +35 -0
  16. data/lib/wakame/actions/launch_cluster.rb +8 -10
  17. data/lib/wakame/actions/launch_vm.rb +26 -20
  18. data/lib/wakame/actions/migrate_service.rb +30 -19
  19. data/lib/wakame/actions/notify_child_changed.rb +34 -0
  20. data/lib/wakame/actions/notify_parent_changed.rb +34 -0
  21. data/lib/wakame/actions/propagate_resource.rb +27 -0
  22. data/lib/wakame/actions/propagate_service.rb +27 -0
  23. data/lib/wakame/actions/reload_service.rb +21 -9
  24. data/lib/wakame/actions/shutdown_cluster.rb +3 -3
  25. data/lib/wakame/actions/shutdown_vm.rb +14 -5
  26. data/lib/wakame/actions/start_service.rb +53 -47
  27. data/lib/wakame/actions/stop_service.rb +35 -23
  28. data/lib/wakame/actor/system.rb +6 -3
  29. data/lib/wakame/agent.rb +29 -7
  30. data/lib/wakame/amqp_client.rb +26 -5
  31. data/lib/wakame/command/action_status.rb +7 -7
  32. data/lib/wakame/command/actor.rb +10 -10
  33. data/lib/wakame/command/import_cluster_config.rb +10 -0
  34. data/lib/wakame/command/launch_cluster.rb +2 -2
  35. data/lib/wakame/command/launch_vm.rb +3 -3
  36. data/lib/wakame/command/migrate_service.rb +7 -7
  37. data/lib/wakame/command/propagate_resource.rb +42 -0
  38. data/lib/wakame/command/propagate_service.rb +21 -19
  39. data/lib/wakame/command/reload_service.rb +3 -13
  40. data/lib/wakame/command/shutdown_cluster.rb +2 -2
  41. data/lib/wakame/command/start_service.rb +14 -0
  42. data/lib/wakame/command/status.rb +32 -10
  43. data/lib/wakame/command/stop_service.rb +27 -21
  44. data/lib/wakame/command.rb +19 -3
  45. data/lib/wakame/command_queue.rb +87 -67
  46. data/lib/wakame/configuration.rb +6 -0
  47. data/lib/wakame/event.rb +17 -0
  48. data/lib/wakame/event_dispatcher.rb +32 -23
  49. data/lib/wakame/graph.rb +2 -1
  50. data/lib/wakame/initializer.rb +11 -8
  51. data/lib/wakame/master.rb +327 -209
  52. data/lib/wakame/monitor/agent.rb +5 -1
  53. data/lib/wakame/monitor/service.rb +6 -5
  54. data/lib/wakame/packets.rb +13 -21
  55. data/lib/wakame/runner/administrator_command.rb +383 -264
  56. data/lib/wakame/runner/agent.rb +1 -5
  57. data/lib/wakame/runner/master.rb +0 -3
  58. data/lib/wakame/service.rb +817 -538
  59. data/lib/wakame/status_db.rb +383 -0
  60. data/lib/wakame/template.rb +27 -130
  61. data/lib/wakame/trigger.rb +10 -18
  62. data/lib/wakame/triggers/instance_count_update.rb +1 -1
  63. data/lib/wakame/triggers/load_history.rb +1 -1
  64. data/lib/wakame/triggers/maintain_ssh_known_hosts.rb +8 -5
  65. data/lib/wakame/triggers/shutdown_unused_vm.rb +1 -1
  66. data/lib/wakame/util.rb +64 -55
  67. data/lib/wakame.rb +4 -0
  68. data/tests/test_action_manager.rb +111 -0
  69. data/tests/test_service.rb +128 -23
  70. data/tests/test_status_db.rb +82 -0
  71. data/tests/test_uri_amqp.rb +10 -0
  72. data/wakame_generators/resource/templates/apache_app/apache_app.rb +19 -18
  73. data/wakame_generators/resource/templates/apache_app/conf/apache2.conf +14 -2
  74. data/wakame_generators/resource/templates/apache_app/conf/system-app.conf +1 -1
  75. data/wakame_generators/resource/templates/apache_app/conf/vh/aaa.test.conf +9 -0
  76. data/wakame_generators/resource/templates/apache_lb/apache_lb.rb +21 -20
  77. data/wakame_generators/resource/templates/apache_lb/conf/apache2.conf +14 -2
  78. data/wakame_generators/resource/templates/apache_lb/conf/system-lb.conf +17 -2
  79. data/wakame_generators/resource/templates/apache_lb/conf/vh/aaa.test.conf +37 -0
  80. data/wakame_generators/resource/templates/apache_www/apache_www.rb +20 -18
  81. data/wakame_generators/resource/templates/apache_www/conf/apache2.conf +14 -2
  82. data/wakame_generators/resource/templates/apache_www/conf/system-www.conf +1 -1
  83. data/wakame_generators/resource/templates/apache_www/conf/vh/aaa.test.conf +9 -0
  84. data/wakame_generators/resource/templates/ec2_elastic_ip/ec2_elastic_ip.rb +6 -8
  85. data/wakame_generators/resource/templates/ec2_elb/ec2_elb.rb +7 -6
  86. data/wakame_generators/resource/templates/memcached/conf/memcached.conf +47 -0
  87. data/wakame_generators/resource/templates/memcached/init.d/memcached +61 -0
  88. data/wakame_generators/resource/templates/memcached/memcached.rb +73 -0
  89. data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +5 -7
  90. data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +35 -34
  91. data/wakame_generators/resource/templates/mysql_slave/conf/my.cnf +6 -6
  92. data/wakame_generators/resource/templates/mysql_slave/mysql_slave.rb +21 -24
  93. data/wakame_generators/resource/templates/nginx/conf/nginx.conf +17 -27
  94. data/wakame_generators/resource/templates/nginx/conf/vh/aaa.test.conf +30 -0
  95. data/wakame_generators/resource/templates/nginx/nginx.rb +18 -18
  96. metadata +34 -21
  97. data/lib/wakame/actions/propagate_instances.rb +0 -70
  98. data/lib/wakame/manager/commands.rb +0 -134
  99. data/lib/wakame/rule.rb +0 -116
  100. data/lib/wakame/triggers/process_command.rb +0 -41
  101. data/tests/test_rule_engine.rb +0 -127
  102. data/wakame_generators/resource/templates/apache_app/conf/sites-app.conf +0 -23
  103. data/wakame_generators/resource/templates/apache_lb/conf/sites-lb.conf +0 -54
  104. data/wakame_generators/resource/templates/apache_www/conf/sites-www.conf +0 -23
data/lib/wakame/util.rb CHANGED
@@ -198,6 +198,7 @@ end
198
198
 
199
199
  module AttributeHelper
200
200
 
201
+ CLASS_TYPE_KEY=:class_type
201
202
  PRIMITIVE_CLASSES=[NilClass, TrueClass, FalseClass, Numeric, String, Symbol]
202
203
  CONVERT_CLASSES={Time => proc{|i| i.to_s } }
203
204
 
@@ -206,49 +207,53 @@ module AttributeHelper
206
207
  @attr_attributes ||= {}
207
208
  end
208
209
 
209
- # def attr(name, assignable=false)
210
- # attr_attributes[name.to_sym]={}
211
- # attr_without_trap(name, assignable)
212
- # end
213
-
214
- # # Override Object.attr_accessor to
215
- # def attr_accessor(*args)
216
- # args.each { |name|
217
- # attr(name, true)
218
- # }
219
- # end
220
-
221
- # def attr_reader(*args)
222
- # args.each { |name|
223
- # attr(name, false)
224
- # }
225
- # end
226
-
227
- # def attr_writer(*args)
228
- # args.each { |name|
229
- # attr(name, true)
230
- # }
231
- # end
210
+ def merged_attr_attributes
211
+ hash = {}
212
+ self.ancestors.reverse.each { |klass|
213
+ next unless klass.include?(AttributeHelper)
214
+ hash.merge!(klass.attr_attributes.dup)
215
+ }
216
+ hash
217
+ end
218
+
219
+ def get_attr_attribute(attr_name)
220
+ merged_attr_attributes[attr_name]
221
+ end
232
222
 
233
223
  def def_attribute(name, *args)
234
- attr = {}
235
- attr_attributes[name.to_sym] = begin
236
- if args.size == 0
237
- {:default=>nil}
238
- else
239
- case args[0]
240
- when Hash
241
- args[0].dup
242
- else
243
- {:default=>args[0]}
244
- end
245
- end
246
- end
247
- class_eval <<-__E__
248
- def #{name}=(v)
249
- @#{name}=v
224
+ attr = begin
225
+ if args.size == 0
226
+ {:default=>nil}
227
+ else
228
+ case args[0]
229
+ when Hash
230
+ args[0].dup
231
+ else
232
+ {:default=>args[0]}
233
+ end
234
+ end
235
+ end
236
+
237
+ (attr_attributes[name.to_sym] ||= {}).merge!(attr)
238
+
239
+ if attr[:read_only]
240
+ if self.respond_to? "#{name}=".to_sym
241
+ class_eval %Q{
242
+ undef_method "#{name}=".to_sym
243
+ }
244
+ end
245
+ else
246
+ class_eval <<-__E__
247
+ def #{name}=(v)
248
+ self.#{name}
249
+ @#{name}=v
250
+ end
251
+
252
+ public :#{name}=
253
+ __E__
250
254
  end
251
-
255
+
256
+ class_eval <<-__E__
252
257
  def #{name}
253
258
  if @#{name}.nil?
254
259
  retrieve_attr_attribute { |a|
@@ -258,7 +263,7 @@ module AttributeHelper
258
263
  when Proc
259
264
  @#{name} = defval.call(self)
260
265
  else
261
- @#{name} = defval
266
+ @#{name} = defval.dup rescue defval
262
267
  end
263
268
  break
264
269
  end
@@ -267,7 +272,7 @@ module AttributeHelper
267
272
  @#{name}
268
273
  end
269
274
 
270
- public :#{name}, :#{name}=
275
+ public :#{name}
271
276
  __E__
272
277
  end
273
278
 
@@ -275,47 +280,51 @@ module AttributeHelper
275
280
 
276
281
  private
277
282
  def self.included(klass)
278
- klass.class.class_eval {
279
- #alias :attr_without_trap :attr unless self.respond_to?(:attr_without_trap, true)
280
- }
281
283
  klass.extend ClassMethods
282
284
  end
283
285
 
284
286
 
285
287
  public
286
- def dump_attrs(root=nil)
288
+ def dump_attrs(root=nil, &blk)
287
289
  if root.nil?
288
290
  root = self
289
291
  end
290
292
 
291
- return dump_internal(root)
293
+ return dump_internal(root, &blk)
292
294
  end
293
295
  #thread_immutable_method :dump_attrs if self.kind_of?(ThreadImmutable)
294
296
  #module_function :dump_attrs
295
297
 
296
-
297
- private
298
298
  def retrieve_attr_attribute(&blk)
299
299
  self.class.ancestors.each { |klass|
300
300
  blk.call(klass.attr_attributes) if klass.include?(AttributeHelper)
301
301
  }
302
302
  end
303
303
 
304
- def dump_internal(root)
304
+ private
305
+ def dump_internal(root, &blk)
305
306
  case root
306
307
  when AttributeHelper
307
308
  t={}
308
- t[:type] = root.class.to_s
309
+ t[CLASS_TYPE_KEY] = root.class.to_s
309
310
 
310
- retrieve_attr_attribute { |a|
311
- a.each_key {|k| t[k] = dump_internal(root.__send__(k.to_sym)) }
311
+ default_dumper = lambda { |k|
312
+ t[k] = dump_internal(root.__send__(k.to_sym), &blk)
313
+ }
314
+
315
+ self.class.merged_attr_attributes.each { |k,v|
316
+ if blk
317
+ blk.call(k,v, default_dumper)
318
+ else
319
+ default_dumper.call(k)
320
+ end
312
321
  }
313
322
  t
314
323
  when Array
315
- root.collect { |a| dump_internal(a) }
324
+ root.collect { |a| dump_internal(a, &blk) }
316
325
  when Hash
317
326
  t={}
318
- root.each {|k,v| t[k] = dump_internal(v) }
327
+ root.each {|k,v| t[k] = dump_internal(v, &blk) }
319
328
  t
320
329
  else
321
330
  if CONVERT_CLASSES.any?{|t, p| root.kind_of?(t) }
data/lib/wakame.rb CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  require 'rubygems'
3
3
 
4
+ require 'uri'
5
+ require 'ext/uri'
4
6
  # For debugging
5
7
  Thread.abort_on_exception = true
6
8
 
@@ -30,6 +32,8 @@ module Wakame
30
32
  autoload :Trigger, 'wakame/trigger'
31
33
  autoload :Action, 'wakame/action'
32
34
  autoload :RuleEngine, 'wakame/rule_engine'
35
+ autoload :StatusDB, 'wakame/status_db'
36
+ autoload :ActionManager, 'wakame/action_manager'
33
37
  #autoload :Initializer, 'wakame/initializer' # Do not autoload this class since the constant is used for the flag in bootstrap.
34
38
 
35
39
  def gen_id(str=nil)
@@ -0,0 +1,111 @@
1
+
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+ $:.unshift(File.dirname(__FILE__))
4
+
5
+ require 'setup_master.rb'
6
+
7
+ require 'eventmachine'
8
+
9
+ require 'test/unit'
10
+ require 'wakame'
11
+
12
+ #WAKAME_ROOT="#{File.dirname(__FILE__)}/.."
13
+
14
+ Wakame::EventDispatcher
15
+
16
+ class TestRuleEngine < Test::Unit::TestCase
17
+
18
+ class Action1 < Wakame::Action
19
+ def run
20
+ trigger_action(Action2.new)
21
+ flush_subactions
22
+ end
23
+ end
24
+ class Action2 < Wakame::Action
25
+ def run
26
+ 100.times {
27
+ act3 = Action3.new
28
+ trigger_action(act3)
29
+ }
30
+ flush_subactions
31
+ end
32
+ end
33
+ class Action3 < Wakame::Action
34
+ def run
35
+ puts "sleeping(2)..."
36
+ sleep (0.2 + rand(5))
37
+ end
38
+ end
39
+
40
+ def test_nested_actions
41
+ EM.run {
42
+ manager = Wakame::ActionManager.new
43
+
44
+ job_id = manager.trigger_action(Action1.new)
45
+
46
+ EM.add_periodic_timer(1) {
47
+ EM.stop if manager.active_jobs[job_id] == nil
48
+ }
49
+ }
50
+ end
51
+
52
+
53
+ class Action4 < Wakame::Action
54
+ def run
55
+ trigger_action(Action1.new)
56
+
57
+ trigger_action(FailAction1.new)
58
+
59
+ flush_subactions
60
+ end
61
+ end
62
+
63
+ class FailAction1 < Wakame::Action
64
+ def run
65
+ trigger_action(Action1.new)
66
+ raise StandardError
67
+ end
68
+ end
69
+
70
+ def test_exception_escalation
71
+ EM.run {
72
+ manager = Wakame::ActionManager.new
73
+
74
+ job_id = manager.trigger_action(Action4.new)
75
+ EM.add_timer(10) { EM.stop }
76
+ }
77
+ end
78
+
79
+
80
+ def test_each_subaction
81
+ EM.run {
82
+ manager = Wakame::ActionManager.new
83
+ engine.register_rule(Rule1.new)
84
+ EM.add_timer(1) {
85
+ engine.active_jobs.each { |k, v|
86
+ v[:root_action].walk_subactions {|a|
87
+ puts a
88
+ }
89
+ }
90
+
91
+ }
92
+ EM.add_timer(5) { EM.stop }
93
+ }
94
+ end
95
+
96
+
97
+ def test_cancel_action
98
+ EM.run {
99
+ manager = Wakame::ActionManager.new
100
+
101
+ job_id = manager.trigger_action(Action1.new)
102
+ EM.add_timer(1){
103
+ manager.cancel_action(job_id)
104
+ }
105
+ EM.add_timer(5) { EM.stop }
106
+ }
107
+ end
108
+
109
+
110
+
111
+ end
@@ -5,55 +5,160 @@ $:.unshift(File.dirname(__FILE__))
5
5
 
6
6
  require 'setup_master.rb'
7
7
 
8
+ require 'eventmachine'
8
9
  require 'wakame/service.rb'
10
+ require 'wakame/event_dispatcher.rb'
11
+
12
+ # Store to sqlite memory database
13
+ Wakame.config.status_db_dsn = 'sqlite:///'
9
14
 
10
15
  class TestService < Test::Unit::TestCase
11
16
  include Wakame::Service
12
17
 
18
+ module ResType1; end
19
+ module ResType2; end
20
+ module ResType3; end
21
+
22
+ class Res1 < Resource
23
+ include ResType1
24
+ end
25
+
26
+ class Res2 < Resource
27
+ include ResType2
28
+ end
29
+
30
+ class Res3 < Resource
31
+ include ResType3
32
+ end
33
+
34
+ class Res4 < Resource
35
+ end
36
+
37
+ def create_dummy_cluster
38
+ c = ServiceCluster.new
39
+ c.name= 'TestCluster1'
40
+ c.add_resource(Res1.new)
41
+ c.add_resource(Res2.new)
42
+ c.add_resource(Res3.new)
43
+ c.add_resource(Res4.new)
44
+
45
+ c.set_dependency(Res2, Res1)
46
+ c.set_dependency(Res3, Res1)
47
+ c.set_dependency(Res4, Res3)
48
+
49
+ c.save
50
+ c
51
+ end
52
+
53
+ def teardown
54
+ #Wakame::StatusDB.adapter.clear_store
55
+ end
56
+
57
+ def test_resource
58
+ assert_equal(Res1.id, Resource.id(Res1))
59
+ res1 = Res1.new
60
+ assert_equal(res1.id, Resource.id(Res1))
61
+ assert_not_equal(Res2.id, Resource.id(Res3))
62
+ assert_equal(Res4.id, Resource.id(Res4))
63
+ end
64
+
65
+ def test_create_cluster
66
+ c = create_dummy_cluster
67
+ end
68
+
69
+ def hash_sort_ary(ary)
70
+ ary.collect{|i| i.id.hash }.sort
71
+ end
72
+
13
73
  def test_dg
14
- c = WebCluster.new(nil)
15
- c.dg.each_level{ |s|
16
- p s
74
+ c = create_dummy_cluster
75
+
76
+ assert_equal([hash_sort_ary([Res4, Res2]), hash_sort_ary([Res3]), hash_sort_ary([Res1])],
77
+ c.dg.levels.collect{|i| i.collect{|k| k.id.hash}.sort })
78
+
79
+ assert_equal(hash_sort_ary([Res2, Res3]), hash_sort_ary(c.dg.parents(Res1)))
80
+ assert_equal([], c.dg.children(Res1))
81
+ assert_equal(hash_sort_ary([Res1]), hash_sort_ary(c.dg.children(Res2)))
82
+ assert_equal([], c.dg.parents(Res2))
83
+ assert_equal(hash_sort_ary([Res1]), hash_sort_ary(c.dg.children(Res3)))
84
+ assert_equal(hash_sort_ary([Res4]), hash_sort_ary(c.dg.parents(Res3)))
85
+ assert_equal(hash_sort_ary([Res3]), hash_sort_ary(c.dg.children(Res4)))
86
+ assert_equal([], c.dg.parents(Res4))
87
+ end
88
+
89
+
90
+ def test_cluster_methods
91
+ c = create_dummy_cluster
92
+ res2 = Resource.find(Res2.id)
93
+ res2.max_instances = 3
94
+ res2.save
95
+
96
+ h = c.add_host
97
+
98
+ c.propagate(Res1, h.id)
99
+ c.propagate(Res2, h.id)
100
+ c.propagate(Res3, h.id)
101
+ c.propagate(Res4, h.id)
102
+
103
+ assert_equal(4, c.services.size)
104
+ assert_equal(1, c.hosts.size)
105
+ [Res1, Res2, Res3, Res4].each {|r|
106
+ assert( c.resources.member?(r.id) )
107
+ }
108
+
109
+ assert_raise(RuntimeError) {
110
+ c.propagate(Res2)
111
+ }
112
+ assert_raise(RuntimeError) {
113
+ c.propagate(Res2, h.id)
17
114
  }
18
115
 
19
- p c.dg.levels
116
+ h2 = c.add_host { |h|
117
+ h.vm_spec.attr1 = "attr1"
118
+ h.vm_spec.attr2 = "attr2"
119
+ h.vm_spec.attr3 = "attr3"
120
+ }
121
+
122
+ res2_svc2 = c.propagate(Res2, h2.id)
123
+ assert_equal(2, c.hosts.size)
124
+ assert_equal(5, c.services.size)
20
125
 
21
- p c.dg.children(MySQL_Master)
22
- p c.dg.parents(Apache_APP)
126
+ res2_svc3 = c.propagate_service(res2_svc2.id)
127
+ assert_equal(3, c.hosts.size)
128
+ assert_equal(6, c.services.size)
129
+ assert_equal({:attr1=>"attr1", :attr2=>"attr2", :attr3=>"attr3"}, res2_svc3.host.vm_attr)
130
+
23
131
  end
24
132
 
25
133
 
26
134
  def test_each_instance
27
- c = WebCluster.new(nil)
135
+ c = create_dummy_cluster
28
136
  c.launch
29
- c.each_instance(WebCluster::HttpLoadBalanceServer) { |svc|
30
- assert(svc.property.is_a?(Apache_LB))
137
+
138
+ {ResType1=>Res1, ResType2=>Res2, ResType3=>Res3}.each { |k,v|
139
+ c.each_instance(k) { |svc|
140
+ assert(svc.resource.is_a?(v))
141
+ }
31
142
  }
32
143
  end
33
144
 
34
145
 
35
146
  def test_vmspec
36
- spec = VmSpec.define {
37
- environment(:EC2) { |ec2|
38
- ec2.instance_type = 'm1.small'
39
- ec2.availability_zone = 'us-east-c1'
40
- ec2.security_groups << 'default'
41
- }
42
-
43
- environment(:StandAlone) {
44
- }
45
- }
46
-
47
147
 
48
148
  Wakame.config.vm_environment = :EC2
49
- p spec.current.attrs
149
+ assert_equal(VmSpec::EC2, VmSpec.current.class)
150
+
50
151
  Wakame.config.vm_environment = :StandAlone
51
- p spec.current.attrs
152
+ assert_equal(VmSpec::StandAlone, VmSpec.current.class)
52
153
 
53
154
  assert_raise(RuntimeError) {
54
155
  Wakame.config.vm_environment = :EC3
55
- spec.current.attrs
156
+ VmSpec.current
56
157
  }
158
+
159
+ Wakame.config.vm_environment = :EC2
160
+ spec = VmSpec.current
161
+ spec
57
162
  end
58
163
 
59
164
 
@@ -0,0 +1,82 @@
1
+
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+ $:.unshift(File.dirname(__FILE__))
4
+
5
+ require 'setup_master.rb'
6
+
7
+ Wakame.config.status_db_dsn = 'sqlite:///'
8
+
9
+ class TestStatusDB < Test::Unit::TestCase
10
+
11
+ class Model1 < Wakame::StatusDB::Model
12
+ property :a
13
+ property :b
14
+ property :c
15
+ property :d
16
+
17
+ property :e, {:default=>"set in Model1"}
18
+ property :f, {:default=>"f"}
19
+ end
20
+
21
+ class Model2 < Model1
22
+ property :n
23
+ property :e, {:default=>"set in Model2"}
24
+ def_attribute :f, {:persistent=>false}
25
+ end
26
+
27
+ def test_model1
28
+ m1 = Model1.new
29
+ m1.a = "a"
30
+ m1.b = 12.33
31
+ m1.c = nil
32
+ time_d = m1.d = Time.new
33
+
34
+ pk = m1.id
35
+
36
+ assert_equal(true, m1.dirty?)
37
+ m1.save
38
+
39
+ assert_equal(true, Model1.exists?(pk))
40
+ assert_equal(false, Model1.exists?(pk+"hoge"))
41
+
42
+ m1 = Model1.find(pk)
43
+ assert_equal(pk, m1.id)
44
+ assert_equal("a", m1.a)
45
+ assert_equal(12.33, m1.b)
46
+ assert_equal(nil, m1.c)
47
+ assert_equal(time_d.to_s, m1.d)
48
+ assert_equal(false, m1.dirty?)
49
+
50
+ m1.a = "b"
51
+ assert_equal("b", m1.a)
52
+ assert_equal(true, m1.dirty?)
53
+ assert_equal(true, m1.dirty?(:a))
54
+
55
+ m1.save
56
+ assert_equal(false, m1.dirty?)
57
+ assert_equal(false, m1.dirty?(:a))
58
+ assert_equal("b", m1.a)
59
+
60
+ end
61
+
62
+ def test_model2
63
+ m = Model2.new
64
+ pk = m.id
65
+ m.a = "a"
66
+ m.n = "n"
67
+
68
+ assert_equal(nil, m.f)
69
+
70
+ m.save
71
+
72
+ m = Model1.find(pk)
73
+ assert_equal(Model2, m.class)
74
+ assert_equal("a", m.a)
75
+ assert_equal(nil, m.b)
76
+ assert_equal(nil, m.f)
77
+ assert_equal("n", m.n)
78
+ assert_equal("set in Model2", m.e)
79
+
80
+ end
81
+
82
+ end
@@ -16,4 +16,14 @@ class TestUriAMQP < Test::Unit::TestCase
16
16
  u=URI.parse('amqp://127.0.0.1/vvv')
17
17
  assert_equal('/vvv', u.vhost)
18
18
  end
19
+
20
+ def test_build
21
+ uri = URI::AMQP.build(:host=>'192.168.1.1', :path=>'/aaa')
22
+ assert_equal('amqp://192.168.1.1/aaa', uri.to_s)
23
+ uri.vhost = '/bbb'
24
+ assert_equal('amqp://192.168.1.1/bbb', uri.to_s)
25
+
26
+ uri = URI::AMQP.build(:host=>'192.168.1.1', :userinfo=>'a', :path=>nil)
27
+ assert_equal('amqp://a@192.168.1.1/', uri.to_s)
28
+ end
19
29
  end
@@ -1,14 +1,17 @@
1
1
  class Apache_APP < Wakame::Service::Resource
2
- include Wakame::Service::ApacheBasicProps
3
- include WebCluster::HttpAppServer
2
+ include HttpServer
3
+ include HttpApplicationServer
4
4
 
5
5
  def_attribute :listen_port, {:default=>8001}
6
6
  def_attribute :listen_port_https, {:default=>443}
7
- def_attribute :max_instance, {:default=>5}
8
7
 
9
8
  def render_config(template)
10
- template.cp(%w(conf/envvars-app init.d/apache2-app))
11
- template.render(%w(conf/system-app.conf conf/apache2.conf conf/sites-app.conf))
9
+ template.glob_basedir(%w(conf/envvars-app init.d/apache2-app)) { |d|
10
+ template.cp(d)
11
+ }
12
+ template.glob_basedir(%w(conf/system-app.conf conf/apache2.conf conf/vh/*.conf)) { |d|
13
+ template.render(d)
14
+ }
12
15
  template.chmod("init.d/apache2-app", 0755)
13
16
  end
14
17
 
@@ -16,13 +19,13 @@ class Apache_APP < Wakame::Service::Resource
16
19
  def start(svc, action)
17
20
  cond = ConditionalWait.new { |cond|
18
21
  cond.wait_event(Wakame::Event::ServiceOnline) { |event|
19
- event.instance_id == svc.instance_id
22
+ event.instance_id == svc.id
20
23
  }
21
24
  }
22
25
 
23
- request = action.actor_request(svc.agent.agent_id,
24
- '/service_monitor/register', svc.instance_id, :pidfile, '/var/run/apache2-app.pid').request
25
- action.actor_request(svc.agent.agent_id,
26
+ request = action.actor_request(svc.cloud_host.agent_id,
27
+ '/service_monitor/register', svc.id, :pidfile, '/var/run/apache2-app.pid').request
28
+ action.actor_request(svc.cloud_host.agent_id,
26
29
  '/daemon/start', "apache_app", 'init.d/apache2-app'){ |req|
27
30
  req.wait
28
31
  Wakame.log.debug("#{self.class} process started")
@@ -34,27 +37,25 @@ class Apache_APP < Wakame::Service::Resource
34
37
  def stop(svc, action)
35
38
  cond = ConditionalWait.new { |cond|
36
39
  cond.wait_event(Wakame::Event::ServiceOffline) { |event|
37
- event.instance_id == svc.instance_id
40
+ event.instance_id == svc.id
38
41
  }
39
42
  }
40
43
 
41
- request = action.actor_request(svc.agent.agent_id,
44
+ request = action.actor_request(svc.cloud_host.agent_id,
42
45
  '/daemon/stop', 'apache_app', 'init.d/apache2-app'){ |req|
43
46
  req.wait
44
47
  Wakame.log.debug("#{self.class} process stopped")
45
48
  }
46
49
  cond.wait
47
50
 
48
- request = action.actor_request(svc.agent.agent_id,
49
- '/service_monitor/unregister', svc.instance_id ).request
51
+ request = action.actor_request(svc.cloud_host.agent_id,
52
+ '/service_monitor/unregister', svc.id ).request
50
53
  end
51
54
 
52
55
  def reload(svc, action)
53
- action.actor_request(svc.agent.agent_id,
54
- '/daemon/reload', "apache_app", 'init.d/apache2-app'){ |req|
55
- req.wait
56
- Wakame.log.debug("#{self.class} process reloaded")
57
- }
56
+ request = action.actor_request(svc.cloud_host.agent_id,
57
+ '/daemon/reload', "apache_app", 'init.d/apache2-app').request
58
+ request.wait
58
59
  end
59
60
 
60
61
  end
@@ -1,6 +1,6 @@
1
1
  #ServerRoot "/etc/apache2"
2
2
  #ServerRoot "/home/wakame/config/apache2"
3
- ServerRoot "<%= agent.root_path %>/tmp/config/apache_app/conf"
3
+ ServerRoot "<%= cloud_host.agent.root_path %>/tmp/config/apache_app/conf"
4
4
 
5
5
  LockFile /var/lock/apache2/accept.lock
6
6
  PidFile ${APACHE_PID_FILE}
@@ -43,4 +43,16 @@ LogFormat "%{Referer}i -> %U" referer
43
43
  LogFormat "%{User-agent}i" agent
44
44
  </IfModule>
45
45
 
46
- Include ${SITES_INCLUDE_FILE}
46
+ NameVirtualHost *:<%= resource.listen_port %>
47
+
48
+ # Wild Card Virtual Host
49
+ #<VirtualHost *:<%= resource.listen_port %>>
50
+ #DocumentRoot /var/www
51
+ #
52
+ #LogLevel warn
53
+ #CustomLog /var/log/apache2/access-app.log combined
54
+ #ErrorLog /var/log/apache2/error-app.log
55
+ #
56
+ #</VirtualHost>
57
+
58
+ Include vh/*.conf