Class: Wakame::Manager::CommandDelegator

Inherits:
Object
  • Object
show all
Defined in:
lib/wakame/manager/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_queue) ⇒ CommandDelegator

Returns a new instance of CommandDelegator.



42
43
44
# File 'lib/wakame/manager/commands.rb', line 42

def initialize(command_queue)
  @command_queue = command_queue
end

Instance Attribute Details

#command_queueObject (readonly)

Returns the value of attribute command_queue.



41
42
43
# File 'lib/wakame/manager/commands.rb', line 41

def command_queue
  @command_queue
end

Instance Method Details

#action_statusObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/wakame/manager/commands.rb', line 102

def action_status
  walk_subactions = proc { |a, level|
    res = a.dump_attrs
    unless a.subactions.empty?
      res[:subactions] = a.subactions.collect { |s|
        walk_subactions.call(s, level + 1)
      }
    end
    res
  }

  EM.barrier {
    result = {}
    Master.instance.service_cluster.rule_engine.active_jobs.each { |id, v|
      result[id]={:actions=>[], :created_at=>v[:created_at], :src_rule=>v[:src_rule].class.to_s}

      result[id][:root_action] = walk_subactions.call(v[:root_action], 0)
    }

    result
  }
end

#deploy_config(prop_name = nil) ⇒ Object



81
82
83
84
# File 'lib/wakame/manager/commands.rb', line 81

def deploy_config(prop_name=nil)
  prop = nil
  @command_queue.send_cmd(Commands::DeployConfig.new)
end

#launch_clusterObject



50
51
52
# File 'lib/wakame/manager/commands.rb', line 50

def launch_cluster
  @command_queue.send_cmd(Commands::ClusterLaunch.new)
end

#migrate_service(svc_inst_id, agent_id = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/wakame/manager/commands.rb', line 66

def migrate_service(svc_inst_id, agent_id=nil)
  svc = master.service_cluster.instances[svc_inst_id]
  if svc.nil?
    raise "Unknown Service Instance: #{svc_inst_id}" 
  end
  agent = nil
  if agent_id
    agent = master.agent_monitor.agents.has_key?(agent_id)
    if agent.nil?
      raise "Unknown Agent: #{agent_id}" 
    end
  end

  @command_queue.send_cmd(Commands::MigrateService.new(svc, agent))
end

#nopObject



46
47
48
# File 'lib/wakame/manager/commands.rb', line 46

def nop
  @command_queue.send_cmd(Commands::Nop.new)
end

#propagate_service(prop_name) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/wakame/manager/commands.rb', line 57

def propagate_service(prop_name)
  prop = nil
  prop = master.service_cluster.properties[prop_name.to_s]
  if prop.nil?
    raise "UnknownProperty: #{prop_name}" 
  end

  @command_queue.send_cmd(Commands::PropagateService.new(prop))
end

#shutdown_clusterObject



54
55
56
# File 'lib/wakame/manager/commands.rb', line 54

def shutdown_cluster
  @command_queue.send_cmd(Commands::ClusterShutdown.new)
end

#statusObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/wakame/manager/commands.rb', line 86

def status
  EM.barrier {
    master = Master.instance
    
    sc = master.service_cluster
    result = {
      :rule_engine => {
        :rules => sc.rule_engine.rules
      },
      :service_cluster => sc.dump_status,
      :agent_monitor => master.agent_monitor.dump_status
    }
    result
  }
end