Class: DruidConfig::Entities::Node

Inherits:
Object
  • Object
show all
Includes:
Util, HTTParty
Defined in:
lib/druid_config/entities/node.rb

Overview

Node class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#pop_uri, #query_overlord, #secure_query, #stash_uri

Constructor Details

#initialize(metadata, queue) ⇒ Node

Initialize it with received info

Parameters:

metadata

Hash with the data of the node given by a Druid API query

queue

Hash with segments to load



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/druid_config/entities/node.rb', line 25

def initialize(, queue)
  @host, @port = ['host'].split(':')
  @max_size = ['maxSize']
  @type = ['type'].to_sym
  @tier = ['tier']
  @priority = ['priority']
  @size = ['currSize']
  # Set end point for HTTParty
  self.class.base_uri(
    "#{DruidConfig.client.coordinator}"\
    "druid/coordinator/#{DruidConfig::Version::API_VERSION}")

  # Load more data from queue
  if queue.nil?
    @segments_to_load_count, @segments_to_drop_count = 0, 0
    @segments_to_load_size, @segments_to_drop_size = 0, 0
  else
    @segments_to_load_count = queue['segmentsToLoad']
    @segments_to_drop_count = queue['segmentsToDrop']
    @segments_to_load_size = queue['segmentsToLoadSize']
    @segments_to_drop_size = queue['segmentsToLoadSize']
  end
end

Instance Attribute Details

#hostObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def host
  @host
end

#max_sizeObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def max_size
  @max_size
end

#portObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def port
  @port
end

#priorityObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def priority
  @priority
end

#segments_to_drop_countObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def segments_to_drop_count
  @segments_to_drop_count
end

#segments_to_drop_sizeObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def segments_to_drop_size
  @segments_to_drop_size
end

#segments_to_load_countObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def segments_to_load_count
  @segments_to_load_count
end

#segments_to_load_sizeObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def segments_to_load_size
  @segments_to_load_size
end

#sizeObject (readonly) Also known as: used

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def size
  @size
end

#tierObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def tier
  @tier
end

#typeObject (readonly)

Readers



12
13
14
# File 'lib/druid_config/entities/node.rb', line 12

def type
  @type
end

Instance Method Details

#freeObject

Calculate free space



62
63
64
65
# File 'lib/druid_config/entities/node.rb', line 62

def free
  return @free if @free
  @free = (max_size - size) > 0 ? (max_size - size) : 0
end

#segmentsObject

Return all segments of this node



78
79
80
81
82
83
# File 'lib/druid_config/entities/node.rb', line 78

def segments
  @segments ||=
    self.class.get("/servers/#{uri}/segments?full").map do |s|
      DruidConfig::Entities::Segment.new(s)
    end
end

#segments_countObject

Return all segments of this node



70
71
72
73
# File 'lib/druid_config/entities/node.rb', line 70

def segments_count
  @segments_count ||=
    self.class.get("/servers/#{uri}/segments").size
end

#segments_to_dropObject

Get segments to drop



99
100
101
102
103
104
105
# File 'lib/druid_config/entities/node.rb', line 99

def segments_to_drop
  current_queue = queue
  return [] unless current_queue
  current_queue['segmentsToDrop'].map do |segment|
    DruidConfig::Entities::Segment.new(segment)
  end
end

#segments_to_loadObject

Get segments to load



88
89
90
91
92
93
94
# File 'lib/druid_config/entities/node.rb', line 88

def segments_to_load
  current_queue = queue
  return [] unless current_queue
  current_queue['segmentsToLoad'].map do |segment|
    DruidConfig::Entities::Segment.new(segment)
  end
end

#uriObject

Return the URI of this node



110
111
112
# File 'lib/druid_config/entities/node.rb', line 110

def uri
  "#{@host}:#{@port}"
end

#used_percentObject

Calculate the percent of used space



54
55
56
57
# File 'lib/druid_config/entities/node.rb', line 54

def used_percent
  return 0 unless max_size && max_size != 0
  ((size.to_f / max_size) * 100).round(2)
end