Class: Wakame::Command::Status

Inherits:
Object
  • Object
show all
Includes:
Wakame::Command
Defined in:
lib/wakame/command/status.rb

Constant Summary collapse

STATUS_TMPL =
<<__E__
Cluster : <%= @service_cluster[:name].to_s %> (<%= @service_cluster[:status].to_s %>)
<%- @service_cluster[:properties].each { |prop, v| -%>
  <%= v[:type].to_s %> : <current=<%= v[:instance_count] %> min=<%= v[:min_instances] %>, max=<%= v[:max_instances] %>> 
  <%- v[:instances].each { |id|
         svc_inst = @service_cluster[:instances][id]
  -%>
     <%= svc_inst[:instance_id] %> (<%= trans_svc_status(svc_inst[:status]) %>)
  <%- } -%>
<%- } -%>
<%- if @service_cluster[:instances].size > 0  -%>

Instances :
  <%- @service_cluster[:instances].each { |k, v| -%>
  <%= v[:instance_id] %> : <%= v[:property] %> (<%= trans_svc_status(v[:status]) %>)
    <%- if v[:agent_id ] -%>
    On VM instance: <%= v[:agent_id ]%>
    <%- end -%>
  <%- } -%>
<%- end -%>
<%- if @agent_monitor[:registered].size > 0 -%>

Agents :
  <%- @agent_monitor[:registered].each { |a| -%>
  <%= a[:agent_id] %> : <%= a[:attr][:local_ipv4] %>, <%= a[:attr][:public_ipv4] %> load=<%= a[:attr][:uptime] %>, <%= (Time.now - a[:last_ping_at]).to_i %> sec(s) <%= a[:root_path] %>(<%= a[:status] %>)
    <%- if !a[:services].nil? && a[:services].size > 0 -%>
    Services (<%= a[:services].size %>): <%= a[:services].collect{|id| @service_cluster[:instances][id][:property] }.join(', ') %>
    <%- end -%>
  <%- } -%>
<%- end -%>
__E__
SVC_STATUS_MSG =
{
  Wakame::Service::STATUS_OFFLINE=>'Offline',
  Wakame::Service::STATUS_ONLINE=>'ONLINE',
  Wakame::Service::STATUS_UNKNOWN=>'Unknown',
  Wakame::Service::STATUS_FAIL=>'Fail',
  Wakame::Service::STATUS_STARTING=>'Starting...',
  Wakame::Service::STATUS_STOPPING=>'Stopping...',
  Wakame::Service::STATUS_RELOADING=>'Reloading...',
  Wakame::Service::STATUS_MIGRATING=>'Migrating...',
}

Instance Method Summary collapse

Methods included from Wakame::Command

included

Instance Method Details

#parse(args) ⇒ Object



50
51
# File 'lib/wakame/command/status.rb', line 50

def parse(args)
end


71
72
73
# File 'lib/wakame/command/status.rb', line 71

def print_result
  puts ERB.new(STATUS_TMPL, nil, '-').result(binding)
end

#run(rule) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wakame/command/status.rb', line 53

def run(rule)
  EM.barrier {
    master = rule.master
    
    sc = master.service_cluster
    #result = {
    #  :rule_engine => {
    #    :rules => sc.rule_engine.rules
    #  },
    #  :service_cluster => sc.dump_status,
    #  :agent_monitor => master.agent_monitor.dump_status
    #}

    @service_cluster = master.service_cluster.dump_status
    @agent_monitor = master.agent_monitor.dump_status
  }
end