wakame 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/History.txt +4 -0
  2. data/LICENSE +202 -0
  3. data/Rakefile +11 -12
  4. data/VERSION +1 -1
  5. data/app_generators/wakame/templates/bin/wakame-agent +1 -1
  6. data/app_generators/wakame/templates/bin/wakame-master +1 -1
  7. data/app_generators/wakame/templates/config/cluster.rb +32 -24
  8. data/app_generators/wakame/templates/config/init.d/centos/wakame-agent +40 -0
  9. data/app_generators/wakame/templates/config/init.d/centos/wakame-master +40 -0
  10. data/app_generators/wakame/templates/config/init.d/wakame-master +1 -1
  11. data/lib/ext/eventmachine.rb +5 -5
  12. data/lib/wakame.rb +12 -0
  13. data/lib/wakame/action.rb +10 -11
  14. data/lib/wakame/actions/deploy_application.rb +61 -0
  15. data/lib/wakame/actions/deploy_config.rb +1 -3
  16. data/lib/wakame/actions/freeze_cluster.rb +15 -0
  17. data/lib/wakame/actions/launch_cluster.rb +1 -3
  18. data/lib/wakame/actions/launch_vm.rb +1 -1
  19. data/lib/wakame/actions/migrate_service.rb +4 -3
  20. data/lib/wakame/actions/notify_child_changed.rb +3 -6
  21. data/lib/wakame/actions/notify_parent_changed.rb +4 -7
  22. data/lib/wakame/actions/propagate_resource.rb +1 -3
  23. data/lib/wakame/actions/propagate_service.rb +1 -3
  24. data/lib/wakame/actions/register_agent.rb +43 -0
  25. data/lib/wakame/actions/reload_service.rb +2 -2
  26. data/lib/wakame/actions/shutdown_cluster.rb +4 -6
  27. data/lib/wakame/actions/shutdown_vm.rb +27 -6
  28. data/lib/wakame/actions/start_service.rb +40 -32
  29. data/lib/wakame/actions/stop_service.rb +8 -10
  30. data/lib/wakame/actions/unfreeze_cluster.rb +15 -0
  31. data/lib/wakame/actor.rb +2 -5
  32. data/lib/wakame/actor/deploy.rb +110 -0
  33. data/lib/wakame/actor/monitor.rb +14 -0
  34. data/lib/wakame/actor/s3fs.rb +45 -0
  35. data/lib/wakame/actor/service_monitor.rb +0 -17
  36. data/lib/wakame/actor/system.rb +5 -1
  37. data/lib/wakame/agent.rb +29 -179
  38. data/lib/wakame/agent_manager.rb +11 -0
  39. data/lib/wakame/agent_managers/actor_manager.rb +101 -0
  40. data/lib/wakame/agent_managers/monitor_manager.rb +48 -0
  41. data/lib/wakame/command.rb +4 -7
  42. data/lib/wakame/command/actor.rb +9 -12
  43. data/lib/wakame/command/agent_status.rb +2 -2
  44. data/lib/wakame/command/control_service.rb +66 -0
  45. data/lib/wakame/command/deploy_application.rb +18 -0
  46. data/lib/wakame/command/deploy_config.rb +16 -0
  47. data/lib/wakame/command/launch_cluster.rb +1 -1
  48. data/lib/wakame/command/launch_vm.rb +1 -1
  49. data/lib/wakame/command/propagate_resource.rb +1 -1
  50. data/lib/wakame/command/propagate_service.rb +5 -3
  51. data/lib/wakame/command/reload_service.rb +1 -1
  52. data/lib/wakame/command/shutdown_cluster.rb +1 -1
  53. data/lib/wakame/command/shutdown_vm.rb +37 -11
  54. data/lib/wakame/command/start_service.rb +1 -1
  55. data/lib/wakame/command/status.rb +6 -4
  56. data/lib/wakame/command/stop_service.rb +1 -1
  57. data/lib/wakame/configuration.rb +5 -0
  58. data/lib/wakame/event.rb +85 -33
  59. data/lib/wakame/event_dispatcher.rb +2 -2
  60. data/lib/wakame/initializer.rb +97 -31
  61. data/lib/wakame/master.rb +23 -346
  62. data/lib/wakame/master_manager.rb +11 -0
  63. data/lib/wakame/master_managers/action_manager.rb +321 -0
  64. data/lib/wakame/master_managers/agent_monitor.rb +166 -0
  65. data/lib/wakame/master_managers/cluster_manager.rb +176 -0
  66. data/lib/wakame/master_managers/command_queue.rb +133 -0
  67. data/lib/wakame/models/agent_pool.rb +113 -0
  68. data/lib/wakame/models/application_repository.rb +34 -0
  69. data/lib/wakame/models/object_store.rb +32 -0
  70. data/lib/wakame/models/service_cluster_pool.rb +36 -0
  71. data/lib/wakame/monitor.rb +3 -6
  72. data/lib/wakame/monitor/agent.rb +9 -6
  73. data/lib/wakame/monitor/service.rb +56 -29
  74. data/lib/wakame/runner/administrator_command.rb +210 -24
  75. data/lib/wakame/runner/agent.rb +2 -0
  76. data/lib/wakame/runner/master.rb +2 -1
  77. data/lib/wakame/service.rb +140 -130
  78. data/lib/wakame/status_db.rb +101 -121
  79. data/lib/wakame/util.rb +26 -15
  80. data/tests/setup_master.rb +1 -0
  81. data/tests/test_master.rb +0 -2
  82. data/tests/test_model_agent_pool.rb +21 -0
  83. data/tests/test_service.rb +14 -8
  84. data/tests/test_status_db.rb +2 -0
  85. data/tests/test_util.rb +12 -1
  86. data/wakame_generators/resource/templates/apache_app/apache_app.rb +20 -11
  87. data/wakame_generators/resource/templates/apache_app/conf/vh/aaa.test.conf +1 -1
  88. data/wakame_generators/resource/templates/apache_lb/apache_lb.rb +7 -7
  89. data/wakame_generators/resource/templates/apache_lb/conf/system-lb.conf +6 -4
  90. data/wakame_generators/resource/templates/apache_www/apache_www.rb +15 -13
  91. data/wakame_generators/resource/templates/ec2_elastic_ip/ec2_elastic_ip.rb +17 -17
  92. data/wakame_generators/resource/templates/ec2_elb/ec2_elb.rb +22 -15
  93. data/wakame_generators/resource/templates/mongodb/conf/mongodb.conf +95 -0
  94. data/wakame_generators/resource/templates/mongodb/init.d/mongodb +244 -0
  95. data/wakame_generators/resource/templates/mongodb/mongodb.rb +64 -0
  96. data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +17 -21
  97. data/wakame_generators/resource/templates/nginx/conf/nginx.conf +4 -0
  98. data/wakame_generators/resource/templates/nginx/conf/vh/ec2_elb_common.conf +19 -0
  99. data/wakame_generators/resource/templates/nginx/init.d/nginx +6 -0
  100. data/wakame_generators/resource/templates/nginx/init.d/spawn-fcgi +46 -0
  101. data/wakame_generators/resource/templates/nginx/nginx.rb +15 -10
  102. data/wakame_generators/resource/templates/nginx_passenger/conf/nginx-passenger.conf +39 -0
  103. data/wakame_generators/resource/templates/nginx_passenger/conf/vh/ec2_elb_common.conf +10 -0
  104. data/wakame_generators/resource/templates/nginx_passenger/init.d/nginx-passenger +70 -0
  105. data/wakame_generators/resource/templates/nginx_passenger/nginx_passenger.rb +71 -0
  106. data/wakame_generators/resource/templates/s3fs/s3fs.rb +24 -0
  107. metadata +195 -74
  108. data/lib/wakame/action_manager.rb +0 -303
  109. data/lib/wakame/command/clone_service.rb +0 -12
  110. data/lib/wakame/command_queue.rb +0 -135
  111. data/lib/wakame/vm_manipulator.rb +0 -187
@@ -0,0 +1,32 @@
1
+
2
+ require 'sequel/model'
3
+
4
+ module Wakame
5
+ module Models
6
+ class ObjectStore < Sequel::Model
7
+ plugin :schema
8
+ plugin :hook_class_methods
9
+
10
+ unrestrict_primary_key
11
+
12
+ set_schema {
13
+ primary_key :id, :string, :size=>50, :auto_increment=>false
14
+ column :class_type, :string
15
+ column :dump, :text
16
+ column :created_at, :datetime
17
+ column :updated_at, :datetime
18
+ }
19
+
20
+ before_create(:set_created_at) do
21
+ self.updated_at = self.created_at = Time.now
22
+ end
23
+ before_update(:set_updated_at) do
24
+ self.updated_at = Time.now
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ Initializer.loaded_classes << Models::ObjectStore
31
+ end
32
+
@@ -0,0 +1,36 @@
1
+
2
+ require 'sequel/model'
3
+
4
+ module Wakame
5
+ module Models
6
+ class ServiceClusterPool < Sequel::Model
7
+ plugin :schema
8
+
9
+ set_schema {
10
+ primary_key :id, :type => Integer
11
+ varchar :service_cluster_id
12
+ }
13
+
14
+
15
+ def self.register_cluster(name)
16
+ id = Service::ServiceCluster.id(name)
17
+
18
+ self.find_or_create(:service_cluster_id=>id)
19
+ end
20
+
21
+ def self.unregister_cluster(name)
22
+ id = Service::ServiceCluster.id(name)
23
+ self.delete(:service_cluster_id=>id)
24
+ end
25
+
26
+ def self.each_cluster(&blk)
27
+ self.all.each { |m|
28
+ cluster = Service::ServiceCluster.find(m.service_cluster_id)
29
+ blk.call(cluster)
30
+ }
31
+ end
32
+ end
33
+ end
34
+
35
+ Initializer.loaded_classes << Models::ServiceClusterPool
36
+ end
@@ -14,18 +14,15 @@ module Wakame
14
14
  }
15
15
  end
16
16
 
17
- def handle_request(request)
18
- end
19
-
20
- def setup(assigned_path)
21
- end
22
-
23
17
  def enable
24
18
  end
25
19
 
26
20
  def disable
27
21
  end
28
22
 
23
+ def reload(config)
24
+ end
25
+
29
26
  def publish_to(exchange, data)
30
27
  agent.publish_to(exchange, data)
31
28
  end
@@ -10,18 +10,21 @@ class Wakame::Monitor::Agent
10
10
  publish_to('ping', Wakame::Packets::Ping.new(agent, hash[:attrs], hash[:actors], hash[:monitors], hash[:services]).marshal)
11
11
  end
12
12
 
13
- def setup(path)
13
+ def reload(config)
14
14
  # Send the first ping signal as soon as possible since the ping contanins vital information to construct the Agent object on master node.
15
15
  send_ping(check())
16
16
 
17
+ if @timer && @time.running?
18
+ @timer.stop
19
+ end
20
+
17
21
  # Setup periodical ping publisher.
18
- @timer = CheckerTimer.new(10) {
22
+ @timer = CheckerTimer.new(config[:interval] || 10) {
19
23
  send_ping(check())
20
24
  }
21
25
  @timer.start
22
26
  end
23
27
 
24
-
25
28
  def check
26
29
  if Wakame.config.environment == :EC2
27
30
  attrs = Wakame::Agent.ec2_fetch_local_attrs
@@ -31,14 +34,14 @@ class Wakame::Monitor::Agent
31
34
 
32
35
  res = {:attrs=>attrs, :monitors=>[], :actors=>[], :services=>{}}
33
36
  EM.barrier {
34
- agent.monitor_registry.monitors.each { |key, m|
37
+ agent.monitor_manager.monitors.each { |key, m|
35
38
  res[:monitors] << {:class=>m.class.to_s}
36
39
  }
37
- agent.actor_registry.actors.each { |key, a|
40
+ agent.actor_manager.actors.each { |key, a|
38
41
  res[:actors] << {:class=>a.class.to_s}
39
42
  }
40
43
 
41
- svcmon = agent.monitor_registry.find_monitor('/service')
44
+ svcmon = agent.monitor_manager.find_monitor('/service')
42
45
  svcmon.checkers.each { |svc_id, a|
43
46
  res[:services][svc_id]={:status=>a.status}
44
47
  }
@@ -1,20 +1,20 @@
1
1
 
2
2
  require 'open4'
3
- require 'wakame'
4
3
 
5
4
  class Wakame::Monitor::Service
6
5
 
7
6
  class ServiceChecker
8
7
  #include Wakame::Packets::Agent
9
- attr_reader :timer, :svc_id
8
+ attr_reader :timer, :svc_id, :interval
10
9
  attr_accessor :last_checked_at, :status
11
10
 
12
- def initialize(svc_id, svc_mon)
11
+ def initialize(svc_id, svc_mon, interval)
13
12
  @svc_id = svc_id
14
13
  @service_monitor = svc_mon
14
+ @interval = interval
15
15
  @status = Wakame::Service::STATUS_OFFLINE
16
16
  count = 0
17
- @timer = Wakame::Monitor::CheckerTimer.new(5) {
17
+ @timer = Wakame::Monitor::CheckerTimer.new(@interval) {
18
18
  self.signal_checker
19
19
  }
20
20
  end
@@ -80,8 +80,8 @@ class Wakame::Monitor::Service
80
80
  end
81
81
 
82
82
  class PidFileChecker < ServiceChecker
83
- def initialize(svc_id, svc_mon, pidpath)
84
- super(svc_id, svc_mon)
83
+ def initialize(svc_id, svc_mon, pidpath, interval)
84
+ super(svc_id, svc_mon, interval)
85
85
  @pidpath = pidpath
86
86
  end
87
87
 
@@ -99,8 +99,8 @@ class Wakame::Monitor::Service
99
99
  class CommandChecker < ServiceChecker
100
100
  attr_reader :command
101
101
 
102
- def initialize(svc_id, svc_mon, cmdstr)
103
- super(svc_id, svc_mon)
102
+ def initialize(svc_id, svc_mon, cmdstr, interval)
103
+ super(svc_id, svc_mon, interval)
104
104
  @command = cmdstr
105
105
  end
106
106
 
@@ -114,10 +114,11 @@ class Wakame::Monitor::Service
114
114
  outputs << l
115
115
  }
116
116
  }
117
- Wakame.log.debug("#{self.class}: Exit Status #{@command}: #{cmdstat}")
118
117
  if outputs.size > 0
119
118
  @service_monitor.send_event(Wakame::Packets::MonitoringOutput.new(@service_monitor.agent, self.svc_id, outputs.join('')))
120
119
  end
120
+
121
+ Wakame.log.debug("#{self.class}: Detected the failed exit status: #{@command}: #{cmdstat}") if cmdstat.exitstatus != 0
121
122
  cmdstat.exitstatus == 0 ? Wakame::Service::STATUS_ONLINE : Wakame::Service::STATUS_OFFLINE
122
123
  end
123
124
  end
@@ -131,28 +132,11 @@ class Wakame::Monitor::Service
131
132
  @checkers = {}
132
133
  end
133
134
 
134
- def setup(path)
135
- end
136
-
137
- def handle_request(request)
138
- svc_id = request[:svc_id]
139
- case request[:command]
140
- when :start
141
- register(svc_id, request[:cmdstr])
142
- when :stop
143
- unregister(svc_id)
144
- end
145
- end
146
-
147
135
  def send_event(a)
148
- Wakame.log.debug("Sending back the event: #{a.class}")
136
+ #Wakame.log.debug("Sending back the event: #{a.class}")
149
137
  publish_to('agent_event', a.marshal)
150
138
  end
151
139
 
152
- def dump_attrs
153
-
154
- end
155
-
156
140
  def find_checker(svc_id)
157
141
  @checkers[svc_id]
158
142
  end
@@ -164,9 +148,9 @@ class Wakame::Monitor::Service
164
148
  end
165
149
  case checker_type.to_sym
166
150
  when :pidfile
167
- chk = PidFileChecker.new(svc_id, self, args[0])
151
+ chk = PidFileChecker.new(svc_id, self, args[0], args[1])
168
152
  when :command
169
- chk = CommandChecker.new(svc_id, self, args[0])
153
+ chk = CommandChecker.new(svc_id, self, args[0], args[1])
170
154
  else
171
155
  raise "Unsupported checker type: #{checker_type}"
172
156
  end
@@ -193,4 +177,47 @@ class Wakame::Monitor::Service
193
177
  end
194
178
  end
195
179
 
180
+ def unregister_all
181
+ @checkers.keys.each { |svc_id|
182
+ unregister(svc_id)
183
+ }
184
+ end
185
+
186
+ # Reloading the service monitor with new configuration.
187
+ #
188
+ # Example of Hash data in config:
189
+ # config = {
190
+ # 'svc_id_abcde'=>{:type=>:pidfile, :path=>'/var/run/a.pid', :interval=>5},
191
+ # 'svc_id_12345'=>{:type=>:command, :cmdline=>'/bin/ps -ef | grep processname', :interval=>10}
192
+ # }
193
+ def reload(config)
194
+ unregister_all
195
+
196
+ reg_single = proc { |svc_id, data|
197
+ data[:interval] ||= 5
198
+
199
+ case data[:type]
200
+ when :pidfile
201
+ register(svc_id, data[:type], data[:path], data[:interval])
202
+ when :command
203
+ register(svc_id, data[:type], data[:cmdline], data[:interval])
204
+ else
205
+ raise "Unsupported checker type: #{data[:type]}"
206
+ end
207
+ }
208
+
209
+ config.each { |svc_id, data|
210
+ if data.is_a?(Array)
211
+ # TODO: Multiple monitors for single service ID
212
+ raise "TODO: Multiple monitors for single service ID"
213
+ data.each { |d|
214
+ reg_single.call(svc_id, d)
215
+ }
216
+ elsif data.is_a?(Hash)
217
+ reg_single.call(svc_id, data)
218
+ else
219
+ end
220
+ }
221
+ end
222
+
196
223
  end
@@ -197,21 +197,15 @@ module Wakame
197
197
  def self.included(klass)
198
198
  klass.class_eval {
199
199
  class << self
200
- def command_name
200
+ def command_name(name=nil)
201
+ @command_name = name if name
201
202
  @command_name ||= Util.snake_case(self.to_s.split('::').last)
202
203
  end
203
204
 
204
- def command_name=(name)
205
- @command_name=name
206
- end
207
-
208
- def summary
205
+ def summary(str=nil)
206
+ @summary = str if str
209
207
  @summary
210
208
  end
211
-
212
- def summary=(summary)
213
- @summary=summary
214
- end
215
209
  end
216
210
  }
217
211
  end
@@ -241,8 +235,8 @@ end
241
235
  class Wakame::Cli::Subcommand::LaunchCluster
242
236
  include Wakame::Cli::Subcommand
243
237
 
244
- command_name = 'launch_cluster'
245
- summary = "Start up the cluster"
238
+ command_name 'launch_cluster'
239
+ summary "Start up the cluster"
246
240
 
247
241
  def parse(args)
248
242
  create_parser(args) {|opts|
@@ -261,7 +255,7 @@ end
261
255
  class Wakame::Cli::Subcommand::ShutdownCluster
262
256
  include Wakame::Cli::Subcommand
263
257
 
264
- summary = "Shutdown the cluster"
258
+ summary "Shutdown the cluster"
265
259
 
266
260
  def parse(args)
267
261
  create_parser(args) {|opts|
@@ -279,17 +273,81 @@ end
279
273
  class Wakame::Cli::Subcommand::Status
280
274
  include Wakame::Cli::Subcommand
281
275
 
282
- summary = "Show summary status across the cluster"
276
+ summary "Show summary status across the cluster"
277
+
278
+ if Wakame.config.environment == :EC2
279
+ STATUS_TMPL = <<__E__
280
+ <%- if cluster -%>
281
+ Cluster : <%= cluster["name"].to_s %> (<%= cluster_status_msg(cluster["status"]) %>)
282
+ <%- cluster["resources"].keys.each { |res_id|
283
+ resource = body["resources"][res_id]
284
+ -%>
285
+ <%= resource["class_type"] %> : <current=<%= resource["instance_count"] %> min=<%= resource["min_instances"] %>, max=<%= resource["max_instances"] %><%= resource["require_agent"] ? "" : ", AgentLess" %>>
286
+ <%- resource["services_ref"].each { |svc| -%>
287
+ <%= svc["id"] %> (<%= svc_status_msg(svc["status"]) %>:<%= monitor_status_msg(svc["monitor_status"]) %>)
288
+ <%- } -%>
289
+ <%- } -%>
290
+ <%- if cluster["services"].size > 0 -%>
291
+
292
+ Instances (<%= cluster["services"].size %>):
293
+ <%- cluster["services"].keys.each { |svc_id|
294
+ svc = body["services"][svc_id]
295
+ -%>
296
+ <%= svc_id %> : <%= svc["resource_ref"]["class_type"] %> (<%= svc_status_msg(svc["status"]) %>:<%= monitor_status_msg(svc["monitor_status"]) %>)
297
+ <%- if svc["agent_ref"] -%>
298
+ On VM: <%= svc["agent_ref"]["id"] %>
299
+ <%- end -%>
300
+ <%- } -%>
301
+ <%- end -%>
302
+ <%- if cluster["cloud_hosts"].size > 0 -%>
303
+
304
+ Cloud Host (<%= cluster["cloud_hosts"].size %>):
305
+ <%- cluster["cloud_hosts"].keys.each { |host_id|
306
+ cloud_host = body["cloud_hosts"][host_id]
307
+ -%>
308
+ <%= host_id %> : <% if cloud_host["agent_id"] %>bind to <%= cloud_host["agent_id"] %><% end %>
309
+ <%- assigned_svcs = body['services'].values.find_all{|data| data['cloud_host_id'] == host_id } -%>
310
+ <%- if assigned_svcs.size > 0 -%>
311
+ Assigned: <%= body['services'].values.find_all{|data| data['cloud_host_id'] == host_id }.map{|data| data['resource_ref']['class_type'] }.join(', ') %>
312
+ <%- end -%>
313
+ <%- } -%>
314
+ <%- end -%>
315
+ <%- else # if cluster -%>
316
+ Cluster:
317
+ No cluster data is loaded in master. (Run import_cluster_config first)
318
+ <%- end # if cluster -%>
319
+
320
+ <%- if agent_pool && agent_pool["group_active"].size > 0 -%>
321
+
322
+ Agents (<%= agent_pool["group_active"].size %>):
323
+ <%- agent_pool["group_active"].each { |agent_id|
324
+ a = body["agents"][agent_id]
325
+ -%>
326
+ <%= a["id"] %> : <%= a["vm_attr"]["private_dns_name"] %>, <%= a["vm_attr"]["dns_name"] %>, <%= (Time.now - Time.parse(a["last_ping_at"])).to_i %> sec(s), placement=<%= a["vm_attr"]["aws_availability_zone"] %> (<%= agent_status_msg(a["status"]) %>)
327
+ <%- if a["reported_services"].size > 0 && !cluster["services"].empty? -%>
328
+ Services (<%= a["reported_services"].size %>): <%= a["reported_services"].keys.collect{ |svc_id|
329
+ body['services'][svc_id].nil? ? 'Unknown:' + svc_id[0,5] + '...' : body["services"][svc_id]["resource_ref"]["class_type"]
330
+ }.join(', ') %>
331
+ <%- end -%>
332
+ <%- } -%>
333
+ <%- else -%>
334
+
335
+ Agents (0):
336
+ .....
337
+ None of agents are observed.
338
+ <%- end -%>
339
+ __E__
283
340
 
284
- STATUS_TMPL = <<__E__
341
+ else
342
+ STATUS_TMPL = <<__E__
285
343
  <%- if cluster -%>
286
344
  Cluster : <%= cluster["name"].to_s %> (<%= cluster_status_msg(cluster["status"]) %>)
287
345
  <%- cluster["resources"].keys.each { |res_id|
288
346
  resource = body["resources"][res_id]
289
347
  -%>
290
348
  <%= resource["class_type"] %> : <current=<%= resource["instance_count"] %> min=<%= resource["min_instances"] %>, max=<%= resource["max_instances"] %><%= resource["require_agent"] ? "" : ", AgentLess" %>>
291
- <%- resource["services_ref"].each { |svc_inst| -%>
292
- <%= svc_inst["id"] %> (<%= svc_status_msg(svc_inst["status"]) %>)
349
+ <%- resource["services_ref"].each { |svc| -%>
350
+ <%= svc["id"] %> (<%= svc_status_msg(svc["status"]) %>:<%= monitor_status_msg(svc["monitor_status"]) %>)
293
351
  <%- } -%>
294
352
  <%- } -%>
295
353
  <%- if cluster["services"].size > 0 -%>
@@ -298,7 +356,7 @@ Instances (<%= cluster["services"].size %>):
298
356
  <%- cluster["services"].keys.each { |svc_id|
299
357
  svc = body["services"][svc_id]
300
358
  -%>
301
- <%= svc_id %> : <%= svc["resource_ref"]["class_type"] %> (<%= svc_status_msg(svc["status"]) %>)
359
+ <%= svc_id %> : <%= svc["resource_ref"]["class_type"] %> (<%= svc_status_msg(svc["status"]) %>:<%= monitor_status_msg(svc["monitor_status"]) %>)
302
360
  <%- if svc["agent_ref"] -%>
303
361
  On VM: <%= svc["agent_ref"]["id"] %>
304
362
  <%- end -%>
@@ -311,29 +369,40 @@ Cloud Host (<%= cluster["cloud_hosts"].size %>):
311
369
  cloud_host = body["cloud_hosts"][host_id]
312
370
  -%>
313
371
  <%= host_id %> : <% if cloud_host["agent_id"] %>bind to <%= cloud_host["agent_id"] %><% end %>
372
+ <%- assigned_svcs = body['services'].values.find_all{|data| data['cloud_host_id'] == host_id } -%>
373
+ <%- if assigned_svcs.size > 0 -%>
374
+ Assigned: <%= body['services'].values.find_all{|data| data['cloud_host_id'] == host_id }.map{|data| data['resource_ref']['class_type'] }.join(', ') %>
375
+ <%- end -%>
314
376
  <%- } -%>
315
377
  <%- end -%>
316
378
  <%- else # if cluster -%>
317
379
  Cluster:
318
380
  No cluster data is loaded in master. (Run import_cluster_config first)
319
381
  <%- end # if cluster -%>
382
+
320
383
  <%- if agent_pool && agent_pool["group_active"].size > 0 -%>
321
384
 
322
385
  Agents (<%= agent_pool["group_active"].size %>):
323
- <%- agent_pool["group_active"].keys.each { |agent_id|
386
+ <%- agent_pool["group_active"].each { |agent_id|
324
387
  a = body["agents"][agent_id]
325
388
  -%>
326
- <%= a["id"] %> : <%= a["vm_attr"]["local_ipv4"] %>, <%= a["vm_attr"]["public_ipv4"] %>, <%= (Time.now - Time.parse(a["last_ping_at"])).to_i %> sec(s), placement=<%= a["vm_attr"]["availability_zone"] %> (<%= svc_status_msg(a["status"]) %>)
389
+ <%= a["id"] %> : <%= (Time.now - Time.parse(a["last_ping_at"])).to_i %> sec(s) (<%= agent_status_msg(a["status"]) %>)
327
390
  <%- if a["reported_services"].size > 0 && !cluster["services"].empty? -%>
328
- Services (<%= a["reported_services"].size %>): <%= a["reported_services"].keys.collect{ |svc_id| body["services"][svc_id]["resource_ref"]["class_type"] }.join(', ') %>
391
+ Services (<%= a["reported_services"].size %>): <%= a["reported_services"].keys.collect{ |svc_id|
392
+ body['services'][svc_id].nil? ? 'Unknown:' + svc_id[0,5] + '...' : body["services"][svc_id]["resource_ref"]["class_type"]
393
+ }.join(', ') %>
329
394
  <%- end -%>
330
395
  <%- } -%>
331
396
  <%- else -%>
332
397
 
333
398
  Agents (0):
399
+ .....
334
400
  None of agents are observed.
335
401
  <%- end -%>
336
402
  __E__
403
+ end
404
+
405
+
337
406
 
338
407
  SVC_STATUS_MSG={
339
408
  Wakame::Service::STATUS_TERMINATE=>'Terminated',
@@ -347,7 +416,27 @@ __E__
347
416
  Wakame::Service::STATUS_RELOADING=>'Reloading...',
348
417
  Wakame::Service::STATUS_MIGRATING=>'Migrating...',
349
418
  Wakame::Service::STATUS_ENTERING=>'Entering...',
350
- Wakame::Service::STATUS_QUITTING=>'Quitting...'
419
+ Wakame::Service::STATUS_QUITTING=>'Quitting...',
420
+ Wakame::Service::STATUS_RUNNING=>'Running'
421
+ }
422
+
423
+ SVC_MONITOR_STATUS_MSG={
424
+ Wakame::Service::STATUS_OFFLINE=>'Offline',
425
+ Wakame::Service::STATUS_ONLINE=>'Online',
426
+ Wakame::Service::STATUS_UNKNOWN=>'Unknown',
427
+ Wakame::Service::STATUS_FAIL=>'Fail'
428
+ }
429
+
430
+ AGENT_STATUS_MSG={
431
+ Wakame::Service::Agent::STATUS_END => 'Terminated',
432
+ Wakame::Service::Agent::STATUS_INIT => 'Initialized',
433
+ Wakame::Service::Agent::STATUS_OFFLINE => 'Offline',
434
+ Wakame::Service::Agent::STATUS_ONLINE => 'Online',
435
+ Wakame::Service::Agent::STATUS_UNKNOWN => 'Unknown',
436
+ Wakame::Service::Agent::STATUS_TIMEOUT => 'Timedout',
437
+ Wakame::Service::Agent::STATUS_RUNNING => 'Running',
438
+ Wakame::Service::Agent::STATUS_REGISTERRING => 'Registerring...',
439
+ Wakame::Service::Agent::STATUS_TERMINATING => 'Terminating...'
351
440
  }
352
441
 
353
442
  CLUSTER_STATUS_MSG={
@@ -381,11 +470,19 @@ __E__
381
470
 
382
471
  private
383
472
  def svc_status_msg(stat)
384
- SVC_STATUS_MSG[stat]
473
+ SVC_STATUS_MSG[stat.to_i] || "Unknown Code: #{stat}"
474
+ end
475
+
476
+ def monitor_status_msg(stat)
477
+ SVC_MONITOR_STATUS_MSG[stat.to_i] || "Unknown Code: #{stat}"
478
+ end
479
+
480
+ def agent_status_msg(stat)
481
+ AGENT_STATUS_MSG[stat.to_i] || "Unknown Code: #{stat}"
385
482
  end
386
483
 
387
484
  def cluster_status_msg(stat)
388
- CLUSTER_STATUS_MSG[stat]
485
+ CLUSTER_STATUS_MSG[stat.to_i] || "Unknown Code: #{stat}"
389
486
  end
390
487
 
391
488
  def map_ref_data(body)
@@ -700,3 +797,92 @@ __E__
700
797
  SVC_STATUS_MSG[stat]
701
798
  end
702
799
  end
800
+
801
+ class Wakame::Cli::Subcommand::DeployApplication
802
+ include Wakame::Cli::Subcommand
803
+
804
+ def parse(args)
805
+ @params = {}
806
+ cmd = create_parser(args) { |opts|
807
+ opts.banner = "Usage: deploy_application [options] \"Application Name\""
808
+ opts.separator ""
809
+ }
810
+ @params[:app_name] = args.shift || abort("[ERROR]: Application name was not given")
811
+ @params
812
+ end
813
+
814
+ def run(requester)
815
+ requester.request(@params)
816
+ end
817
+
818
+ end
819
+
820
+ class Wakame::Cli::Subcommand::DeployConfig
821
+ include Wakame::Cli::Subcommand
822
+
823
+ command_name 'deploy_config'
824
+ summary "Deploy configuration files"
825
+
826
+ def parse(args)
827
+ create_parser(args) {|opts|
828
+ opts.banner = "Usage: deploy_config"
829
+ opts.separator ""
830
+ opts.separator "options:"
831
+ }
832
+ end
833
+
834
+ def run(requester)
835
+ requester.request()
836
+ end
837
+
838
+ end
839
+
840
+ class Wakame::Cli::Subcommand::Actor
841
+ include Wakame::Cli::Subcommand
842
+
843
+ summary 'Call actor method on an arbitrary agent.'
844
+
845
+ def parse(args)
846
+ @params = {}
847
+ cmd = create_parser(args) { |opts|
848
+ opts.banner = "Usage: actor [options] \"Agent ID\" \"/actor/path\" [\"args\"]"
849
+ opts.separator ""
850
+ opts.separator "options:"
851
+ }
852
+ @params[:agent_id] = args.shift || abort("[ERROR]: Agent ID was not given")
853
+ @params[:path] = args.shift || abort("[ERROR]: Path was not given")
854
+ @params[:args] = args.shift
855
+ @params
856
+ end
857
+
858
+ def run(requester)
859
+ requester.request(@params)
860
+ end
861
+
862
+ end
863
+
864
+ class Wakame::Cli::Subcommand::ControlService
865
+ include Wakame::Cli::Subcommand
866
+
867
+ def parse(args)
868
+ @params = {}
869
+ create_parser(args) {|opts|
870
+ opts.banner = 'Usage: control_service [options] "Resource Name" "Service ID" "Number"'
871
+ opts.separator('Options:')
872
+ }
873
+
874
+ raise "Unknown Resource Name: #{args}" unless args.size > 0
875
+ @params["resource"] = args.shift
876
+
877
+ raise "Unknown Service ID: #{args}" unless args.size > 0
878
+ @params[:service_id] = args.shift
879
+
880
+ raise "Unknown Number: #{args}" unless args.size > 0
881
+ @params[:number] = args.shift.to_i
882
+ end
883
+
884
+ def run(requester)
885
+ requester.request(@params)
886
+ end
887
+
888
+ end