Class: Riak::Client::Node
- Inherits:
-
Object
- Object
- Riak::Client::Node
- Includes:
- Util::Escape, Util::Translation
- Defined in:
- lib/riak/client/node.rb
Constant Summary
- VALID_OPTIONS =
[:host, :http_port, :pb_port, :http_paths, :prefix, :mapred, :luwak, :solr, :port, :basic_auth, :ssl_options, :ssl]
- ERRORS_DECAY_RATE =
For a score which halves in 10 seconds, choose ln(1/2)/10
Math.log(0.5)/10
Instance Attribute Summary (collapse)
-
- (Object) basic_auth
A "user:password" string.
-
- (Object) error_rate
readonly
A Decaying rate of errors.
-
- (Object) host
What IP address or hostname does this node listen on?.
-
- (Object) http_paths
A hash of HTTP paths used on this node.
-
- (Object) http_port
Which port does the HTTP interface listen on?.
-
- (Object) pb_port
Which port does the protocol buffers interface listen on?.
-
- (Object) ssl_options
Returns the value of attribute ssl_options.
Instance Method Summary (collapse)
- - (Object) ==(o)
-
- (Boolean) http?
Can this node be used for HTTP requests?.
-
- (Node) initialize(client, opts = {})
constructor
A new instance of Node.
- - (Object) inspect
-
- (Boolean) protobuffs?
Can this node be used for protocol buffers requests?.
-
- (Object) ssl=(value)
Enables or disables SSL on this node to be utilized by the HTTP Backends.
- - (Object) ssl_disable
- - (Object) ssl_enable
-
- (Boolean) ssl_enabled?
Checks if SSL is enabled for HTTP.
Methods included from Util::Escape
#escape, #maybe_escape, #maybe_unescape, #unescape
Methods included from Util::Translation
Constructor Details
- (Node) initialize(client, opts = {})
A new instance of Node
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/riak/client/node.rb', line 30 def initialize(client, opts = {}) @client = client @ssl = opts[:ssl] @ssl_options = opts[:ssl_options] @host = opts[:host] || "127.0.0.1" @http_port = opts[:http_port] || opts[:port] || 8098 @pb_port = opts[:pb_port] || 8087 @http_paths = { :prefix => opts[:prefix] || "/riak/", :mapred => opts[:mapred] || "/mapred", :luwak => opts[:luwak] || "/luwak", :solr => opts[:solr] || "/solr" # Unused? }.merge(opts[:http_paths] || {}) self.basic_auth = opts[:basic_auth] @error_rate = Decaying.new end |
Instance Attribute Details
- (Object) basic_auth
A "user:password" string.
25 26 27 |
# File 'lib/riak/client/node.rb', line 25 def basic_auth @basic_auth end |
- (Object) error_rate (readonly)
A Decaying rate of errors.
28 29 30 |
# File 'lib/riak/client/node.rb', line 28 def error_rate @error_rate end |
- (Object) host
What IP address or hostname does this node listen on?
17 18 19 |
# File 'lib/riak/client/node.rb', line 17 def host @host end |
- (Object) http_paths
A hash of HTTP paths used on this node.
23 24 25 |
# File 'lib/riak/client/node.rb', line 23 def http_paths @http_paths end |
- (Object) http_port
Which port does the HTTP interface listen on?
19 20 21 |
# File 'lib/riak/client/node.rb', line 19 def http_port @http_port end |
- (Object) pb_port
Which port does the protocol buffers interface listen on?
21 22 23 |
# File 'lib/riak/client/node.rb', line 21 def pb_port @pb_port end |
- (Object) ssl_options
Returns the value of attribute ssl_options
26 27 28 |
# File 'lib/riak/client/node.rb', line 26 def @ssl_options end |
Instance Method Details
- (Object) ==(o)
48 49 50 51 52 53 |
# File 'lib/riak/client/node.rb', line 48 def ==(o) o.kind_of? Node and @host == o.host and @http_port == o.http_port and @pb_port == o.pb_port end |
- (Boolean) http?
Can this node be used for HTTP requests?
68 69 70 71 |
# File 'lib/riak/client/node.rb', line 68 def http? # TODO: Need to sort out capabilities true end |
- (Object) inspect
106 107 108 |
# File 'lib/riak/client/node.rb', line 106 def inspect "<#Node #{@host}:#{@http_port}:#{@pb_port}>" end |
- (Boolean) protobuffs?
Can this node be used for protocol buffers requests?
74 75 76 77 |
# File 'lib/riak/client/node.rb', line 74 def protobuffs? # TODO: Need to sort out capabilities true end |
- (Object) ssl=(value)
Enables or disables SSL on this node to be utilized by the HTTP Backends
81 82 83 84 |
# File 'lib/riak/client/node.rb', line 81 def ssl=(value) @ssl_options = Hash === value ? value : {} value ? ssl_enable : ssl_disable end |
- (Object) ssl_disable
101 102 103 104 |
# File 'lib/riak/client/node.rb', line 101 def ssl_disable @client.protocol = 'http' @ssl_options = nil end |
- (Object) ssl_enable
91 92 93 94 95 96 97 98 99 |
# File 'lib/riak/client/node.rb', line 91 def ssl_enable @client.protocol = 'https' @ssl_options[:pem] = File.read(@ssl_options[:pem_file]) if @ssl_options[:pem_file] @ssl_options[:verify_mode] ||= "peer" if @ssl_options.stringify_keys.any? {|k,v| %w[pem ca_file ca_path].include?(k)} @ssl_options[:verify_mode] ||= "none" raise ArgumentError.new(t('invalid_ssl_verify_mode', :invalid => @ssl_options[:verify_mode])) unless %w[none peer].include?(@ssl_options[:verify_mode]) @ssl_options end |
- (Boolean) ssl_enabled?
Checks if SSL is enabled for HTTP
87 88 89 |
# File 'lib/riak/client/node.rb', line 87 def ssl_enabled? @client.protocol == 'https' || @ssl_options.present? end |