Class: DruidConfig::Entities::Node
- Inherits:
-
Object
- Object
- DruidConfig::Entities::Node
- Includes:
- Util, HTTParty
- Defined in:
- lib/druid_config/entities/node.rb
Overview
Node class
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Readers.
-
#max_size ⇒ Object
readonly
Readers.
-
#port ⇒ Object
readonly
Readers.
-
#priority ⇒ Object
readonly
Readers.
-
#segments_to_drop_count ⇒ Object
readonly
Readers.
-
#segments_to_drop_size ⇒ Object
readonly
Readers.
-
#segments_to_load_count ⇒ Object
readonly
Readers.
-
#segments_to_load_size ⇒ Object
readonly
Readers.
-
#size ⇒ Object
(also: #used)
readonly
Readers.
-
#tier ⇒ Object
readonly
Readers.
-
#type ⇒ Object
readonly
Readers.
Instance Method Summary collapse
-
#free ⇒ Object
Calculate free space.
-
#initialize(metadata, queue) ⇒ Node
constructor
Initialize it with received info.
-
#segments ⇒ Object
Return all segments of this node.
-
#segments_count ⇒ Object
Return all segments of this node.
-
#segments_to_drop ⇒ Object
Get segments to drop.
-
#segments_to_load ⇒ Object
Get segments to load.
-
#uri ⇒ Object
Return the URI of this node.
-
#used_percent ⇒ Object
Calculate the percent of used space.
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
#host ⇒ Object (readonly)
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def host @host end |
#max_size ⇒ Object (readonly)
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def max_size @max_size end |
#port ⇒ Object (readonly)
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def port @port end |
#priority ⇒ Object (readonly)
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def priority @priority end |
#segments_to_drop_count ⇒ Object (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_size ⇒ Object (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_count ⇒ Object (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_size ⇒ Object (readonly)
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def segments_to_load_size @segments_to_load_size end |
#size ⇒ Object (readonly) Also known as: used
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def size @size end |
#tier ⇒ Object (readonly)
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def tier @tier end |
#type ⇒ Object (readonly)
Readers
12 13 14 |
# File 'lib/druid_config/entities/node.rb', line 12 def type @type end |
Instance Method Details
#free ⇒ Object
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 |
#segments ⇒ Object
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_count ⇒ Object
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_drop ⇒ Object
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_load ⇒ Object
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 |
#uri ⇒ Object
Return the URI of this node
110 111 112 |
# File 'lib/druid_config/entities/node.rb', line 110 def uri "#{@host}:#{@port}" end |
#used_percent ⇒ Object
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 |