1 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"..","..",".."))
2 require 'puppet/util/es_instance_validator'
4 # This file contains a provider for the resource type `es_instance_conn_validator`,
5 # which validates the Elasticsearch instance connection by attempting an https connection.
7 Puppet::Type.type(:es_instance_conn_validator).provide(:tcp_port) do
8 desc "A provider for the resource type `es_instance_conn_validator`,
9 which validates the connection by attempting an https
10 connection to the Elasticsearch instance."
14 timeout = resource[:timeout]
16 success = validator.attempt_connection
18 while success == false && ((Time.now - start_time) < timeout)
19 # It can take several seconds for the Elasticsearch instance to start up;
20 # especially on the first install. Therefore, our first connection attempt
21 # may fail. Here we have somewhat arbitrarily chosen to retry every 2
22 # seconds until the configurable timeout has expired.
23 Puppet.debug("Failed to connect to the Elasticsearch instance; sleeping 2 seconds before retry")
25 success = validator.attempt_connection
29 Puppet.debug("Connected to the ES instance in #{Time.now - start_time} seconds.")
31 Puppet.notice("Failed to connect to the ES instance within timeout window of #{timeout} seconds; giving up.")
38 # If `#create` is called, that means that `#exists?` returned false, which
39 # means that the connection could not be established... so we need to
40 # cause a failure here.
41 raise Puppet::Error, "Unable to connect to ES instance ! (#{@validator.instance_server}:#{@validator.instance_port})"
48 @validator ||= Puppet::Util::EsInstanceValidator.new(resource[:server], resource[:port])