repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
rightscale/right_agent
lib/right_agent/actor_registry.rb
RightScale.ActorRegistry.register
def register(actor, prefix) raise ArgumentError, "#{actor.inspect} is not a RightScale::Actor subclass instance" unless RightScale::Actor === actor log_msg = "[actor] #{actor.class.to_s}" log_msg += ", prefix #{prefix}" if prefix && !prefix.empty? Log.info(log_msg) prefix ||= actor.class.d...
ruby
def register(actor, prefix) raise ArgumentError, "#{actor.inspect} is not a RightScale::Actor subclass instance" unless RightScale::Actor === actor log_msg = "[actor] #{actor.class.to_s}" log_msg += ", prefix #{prefix}" if prefix && !prefix.empty? Log.info(log_msg) prefix ||= actor.class.d...
[ "def", "register", "(", "actor", ",", "prefix", ")", "raise", "ArgumentError", ",", "\"#{actor.inspect} is not a RightScale::Actor subclass instance\"", "unless", "RightScale", "::", "Actor", "===", "actor", "log_msg", "=", "\"[actor] #{actor.class.to_s}\"", "log_msg", "+="...
Initialize registry Register as an actor === Parameters actor(Actor):: Actor to be registered prefix(String):: Prefix used in request to identify actor === Return (Actor):: Actor registered === Raises ArgumentError if actor is not an Actor
[ "Initialize", "registry", "Register", "as", "an", "actor" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/actor_registry.rb#L46-L53
train
rightscale/right_agent
lib/right_agent/security/certificate_cache.rb
RightScale.CertificateCache.put
def put(key, item) if @items.include?(key) delete(key) end if @list.size == @max_count delete(@list.first) end @items[key] = item @list.push(key) item end
ruby
def put(key, item) if @items.include?(key) delete(key) end if @list.size == @max_count delete(@list.first) end @items[key] = item @list.push(key) item end
[ "def", "put", "(", "key", ",", "item", ")", "if", "@items", ".", "include?", "(", "key", ")", "delete", "(", "key", ")", "end", "if", "@list", ".", "size", "==", "@max_count", "delete", "(", "@list", ".", "first", ")", "end", "@items", "[", "key", ...
Initialize cache Add item to cache
[ "Initialize", "cache", "Add", "item", "to", "cache" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/security/certificate_cache.rb#L40-L50
train
rightscale/right_agent
lib/right_agent/security/certificate_cache.rb
RightScale.CertificateCache.get
def get(key) if @items.include?(key) @list.each_index do |i| if @list[i] == key @list.delete_at(i) break end end @list.push(key) @items[key] else return nil unless block_given? self[key] = yield end end
ruby
def get(key) if @items.include?(key) @list.each_index do |i| if @list[i] == key @list.delete_at(i) break end end @list.push(key) @items[key] else return nil unless block_given? self[key] = yield end end
[ "def", "get", "(", "key", ")", "if", "@items", ".", "include?", "(", "key", ")", "@list", ".", "each_index", "do", "|", "i", "|", "if", "@list", "[", "i", "]", "==", "key", "@list", ".", "delete_at", "(", "i", ")", "break", "end", "end", "@list",...
Retrieve item from cache Store item returned by given block if any
[ "Retrieve", "item", "from", "cache", "Store", "item", "returned", "by", "given", "block", "if", "any" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/security/certificate_cache.rb#L55-L69
train
rightscale/right_agent
lib/right_agent/security/certificate_cache.rb
RightScale.CertificateCache.delete
def delete(key) c = @items[key] if c @items.delete(key) @list.each_index do |i| if @list[i] == key @list.delete_at(i) break end end c end end
ruby
def delete(key) c = @items[key] if c @items.delete(key) @list.each_index do |i| if @list[i] == key @list.delete_at(i) break end end c end end
[ "def", "delete", "(", "key", ")", "c", "=", "@items", "[", "key", "]", "if", "c", "@items", ".", "delete", "(", "key", ")", "@list", ".", "each_index", "do", "|", "i", "|", "if", "@list", "[", "i", "]", "==", "key", "@list", ".", "delete_at", "...
Delete item from cache
[ "Delete", "item", "from", "cache" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/security/certificate_cache.rb#L73-L85
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.check_health
def check_health(host = nil) begin @http_client.health_check_proc.call(host || @urls.first) rescue StandardError => e if e.respond_to?(:http_code) && RETRY_STATUS_CODES.include?(e.http_code) raise NotResponding.new("#{@server_name || host} not responding", e) else ...
ruby
def check_health(host = nil) begin @http_client.health_check_proc.call(host || @urls.first) rescue StandardError => e if e.respond_to?(:http_code) && RETRY_STATUS_CODES.include?(e.http_code) raise NotResponding.new("#{@server_name || host} not responding", e) else ...
[ "def", "check_health", "(", "host", "=", "nil", ")", "begin", "@http_client", ".", "health_check_proc", ".", "call", "(", "host", "||", "@urls", ".", "first", ")", "rescue", "StandardError", "=>", "e", "if", "e", ".", "respond_to?", "(", ":http_code", ")",...
Create client for making HTTP REST requests @param [Array, String] urls of server being accessed as array or comma-separated string @option options [String] :api_version for X-API-Version header @option options [String] :server_name of server for use in exceptions; defaults to host name @option options [String] :...
[ "Create", "client", "for", "making", "HTTP", "REST", "requests" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L102-L112
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.request_headers
def request_headers(request_uuid, options) headers = {"X-Request-Lineage-Uuid" => request_uuid, :accept => "application/json"} headers["X-API-Version"] = @api_version if @api_version headers.merge!(options[:headers]) if options[:headers] headers["X-DEBUG"] = true if Log.level == :debug hea...
ruby
def request_headers(request_uuid, options) headers = {"X-Request-Lineage-Uuid" => request_uuid, :accept => "application/json"} headers["X-API-Version"] = @api_version if @api_version headers.merge!(options[:headers]) if options[:headers] headers["X-DEBUG"] = true if Log.level == :debug hea...
[ "def", "request_headers", "(", "request_uuid", ",", "options", ")", "headers", "=", "{", "\"X-Request-Lineage-Uuid\"", "=>", "request_uuid", ",", ":accept", "=>", "\"application/json\"", "}", "headers", "[", "\"X-API-Version\"", "]", "=", "@api_version", "if", "@api...
Construct headers for request @param [String] request_uuid uniquely identifying request @param [Hash] options per #request @return [Hash] headers for request
[ "Construct", "headers", "for", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L208-L214
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.rest_request
def rest_request(verb, path, connect_options, request_options, used) result, code, body, headers = @balancer.request do |host| uri = URI.parse(host) uri.user = uri.password = nil used[:host] = uri.to_s @http_client.request(verb, path, host, connect_options, request_options) e...
ruby
def rest_request(verb, path, connect_options, request_options, used) result, code, body, headers = @balancer.request do |host| uri = URI.parse(host) uri.user = uri.password = nil used[:host] = uri.to_s @http_client.request(verb, path, host, connect_options, request_options) e...
[ "def", "rest_request", "(", "verb", ",", "path", ",", "connect_options", ",", "request_options", ",", "used", ")", "result", ",", "code", ",", "body", ",", "headers", "=", "@balancer", ".", "request", "do", "|", "host", "|", "uri", "=", "URI", ".", "pa...
Make REST request @param [Symbol] verb for HTTP REST request @param [String] path in URI for desired resource @param [Hash] connect_options for HTTP connection @param [Hash] request_options for HTTP request @param [Hash] used container for returning :host used for request; needed so that can return it even whe...
[ "Make", "REST", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L229-L237
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.poll_request
def poll_request(path, connect_options, request_options, request_timeout, started_at, used) result = code = body = headers = nil if (connection = @http_client.connections[path]).nil? || Time.now >= connection[:expires_at] # Use normal :get request using request balancer for first poll result...
ruby
def poll_request(path, connect_options, request_options, request_timeout, started_at, used) result = code = body = headers = nil if (connection = @http_client.connections[path]).nil? || Time.now >= connection[:expires_at] # Use normal :get request using request balancer for first poll result...
[ "def", "poll_request", "(", "path", ",", "connect_options", ",", "request_options", ",", "request_timeout", ",", "started_at", ",", "used", ")", "result", "=", "code", "=", "body", "=", "headers", "=", "nil", "if", "(", "connection", "=", "@http_client", "."...
Make long-polling request @param [String] path in URI for desired resource @param [Hash] connect_options for HTTP connection @param [Hash] request_options for HTTP request @param [Integer] request_timeout for a non-nil result @param [Time] started_at time for request @param [Hash] used container for returning :h...
[ "Make", "long", "-", "polling", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L253-L272
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.handle_no_result
def handle_no_result(no_result, host) server_name = @server_name || host e = no_result.details.values.flatten.last if no_result.details.empty? yield(no_result) raise NotResponding.new("#{server_name} not responding", no_result) elsif e.respond_to?(:http_code) && RETRY_STATUS_CODE...
ruby
def handle_no_result(no_result, host) server_name = @server_name || host e = no_result.details.values.flatten.last if no_result.details.empty? yield(no_result) raise NotResponding.new("#{server_name} not responding", no_result) elsif e.respond_to?(:http_code) && RETRY_STATUS_CODE...
[ "def", "handle_no_result", "(", "no_result", ",", "host", ")", "server_name", "=", "@server_name", "||", "host", "e", "=", "no_result", ".", "details", ".", "values", ".", "flatten", ".", "last", "if", "no_result", ".", "details", ".", "empty?", "yield", "...
Handle no result from balancer Distinguish the not responding case since it likely warrants a retry by the client Also try to distinguish between the targeted server not responding and that server gatewaying to another server that is not responding, so that the receiver of the resulting exception is clearer as to t...
[ "Handle", "no", "result", "from", "balancer", "Distinguish", "the", "not", "responding", "case", "since", "it", "likely", "warrants", "a", "retry", "by", "the", "client", "Also", "try", "to", "distinguish", "between", "the", "targeted", "server", "not", "respo...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L290-L312
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.log_success
def log_success(result, code, body, headers, host, path, request_uuid, started_at, log_level) length = (headers && headers[:content_length]) || (body && body.size) || "-" duration = "%.0fms" % ((Time.now - started_at) * 1000) completed = "Completed <#{request_uuid}> in #{duration} | #{code || "nil"} [...
ruby
def log_success(result, code, body, headers, host, path, request_uuid, started_at, log_level) length = (headers && headers[:content_length]) || (body && body.size) || "-" duration = "%.0fms" % ((Time.now - started_at) * 1000) completed = "Completed <#{request_uuid}> in #{duration} | #{code || "nil"} [...
[ "def", "log_success", "(", "result", ",", "code", ",", "body", ",", "headers", ",", "host", ",", "path", ",", "request_uuid", ",", "started_at", ",", "log_level", ")", "length", "=", "(", "headers", "&&", "headers", "[", ":content_length", "]", ")", "||"...
Log successful request completion @param [Object] result to be returned to client @param [Integer, NilClass] code for response status @param [Object] body of response @param [Hash] headers for response @param [String] host server URL where request was completed @param [String] path in URI for desired resource @...
[ "Log", "successful", "request", "completion" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L328-L335
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.log_failure
def log_failure(host, path, params, filter, request_uuid, started_at, exception) code = exception.respond_to?(:http_code) ? exception.http_code : "nil" duration = "%.0fms" % ((Time.now - started_at) * 1000) ErrorTracker.log(self, "Failed <#{request_uuid}> in #{duration} | #{code} " + log_text(path, pa...
ruby
def log_failure(host, path, params, filter, request_uuid, started_at, exception) code = exception.respond_to?(:http_code) ? exception.http_code : "nil" duration = "%.0fms" % ((Time.now - started_at) * 1000) ErrorTracker.log(self, "Failed <#{request_uuid}> in #{duration} | #{code} " + log_text(path, pa...
[ "def", "log_failure", "(", "host", ",", "path", ",", "params", ",", "filter", ",", "request_uuid", ",", "started_at", ",", "exception", ")", "code", "=", "exception", ".", "respond_to?", "(", ":http_code", ")", "?", "exception", ".", "http_code", ":", "\"n...
Log request failure Also report it as audit entry if an instance is targeted @param [String] host server URL where request was attempted if known @param [String] path in URI for desired resource @param [Hash] params for request @param [Array] filter list of parameters whose value is to be hidden @param [String] ...
[ "Log", "request", "failure", "Also", "report", "it", "as", "audit", "entry", "if", "an", "instance", "is", "targeted" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L349-L354
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.log_text
def log_text(path, params, filter, host = nil, exception = nil) text = "#{path} #{filter(params, filter).inspect}" text = "[#{host}#{text}]" if host text << " | #{self.class.exception_text(exception)}" if exception text end
ruby
def log_text(path, params, filter, host = nil, exception = nil) text = "#{path} #{filter(params, filter).inspect}" text = "[#{host}#{text}]" if host text << " | #{self.class.exception_text(exception)}" if exception text end
[ "def", "log_text", "(", "path", ",", "params", ",", "filter", ",", "host", "=", "nil", ",", "exception", "=", "nil", ")", "text", "=", "\"#{path} #{filter(params, filter).inspect}\"", "text", "=", "\"[#{host}#{text}]\"", "if", "host", "text", "<<", "\" | #{self....
Generate log text describing request and failure if any @param [String] path in URI for desired resource @param [Hash] params for HTTP request @param [Array, NilClass] filter augmentation to base filter list @param [String] host server URL where request was attempted if known @param [Exception, String, NilClass] ...
[ "Generate", "log", "text", "describing", "request", "and", "failure", "if", "any" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L365-L370
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.filter
def filter(params, filter) if filter.empty? || !params.is_a?(Hash) params else filtered_params = {} params.each do |k, p| s = k.to_s if filter.include?(s) filtered_params[k] = FILTERED_PARAM_VALUE else filtered_params[k] = CONTENT...
ruby
def filter(params, filter) if filter.empty? || !params.is_a?(Hash) params else filtered_params = {} params.each do |k, p| s = k.to_s if filter.include?(s) filtered_params[k] = FILTERED_PARAM_VALUE else filtered_params[k] = CONTENT...
[ "def", "filter", "(", "params", ",", "filter", ")", "if", "filter", ".", "empty?", "||", "!", "params", ".", "is_a?", "(", "Hash", ")", "params", "else", "filtered_params", "=", "{", "}", "params", ".", "each", "do", "|", "k", ",", "p", "|", "s", ...
Apply parameter hiding filter @param [Hash, Object] params to be filtered with strings or symbols as keys @param [Array] filter names of params as strings (not symbols) whose value is to be hidden; also filter the contents of any CONTENT_FILTERED_PARAMS @return [Hash] filtered parameters
[ "Apply", "parameter", "hiding", "filter" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L379-L394
train
rightscale/right_agent
lib/right_agent/clients/balanced_http_client.rb
RightScale.BalancedHttpClient.split
def split(object, pattern = /,\s*/) object ? (object.is_a?(Array) ? object : object.split(pattern)) : [] end
ruby
def split(object, pattern = /,\s*/) object ? (object.is_a?(Array) ? object : object.split(pattern)) : [] end
[ "def", "split", "(", "object", ",", "pattern", "=", "/", "\\s", "/", ")", "object", "?", "(", "object", ".", "is_a?", "(", "Array", ")", "?", "object", ":", "object", ".", "split", "(", "pattern", ")", ")", ":", "[", "]", "end" ]
Split string into an array unless nil or already an array @param [String, Array, NilClass] object to be split @param [String, Regex] pattern on which to split; defaults to comma @return [Array] split object
[ "Split", "string", "into", "an", "array", "unless", "nil", "or", "already", "an", "array" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/balanced_http_client.rb#L402-L404
train
rightscale/right_agent
lib/right_agent/scripts/stats_manager.rb
RightScale.StatsManager.manage
def manage(options) init_log if options[:verbose] AgentConfig.cfg_dir = options[:cfg_dir] options[:timeout] ||= DEFAULT_TIMEOUT request_stats(options) rescue Exception => e fail("#{e}\n#{e.backtrace.join("\n")}") unless e.is_a?(SystemExit) end
ruby
def manage(options) init_log if options[:verbose] AgentConfig.cfg_dir = options[:cfg_dir] options[:timeout] ||= DEFAULT_TIMEOUT request_stats(options) rescue Exception => e fail("#{e}\n#{e.backtrace.join("\n")}") unless e.is_a?(SystemExit) end
[ "def", "manage", "(", "options", ")", "init_log", "if", "options", "[", ":verbose", "]", "AgentConfig", ".", "cfg_dir", "=", "options", "[", ":cfg_dir", "]", "options", "[", ":timeout", "]", "||=", "DEFAULT_TIMEOUT", "request_stats", "(", "options", ")", "re...
Initialize manager Handle stats request === Parameters options(Hash):: Command line options === Return true:: Always return true
[ "Initialize", "manager", "Handle", "stats", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/scripts/stats_manager.rb#L65-L72
train
rightscale/right_agent
lib/right_agent/scripts/stats_manager.rb
RightScale.StatsManager.request_stats
def request_stats(options) # Determine candidate agents agent_names = if options[:agent_name] [options[:agent_name]] else AgentConfig.cfg_agents end fail("No agents configured") if agent_names.empty? # Request stats from agents count = 0 agent_names.each ...
ruby
def request_stats(options) # Determine candidate agents agent_names = if options[:agent_name] [options[:agent_name]] else AgentConfig.cfg_agents end fail("No agents configured") if agent_names.empty? # Request stats from agents count = 0 agent_names.each ...
[ "def", "request_stats", "(", "options", ")", "agent_names", "=", "if", "options", "[", ":agent_name", "]", "[", "options", "[", ":agent_name", "]", "]", "else", "AgentConfig", ".", "cfg_agents", "end", "fail", "(", "\"No agents configured\"", ")", "if", "agent...
Request and display statistics for agents === Parameters options(Hash):: Command line options === Return true:: Always return true
[ "Request", "and", "display", "statistics", "for", "agents" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/scripts/stats_manager.rb#L129-L148
train
rightscale/right_agent
lib/right_agent/scripts/stats_manager.rb
RightScale.StatsManager.request_agent_stats
def request_agent_stats(agent_name, options) res = false config_options = AgentConfig.agent_options(agent_name) unless config_options.empty? || (listen_port = config_options[:listen_port]).nil? client = CommandClient.new(listen_port, config_options[:cookie]) command = {:name => :stats,...
ruby
def request_agent_stats(agent_name, options) res = false config_options = AgentConfig.agent_options(agent_name) unless config_options.empty? || (listen_port = config_options[:listen_port]).nil? client = CommandClient.new(listen_port, config_options[:cookie]) command = {:name => :stats,...
[ "def", "request_agent_stats", "(", "agent_name", ",", "options", ")", "res", "=", "false", "config_options", "=", "AgentConfig", ".", "agent_options", "(", "agent_name", ")", "unless", "config_options", ".", "empty?", "||", "(", "listen_port", "=", "config_options...
Request and display statistics for agent === Parameters agent_name(String):: Agent name options(Hash):: Command line options === Return (Boolean):: true if agent running, otherwise false
[ "Request", "and", "display", "statistics", "for", "agent" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/scripts/stats_manager.rb#L158-L174
train
rightscale/right_agent
lib/right_agent/offline_handler.rb
RightScale.OfflineHandler.disable
def disable if offline? && @state != :created Log.info("[offline] Connection to RightNet re-established") @offline_stats.finish cancel_timer @state = :flushing # Wait a bit to avoid flooding RightNet EM.add_timer(rand(MAX_QUEUE_FLUSH_DELAY)) { flush } end ...
ruby
def disable if offline? && @state != :created Log.info("[offline] Connection to RightNet re-established") @offline_stats.finish cancel_timer @state = :flushing # Wait a bit to avoid flooding RightNet EM.add_timer(rand(MAX_QUEUE_FLUSH_DELAY)) { flush } end ...
[ "def", "disable", "if", "offline?", "&&", "@state", "!=", ":created", "Log", ".", "info", "(", "\"[offline] Connection to RightNet re-established\"", ")", "@offline_stats", ".", "finish", "cancel_timer", "@state", "=", ":flushing", "EM", ".", "add_timer", "(", "rand...
Switch back to sending requests after in-memory queue gets flushed Idempotent === Return true:: Always return true
[ "Switch", "back", "to", "sending", "requests", "after", "in", "-", "memory", "queue", "gets", "flushed", "Idempotent" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/offline_handler.rb#L149-L159
train
rightscale/right_agent
lib/right_agent/offline_handler.rb
RightScale.OfflineHandler.queue_request
def queue_request(kind, type, payload, target, token, expires_at, skewed_by, &callback) request = {:kind => kind, :type => type, :payload => payload, :target => target, :token => token, :expires_at => expires_at, :skewed_by => skewed_by, :callback => callback} Log.info("[of...
ruby
def queue_request(kind, type, payload, target, token, expires_at, skewed_by, &callback) request = {:kind => kind, :type => type, :payload => payload, :target => target, :token => token, :expires_at => expires_at, :skewed_by => skewed_by, :callback => callback} Log.info("[of...
[ "def", "queue_request", "(", "kind", ",", "type", ",", "payload", ",", "target", ",", "token", ",", "expires_at", ",", "skewed_by", ",", "&", "callback", ")", "request", "=", "{", ":kind", "=>", "kind", ",", ":type", "=>", "type", ",", ":payload", "=>"...
Queue given request in memory === Parameters kind(Symbol):: Kind of request: :send_push or :send_request type(String):: Dispatch route for the request; typically identifies actor and action payload(Object):: Data to be sent with marshalling en route target(Hash|NilClass):: Target for request token(String):: Toke...
[ "Queue", "given", "request", "in", "memory" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/offline_handler.rb#L179-L192
train
rightscale/right_agent
lib/right_agent/offline_handler.rb
RightScale.OfflineHandler.flush
def flush(again = false) if @state == :flushing Log.info("[offline] Starting to flush request queue of size #{@queue.size}") unless again || @mode == :initializing if @queue.any? r = @queue.shift options = {:token => r[:token]} if r[:expires_at] != 0 && (options[:time...
ruby
def flush(again = false) if @state == :flushing Log.info("[offline] Starting to flush request queue of size #{@queue.size}") unless again || @mode == :initializing if @queue.any? r = @queue.shift options = {:token => r[:token]} if r[:expires_at] != 0 && (options[:time...
[ "def", "flush", "(", "again", "=", "false", ")", "if", "@state", "==", ":flushing", "Log", ".", "info", "(", "\"[offline] Starting to flush request queue of size #{@queue.size}\"", ")", "unless", "again", "||", "@mode", "==", ":initializing", "if", "@queue", ".", ...
Send any requests that were queued while in offline mode and have not yet timed out Do this asynchronously to allow for agents to respond to requests Once all in-memory requests have been flushed, switch off offline mode === Parameters again(Boolean):: Whether being called in a loop === Return true:: Always ret...
[ "Send", "any", "requests", "that", "were", "queued", "while", "in", "offline", "mode", "and", "have", "not", "yet", "timed", "out", "Do", "this", "asynchronously", "to", "allow", "for", "agents", "to", "respond", "to", "requests", "Once", "all", "in", "-",...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/offline_handler.rb#L215-L237
train
rightscale/right_agent
lib/right_agent/core_payload_types/login_policy.rb
RightScale.LoginPolicy.fingerprint
def fingerprint h = Digest::SHA2.new h << (self.exclusive ? 'true' : 'false') users = self.users.sort { |a, b| a.uuid <=> b.uuid } users.each do |u| h << format(",(%d,%s,%s,%d,%s", u.uuid, u.common_name, (u.superuser ? 'true' : 'false'), ...
ruby
def fingerprint h = Digest::SHA2.new h << (self.exclusive ? 'true' : 'false') users = self.users.sort { |a, b| a.uuid <=> b.uuid } users.each do |u| h << format(",(%d,%s,%s,%d,%s", u.uuid, u.common_name, (u.superuser ? 'true' : 'false'), ...
[ "def", "fingerprint", "h", "=", "Digest", "::", "SHA2", ".", "new", "h", "<<", "(", "self", ".", "exclusive", "?", "'true'", ":", "'false'", ")", "users", "=", "self", ".", "users", ".", "sort", "{", "|", "a", ",", "b", "|", "a", ".", "uuid", "...
Compute a cryptographic hash of the information in this policy; helps callers compare two policies to see if they are equivalent. @see https://github.com/rightscale/cmaro/domain/login_policy.go
[ "Compute", "a", "cryptographic", "hash", "of", "the", "information", "in", "this", "policy", ";", "helps", "callers", "compare", "two", "policies", "to", "see", "if", "they", "are", "equivalent", "." ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/core_payload_types/login_policy.rb#L52-L71
train
rightscale/right_agent
lib/right_agent/clients/blocking_client.rb
RightScale.BlockingClient.request
def request(verb, path, host, connect_options, request_options) url = host + path + request_options.delete(:query).to_s result = request_once(verb, url, request_options) @connections[path] = {:host => host, :path => path, :expires_at => Time.now + BalancedHttpClient::CONNECTION_REUSE_TIMEOUT } r...
ruby
def request(verb, path, host, connect_options, request_options) url = host + path + request_options.delete(:query).to_s result = request_once(verb, url, request_options) @connections[path] = {:host => host, :path => path, :expires_at => Time.now + BalancedHttpClient::CONNECTION_REUSE_TIMEOUT } r...
[ "def", "request", "(", "verb", ",", "path", ",", "host", ",", "connect_options", ",", "request_options", ")", "url", "=", "host", "+", "path", "+", "request_options", ".", "delete", "(", ":query", ")", ".", "to_s", "result", "=", "request_once", "(", "ve...
Make HTTP request @param [Symbol] verb for HTTP REST request @param [String] path in URI for desired resource @param [String] host name of server @param [Hash] connect_options for HTTP connection (ignored) @param [Hash] request_options for HTTP request @return [Array] result to be returned followed by response ...
[ "Make", "HTTP", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/blocking_client.rb#L108-L113
train
rightscale/right_agent
lib/right_agent/clients/blocking_client.rb
RightScale.BlockingClient.poll
def poll(connection, request_options, stop_at) url = connection[:host] + connection[:path] + request_options.delete(:query).to_s begin result, code, body, headers = request_once(:get, url, request_options) end until result || Time.now >= stop_at connection[:expires_at] = Time.now + Balan...
ruby
def poll(connection, request_options, stop_at) url = connection[:host] + connection[:path] + request_options.delete(:query).to_s begin result, code, body, headers = request_once(:get, url, request_options) end until result || Time.now >= stop_at connection[:expires_at] = Time.now + Balan...
[ "def", "poll", "(", "connection", ",", "request_options", ",", "stop_at", ")", "url", "=", "connection", "[", ":host", "]", "+", "connection", "[", ":path", "]", "+", "request_options", ".", "delete", "(", ":query", ")", ".", "to_s", "begin", "result", "...
Make long-polling requests until receive data, hit error, or timeout @param [Hash] connection to server from previous request with keys :host, :path, and :expires_at, with the :expires_at being adjusted on return @param [Hash] request_options for HTTP request @param [Time] stop_at time for polling @return [Arr...
[ "Make", "long", "-", "polling", "requests", "until", "receive", "data", "hit", "error", "or", "timeout" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/blocking_client.rb#L125-L132
train
rightscale/right_agent
lib/right_agent/clients/blocking_client.rb
RightScale.BlockingClient.request_once
def request_once(verb, url, request_options) if (r = RightSupport::Net::HTTPClient.new.send(verb, url, request_options)) [BalancedHttpClient.response(r.code, r.body, r.headers, request_options[:headers][:accept]), r.code, r.body, r.headers] else [nil, nil, nil, nil] end end
ruby
def request_once(verb, url, request_options) if (r = RightSupport::Net::HTTPClient.new.send(verb, url, request_options)) [BalancedHttpClient.response(r.code, r.body, r.headers, request_options[:headers][:accept]), r.code, r.body, r.headers] else [nil, nil, nil, nil] end end
[ "def", "request_once", "(", "verb", ",", "url", ",", "request_options", ")", "if", "(", "r", "=", "RightSupport", "::", "Net", "::", "HTTPClient", ".", "new", ".", "send", "(", "verb", ",", "url", ",", "request_options", ")", ")", "[", "BalancedHttpClien...
Make HTTP request once @param [Symbol] verb for HTTP REST request @param [String] url for request @param [Hash] request_options for HTTP request @return [Array] result to be returned followed by response code, body, and headers @raise [HttpException] HTTP failure with associated status code
[ "Make", "HTTP", "request", "once" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/blocking_client.rb#L155-L161
train
rightscale/right_agent
lib/right_agent/pending_requests.rb
RightScale.PendingRequests.[]=
def []=(token, pending_request) now = Time.now if (now - @last_cleanup) > MIN_CLEANUP_INTERVAL self.reject! { |t, r| r.kind == :send_push && (now - r.receive_time) > MAX_PUSH_AGE } @last_cleanup = now end super end
ruby
def []=(token, pending_request) now = Time.now if (now - @last_cleanup) > MIN_CLEANUP_INTERVAL self.reject! { |t, r| r.kind == :send_push && (now - r.receive_time) > MAX_PUSH_AGE } @last_cleanup = now end super end
[ "def", "[]=", "(", "token", ",", "pending_request", ")", "now", "=", "Time", ".", "now", "if", "(", "now", "-", "@last_cleanup", ")", ">", "MIN_CLEANUP_INTERVAL", "self", ".", "reject!", "{", "|", "t", ",", "r", "|", "r", ".", "kind", "==", ":send_pu...
Create cache Store pending request === Parameters token(String):: Generated message identifier pending_request(PendingRequest):: Pending request === Return (PendingRequest):: Stored request
[ "Create", "cache", "Store", "pending", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/pending_requests.rb#L78-L85
train
rightscale/right_agent
lib/right_agent/scripts/agent_deployer.rb
RightScale.AgentDeployer.deploy
def deploy(options) # Initialize directory settings AgentConfig.root_dir = options[:root_dir] AgentConfig.cfg_dir = options[:cfg_dir] AgentConfig.pid_dir = options[:pid_dir] # Configure agent cfg = load_init_cfg check_agent(options, cfg) cfg = configure(options, cfg) ...
ruby
def deploy(options) # Initialize directory settings AgentConfig.root_dir = options[:root_dir] AgentConfig.cfg_dir = options[:cfg_dir] AgentConfig.pid_dir = options[:pid_dir] # Configure agent cfg = load_init_cfg check_agent(options, cfg) cfg = configure(options, cfg) ...
[ "def", "deploy", "(", "options", ")", "AgentConfig", ".", "root_dir", "=", "options", "[", ":root_dir", "]", "AgentConfig", ".", "cfg_dir", "=", "options", "[", ":cfg_dir", "]", "AgentConfig", ".", "pid_dir", "=", "options", "[", ":pid_dir", "]", "cfg", "=...
Generate configuration from specified options and the agent's base options and write them to a file === Parameters options(Hash):: Command line options === Return true:: Always return true
[ "Generate", "configuration", "from", "specified", "options", "and", "the", "agent", "s", "base", "options", "and", "write", "them", "to", "a", "file" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/scripts/agent_deployer.rb#L86-L103
train
rightscale/right_agent
lib/right_agent/scripts/agent_deployer.rb
RightScale.AgentDeployer.load_init_cfg
def load_init_cfg cfg = {} if (cfg_file = AgentConfig.init_cfg_file) && (cfg_data = YAML.load(IO.read(cfg_file))) cfg = SerializationHelper.symbolize_keys(cfg_data) rescue nil fail("Cannot read configuration for agent #{cfg_file.inspect}") unless cfg end cfg end
ruby
def load_init_cfg cfg = {} if (cfg_file = AgentConfig.init_cfg_file) && (cfg_data = YAML.load(IO.read(cfg_file))) cfg = SerializationHelper.symbolize_keys(cfg_data) rescue nil fail("Cannot read configuration for agent #{cfg_file.inspect}") unless cfg end cfg end
[ "def", "load_init_cfg", "cfg", "=", "{", "}", "if", "(", "cfg_file", "=", "AgentConfig", ".", "init_cfg_file", ")", "&&", "(", "cfg_data", "=", "YAML", ".", "load", "(", "IO", ".", "read", "(", "cfg_file", ")", ")", ")", "cfg", "=", "SerializationHelpe...
Load initial configuration for agent, if any === Return cfg(Hash):: Initial agent configuration options
[ "Load", "initial", "configuration", "for", "agent", "if", "any" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/scripts/agent_deployer.rb#L261-L268
train
rightscale/right_agent
lib/right_agent/scripts/agent_deployer.rb
RightScale.AgentDeployer.check_agent
def check_agent(options, cfg) identity = options[:identity] agent_type = options[:agent_type] type = AgentIdentity.parse(identity).agent_type if identity fail("Agent type #{agent_type.inspect} and identity #{identity.inspect} are inconsistent") if agent_type != type fail("Cannot find agent...
ruby
def check_agent(options, cfg) identity = options[:identity] agent_type = options[:agent_type] type = AgentIdentity.parse(identity).agent_type if identity fail("Agent type #{agent_type.inspect} and identity #{identity.inspect} are inconsistent") if agent_type != type fail("Cannot find agent...
[ "def", "check_agent", "(", "options", ",", "cfg", ")", "identity", "=", "options", "[", ":identity", "]", "agent_type", "=", "options", "[", ":agent_type", "]", "type", "=", "AgentIdentity", ".", "parse", "(", "identity", ")", ".", "agent_type", "if", "ide...
Check agent type consistency and existence of initialization file and actors directory === Parameters options(Hash):: Command line options cfg(Hash):: Initial configuration settings === Return true:: Always return true
[ "Check", "agent", "type", "consistency", "and", "existence", "of", "initialization", "file", "and", "actors", "directory" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/scripts/agent_deployer.rb#L278-L294
train
rightscale/right_agent
lib/right_agent/scripts/agent_deployer.rb
RightScale.AgentDeployer.persist
def persist(options, cfg) overrides = options[:options] overrides.each { |k, v| cfg[k] = v } if overrides cfg_file = AgentConfig.store_cfg(options[:agent_name], cfg) unless options[:quiet] puts "Generated configuration file for #{options[:agent_name]} agent: #{cfg_file}" unless options[:...
ruby
def persist(options, cfg) overrides = options[:options] overrides.each { |k, v| cfg[k] = v } if overrides cfg_file = AgentConfig.store_cfg(options[:agent_name], cfg) unless options[:quiet] puts "Generated configuration file for #{options[:agent_name]} agent: #{cfg_file}" unless options[:...
[ "def", "persist", "(", "options", ",", "cfg", ")", "overrides", "=", "options", "[", ":options", "]", "overrides", ".", "each", "{", "|", "k", ",", "v", "|", "cfg", "[", "k", "]", "=", "v", "}", "if", "overrides", "cfg_file", "=", "AgentConfig", "....
Write configuration options to file after applying any overrides === Parameters options(Hash):: Command line options cfg(Hash):: Configurations options with which specified options are to be merged === Return true:: Always return true
[ "Write", "configuration", "options", "to", "file", "after", "applying", "any", "overrides" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/scripts/agent_deployer.rb#L344-L352
train
rightscale/right_agent
lib/right_agent/core_payload_types/dev_repositories.rb
RightScale.DevRepositories.add_repo
def add_repo(repo_sha, repo_detail, cookbook_positions) @repositories ||= {} @repositories[repo_sha] = DevRepository.new(repo_detail[:repo_type], repo_detail[:url], repo_detail[:tag], ...
ruby
def add_repo(repo_sha, repo_detail, cookbook_positions) @repositories ||= {} @repositories[repo_sha] = DevRepository.new(repo_detail[:repo_type], repo_detail[:url], repo_detail[:tag], ...
[ "def", "add_repo", "(", "repo_sha", ",", "repo_detail", ",", "cookbook_positions", ")", "@repositories", "||=", "{", "}", "@repositories", "[", "repo_sha", "]", "=", "DevRepository", ".", "new", "(", "repo_detail", "[", ":repo_type", "]", ",", "repo_detail", "...
Add a repository... === Parameters (Hash):: collection of repos to be checked out on the instance :repo_sha (String):: the hash id (SHA) of the repository :repo_detail (Hash):: info needed to checkout this repo { <Symbol> Type of repository: one of :git, :svn, :download or :local * :git denotes a 'g...
[ "Add", "a", "repository", "..." ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/core_payload_types/dev_repositories.rb#L79-L90
train
rightscale/right_agent
lib/right_agent/command/agent_manager_commands.rb
RightScale.AgentManagerCommands.list_command
def list_command(opts) usage = "Agent exposes the following commands:\n" COMMANDS.reject { |k, _| k == :list || k.to_s =~ /test/ }.each do |c| c.each { |k, v| usage += " - #{k.to_s}: #{v}\n" } end CommandIO.instance.reply(opts[:conn], usage) end
ruby
def list_command(opts) usage = "Agent exposes the following commands:\n" COMMANDS.reject { |k, _| k == :list || k.to_s =~ /test/ }.each do |c| c.each { |k, v| usage += " - #{k.to_s}: #{v}\n" } end CommandIO.instance.reply(opts[:conn], usage) end
[ "def", "list_command", "(", "opts", ")", "usage", "=", "\"Agent exposes the following commands:\\n\"", "COMMANDS", ".", "reject", "{", "|", "k", ",", "_", "|", "k", "==", ":list", "||", "k", ".", "to_s", "=~", "/", "/", "}", ".", "each", "do", "|", "c"...
List command implementation === Parameters opts(Hash):: Should contain the connection for sending data === Return true:: Always return true
[ "List", "command", "implementation" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/command/agent_manager_commands.rb#L73-L79
train
rightscale/right_agent
lib/right_agent/command/agent_manager_commands.rb
RightScale.AgentManagerCommands.set_log_level_command
def set_log_level_command(opts) Log.level = opts[:level] if [ :debug, :info, :warn, :error, :fatal ].include?(opts[:level]) CommandIO.instance.reply(opts[:conn], Log.level) end
ruby
def set_log_level_command(opts) Log.level = opts[:level] if [ :debug, :info, :warn, :error, :fatal ].include?(opts[:level]) CommandIO.instance.reply(opts[:conn], Log.level) end
[ "def", "set_log_level_command", "(", "opts", ")", "Log", ".", "level", "=", "opts", "[", ":level", "]", "if", "[", ":debug", ",", ":info", ",", ":warn", ",", ":error", ",", ":fatal", "]", ".", "include?", "(", "opts", "[", ":level", "]", ")", "Comman...
Set log level command === Return true:: Always return true
[ "Set", "log", "level", "command" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/command/agent_manager_commands.rb#L85-L88
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.send_push
def send_push(type, payload = nil, target = nil, options = {}, &callback) build_and_send_packet(:send_push, type, payload, target, options, &callback) end
ruby
def send_push(type, payload = nil, target = nil, options = {}, &callback) build_and_send_packet(:send_push, type, payload, target, options, &callback) end
[ "def", "send_push", "(", "type", ",", "payload", "=", "nil", ",", "target", "=", "nil", ",", "options", "=", "{", "}", ",", "&", "callback", ")", "build_and_send_packet", "(", ":send_push", ",", "type", ",", "payload", ",", "target", ",", "options", ",...
Send a request to a single target or multiple targets with no response expected other than routing failures Persist the request en route to reduce the chance of it being lost at the expense of some additional network overhead Enqueue the request if the target is not currently available Never automatically retry th...
[ "Send", "a", "request", "to", "a", "single", "target", "or", "multiple", "targets", "with", "no", "response", "expected", "other", "than", "routing", "failures", "Persist", "the", "request", "en", "route", "to", "reduce", "the", "chance", "of", "it", "being"...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L207-L209
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.send_request
def send_request(type, payload = nil, target = nil, options = {}, &callback) raise ArgumentError, "Missing block for response callback" unless callback build_and_send_packet(:send_request, type, payload, target, options, &callback) end
ruby
def send_request(type, payload = nil, target = nil, options = {}, &callback) raise ArgumentError, "Missing block for response callback" unless callback build_and_send_packet(:send_request, type, payload, target, options, &callback) end
[ "def", "send_request", "(", "type", ",", "payload", "=", "nil", ",", "target", "=", "nil", ",", "options", "=", "{", "}", ",", "&", "callback", ")", "raise", "ArgumentError", ",", "\"Missing block for response callback\"", "unless", "callback", "build_and_send_p...
Send a request to a single target with a response expected Automatically retry the request if a response is not received in a reasonable amount of time or if there is a non-delivery response indicating the target is not currently available Timeout the request if a response is not received in time, typically configur...
[ "Send", "a", "request", "to", "a", "single", "target", "with", "a", "response", "expected", "Automatically", "retry", "the", "request", "if", "a", "response", "is", "not", "received", "in", "a", "reasonable", "amount", "of", "time", "or", "if", "there", "i...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L248-L251
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.build_and_send_packet
def build_and_send_packet(kind, type, payload, target, options = {}, &callback) if (packet = build_packet(kind, type, payload, target, options, &callback)) action = type.split('/').last received_at = @request_stats.update(action, packet.token) @request_kind_stats.update((packet.selector ==...
ruby
def build_and_send_packet(kind, type, payload, target, options = {}, &callback) if (packet = build_packet(kind, type, payload, target, options, &callback)) action = type.split('/').last received_at = @request_stats.update(action, packet.token) @request_kind_stats.update((packet.selector ==...
[ "def", "build_and_send_packet", "(", "kind", ",", "type", ",", "payload", ",", "target", ",", "options", "=", "{", "}", ",", "&", "callback", ")", "if", "(", "packet", "=", "build_packet", "(", "kind", ",", "type", ",", "payload", ",", "target", ",", ...
Build and send packet === Parameters kind(Symbol):: Kind of request: :send_push or :send_request type(String):: Dispatch route for the request; typically identifies actor and action payload(Object):: Data to be sent with marshalling en route target(Hash|NilClass):: Target for request :agent_id(String):: Identi...
[ "Build", "and", "send", "packet" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L282-L290
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.build_packet
def build_packet(kind, type, payload, target, options = {}, &callback) validate_target(target, kind == :send_push) if kind == :send_push packet = Push.new(type, payload) packet.selector = target[:selector] || :any if target.is_a?(Hash) packet.persistent = true packet.confirm ...
ruby
def build_packet(kind, type, payload, target, options = {}, &callback) validate_target(target, kind == :send_push) if kind == :send_push packet = Push.new(type, payload) packet.selector = target[:selector] || :any if target.is_a?(Hash) packet.persistent = true packet.confirm ...
[ "def", "build_packet", "(", "kind", ",", "type", ",", "payload", ",", "target", ",", "options", "=", "{", "}", ",", "&", "callback", ")", "validate_target", "(", "target", ",", "kind", "==", ":send_push", ")", "if", "kind", "==", ":send_push", "packet", ...
Build packet or queue it if offline === Parameters kind(Symbol):: Kind of request: :send_push or :send_request type(String):: Dispatch route for the request; typically identifies actor and action payload(Object):: Data to be sent with marshalling en route target(Hash|NilClass):: Target for request :agent_id(St...
[ "Build", "packet", "or", "queue", "it", "if", "offline" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L321-L354
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.handle_response
def handle_response(response) if response.is_a?(Result) token = response.token if (result = OperationResult.from_results(response)) if result.non_delivery? @non_delivery_stats.update(result.content.nil? ? "nil" : result.content) elsif result.error? @resu...
ruby
def handle_response(response) if response.is_a?(Result) token = response.token if (result = OperationResult.from_results(response)) if result.non_delivery? @non_delivery_stats.update(result.content.nil? ? "nil" : result.content) elsif result.error? @resu...
[ "def", "handle_response", "(", "response", ")", "if", "response", ".", "is_a?", "(", "Result", ")", "token", "=", "response", ".", "token", "if", "(", "result", "=", "OperationResult", ".", "from_results", "(", "response", ")", ")", "if", "result", ".", ...
Handle response to a request === Parameters response(Result):: Packet received as result of request === Return true:: Always return true
[ "Handle", "response", "to", "a", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L363-L405
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.terminate
def terminate if @offline_handler @offline_handler.terminate @connectivity_checker.terminate if @connectivity_checker pending = @pending_requests.kind(:send_request) [pending.size, PendingRequests.youngest_age(pending)] else [0, nil] end end
ruby
def terminate if @offline_handler @offline_handler.terminate @connectivity_checker.terminate if @connectivity_checker pending = @pending_requests.kind(:send_request) [pending.size, PendingRequests.youngest_age(pending)] else [0, nil] end end
[ "def", "terminate", "if", "@offline_handler", "@offline_handler", ".", "terminate", "@connectivity_checker", ".", "terminate", "if", "@connectivity_checker", "pending", "=", "@pending_requests", ".", "kind", "(", ":send_request", ")", "[", "pending", ".", "size", ",",...
Take any actions necessary to quiesce client interaction in preparation for agent termination but allow message receipt to continue === Return (Array):: Number of pending non-push requests and age of youngest request
[ "Take", "any", "actions", "necessary", "to", "quiesce", "client", "interaction", "in", "preparation", "for", "agent", "termination", "but", "allow", "message", "receipt", "to", "continue" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L412-L421
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.dump_requests
def dump_requests info = [] if @pending_requests @pending_requests.kind(:send_request).each do |token, request| info << "#{request.receive_time.localtime} <#{token}>" end info.sort!.reverse! info = info[0..49] + ["..."] if info.size > 50 end info end
ruby
def dump_requests info = [] if @pending_requests @pending_requests.kind(:send_request).each do |token, request| info << "#{request.receive_time.localtime} <#{token}>" end info.sort!.reverse! info = info[0..49] + ["..."] if info.size > 50 end info end
[ "def", "dump_requests", "info", "=", "[", "]", "if", "@pending_requests", "@pending_requests", ".", "kind", "(", ":send_request", ")", ".", "each", "do", "|", "token", ",", "request", "|", "info", "<<", "\"#{request.receive_time.localtime} <#{token}>\"", "end", "i...
Create displayable dump of unfinished non-push request information Truncate list if there are more than 50 requests === Return info(Array(String)):: Receive time and token for each request in descending time order
[ "Create", "displayable", "dump", "of", "unfinished", "non", "-", "push", "request", "information", "Truncate", "list", "if", "there", "are", "more", "than", "50", "requests" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L428-L438
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.stats
def stats(reset = false) stats = {} if @agent offlines = @offline_stats.all offlines.merge!("duration" => @offline_stats.avg_duration) if offlines if @pending_requests.size > 0 pending = {} pending["pushes"] = @pending_requests.kind(:send_push).size requ...
ruby
def stats(reset = false) stats = {} if @agent offlines = @offline_stats.all offlines.merge!("duration" => @offline_stats.avg_duration) if offlines if @pending_requests.size > 0 pending = {} pending["pushes"] = @pending_requests.kind(:send_push).size requ...
[ "def", "stats", "(", "reset", "=", "false", ")", "stats", "=", "{", "}", "if", "@agent", "offlines", "=", "@offline_stats", ".", "all", "offlines", ".", "merge!", "(", "\"duration\"", "=>", "@offline_stats", ".", "avg_duration", ")", "if", "offlines", "if"...
Get sender statistics === Parameters reset(Boolean):: Whether to reset the statistics after getting the current ones === Return stats(Hash):: Current statistics: "non-deliveries"(Hash|nil):: Non-delivery activity stats with keys "total", "percent", "last", and 'rate' with percentage breakdown per reason, ...
[ "Get", "sender", "statistics" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L467-L495
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.reset_stats
def reset_stats @ping_stats = RightSupport::Stats::Activity.new @retry_stats = RightSupport::Stats::Activity.new @request_stats = RightSupport::Stats::Activity.new @result_stats = RightSupport::Stats::Activity.new @result_error_stats = RightSupport::Stats::Activity.new @non_delivery_...
ruby
def reset_stats @ping_stats = RightSupport::Stats::Activity.new @retry_stats = RightSupport::Stats::Activity.new @request_stats = RightSupport::Stats::Activity.new @result_stats = RightSupport::Stats::Activity.new @result_error_stats = RightSupport::Stats::Activity.new @non_delivery_...
[ "def", "reset_stats", "@ping_stats", "=", "RightSupport", "::", "Stats", "::", "Activity", ".", "new", "@retry_stats", "=", "RightSupport", "::", "Stats", "::", "Activity", ".", "new", "@request_stats", "=", "RightSupport", "::", "Stats", "::", "Activity", ".", ...
Reset dispatch statistics === Return true:: Always return true
[ "Reset", "dispatch", "statistics" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L503-L514
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.http_send
def http_send(kind, target, packet, received_at, &callback) if @options[:async_response] EM_S.next_tick do begin http_send_once(kind, target, packet, received_at, &callback) rescue StandardError => e ErrorTracker.log(self, "Failed sending or handling response fo...
ruby
def http_send(kind, target, packet, received_at, &callback) if @options[:async_response] EM_S.next_tick do begin http_send_once(kind, target, packet, received_at, &callback) rescue StandardError => e ErrorTracker.log(self, "Failed sending or handling response fo...
[ "def", "http_send", "(", "kind", ",", "target", ",", "packet", ",", "received_at", ",", "&", "callback", ")", "if", "@options", "[", ":async_response", "]", "EM_S", ".", "next_tick", "do", "begin", "http_send_once", "(", "kind", ",", "target", ",", "packet...
Send request via HTTP Use next_tick for asynchronous response and to ensure that the request is sent using the main EM reactor thread === Parameters kind(Symbol):: Kind of request: :send_push or :send_request target(Hash|NilClass):: Target for request packet(Push|Request):: Request packet to send received_at(Ti...
[ "Send", "request", "via", "HTTP", "Use", "next_tick", "for", "asynchronous", "response", "and", "to", "ensure", "that", "the", "request", "is", "sent", "using", "the", "main", "EM", "reactor", "thread" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L601-L614
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.http_send_once
def http_send_once(kind, target, packet, received_at, &callback) begin method = packet.class.name.split("::").last.downcase options = {:request_uuid => packet.token} options[:time_to_live] = (packet.expires_at - Time.now.to_i) if packet.expires_at > 0 result = success_result(@agent...
ruby
def http_send_once(kind, target, packet, received_at, &callback) begin method = packet.class.name.split("::").last.downcase options = {:request_uuid => packet.token} options[:time_to_live] = (packet.expires_at - Time.now.to_i) if packet.expires_at > 0 result = success_result(@agent...
[ "def", "http_send_once", "(", "kind", ",", "target", ",", "packet", ",", "received_at", ",", "&", "callback", ")", "begin", "method", "=", "packet", ".", "class", ".", "name", ".", "split", "(", "\"::\"", ")", ".", "last", ".", "downcase", "options", "...
Send request via HTTP and then immediately handle response === Parameters kind(Symbol):: Kind of request: :send_push or :send_request target(Hash|NilClass):: Target for request packet(Push|Request):: Request packet to send received_at(Time):: Time when request received === Block Optional block used to process ...
[ "Send", "request", "via", "HTTP", "and", "then", "immediately", "handle", "response" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L630-L671
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.amqp_send
def amqp_send(kind, target, packet, received_at, &callback) begin @pending_requests[packet.token] = PendingRequest.new(kind, received_at, callback) if callback if packet.class == Request amqp_send_retry(packet, packet.token) else amqp_send_once(packet) end ...
ruby
def amqp_send(kind, target, packet, received_at, &callback) begin @pending_requests[packet.token] = PendingRequest.new(kind, received_at, callback) if callback if packet.class == Request amqp_send_retry(packet, packet.token) else amqp_send_once(packet) end ...
[ "def", "amqp_send", "(", "kind", ",", "target", ",", "packet", ",", "received_at", ",", "&", "callback", ")", "begin", "@pending_requests", "[", "packet", ".", "token", "]", "=", "PendingRequest", ".", "new", "(", "kind", ",", "received_at", ",", "callback...
Send request via AMQP If lack connectivity and queueing enabled, queue request === Parameters kind(Symbol):: Kind of request: :send_push or :send_request target(Hash|NilClass):: Target for request packet(Push|Request):: Request packet to send received_at(Time):: Time when request received === Block Optional b...
[ "Send", "request", "via", "AMQP", "If", "lack", "connectivity", "and", "queueing", "enabled", "queue", "request" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L688-L712
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.amqp_send_once
def amqp_send_once(packet, ids = nil) exchange = {:type => :fanout, :name => @request_queue, :options => {:durable => true, :no_declare => @secure}} @agent.client.publish(exchange, packet, :persistent => packet.persistent, :mandatory => true, :log_filter => [:tags, :target, :trie...
ruby
def amqp_send_once(packet, ids = nil) exchange = {:type => :fanout, :name => @request_queue, :options => {:durable => true, :no_declare => @secure}} @agent.client.publish(exchange, packet, :persistent => packet.persistent, :mandatory => true, :log_filter => [:tags, :target, :trie...
[ "def", "amqp_send_once", "(", "packet", ",", "ids", "=", "nil", ")", "exchange", "=", "{", ":type", "=>", ":fanout", ",", ":name", "=>", "@request_queue", ",", ":options", "=>", "{", ":durable", "=>", "true", ",", ":no_declare", "=>", "@secure", "}", "}"...
Send request via AMQP without retrying Use mandatory flag to request return of message if it cannot be delivered === Parameters packet(Push|Request):: Request packet to send ids(Array|nil):: Identity of specific brokers to choose from, or nil if any okay === Return (Array):: Identity of brokers to which request...
[ "Send", "request", "via", "AMQP", "without", "retrying", "Use", "mandatory", "flag", "to", "request", "return", "of", "message", "if", "it", "cannot", "be", "delivered" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L728-L740
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.amqp_send_retry
def amqp_send_retry(packet, parent_token, count = 0, multiplier = 1, elapsed = 0, broker_ids = nil) check_broker_ids = amqp_send_once(packet, broker_ids) if @retry_interval && @retry_timeout && parent_token interval = [(@retry_interval * multiplier) + (@request_stats.avg_duration || 0), @retry_time...
ruby
def amqp_send_retry(packet, parent_token, count = 0, multiplier = 1, elapsed = 0, broker_ids = nil) check_broker_ids = amqp_send_once(packet, broker_ids) if @retry_interval && @retry_timeout && parent_token interval = [(@retry_interval * multiplier) + (@request_stats.avg_duration || 0), @retry_time...
[ "def", "amqp_send_retry", "(", "packet", ",", "parent_token", ",", "count", "=", "0", ",", "multiplier", "=", "1", ",", "elapsed", "=", "0", ",", "broker_ids", "=", "nil", ")", "check_broker_ids", "=", "amqp_send_once", "(", "packet", ",", "broker_ids", ")...
Send request via AMQP with one or more retries if do not receive a response in time Send timeout result if reach configured retry timeout limit Use exponential backoff with RETRY_BACKOFF_FACTOR for retry spacing Adjust retry interval by average response time to avoid adding to system load when system gets slow Rot...
[ "Send", "request", "via", "AMQP", "with", "one", "or", "more", "retries", "if", "do", "not", "receive", "a", "response", "in", "time", "Send", "timeout", "result", "if", "reach", "configured", "retry", "timeout", "limit", "Use", "exponential", "backoff", "wi...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L760-L798
train
rightscale/right_agent
lib/right_agent/sender.rb
RightScale.Sender.deliver_response
def deliver_response(response, pending_request) @request_stats.finish(pending_request.receive_time, response.token) @pending_requests.delete(response.token) if pending_request.kind == :send_request if (parent_token = pending_request.retry_parent_token) @pending_requests.reject! { |k, v| k == ...
ruby
def deliver_response(response, pending_request) @request_stats.finish(pending_request.receive_time, response.token) @pending_requests.delete(response.token) if pending_request.kind == :send_request if (parent_token = pending_request.retry_parent_token) @pending_requests.reject! { |k, v| k == ...
[ "def", "deliver_response", "(", "response", ",", "pending_request", ")", "@request_stats", ".", "finish", "(", "pending_request", ".", "receive_time", ",", "response", ".", "token", ")", "@pending_requests", ".", "delete", "(", "response", ".", "token", ")", "if...
Deliver the response and remove associated non-push requests from pending including all associated retry requests === Parameters response(Result):: Packet received as result of request pending_request(Hash):: Associated pending request === Return true:: Always return true
[ "Deliver", "the", "response", "and", "remove", "associated", "non", "-", "push", "requests", "from", "pending", "including", "all", "associated", "retry", "requests" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/sender.rb#L809-L819
train
rightscale/right_agent
lib/right_agent/clients/right_http_client.rb
RightScale.RightHttpClient.init
def init(auth_client, options = {}) raise ArgumentError, "No authorization client provided" unless auth_client.is_a?(AuthClient) @status = {} callback = lambda { |type, state| update_status(type, state) } @auth = auth_client @status[:auth] = @auth.status(&callback) @router = RouterCl...
ruby
def init(auth_client, options = {}) raise ArgumentError, "No authorization client provided" unless auth_client.is_a?(AuthClient) @status = {} callback = lambda { |type, state| update_status(type, state) } @auth = auth_client @status[:auth] = @auth.status(&callback) @router = RouterCl...
[ "def", "init", "(", "auth_client", ",", "options", "=", "{", "}", ")", "raise", "ArgumentError", ",", "\"No authorization client provided\"", "unless", "auth_client", ".", "is_a?", "(", "AuthClient", ")", "@status", "=", "{", "}", "callback", "=", "lambda", "{...
Initialize RightNet client Must be called before any other functions are usable @param [AuthClient] auth_client providing authorization session for HTTP requests @option options [Numeric] :open_timeout maximum wait for connection @option options [Numeric] :request_timeout maximum wait for response @option option...
[ "Initialize", "RightNet", "client", "Must", "be", "called", "before", "any", "other", "functions", "are", "usable" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/right_http_client.rb#L58-L71
train
rightscale/right_agent
lib/right_agent/clients/right_http_client.rb
RightScale.RightHttpClient.push
def push(type, payload = nil, target = nil, options = {}) raise RuntimeError, "#{self.class.name}#init was not called" unless @auth client = (@api && @api.support?(type)) ? @api : @router client.push(type, payload, target, options) end
ruby
def push(type, payload = nil, target = nil, options = {}) raise RuntimeError, "#{self.class.name}#init was not called" unless @auth client = (@api && @api.support?(type)) ? @api : @router client.push(type, payload, target, options) end
[ "def", "push", "(", "type", ",", "payload", "=", "nil", ",", "target", "=", "nil", ",", "options", "=", "{", "}", ")", "raise", "RuntimeError", ",", "\"#{self.class.name}#init was not called\"", "unless", "@auth", "client", "=", "(", "@api", "&&", "@api", ...
Route a request to a single target or multiple targets with no response expected Persist the request en route to reduce the chance of it being lost at the expense of some additional network overhead Enqueue the request if the target is not currently available Never automatically retry the request if there is the po...
[ "Route", "a", "request", "to", "a", "single", "target", "or", "multiple", "targets", "with", "no", "response", "expected", "Persist", "the", "request", "en", "route", "to", "reduce", "the", "chance", "of", "it", "being", "lost", "at", "the", "expense", "of...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/right_http_client.rb#L107-L111
train
rightscale/right_agent
lib/right_agent/clients/right_http_client.rb
RightScale.RightHttpClient.communicated
def communicated(types = [], &callback) raise RuntimeError, "#{self.class.name}#init was not called" unless @auth @auth.communicated(&callback) if types.empty? || types.include?(:auth) @api.communicated(&callback) if @api && (types.empty? || types.include?(:api)) @router.communicated(&callback) ...
ruby
def communicated(types = [], &callback) raise RuntimeError, "#{self.class.name}#init was not called" unless @auth @auth.communicated(&callback) if types.empty? || types.include?(:auth) @api.communicated(&callback) if @api && (types.empty? || types.include?(:api)) @router.communicated(&callback) ...
[ "def", "communicated", "(", "types", "=", "[", "]", ",", "&", "callback", ")", "raise", "RuntimeError", ",", "\"#{self.class.name}#init was not called\"", "unless", "@auth", "@auth", ".", "communicated", "(", "&", "callback", ")", "if", "types", ".", "empty?", ...
Set callback for each successful communication excluding health checks @param [Array] types of server: :auth, :api, or :router; defaults to all @yield [] required block executed after successful communication @return [TrueClass] always true @raise [RuntimeError] init was not called
[ "Set", "callback", "for", "each", "successful", "communication", "excluding", "health", "checks" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/right_http_client.rb#L221-L227
train
rightscale/right_agent
lib/right_agent/enrollment_result.rb
RightScale.EnrollmentResult.to_s
def to_s @serializer.dump({ 'r_s_version' => @r_s_version.to_s, 'timestamp' => @timestamp.to_i.to_s, 'iv' => Base64::encode64(@iv).chop, 'ciphertext' => Base64::encode64(@ciphertext).chop, 'mac' => Base64::encode64(@mac).chop }) end
ruby
def to_s @serializer.dump({ 'r_s_version' => @r_s_version.to_s, 'timestamp' => @timestamp.to_i.to_s, 'iv' => Base64::encode64(@iv).chop, 'ciphertext' => Base64::encode64(@ciphertext).chop, 'mac' => Base64::encode64(@mac).chop }) end
[ "def", "to_s", "@serializer", ".", "dump", "(", "{", "'r_s_version'", "=>", "@r_s_version", ".", "to_s", ",", "'timestamp'", "=>", "@timestamp", ".", "to_i", ".", "to_s", ",", "'iv'", "=>", "Base64", "::", "encode64", "(", "@iv", ")", ".", "chop", ",", ...
Create a new instance of this class === Parameters timestamp(Time):: Timestamp associated with this result router_cert(String):: Arbitrary string id_cert(String):: Arbitrary string id_key(String):: Arbitrary string secret(String):: Shared secret with which the result is encrypted Serialize an enrollment result...
[ "Create", "a", "new", "instance", "of", "this", "class" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/enrollment_result.rb#L76-L84
train
rightscale/right_agent
lib/right_agent/clients/auth_client.rb
RightScale.AuthClient.check_authorized
def check_authorized if state == :expired raise Exceptions::RetryableError, "Authorization expired" elsif state != :authorized raise Exceptions::Unauthorized, "Not authorized with RightScale" if state != :authorized end true end
ruby
def check_authorized if state == :expired raise Exceptions::RetryableError, "Authorization expired" elsif state != :authorized raise Exceptions::Unauthorized, "Not authorized with RightScale" if state != :authorized end true end
[ "def", "check_authorized", "if", "state", "==", ":expired", "raise", "Exceptions", "::", "RetryableError", ",", "\"Authorization expired\"", "elsif", "state", "!=", ":authorized", "raise", "Exceptions", "::", "Unauthorized", ",", "\"Not authorized with RightScale\"", "if"...
Check whether authorized @return [TrueClass] always true if don't raise exception @raise [Exceptions::Unauthorized] not authorized @raise [Exceptions::RetryableError] authorization expired, but retry may succeed
[ "Check", "whether", "authorized" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/auth_client.rb#L201-L208
train
rightscale/right_agent
lib/right_agent/core_payload_types/dev_repository.rb
RightScale.DevRepository.to_scraper_hash
def to_scraper_hash repo = {} repo[:repo_type] = repo_type.to_sym unless repo_type.nil? repo[:url] = url repo[:tag] = tag repo[:resources_path] = cookbooks_path if !ssh_key.nil? repo[:first_credential] = ssh_key elsif...
ruby
def to_scraper_hash repo = {} repo[:repo_type] = repo_type.to_sym unless repo_type.nil? repo[:url] = url repo[:tag] = tag repo[:resources_path] = cookbooks_path if !ssh_key.nil? repo[:first_credential] = ssh_key elsif...
[ "def", "to_scraper_hash", "repo", "=", "{", "}", "repo", "[", ":repo_type", "]", "=", "repo_type", ".", "to_sym", "unless", "repo_type", ".", "nil?", "repo", "[", ":url", "]", "=", "url", "repo", "[", ":tag", "]", "=", "tag", "repo", "[", ":resources_p...
Maps the given DevRepository to a has that can be consumed by the RightScraper gem === Returns (Hash):: :repo_type (Symbol):: Type of repository: one of :git, :svn, :download or :local * :git denotes a 'git' repository that should be retrieved via 'git clone' * :svn denotes a 'svn' repository that shoul...
[ "Maps", "the", "given", "DevRepository", "to", "a", "has", "that", "can", "be", "consumed", "by", "the", "RightScraper", "gem" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/core_payload_types/dev_repository.rb#L93-L106
train
rightscale/right_agent
lib/right_agent/core_payload_types/planned_volume.rb
RightScale.PlannedVolume.is_valid?
def is_valid? result = false == is_blank?(@volume_id) && false == is_blank?(@device_name) && false == is_blank?(@volume_status) && false == is_blank?(@mount_points) && nil == @mount_points.find { |mount_point| is_blank?(mount_point) } return result...
ruby
def is_valid? result = false == is_blank?(@volume_id) && false == is_blank?(@device_name) && false == is_blank?(@volume_status) && false == is_blank?(@mount_points) && nil == @mount_points.find { |mount_point| is_blank?(mount_point) } return result...
[ "def", "is_valid?", "result", "=", "false", "==", "is_blank?", "(", "@volume_id", ")", "&&", "false", "==", "is_blank?", "(", "@device_name", ")", "&&", "false", "==", "is_blank?", "(", "@volume_status", ")", "&&", "false", "==", "is_blank?", "(", "@mount_po...
Determines if this object is valid. === Return result(Boolean):: true if this object is valid, false if required fields are nil or empty
[ "Determines", "if", "this", "object", "is", "valid", "." ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/core_payload_types/planned_volume.rb#L71-L78
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.run
def run Log.init(@identity, @options[:log_path], :print => true) Log.level = @options[:log_level] if @options[:log_level] RightSupport::Log::Mixin.default_logger = Log ErrorTracker.init(self, @options[:agent_name], :shard_id => @options[:shard_id], :trace_level => TRACE_LEVEL, ...
ruby
def run Log.init(@identity, @options[:log_path], :print => true) Log.level = @options[:log_level] if @options[:log_level] RightSupport::Log::Mixin.default_logger = Log ErrorTracker.init(self, @options[:agent_name], :shard_id => @options[:shard_id], :trace_level => TRACE_LEVEL, ...
[ "def", "run", "Log", ".", "init", "(", "@identity", ",", "@options", "[", ":log_path", "]", ",", ":print", "=>", "true", ")", "Log", ".", "level", "=", "@options", "[", ":log_level", "]", "if", "@options", "[", ":log_level", "]", "RightSupport", "::", ...
Initialize the new agent === Parameters opts(Hash):: Configuration options per start method above === Return true:: Always return true Put the agent in service This requires making a RightNet connection via HTTP or AMQP and other initialization like loading actors === Return true:: Always return true
[ "Initialize", "the", "new", "agent" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L196-L248
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.connect
def connect(host, port, index, priority = nil, force = false) @connect_request_stats.update("connect b#{index}") even_if = " even if already connected" if force Log.info("Connecting to broker at host #{host.inspect} port #{port.inspect} " + "index #{index.inspect} priority #{priority.in...
ruby
def connect(host, port, index, priority = nil, force = false) @connect_request_stats.update("connect b#{index}") even_if = " even if already connected" if force Log.info("Connecting to broker at host #{host.inspect} port #{port.inspect} " + "index #{index.inspect} priority #{priority.in...
[ "def", "connect", "(", "host", ",", "port", ",", "index", ",", "priority", "=", "nil", ",", "force", "=", "false", ")", "@connect_request_stats", ".", "update", "(", "\"connect b#{index}\"", ")", "even_if", "=", "\" even if already connected\"", "if", "force", ...
Connect to an additional AMQP broker or reconnect it if connection has failed Subscribe to identity queue on this broker Update config file if this is a new broker Assumes already has credentials on this broker and identity queue exists === Parameters host(String):: Host name of broker port(Integer):: Port numbe...
[ "Connect", "to", "an", "additional", "AMQP", "broker", "or", "reconnect", "it", "if", "connection", "has", "failed", "Subscribe", "to", "identity", "queue", "on", "this", "broker", "Update", "config", "file", "if", "this", "is", "a", "new", "broker", "Assume...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L299-L331
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.disconnect
def disconnect(host, port, remove = false) and_remove = " and removing" if remove Log.info("Disconnecting#{and_remove} broker at host #{host.inspect} port #{port.inspect}") Log.info("Current broker configuration: #{@client.status.inspect}") id = RightAMQP::HABrokerClient.identity(host, port) ...
ruby
def disconnect(host, port, remove = false) and_remove = " and removing" if remove Log.info("Disconnecting#{and_remove} broker at host #{host.inspect} port #{port.inspect}") Log.info("Current broker configuration: #{@client.status.inspect}") id = RightAMQP::HABrokerClient.identity(host, port) ...
[ "def", "disconnect", "(", "host", ",", "port", ",", "remove", "=", "false", ")", "and_remove", "=", "\" and removing\"", "if", "remove", "Log", ".", "info", "(", "\"Disconnecting#{and_remove} broker at host #{host.inspect} port #{port.inspect}\"", ")", "Log", ".", "in...
Disconnect from an AMQP broker and optionally remove it from the configuration Refuse to do so if it is the last connected broker === Parameters host(String):: Host name of broker port(Integer):: Port number of broker remove(Boolean):: Whether to remove broker from configuration rather than just closing it, de...
[ "Disconnect", "from", "an", "AMQP", "broker", "and", "optionally", "remove", "it", "from", "the", "configuration", "Refuse", "to", "do", "so", "if", "it", "is", "the", "last", "connected", "broker" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L344-L373
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.connect_failed
def connect_failed(ids) aliases = @client.aliases(ids).join(", ") @connect_request_stats.update("enroll failed #{aliases}") result = nil begin Log.info("Received indication that service initialization for this agent for brokers #{ids.inspect} has failed") connected = @client.conn...
ruby
def connect_failed(ids) aliases = @client.aliases(ids).join(", ") @connect_request_stats.update("enroll failed #{aliases}") result = nil begin Log.info("Received indication that service initialization for this agent for brokers #{ids.inspect} has failed") connected = @client.conn...
[ "def", "connect_failed", "(", "ids", ")", "aliases", "=", "@client", ".", "aliases", "(", "ids", ")", ".", "join", "(", "\", \"", ")", "@connect_request_stats", ".", "update", "(", "\"enroll failed #{aliases}\"", ")", "result", "=", "nil", "begin", "Log", "....
There were problems while setting up service for this agent on the given AMQP brokers, so mark these brokers as failed if not currently connected and later, during the periodic status check, attempt to reconnect === Parameters ids(Array):: Identity of brokers === Return (String|nil):: Error message if failed, o...
[ "There", "were", "problems", "while", "setting", "up", "service", "for", "this", "agent", "on", "the", "given", "AMQP", "brokers", "so", "mark", "these", "brokers", "as", "failed", "if", "not", "currently", "connected", "and", "later", "during", "the", "peri...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L384-L400
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.terminate
def terminate(reason = nil, exception = nil) begin @history.update("stop") if @history ErrorTracker.log(self, "[stop] Terminating because #{reason}", exception) if reason if exception.is_a?(Exception) h = @history.analyze_service if h[:last_crashed] delay = ...
ruby
def terminate(reason = nil, exception = nil) begin @history.update("stop") if @history ErrorTracker.log(self, "[stop] Terminating because #{reason}", exception) if reason if exception.is_a?(Exception) h = @history.analyze_service if h[:last_crashed] delay = ...
[ "def", "terminate", "(", "reason", "=", "nil", ",", "exception", "=", "nil", ")", "begin", "@history", ".", "update", "(", "\"stop\"", ")", "if", "@history", "ErrorTracker", ".", "log", "(", "self", ",", "\"[stop] Terminating because #{reason}\"", ",", "except...
Gracefully terminate execution by allowing unfinished tasks to complete Immediately terminate if called a second time Report reason for termination if it is abnormal === Parameters reason(String):: Reason for abnormal termination, if any exception(Exception|String):: Exception or other parenthetical error informa...
[ "Gracefully", "terminate", "execution", "by", "allowing", "unfinished", "tasks", "to", "complete", "Immediately", "terminate", "if", "called", "a", "second", "time", "Report", "reason", "for", "termination", "if", "it", "is", "abnormal" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L434-L465
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.stats
def stats(options = {}) now = Time.now reset = options[:reset] stats = { "name" => @agent_name, "identity" => @identity, "hostname" => Socket.gethostname, "memory" => Platform.process.resident_set_size, "version" => Agen...
ruby
def stats(options = {}) now = Time.now reset = options[:reset] stats = { "name" => @agent_name, "identity" => @identity, "hostname" => Socket.gethostname, "memory" => Platform.process.resident_set_size, "version" => Agen...
[ "def", "stats", "(", "options", "=", "{", "}", ")", "now", "=", "Time", ".", "now", "reset", "=", "options", "[", ":reset", "]", "stats", "=", "{", "\"name\"", "=>", "@agent_name", ",", "\"identity\"", "=>", "@identity", ",", "\"hostname\"", "=>", "Soc...
Retrieve statistics about agent operation === Parameters: options(Hash):: Request options: :reset(Boolean):: Whether to reset the statistics after getting the current ones === Return result(OperationResult):: Always returns success
[ "Retrieve", "statistics", "about", "agent", "operation" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L475-L501
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.agent_stats
def agent_stats(reset = false) stats = { "request failures" => @request_failure_stats.all, "response failures" => @response_failure_stats.all }.merge(ErrorTracker.stats(reset)) if @mode != :http stats["connect requests"] = @connect_request_stats.all stats["non-deliveri...
ruby
def agent_stats(reset = false) stats = { "request failures" => @request_failure_stats.all, "response failures" => @response_failure_stats.all }.merge(ErrorTracker.stats(reset)) if @mode != :http stats["connect requests"] = @connect_request_stats.all stats["non-deliveri...
[ "def", "agent_stats", "(", "reset", "=", "false", ")", "stats", "=", "{", "\"request failures\"", "=>", "@request_failure_stats", ".", "all", ",", "\"response failures\"", "=>", "@response_failure_stats", ".", "all", "}", ".", "merge", "(", "ErrorTracker", ".", ...
Get request statistics === Parameters reset(Boolean):: Whether to reset the statistics after getting the current ones === Return stats(Hash):: Current statistics: "connect requests"(Hash|nil):: Stats about requests to update AMQP broker connections with keys "total", "percent", and "last" with percentage ...
[ "Get", "request", "statistics" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L524-L535
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.reset_agent_stats
def reset_agent_stats @connect_request_stats = RightSupport::Stats::Activity.new(measure_rate = false) @non_delivery_stats = RightSupport::Stats::Activity.new @request_failure_stats = RightSupport::Stats::Activity.new @response_failure_stats = RightSupport::Stats::Activity.new true end
ruby
def reset_agent_stats @connect_request_stats = RightSupport::Stats::Activity.new(measure_rate = false) @non_delivery_stats = RightSupport::Stats::Activity.new @request_failure_stats = RightSupport::Stats::Activity.new @response_failure_stats = RightSupport::Stats::Activity.new true end
[ "def", "reset_agent_stats", "@connect_request_stats", "=", "RightSupport", "::", "Stats", "::", "Activity", ".", "new", "(", "measure_rate", "=", "false", ")", "@non_delivery_stats", "=", "RightSupport", "::", "Stats", "::", "Activity", ".", "new", "@request_failure...
Reset agent statistics === Return true:: Always return true
[ "Reset", "agent", "statistics" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L541-L547
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.set_configuration
def set_configuration(opts) @options = DEFAULT_OPTIONS.clone @options.update(opts) AgentConfig.root_dir = @options[:root_dir] AgentConfig.pid_dir = @options[:pid_dir] @options[:log_path] = false if @options[:daemonize] || @options[:log_dir] @options[:log_path] = (@options[:...
ruby
def set_configuration(opts) @options = DEFAULT_OPTIONS.clone @options.update(opts) AgentConfig.root_dir = @options[:root_dir] AgentConfig.pid_dir = @options[:pid_dir] @options[:log_path] = false if @options[:daemonize] || @options[:log_dir] @options[:log_path] = (@options[:...
[ "def", "set_configuration", "(", "opts", ")", "@options", "=", "DEFAULT_OPTIONS", ".", "clone", "@options", ".", "update", "(", "opts", ")", "AgentConfig", ".", "root_dir", "=", "@options", "[", ":root_dir", "]", "AgentConfig", ".", "pid_dir", "=", "@options",...
Set the agent's configuration using the supplied options === Parameters opts(Hash):: Configuration options === Return true:: Always return true
[ "Set", "the", "agent", "s", "configuration", "using", "the", "supplied", "options" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L564-L593
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.handle_event
def handle_event(event) if event.is_a?(Hash) if ["Push", "Request"].include?(event[:type]) # Use next_tick to ensure that on main reactor thread # so that any data access is thread safe EM_S.next_tick do begin if (result = @dispatcher.dispatch(event_...
ruby
def handle_event(event) if event.is_a?(Hash) if ["Push", "Request"].include?(event[:type]) # Use next_tick to ensure that on main reactor thread # so that any data access is thread safe EM_S.next_tick do begin if (result = @dispatcher.dispatch(event_...
[ "def", "handle_event", "(", "event", ")", "if", "event", ".", "is_a?", "(", "Hash", ")", "if", "[", "\"Push\"", ",", "\"Request\"", "]", ".", "include?", "(", "event", "[", ":type", "]", ")", "EM_S", ".", "next_tick", "do", "begin", "if", "(", "resul...
Handle events received by this agent === Parameters event(Hash):: Event received === Return nil:: Always return nil indicating no response since handled separately via notify
[ "Handle", "events", "received", "by", "this", "agent" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L636-L664
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.event_to_packet
def event_to_packet(event) packet = nil case event[:type] when "Push" packet = RightScale::Push.new(event[:path], event[:data], {:from => event[:from], :token => event[:uuid]}) packet.expires_at = event[:expires_at].to_i if event.has_key?(:expires_at) packet.skewed_by = event[:...
ruby
def event_to_packet(event) packet = nil case event[:type] when "Push" packet = RightScale::Push.new(event[:path], event[:data], {:from => event[:from], :token => event[:uuid]}) packet.expires_at = event[:expires_at].to_i if event.has_key?(:expires_at) packet.skewed_by = event[:...
[ "def", "event_to_packet", "(", "event", ")", "packet", "=", "nil", "case", "event", "[", ":type", "]", "when", "\"Push\"", "packet", "=", "RightScale", "::", "Push", ".", "new", "(", "event", "[", ":path", "]", ",", "event", "[", ":data", "]", ",", "...
Convert event hash to packet === Parameters event(Hash):: Event to be converted === Return (Push|Request):: Packet
[ "Convert", "event", "hash", "to", "packet" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L673-L687
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.result_to_event
def result_to_event(result) { :type => "Result", :from => result.from, :data => { :result => result.results, :duration => result.duration, :request_uuid => result.token, :request_from => result.request_from } } end
ruby
def result_to_event(result) { :type => "Result", :from => result.from, :data => { :result => result.results, :duration => result.duration, :request_uuid => result.token, :request_from => result.request_from } } end
[ "def", "result_to_event", "(", "result", ")", "{", ":type", "=>", "\"Result\"", ",", ":from", "=>", "result", ".", "from", ",", ":data", "=>", "{", ":result", "=>", "result", ".", "results", ",", ":duration", "=>", "result", ".", "duration", ",", ":reque...
Convert result packet to event === Parameters result(Result):: Event to be converted === Return (Hash):: Event
[ "Convert", "result", "packet", "to", "event" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L696-L704
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.create_dispatchers
def create_dispatchers cache = DispatchedCache.new(@identity) if @options[:dup_check] @dispatcher = Dispatcher.new(self, cache) @queues.inject({}) { |dispatchers, queue| dispatchers[queue] = @dispatcher; dispatchers } end
ruby
def create_dispatchers cache = DispatchedCache.new(@identity) if @options[:dup_check] @dispatcher = Dispatcher.new(self, cache) @queues.inject({}) { |dispatchers, queue| dispatchers[queue] = @dispatcher; dispatchers } end
[ "def", "create_dispatchers", "cache", "=", "DispatchedCache", ".", "new", "(", "@identity", ")", "if", "@options", "[", ":dup_check", "]", "@dispatcher", "=", "Dispatcher", ".", "new", "(", "self", ",", "cache", ")", "@queues", ".", "inject", "(", "{", "}"...
Create dispatcher per queue for use in handling incoming requests === Return [Hash]:: Dispatchers with queue name as key
[ "Create", "dispatcher", "per", "queue", "for", "use", "in", "handling", "incoming", "requests" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L710-L714
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.load_actors
def load_actors # Load agent's configured actors actors = (@options[:actors] || []).clone Log.info("[setup] Agent #{@identity} with actors #{actors.inspect}") actors_dirs = AgentConfig.actors_dirs actors_dirs.each do |dir| Dir["#{dir}/*.rb"].each do |file| actor = File.ba...
ruby
def load_actors # Load agent's configured actors actors = (@options[:actors] || []).clone Log.info("[setup] Agent #{@identity} with actors #{actors.inspect}") actors_dirs = AgentConfig.actors_dirs actors_dirs.each do |dir| Dir["#{dir}/*.rb"].each do |file| actor = File.ba...
[ "def", "load_actors", "actors", "=", "(", "@options", "[", ":actors", "]", "||", "[", "]", ")", ".", "clone", "Log", ".", "info", "(", "\"[setup] Agent #{@identity} with actors #{actors.inspect}\"", ")", "actors_dirs", "=", "AgentConfig", ".", "actors_dirs", "acto...
Load the ruby code for the actors === Return true:: Always return true
[ "Load", "the", "ruby", "code", "for", "the", "actors" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L728-L752
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.setup_http
def setup_http(auth_client) @auth_client = auth_client if @mode == :http RightHttpClient.init(@auth_client, @options.merge(:retry_enabled => true)) @client = RightHttpClient.instance end true end
ruby
def setup_http(auth_client) @auth_client = auth_client if @mode == :http RightHttpClient.init(@auth_client, @options.merge(:retry_enabled => true)) @client = RightHttpClient.instance end true end
[ "def", "setup_http", "(", "auth_client", ")", "@auth_client", "=", "auth_client", "if", "@mode", "==", ":http", "RightHttpClient", ".", "init", "(", "@auth_client", ",", "@options", ".", "merge", "(", ":retry_enabled", "=>", "true", ")", ")", "@client", "=", ...
Create client for HTTP-based RightNet communication The code loaded with the actors specific to this application is responsible for calling this function === Parameters auth_client(AuthClient):: Authorization client to be used by this agent === Return true:: Always return true
[ "Create", "client", "for", "HTTP", "-", "based", "RightNet", "communication", "The", "code", "loaded", "with", "the", "actors", "specific", "to", "this", "application", "is", "responsible", "for", "calling", "this", "function" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L763-L770
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.setup_status
def setup_status @status = {} if @client if @mode == :http @status = @client.status { |type, state| update_status(type, state) }.dup else @client.connection_status { |state| update_status(:broker, state) } @status[:broker] = :connected @status[:auth] =...
ruby
def setup_status @status = {} if @client if @mode == :http @status = @client.status { |type, state| update_status(type, state) }.dup else @client.connection_status { |state| update_status(:broker, state) } @status[:broker] = :connected @status[:auth] =...
[ "def", "setup_status", "@status", "=", "{", "}", "if", "@client", "if", "@mode", "==", ":http", "@status", "=", "@client", ".", "status", "{", "|", "type", ",", "state", "|", "update_status", "(", "type", ",", "state", ")", "}", ".", "dup", "else", "...
Setup client status collection === Return true:: Always return true
[ "Setup", "client", "status", "collection" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L798-L810
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.setup_non_delivery
def setup_non_delivery @client.non_delivery do |reason, type, token, from, to| begin @non_delivery_stats.update(type) reason = case reason when "NO_ROUTE" then OperationResult::NO_ROUTE_TO_TARGET when "NO_CONSUMERS" then OperationResult::TARGET_NOT_CONNECTED ...
ruby
def setup_non_delivery @client.non_delivery do |reason, type, token, from, to| begin @non_delivery_stats.update(type) reason = case reason when "NO_ROUTE" then OperationResult::NO_ROUTE_TO_TARGET when "NO_CONSUMERS" then OperationResult::TARGET_NOT_CONNECTED ...
[ "def", "setup_non_delivery", "@client", ".", "non_delivery", "do", "|", "reason", ",", "type", ",", "token", ",", "from", ",", "to", "|", "begin", "@non_delivery_stats", ".", "update", "(", "type", ")", "reason", "=", "case", "reason", "when", "\"NO_ROUTE\""...
Setup non-delivery handler === Return true:: Always return true
[ "Setup", "non", "-", "delivery", "handler" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L816-L831
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.setup_queue
def setup_queue(name, ids = nil) queue = {:name => name, :options => {:durable => true, :no_declare => @options[:secure]}} filter = [:from, :tags, :tries, :persistent] options = {:ack => true, Push => filter, Request => filter, Result => [:from], :brokers => ids} @client.subscribe(queue, nil, op...
ruby
def setup_queue(name, ids = nil) queue = {:name => name, :options => {:durable => true, :no_declare => @options[:secure]}} filter = [:from, :tags, :tries, :persistent] options = {:ack => true, Push => filter, Request => filter, Result => [:from], :brokers => ids} @client.subscribe(queue, nil, op...
[ "def", "setup_queue", "(", "name", ",", "ids", "=", "nil", ")", "queue", "=", "{", ":name", "=>", "name", ",", ":options", "=>", "{", ":durable", "=>", "true", ",", ":no_declare", "=>", "@options", "[", ":secure", "]", "}", "}", "filter", "=", "[", ...
Setup queue for this agent === Parameters name(String):: Queue name ids(Array):: Identity of brokers for which to subscribe, defaults to all usable === Return (Array):: Identity of brokers to which subscribe submitted (although may still fail)
[ "Setup", "queue", "for", "this", "agent" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L854-L859
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.handle_packet
def handle_packet(queue, packet, header) begin # Continue to dispatch/ack requests even when terminating otherwise will block results # Ideally would reject requests when terminating but broker client does not yet support that case packet when Push, Request then dispatch_request(pa...
ruby
def handle_packet(queue, packet, header) begin # Continue to dispatch/ack requests even when terminating otherwise will block results # Ideally would reject requests when terminating but broker client does not yet support that case packet when Push, Request then dispatch_request(pa...
[ "def", "handle_packet", "(", "queue", ",", "packet", ",", "header", ")", "begin", "case", "packet", "when", "Push", ",", "Request", "then", "dispatch_request", "(", "packet", ",", "queue", ")", "when", "Result", "then", "deliver_response", "(", "packet", ")"...
Handle packet from queue === Parameters queue(String):: Name of queue from which message was received packet(Packet):: Packet received header(AMQP::Frame::Header):: Packet header containing ack control === Return true:: Always return true
[ "Handle", "packet", "from", "queue" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L870-L887
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.dispatch_request
def dispatch_request(request, queue) begin if (dispatcher = @dispatchers[queue]) if (result = dispatcher.dispatch(request)) exchange = {:type => :queue, :name => request.reply_to, :options => {:durable => true, :no_declare => @options[:secure]}} @client.publish(exchange, ...
ruby
def dispatch_request(request, queue) begin if (dispatcher = @dispatchers[queue]) if (result = dispatcher.dispatch(request)) exchange = {:type => :queue, :name => request.reply_to, :options => {:durable => true, :no_declare => @options[:secure]}} @client.publish(exchange, ...
[ "def", "dispatch_request", "(", "request", ",", "queue", ")", "begin", "if", "(", "dispatcher", "=", "@dispatchers", "[", "queue", "]", ")", "if", "(", "result", "=", "dispatcher", ".", "dispatch", "(", "request", ")", ")", "exchange", "=", "{", ":type",...
Dispatch request and then send response if any === Parameters request(Push|Request):: Packet containing request queue(String):: Name of queue from which message was received === Return true:: Always return true
[ "Dispatch", "request", "and", "then", "send", "response", "if", "any" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L897-L917
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.deliver_response
def deliver_response(result) begin @sender.handle_response(result) rescue StandardError => e ErrorTracker.log(self, "Failed to deliver response #{result.trace}", e) @response_failure_stats.update(e.class.name) end true end
ruby
def deliver_response(result) begin @sender.handle_response(result) rescue StandardError => e ErrorTracker.log(self, "Failed to deliver response #{result.trace}", e) @response_failure_stats.update(e.class.name) end true end
[ "def", "deliver_response", "(", "result", ")", "begin", "@sender", ".", "handle_response", "(", "result", ")", "rescue", "StandardError", "=>", "e", "ErrorTracker", ".", "log", "(", "self", ",", "\"Failed to deliver response #{result.trace}\"", ",", "e", ")", "@re...
Deliver response to request sender === Parameters result(Result):: Packet containing response === Return true:: Always return true
[ "Deliver", "response", "to", "request", "sender" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L926-L934
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.finish_setup
def finish_setup @client.failed.each do |id| p = {:agent_identity => @identity} p[:host], p[:port], p[:id], p[:priority] = @client.identity_parts(id) @sender.send_push("/registrar/connect", p) end true end
ruby
def finish_setup @client.failed.each do |id| p = {:agent_identity => @identity} p[:host], p[:port], p[:id], p[:priority] = @client.identity_parts(id) @sender.send_push("/registrar/connect", p) end true end
[ "def", "finish_setup", "@client", ".", "failed", ".", "each", "do", "|", "id", "|", "p", "=", "{", ":agent_identity", "=>", "@identity", "}", "p", "[", ":host", "]", ",", "p", "[", ":port", "]", ",", "p", "[", ":id", "]", ",", "p", "[", ":priorit...
Finish any remaining agent setup === Return true:: Always return true
[ "Finish", "any", "remaining", "agent", "setup" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L940-L947
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.publish_stats
def publish_stats s = stats({}).content if @mode == :http @client.notify({:type => "Stats", :from => @identity, :data => s}, nil) else exchange = {:type => :topic, :name => "stats", :options => {:no_declare => true}} @client.publish(exchange, Stats.new(s, @identity), :no_log =>...
ruby
def publish_stats s = stats({}).content if @mode == :http @client.notify({:type => "Stats", :from => @identity, :data => s}, nil) else exchange = {:type => :topic, :name => "stats", :options => {:no_declare => true}} @client.publish(exchange, Stats.new(s, @identity), :no_log =>...
[ "def", "publish_stats", "s", "=", "stats", "(", "{", "}", ")", ".", "content", "if", "@mode", "==", ":http", "@client", ".", "notify", "(", "{", ":type", "=>", "\"Stats\"", ",", ":from", "=>", "@identity", ",", ":data", "=>", "s", "}", ",", "nil", ...
Publish current stats === Return true:: Always return true
[ "Publish", "current", "stats" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L1035-L1045
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.stop_gracefully
def stop_gracefully(timeout) if @mode == :http @client.close else @client.unusable.each { |id| @client.close_one(id, propagate = false) } end finish_terminating(timeout) end
ruby
def stop_gracefully(timeout) if @mode == :http @client.close else @client.unusable.each { |id| @client.close_one(id, propagate = false) } end finish_terminating(timeout) end
[ "def", "stop_gracefully", "(", "timeout", ")", "if", "@mode", "==", ":http", "@client", ".", "close", "else", "@client", ".", "unusable", ".", "each", "{", "|", "id", "|", "@client", ".", "close_one", "(", "id", ",", "propagate", "=", "false", ")", "}"...
Gracefully stop processing Close clients except for authorization === Parameters timeout(Integer):: Maximum number of seconds to wait after last request received before terminating regardless of whether there are still unfinished requests === Return true:: Always return true
[ "Gracefully", "stop", "processing", "Close", "clients", "except", "for", "authorization" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L1079-L1086
train
rightscale/right_agent
lib/right_agent/agent.rb
RightScale.Agent.finish_terminating
def finish_terminating(timeout) if @sender request_count, request_age = @sender.terminate finish = lambda do request_count, request_age = @sender.terminate Log.info("[stop] The following #{request_count} requests initiated as recently as #{request_age} " + "...
ruby
def finish_terminating(timeout) if @sender request_count, request_age = @sender.terminate finish = lambda do request_count, request_age = @sender.terminate Log.info("[stop] The following #{request_count} requests initiated as recently as #{request_age} " + "...
[ "def", "finish_terminating", "(", "timeout", ")", "if", "@sender", "request_count", ",", "request_age", "=", "@sender", ".", "terminate", "finish", "=", "lambda", "do", "request_count", ",", "request_age", "=", "@sender", ".", "terminate", "Log", ".", "info", ...
Finish termination after all requests have been processed === Parameters timeout(Integer):: Maximum number of seconds to wait after last request received before terminating regardless of whether there are still unfinished requests === Return true:: Always return true
[ "Finish", "termination", "after", "all", "requests", "have", "been", "processed" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/agent.rb#L1096-L1131
train
rightscale/right_agent
lib/right_agent/command/command_client.rb
RightScale.CommandClient.send_command
def send_command(options, verbose=false, timeout=20, &handler) return if @closing @last_timeout = timeout manage_em = !EM.reactor_running? response_handler = lambda do EM.stop if manage_em handler.call(@response) if handler && @response @pending -= 1 @close_handle...
ruby
def send_command(options, verbose=false, timeout=20, &handler) return if @closing @last_timeout = timeout manage_em = !EM.reactor_running? response_handler = lambda do EM.stop if manage_em handler.call(@response) if handler && @response @pending -= 1 @close_handle...
[ "def", "send_command", "(", "options", ",", "verbose", "=", "false", ",", "timeout", "=", "20", ",", "&", "handler", ")", "return", "if", "@closing", "@last_timeout", "=", "timeout", "manage_em", "=", "!", "EM", ".", "reactor_running?", "response_handler", "...
Send command to running agent === Parameters options(Hash):: Hash of options and command name options[:name]:: Command name options[:...]:: Other command specific options, passed through to agent verbose(Boolean):: Whether client should display debug info timeout(Integer):: Number of seconds we should wait f...
[ "Send", "command", "to", "running", "agent" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/command/command_client.rb#L71-L96
train
rightscale/right_agent
lib/right_agent/pid_file.rb
RightScale.PidFile.check
def check if pid = read_pid[:pid] if process_running?(pid) raise AlreadyRunning.new("#{@pid_file} already exists and process is running (pid: #{pid})") else Log.info("Removing stale pid file: #{@pid_file}") remove end end true end
ruby
def check if pid = read_pid[:pid] if process_running?(pid) raise AlreadyRunning.new("#{@pid_file} already exists and process is running (pid: #{pid})") else Log.info("Removing stale pid file: #{@pid_file}") remove end end true end
[ "def", "check", "if", "pid", "=", "read_pid", "[", ":pid", "]", "if", "process_running?", "(", "pid", ")", "raise", "AlreadyRunning", ".", "new", "(", "\"#{@pid_file} already exists and process is running (pid: #{pid})\"", ")", "else", "Log", ".", "info", "(", "\"...
Initialize pid file location from agent identity and pid directory Check whether pid file can be created Delete any existing pid file if process is not running anymore === Return true:: Always return true === Raise AlreadyRunning:: If pid file already exists and process is running
[ "Initialize", "pid", "file", "location", "from", "agent", "identity", "and", "pid", "directory", "Check", "whether", "pid", "file", "can", "be", "created", "Delete", "any", "existing", "pid", "file", "if", "process", "is", "not", "running", "anymore" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/pid_file.rb#L54-L64
train
rightscale/right_agent
lib/right_agent/pid_file.rb
RightScale.PidFile.write
def write begin FileUtils.mkdir_p(@pid_dir) open(@pid_file,'w') { |f| f.write(Process.pid) } File.chmod(0644, @pid_file) rescue StandardError => e ErrorTracker.log(self, "Failed to create PID file", e, nil, :caller) raise end true end
ruby
def write begin FileUtils.mkdir_p(@pid_dir) open(@pid_file,'w') { |f| f.write(Process.pid) } File.chmod(0644, @pid_file) rescue StandardError => e ErrorTracker.log(self, "Failed to create PID file", e, nil, :caller) raise end true end
[ "def", "write", "begin", "FileUtils", ".", "mkdir_p", "(", "@pid_dir", ")", "open", "(", "@pid_file", ",", "'w'", ")", "{", "|", "f", "|", "f", ".", "write", "(", "Process", ".", "pid", ")", "}", "File", ".", "chmod", "(", "0644", ",", "@pid_file",...
Write pid to pid file === Return true:: Always return true
[ "Write", "pid", "to", "pid", "file" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/pid_file.rb#L70-L80
train
rightscale/right_agent
lib/right_agent/pid_file.rb
RightScale.PidFile.set_command_options
def set_command_options(options) content = { :listen_port => options[:listen_port], :cookie => options[:cookie] } # This is requried to preserve cookie value to be saved as string, # and not as escaped binary data content[:cookie].force_encoding('utf-8') open(@cookie_file,'w') { |f| f.writ...
ruby
def set_command_options(options) content = { :listen_port => options[:listen_port], :cookie => options[:cookie] } # This is requried to preserve cookie value to be saved as string, # and not as escaped binary data content[:cookie].force_encoding('utf-8') open(@cookie_file,'w') { |f| f.writ...
[ "def", "set_command_options", "(", "options", ")", "content", "=", "{", ":listen_port", "=>", "options", "[", ":listen_port", "]", ",", ":cookie", "=>", "options", "[", ":cookie", "]", "}", "content", "[", ":cookie", "]", ".", "force_encoding", "(", "'utf-8'...
Update associated command protocol port === Parameters options[:listen_port](Integer):: Command protocol port to be used for this agent options[:cookie](String):: Cookie to be used together with command protocol === Return true:: Always return true
[ "Update", "associated", "command", "protocol", "port" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/pid_file.rb#L90-L98
train
rightscale/right_agent
lib/right_agent/pid_file.rb
RightScale.PidFile.read_pid
def read_pid content = {} if exists? open(@pid_file,'r') { |f| content[:pid] = f.read.to_i } open(@cookie_file,'r') do |f| command_options = (YAML.load(f.read) rescue {}) || {} content.merge!(command_options) end if File.readable?(@cookie_file) end con...
ruby
def read_pid content = {} if exists? open(@pid_file,'r') { |f| content[:pid] = f.read.to_i } open(@cookie_file,'r') do |f| command_options = (YAML.load(f.read) rescue {}) || {} content.merge!(command_options) end if File.readable?(@cookie_file) end con...
[ "def", "read_pid", "content", "=", "{", "}", "if", "exists?", "open", "(", "@pid_file", ",", "'r'", ")", "{", "|", "f", "|", "content", "[", ":pid", "]", "=", "f", ".", "read", ".", "to_i", "}", "open", "(", "@cookie_file", ",", "'r'", ")", "do",...
Read pid file content Empty hash if pid file does not exist or content cannot be loaded === Return content(Hash):: Hash containing 3 keys :pid, :cookie and :port
[ "Read", "pid", "file", "content", "Empty", "hash", "if", "pid", "file", "does", "not", "exist", "or", "content", "cannot", "be", "loaded" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/pid_file.rb#L115-L125
train
rightscale/right_agent
lib/right_agent/packets.rb
RightScale.Packet.to_msgpack
def to_msgpack(*a) msg = { 'msgpack_class' => self.class.name, 'data' => instance_variables.inject({}) do |m, ivar| name = ivar.to_s.sub(/@/, '') m[name] = instance_variable_get(ivar) unless NOT_SERIALIZED.include?(name) ...
ruby
def to_msgpack(*a) msg = { 'msgpack_class' => self.class.name, 'data' => instance_variables.inject({}) do |m, ivar| name = ivar.to_s.sub(/@/, '') m[name] = instance_variable_get(ivar) unless NOT_SERIALIZED.include?(name) ...
[ "def", "to_msgpack", "(", "*", "a", ")", "msg", "=", "{", "'msgpack_class'", "=>", "self", ".", "class", ".", "name", ",", "'data'", "=>", "instance_variables", ".", "inject", "(", "{", "}", ")", "do", "|", "m", ",", "ivar", "|", "name", "=", "ivar...
Marshal packet into MessagePack format === Parameters a(Array):: Arguments === Return msg(String):: Marshalled packet
[ "Marshal", "packet", "into", "MessagePack", "format" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/packets.rb#L102-L116
train
rightscale/right_agent
lib/right_agent/packets.rb
RightScale.Packet.to_json
def to_json(*a) # Hack to override RightScale namespace with Nanite for downward compatibility class_name = self.class.name if class_name =~ /^RightScale::(.*)/ class_name = "Nanite::" + Regexp.last_match(1) end js = { 'json_class' => class_name, 'data' => in...
ruby
def to_json(*a) # Hack to override RightScale namespace with Nanite for downward compatibility class_name = self.class.name if class_name =~ /^RightScale::(.*)/ class_name = "Nanite::" + Regexp.last_match(1) end js = { 'json_class' => class_name, 'data' => in...
[ "def", "to_json", "(", "*", "a", ")", "class_name", "=", "self", ".", "class", ".", "name", "if", "class_name", "=~", "/", "/", "class_name", "=", "\"Nanite::\"", "+", "Regexp", ".", "last_match", "(", "1", ")", "end", "js", "=", "{", "'json_class'", ...
Marshal packet into JSON format === Parameters a(Array):: Arguments === Return js(String):: Marshalled packet
[ "Marshal", "packet", "into", "JSON", "format" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/packets.rb#L125-L142
train
rightscale/right_agent
lib/right_agent/packets.rb
RightScale.Packet.enough_precision
def enough_precision(value) scale = [1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0] enough = lambda { |v| (v >= 10.0 ? 0 : (v >= 1.0 ? 1 : (v >= 0.1 ? 2 : (v >= 0.01 ? 3 : (v > 0.001 ? 4...
ruby
def enough_precision(value) scale = [1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0] enough = lambda { |v| (v >= 10.0 ? 0 : (v >= 1.0 ? 1 : (v >= 0.1 ? 2 : (v >= 0.01 ? 3 : (v > 0.001 ? 4...
[ "def", "enough_precision", "(", "value", ")", "scale", "=", "[", "1.0", ",", "10.0", ",", "100.0", ",", "1000.0", ",", "10000.0", ",", "100000.0", "]", "enough", "=", "lambda", "{", "|", "v", "|", "(", "v", ">=", "10.0", "?", "0", ":", "(", "v", ...
Determine enough precision for floating point value to give at least two significant digits and then convert the value to a decimal digit string of that precision === Parameters value(Float):: Value to be converted === Return (String):: Floating point digit string
[ "Determine", "enough", "precision", "for", "floating", "point", "value", "to", "give", "at", "least", "two", "significant", "digits", "and", "then", "convert", "the", "value", "to", "a", "decimal", "digit", "string", "of", "that", "precision" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/packets.rb#L181-L191
train
rightscale/right_agent
lib/right_agent/packets.rb
RightScale.Packet.ids_to_s
def ids_to_s(ids) if ids.is_a?(Array) s = ids.each { |i| id_to_s(i) }.join(', ') s.size > 1000 ? "[#{s[0, 1000]}...]" : "[#{s}]" else id_to_s(ids) end end
ruby
def ids_to_s(ids) if ids.is_a?(Array) s = ids.each { |i| id_to_s(i) }.join(', ') s.size > 1000 ? "[#{s[0, 1000]}...]" : "[#{s}]" else id_to_s(ids) end end
[ "def", "ids_to_s", "(", "ids", ")", "if", "ids", ".", "is_a?", "(", "Array", ")", "s", "=", "ids", ".", "each", "{", "|", "i", "|", "id_to_s", "(", "i", ")", "}", ".", "join", "(", "', '", ")", "s", ".", "size", ">", "1000", "?", "\"[#{s[0, 1...
Generate log friendly serialized identity for one or more ids Limit to 1000 bytes === Parameters ids(Array|String):: Serialized identity or array of serialized identities === Return (String):: Log friendly serialized identity
[ "Generate", "log", "friendly", "serialized", "identity", "for", "one", "or", "more", "ids", "Limit", "to", "1000", "bytes" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/packets.rb#L214-L221
train
rightscale/right_agent
lib/right_agent/packets.rb
RightScale.Packet.trace
def trace audit_id = self.respond_to?(:payload) && payload.is_a?(Hash) && (payload['audit_id'] || payload[:audit_id]) tok = self.respond_to?(:token) && token tr = "<#{audit_id || nil}> <#{tok}>" end
ruby
def trace audit_id = self.respond_to?(:payload) && payload.is_a?(Hash) && (payload['audit_id'] || payload[:audit_id]) tok = self.respond_to?(:token) && token tr = "<#{audit_id || nil}> <#{tok}>" end
[ "def", "trace", "audit_id", "=", "self", ".", "respond_to?", "(", ":payload", ")", "&&", "payload", ".", "is_a?", "(", "Hash", ")", "&&", "(", "payload", "[", "'audit_id'", "]", "||", "payload", "[", ":audit_id", "]", ")", "tok", "=", "self", ".", "r...
Generate token used to trace execution of operation across multiple packets === Return tr(String):: Trace token, may be empty
[ "Generate", "token", "used", "to", "trace", "execution", "of", "operation", "across", "multiple", "packets" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/packets.rb#L254-L258
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.push
def push(type, payload, target, options = {}) params = { :type => type, :payload => payload, :target => target } make_request(:post, "/push", params, type.split("/")[2], options) end
ruby
def push(type, payload, target, options = {}) params = { :type => type, :payload => payload, :target => target } make_request(:post, "/push", params, type.split("/")[2], options) end
[ "def", "push", "(", "type", ",", "payload", ",", "target", ",", "options", "=", "{", "}", ")", "params", "=", "{", ":type", "=>", "type", ",", ":payload", "=>", "payload", ",", ":target", "=>", "target", "}", "make_request", "(", ":post", ",", "\"/pu...
Create RightNet router client @param [AuthClient] auth_client providing authorization session for HTTP requests @option options [Numeric] :open_timeout maximum wait for connection; defaults to DEFAULT_OPEN_TIMEOUT @option options [Numeric] :request_timeout maximum wait for response; defaults to DEFAULT_REQUEST_TIM...
[ "Create", "RightNet", "router", "client" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L134-L140
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.request
def request(type, payload, target, options = {}) params = { :type => type, :payload => payload, :target => target } make_request(:post, "/request", params, type.split("/")[2], options) end
ruby
def request(type, payload, target, options = {}) params = { :type => type, :payload => payload, :target => target } make_request(:post, "/request", params, type.split("/")[2], options) end
[ "def", "request", "(", "type", ",", "payload", ",", "target", ",", "options", "=", "{", "}", ")", "params", "=", "{", ":type", "=>", "type", ",", ":payload", "=>", "payload", ",", ":target", "=>", "target", "}", "make_request", "(", ":post", ",", "\"...
Route a request to a single target with a response expected Automatically retry the request if a response is not received in a reasonable amount of time or if there is a non-delivery response indicating the target is not currently available Timeout the request if a response is not received in time, typically configu...
[ "Route", "a", "request", "to", "a", "single", "target", "with", "a", "response", "expected", "Automatically", "retry", "the", "request", "if", "a", "response", "is", "not", "received", "in", "a", "reasonable", "amount", "of", "time", "or", "if", "there", "...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L173-L179
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.notify
def notify(event, routing_keys) event[:uuid] ||= RightSupport::Data::UUID.generate event[:version] ||= AgentConfig.protocol_version params = {:event => event} params[:routing_keys] = routing_keys if routing_keys if @websocket path = event[:path] ? " #{event[:path]}" : "" to...
ruby
def notify(event, routing_keys) event[:uuid] ||= RightSupport::Data::UUID.generate event[:version] ||= AgentConfig.protocol_version params = {:event => event} params[:routing_keys] = routing_keys if routing_keys if @websocket path = event[:path] ? " #{event[:path]}" : "" to...
[ "def", "notify", "(", "event", ",", "routing_keys", ")", "event", "[", ":uuid", "]", "||=", "RightSupport", "::", "Data", "::", "UUID", ".", "generate", "event", "[", ":version", "]", "||=", "AgentConfig", ".", "protocol_version", "params", "=", "{", ":eve...
Route event Use WebSocket if possible Do not block this request even if in the process of closing since used for request responses @param [Hash] event to send @param [Array, NilClass] routing_keys as strings to assist router in delivering event to interested parties @return [TrueClass] always true @raise [E...
[ "Route", "event", "Use", "WebSocket", "if", "possible", "Do", "not", "block", "this", "request", "even", "if", "in", "the", "process", "of", "closing", "since", "used", "for", "request", "responses" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L197-L211
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.listen
def listen(routing_keys, &handler) raise ArgumentError, "Block missing" unless block_given? @event_uuids = nil @listen_interval = 0 @listen_state = :choose @listen_failures = 0 @connect_interval = CONNECT_INTERVAL @reconnect_interval = RECONNECT_INTERVAL listen_loop(rou...
ruby
def listen(routing_keys, &handler) raise ArgumentError, "Block missing" unless block_given? @event_uuids = nil @listen_interval = 0 @listen_state = :choose @listen_failures = 0 @connect_interval = CONNECT_INTERVAL @reconnect_interval = RECONNECT_INTERVAL listen_loop(rou...
[ "def", "listen", "(", "routing_keys", ",", "&", "handler", ")", "raise", "ArgumentError", ",", "\"Block missing\"", "unless", "block_given?", "@event_uuids", "=", "nil", "@listen_interval", "=", "0", "@listen_state", "=", ":choose", "@listen_failures", "=", "0", "...
Receive events via an HTTP WebSocket if available, otherwise via an HTTP long-polling @param [Array, NilClass] routing_keys for event sources of interest with nil meaning all @yield [event] required block called each time event received @yieldparam [Hash] event received @return [TrueClass] always true, although ...
[ "Receive", "events", "via", "an", "HTTP", "WebSocket", "if", "available", "otherwise", "via", "an", "HTTP", "long", "-", "polling" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L229-L241
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.listen_loop
def listen_loop(routing_keys, &handler) @listen_timer = nil begin # Perform listen action based on current state case @listen_state when :choose # Choose listen method or continue as is if already listening # or want to delay choosing choose_listen_meth...
ruby
def listen_loop(routing_keys, &handler) @listen_timer = nil begin # Perform listen action based on current state case @listen_state when :choose # Choose listen method or continue as is if already listening # or want to delay choosing choose_listen_meth...
[ "def", "listen_loop", "(", "routing_keys", ",", "&", "handler", ")", "@listen_timer", "=", "nil", "begin", "case", "@listen_state", "when", ":choose", "choose_listen_method", "when", ":check", "if", "@websocket", ".", "nil?", "if", "router_not_responding?", "update_...
Perform listen action, then wait prescribed time for next action A periodic timer is not effective here because it does not wa @param [Array, NilClass] routing_keys for event sources of interest with nil meaning all @yield [event] required block called each time event received @yieldparam [Hash] event received ...
[ "Perform", "listen", "action", "then", "wait", "prescribed", "time", "for", "next", "action", "A", "periodic", "timer", "is", "not", "effective", "here", "because", "it", "does", "not", "wa" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L292-L352
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.listen_loop_wait
def listen_loop_wait(started_at, interval, routing_keys, &handler) if @listen_interval == 0 EM_S.next_tick { listen_loop(routing_keys, &handler) } else @listen_timer = EM_S::Timer.new(interval) do remaining = @listen_interval - (Time.now - started_at) if remaining > 0 ...
ruby
def listen_loop_wait(started_at, interval, routing_keys, &handler) if @listen_interval == 0 EM_S.next_tick { listen_loop(routing_keys, &handler) } else @listen_timer = EM_S::Timer.new(interval) do remaining = @listen_interval - (Time.now - started_at) if remaining > 0 ...
[ "def", "listen_loop_wait", "(", "started_at", ",", "interval", ",", "routing_keys", ",", "&", "handler", ")", "if", "@listen_interval", "==", "0", "EM_S", ".", "next_tick", "{", "listen_loop", "(", "routing_keys", ",", "&", "handler", ")", "}", "else", "@lis...
Wait specified interval before next listen loop Continue waiting if interval changes while waiting @param [Time] started_at time when first started waiting @param [Numeric] interval to wait @param [Array, NilClass] routing_keys for event sources of interest with nil meaning all @yield [event] required block call...
[ "Wait", "specified", "interval", "before", "next", "listen", "loop", "Continue", "waiting", "if", "interval", "changes", "while", "waiting" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L365-L379
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.update_listen_state
def update_listen_state(state, interval = 0) if state == :cancel @listen_timer.cancel if @listen_timer @listen_timer = nil @listen_state = state elsif [:choose, :check, :connect, :long_poll, :wait].include?(state) @listen_checks = 0 if state == :check && @listen_state != :che...
ruby
def update_listen_state(state, interval = 0) if state == :cancel @listen_timer.cancel if @listen_timer @listen_timer = nil @listen_state = state elsif [:choose, :check, :connect, :long_poll, :wait].include?(state) @listen_checks = 0 if state == :check && @listen_state != :che...
[ "def", "update_listen_state", "(", "state", ",", "interval", "=", "0", ")", "if", "state", "==", ":cancel", "@listen_timer", ".", "cancel", "if", "@listen_timer", "@listen_timer", "=", "nil", "@listen_state", "=", "state", "elsif", "[", ":choose", ",", ":check...
Update listen state @param [Symbol] state next @param [Integer] interval before next listen action @return [TrueClass] always true @raise [ArgumentError] invalid state
[ "Update", "listen", "state" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L389-L402
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.try_connect
def try_connect(routing_keys, &handler) connect(routing_keys, &handler) update_listen_state(:check, 1) rescue Exception => e ErrorTracker.log(self, "Failed creating WebSocket", e, nil, :caller) backoff_connect_interval update_listen_state(:long_poll) end
ruby
def try_connect(routing_keys, &handler) connect(routing_keys, &handler) update_listen_state(:check, 1) rescue Exception => e ErrorTracker.log(self, "Failed creating WebSocket", e, nil, :caller) backoff_connect_interval update_listen_state(:long_poll) end
[ "def", "try_connect", "(", "routing_keys", ",", "&", "handler", ")", "connect", "(", "routing_keys", ",", "&", "handler", ")", "update_listen_state", "(", ":check", ",", "1", ")", "rescue", "Exception", "=>", "e", "ErrorTracker", ".", "log", "(", "self", "...
Try to create WebSocket connection @param [Array, NilClass] routing_keys for event sources of interest with nil meaning all @yield [event] required block called each time event received @yieldparam [Hash] event received @return [TrueClass] always true
[ "Try", "to", "create", "WebSocket", "connection" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L437-L444
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.connect
def connect(routing_keys, &handler) raise ArgumentError, "Block missing" unless block_given? @attempted_connect_at = Time.now @close_code = @close_reason = nil # Initialize use of proxy if defined if (v = BalancedHttpClient::PROXY_ENVIRONMENT_VARIABLES.detect { |v| ENV.has_key?(v) }) ...
ruby
def connect(routing_keys, &handler) raise ArgumentError, "Block missing" unless block_given? @attempted_connect_at = Time.now @close_code = @close_reason = nil # Initialize use of proxy if defined if (v = BalancedHttpClient::PROXY_ENVIRONMENT_VARIABLES.detect { |v| ENV.has_key?(v) }) ...
[ "def", "connect", "(", "routing_keys", ",", "&", "handler", ")", "raise", "ArgumentError", ",", "\"Block missing\"", "unless", "block_given?", "@attempted_connect_at", "=", "Time", ".", "now", "@close_code", "=", "@close_reason", "=", "nil", "if", "(", "v", "=",...
Connect to RightNet router using WebSocket for receiving events @param [Array, NilClass] routing_keys as strings to assist router in delivering event to interested parties @yield [event] required block called when event received @yieldparam [Object] event received @yieldreturn [Hash, NilClass] event this is re...
[ "Connect", "to", "RightNet", "router", "using", "WebSocket", "for", "receiving", "events" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L459-L530
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.try_long_poll
def try_long_poll(routing_keys, event_uuids, &handler) begin long_poll(routing_keys, event_uuids, &handler) rescue Exception => e e end end
ruby
def try_long_poll(routing_keys, event_uuids, &handler) begin long_poll(routing_keys, event_uuids, &handler) rescue Exception => e e end end
[ "def", "try_long_poll", "(", "routing_keys", ",", "event_uuids", ",", "&", "handler", ")", "begin", "long_poll", "(", "routing_keys", ",", "event_uuids", ",", "&", "handler", ")", "rescue", "Exception", "=>", "e", "e", "end", "end" ]
Try to make long-polling request to receive events @param [Array, NilClass] routing_keys for event sources of interest with nil meaning all @param [Array, NilClass] event_uuids from previous poll @yield [event] required block called each time event received @yieldparam [Hash] event received @return [Array, NilC...
[ "Try", "to", "make", "long", "-", "polling", "request", "to", "receive", "events" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L541-L547
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.try_deferred_long_poll
def try_deferred_long_poll(routing_keys, event_uuids, &handler) # Proc for running long-poll in EM defer thread since this is a blocking call @defer_operation_proc = Proc.new { try_long_poll(routing_keys, event_uuids, &handler) } # Proc that runs in main EM reactor thread to handle result from above ...
ruby
def try_deferred_long_poll(routing_keys, event_uuids, &handler) # Proc for running long-poll in EM defer thread since this is a blocking call @defer_operation_proc = Proc.new { try_long_poll(routing_keys, event_uuids, &handler) } # Proc that runs in main EM reactor thread to handle result from above ...
[ "def", "try_deferred_long_poll", "(", "routing_keys", ",", "event_uuids", ",", "&", "handler", ")", "@defer_operation_proc", "=", "Proc", ".", "new", "{", "try_long_poll", "(", "routing_keys", ",", "event_uuids", ",", "&", "handler", ")", "}", "@defer_callback_pro...
Try to make long-polling request to receive events using EM defer thread Repeat long-polling until there is an error or the stop time has been reached @param [Array, NilClass] routing_keys for event sources of interest with nil meaning all @param [Array, NilClass] event_uuids from previous poll @yield [event] req...
[ "Try", "to", "make", "long", "-", "polling", "request", "to", "receive", "events", "using", "EM", "defer", "thread", "Repeat", "long", "-", "polling", "until", "there", "is", "an", "error", "or", "the", "stop", "time", "has", "been", "reached" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L559-L569
train