class RubyNos::Cloud
Attributes
current_agent[RW]
list[RW]
uuid[RW]
Public Instance Methods
update(agent_info)
click to toggle source
# File lib/ruby_nos/cloud.rb, line 14 def update agent_info if agent_info.is_a?(Hash) self.current_agent = build_remote_agent(agent_info) else self.current_agent = agent_info end if list.is_on_the_list?(self.current_agent.uuid) update_actual_info else RubyNos.logger.send(:info, "Added agent #{self.current_agent.uuid}") list.add(self.current_agent) end end
Private Instance Methods
build_remote_agent(agent_info)
click to toggle source
# File lib/ruby_nos/cloud.rb, line 31 def build_remote_agent agent_info agent = RemoteAgent.new(uuid: agent_info[:agent_uuid], timestamp: (agent_info[:timestamp] || timestamp_for_list)) info = agent_info[:info] agent.endpoints = process_endpoints(info[:endpoints]) if (info && info[:endpoints]) agent end
correct_timestamp?()
click to toggle source
# File lib/ruby_nos/cloud.rb, line 62 def correct_timestamp? timestamp = current_agent.timestamp ((timestamp_for_list - RubyNos.keep_alive_time) < timestamp) && (timestamp <= timestamp_for_list) end
prepare_agent()
click to toggle source
# File lib/ruby_nos/cloud.rb, line 53 def prepare_agent if self.current_agent.endpoints == [] self.current_agent.endpoints = remote_agent_on_the_list.endpoints if remote_agent_on_the_list.endpoints end if self.current_agent.rest_api == nil self.current_agent.rest_api = remote_agent_on_the_list.rest_api if remote_agent_on_the_list.rest_api end end
process_endpoints(endpoints)
click to toggle source
# File lib/ruby_nos/cloud.rb, line 71 def process_endpoints endpoints [].tap do |endpoints_info| endpoints.each do |endpoint| e_info = endpoint.split(",") endpoints_info << Endpoint.new({type: e_info[0], port: e_info[1], host: e_info[2]}) end end end
remote_agent_on_the_list()
click to toggle source
# File lib/ruby_nos/cloud.rb, line 49 def remote_agent_on_the_list list.info_for(self.current_agent.uuid) end
same_info?()
click to toggle source
# File lib/ruby_nos/cloud.rb, line 67 def same_info? remote_agent_on_the_list.same_endpoints?(self.current_agent) && remote_agent_on_the_list.same_api?(self.current_agent) && remote_agent_on_the_list.same_timestamp?(self.current_agent) end
timestamp_for_list()
click to toggle source
# File lib/ruby_nos/cloud.rb, line 38 def timestamp_for_list Formatter.timestamp end
update_actual_info()
click to toggle source
# File lib/ruby_nos/cloud.rb, line 42 def update_actual_info if correct_timestamp? && !same_info? prepare_agent list.update(self.current_agent.uuid, self.current_agent) end end