Class: Wakame::Models::AgentPool
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Wakame::Models::AgentPool
- Defined in:
- lib/wakame/models/agent_pool.rb
Constant Summary collapse
- GROUP_ACTIVE =
1
- GROUP_OBSERVED =
2
- DEFAULT_POOL_ID =
1
Class Method Summary collapse
- .agent_find_or_create(agent_id) ⇒ Object
- .find_agent(agent_id) ⇒ Object
- .group_active ⇒ Object
- .group_observed ⇒ Object
- .instance ⇒ Object
- .register(agent) ⇒ Object
- .register_as_observed(agent) ⇒ Object
- .reset ⇒ Object
- .unregister(agent) ⇒ Object
Class Method Details
.agent_find_or_create(agent_id) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/wakame/models/agent_pool.rb', line 53 def self.agent_find_or_create(agent_id) agent = Service::Agent.find(agent_id) if agent.nil? agent = Service::Agent.new agent.id = agent_id Wakame.log.debug("#{self.class}: Created new agent object with Agent ID: #{agent_id}") end agent end |
.find_agent(agent_id) ⇒ Object
103 104 105 106 |
# File 'lib/wakame/models/agent_pool.rb', line 103 def self.find_agent(agent_id) raise "The agent ID \"#{agent_id}\" is not registered in the pool" unless first(:agent_id=>agent_id, :agent_pool_id=>DEFAULT_POOL_ID) Service::Agent.find(agent_id) || raise("The agent ID #{agent_id} is registered. but not in the database.") end |
.group_active ⇒ Object
45 46 47 |
# File 'lib/wakame/models/agent_pool.rb', line 45 def self.group_active filter(:agent_pool_id=>DEFAULT_POOL_ID, :group_type=>GROUP_ACTIVE).all.map {|row| row[:agent_id] } end |
.group_observed ⇒ Object
49 50 51 |
# File 'lib/wakame/models/agent_pool.rb', line 49 def self.group_observed filter(:agent_pool_id=>DEFAULT_POOL_ID, :group_type=>GROUP_OBSERVED).all.map {|row| row[:agent_id] } end |
.instance ⇒ Object
29 30 31 |
# File 'lib/wakame/models/agent_pool.rb', line 29 def self.instance self end |
.register(agent) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/wakame/models/agent_pool.rb', line 77 def self.register(agent) raise ArgumentError unless agent.is_a?(Service::Agent) row = find_or_create(:agent_id=>agent.id, :agent_pool_id=>DEFAULT_POOL_ID) if row[:group_type].nil? || row[:group_type] == GROUP_OBSERVED # The agent is being registered at first time. # Move the reference from observed group to the active group. row[:group_type]=GROUP_ACTIVE row.save Wakame.log.debug("#{self}: Register agent to active group: #{agent.id}") ED.fire_event(Event::AgentMonitored.new(agent)) elsif row[:group_type] == GROUP_ACTIVE end end |
.register_as_observed(agent) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wakame/models/agent_pool.rb', line 63 def self.register_as_observed(agent) raise ArgumentError unless agent.is_a? Service::Agent row = find_or_create(:agent_id=>agent.id, :agent_pool_id=>DEFAULT_POOL_ID) if row[:group_type].nil? || row[:group_type] == GROUP_ACTIVE # The agent is being registered at first time. # Move the reference from active group to observed group. row[:group_type]=GROUP_OBSERVED row.save Wakame.log.debug("#{self.class}: Register agent to observed group: #{agent.id}") elsif row[:group_type]=GROUP_OBSERVED end end |
.reset ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wakame/models/agent_pool.rb', line 33 def self.reset filter(:agent_pool_id=>DEFAULT_POOL_ID).all.each { |row| agent = Service::Agent.find(row[:agent_id]) if agent agent.cloud_host_id = nil agent.save else row.delete end } end |
.unregister(agent) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/wakame/models/agent_pool.rb', line 92 def self.unregister(agent) raise ArgumentError unless agent.is_a?(Service::Agent) row = first(:agent_id=>agent.id, :agent_pool_id=>DEFAULT_POOL_ID) if row.nil? else row.delete Wakame.log.debug("#{self}: Unregister agent: #{agent.id}") ED.fire_event(Event::AgentUnMonitored.new(agent)) end end |