Class: Aerospike::NodeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/cluster/node_validator.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, host, timeout) ⇒ NodeValidator

Returns a new instance of NodeValidator.



25
26
27
28
29
30
31
32
33
34
# File 'lib/aerospike/cluster/node_validator.rb', line 25

def initialize(cluster, host, timeout)
  @cluster = cluster
  @use_new_info = true
  @host = host

  set_aliases(host)
  set_address(timeout)

  self
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



23
24
25
# File 'lib/aerospike/cluster/node_validator.rb', line 23

def aliases
  @aliases
end

#hostObject (readonly)

Returns the value of attribute host.



23
24
25
# File 'lib/aerospike/cluster/node_validator.rb', line 23

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/aerospike/cluster/node_validator.rb', line 23

def name
  @name
end

#use_new_infoObject (readonly)

Returns the value of attribute use_new_info.



23
24
25
# File 'lib/aerospike/cluster/node_validator.rb', line 23

def use_new_info
  @use_new_info
end

Instance Method Details

#set_address(timeout) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/aerospike/cluster/node_validator.rb', line 48

def set_address(timeout)
  @aliases.each do |aliass|
    begin
      conn = Connection.new(aliass.name, aliass.port, timeout)

      # need to authenticate
      if @cluster.user && @cluster.user != ''
        begin
          command = AdminCommand.new
          command.authenticate(conn, @cluster.user, @cluster.password)
        rescue => e
          # Socket not authenticated. Do not put back into pool.
          conn.close if conn
          raise e
        end
      end

      info_map= Info.request(conn, 'node', 'build')
      if node_name = info_map['node']
        @name = node_name

        # Check new info protocol support for >= 2.6.6 build
        if build_version = info_map['build']
          v1, v2, v3 = parse_version_string(build_version)
          @use_new_info = v1.to_i > 2 || (v1.to_i == 2 && (v2.to_i > 6 || (v2.to_i == 6 && v3.to_i >= 6)))
        end
      end
    ensure
      conn.close if conn
    end

  end
end

#set_aliases(host) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/aerospike/cluster/node_validator.rb', line 36

def set_aliases(host)
  addresses = Resolv.getaddresses(host.name)
  aliases = []
  addresses.each do |addr|
    aliases << Host.new(addr, host.port)
  end

  @aliases = aliases

  Aerospike.logger.debug("Node Validator has #{aliases.length} nodes.")
end