Class: Puppet::Util::EsInstanceValidator
- Inherits:
-
Object
- Object
- Puppet::Util::EsInstanceValidator
- Defined in:
- lib/puppet/util/es_instance_validator.rb
Overview
Helper class to assist with talking to the Elasticsearch service ports.
Instance Attribute Summary collapse
-
#instance_port ⇒ Object
readonly
Returns the value of attribute instance_port.
-
#instance_server ⇒ Object
readonly
Returns the value of attribute instance_server.
Instance Method Summary collapse
-
#attempt_connection ⇒ Object
Utility method; attempts to make an https connection to the Elasticsearch instance.
-
#initialize(instance_server, instance_port) ⇒ EsInstanceValidator
constructor
A new instance of EsInstanceValidator.
Constructor Details
#initialize(instance_server, instance_port) ⇒ EsInstanceValidator
Returns a new instance of EsInstanceValidator.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppet/util/es_instance_validator.rb', line 13 def initialize(instance_server, instance_port) @instance_server = instance_server @instance_port = instance_port # Avoid deprecation warnings in Puppet versions < 4 @timeout = if Facter.value(:puppetversion).split('.').first.to_i < 4 Puppet[:configtimeout] else Puppet[:http_connect_timeout] end end |
Instance Attribute Details
#instance_port ⇒ Object (readonly)
Returns the value of attribute instance_port.
11 12 13 |
# File 'lib/puppet/util/es_instance_validator.rb', line 11 def instance_port @instance_port end |
#instance_server ⇒ Object (readonly)
Returns the value of attribute instance_server.
11 12 13 |
# File 'lib/puppet/util/es_instance_validator.rb', line 11 def instance_server @instance_server end |
Instance Method Details
#attempt_connection ⇒ Object
Utility method; attempts to make an https connection to the Elasticsearch instance. This is abstracted out into a method so that it can be called multiple times for retry attempts.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/puppet/util/es_instance_validator.rb', line 30 def attempt_connection Timeout.timeout(@timeout) do TCPSocket.new(@instance_server, @instance_port).close true rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e Puppet.debug "Unable to connect to Elasticsearch instance (#{@instance_server}:#{@instance_port}): #{e.}" false end rescue Timeout::Error false end |