Class: Elasticsearch::Drain

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch/drain.rb,
lib/elasticsearch/drain/cli.rb,
lib/elasticsearch/drain/base.rb,
lib/elasticsearch/drain/node.rb,
lib/elasticsearch/drain/util.rb,
lib/elasticsearch/drain/nodes.rb,
lib/elasticsearch/drain/cluster.rb,
lib/elasticsearch/drain/version.rb,
lib/elasticsearch/drain/autoscaling.rb

Defined Under Namespace

Modules: Errors, Util Classes: AutoScaling, Base, CLI, Cluster, Node, Nodes

Constant Summary collapse

VERSION =
IO.read(File.expand_path('../../../../VERSION', __FILE__)) rescue '0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hosts = 'localhost:9200', asg = nil, region = nil) ⇒ Elasticsearch::Transport::Client

Sets up the Elasticsearch client

Parameters:

  • [String] (Hash)

    a customizable set of options



19
20
21
22
23
# File 'lib/elasticsearch/drain.rb', line 19

def initialize(hosts = 'localhost:9200', asg = nil, region = nil)
  @hosts = hosts
  @region = region
  @asg_name = asg
end

Instance Attribute Details

#hostsObject (readonly)

The Elasticsearch hosts to connect to



8
9
10
# File 'lib/elasticsearch/drain.rb', line 8

def hosts
  @hosts
end

#regionObject (readonly)

EC2 Region



12
13
14
# File 'lib/elasticsearch/drain.rb', line 12

def region
  @region
end

Instance Method Details

#active_nodes_in_asgObject



53
54
55
56
# File 'lib/elasticsearch/drain.rb', line 53

def active_nodes_in_asg
  instances = asg.instances
  nodes.filter_nodes(instances, true)
end

#asgObject

EC2 AutoScaling Client



37
38
39
# File 'lib/elasticsearch/drain.rb', line 37

def asg
  @asg_client ||= AutoScaling.new(@asg_name, @region)
end

#clientObject

The Elasticsearch client object



26
27
28
29
30
31
32
33
34
# File 'lib/elasticsearch/drain.rb', line 26

def client
  return @client unless @client.nil?
  @client = ::Elasticsearch::Client.new(
    hosts: hosts,
    retry_on_failure: true,
    log: true,
    logger: ::Logger.new('es_client.log', 10, 1_024_000)
  )
end

#clusterElasticsearch::API::Cluster

Convenience method to access Elasticsearch::Drain::Cluster#cluster

Returns:

  • (Elasticsearch::API::Cluster)

    Elasticsearch cluster client



49
50
51
# File 'lib/elasticsearch/drain.rb', line 49

def cluster
  @cluster_client ||= Cluster.new(client)
end

#nodesObject

Convenience method to access Nodes



42
43
44
# File 'lib/elasticsearch/drain.rb', line 42

def nodes
  @nodes ||= Nodes.new(client, asg)
end