Class: DruidConfig::Entities::Node
- Inherits:
-
Object
- Object
- DruidConfig::Entities::Node
- Includes:
- 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 ⇒ Object
readonly
Readers.
-
#segments_to_drop ⇒ Object
readonly
Readers.
-
#segments_to_drop_size ⇒ Object
readonly
Readers.
-
#segments_to_load ⇒ 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.
-
#uri ⇒ Object
Return the URI of this node.
-
#used_percent ⇒ Object
Calculate the percent of used space.
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
24 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 24 def initialize(, queue) @host, @port = ['host'].split(':') @max_size = ['maxSize'] @type = ['type'].to_sym @tier = ['tier'] @priority = ['priority'] @size = ['currSize'] @segments = ['segments'].map do |_, sdata| DruidConfig::Entities::Segment.new(sdata) end if queue.nil? @segments_to_load, @segments_to_drop = [], [] @segments_to_load_size, @segments_to_drop_size = 0, 0 else @segments_to_load = queue['segmentsToLoad'].map do |segment| DruidConfig::Entities::Segment.new(segment) end @segments_to_drop = queue['segmentsToDrop'].map do |segment| DruidConfig::Entities::Segment.new(segment) end @segments_to_load_size = @segments_to_load.map(&:size).reduce(:+) @segments_to_drop_size = @segments_to_drop.map(&:size).reduce(:+) end end |
Instance Attribute Details
#host ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def host @host end |
#max_size ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def max_size @max_size end |
#port ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def port @port end |
#priority ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def priority @priority end |
#segments ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def segments @segments end |
#segments_to_drop ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def segments_to_drop @segments_to_drop end |
#segments_to_drop_size ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def segments_to_drop_size @segments_to_drop_size end |
#segments_to_load ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def segments_to_load @segments_to_load end |
#segments_to_load_size ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def segments_to_load_size @segments_to_load_size end |
#size ⇒ Object (readonly) Also known as: used
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def size @size end |
#tier ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def tier @tier end |
#type ⇒ Object (readonly)
Readers
11 12 13 |
# File 'lib/druid_config/entities/node.rb', line 11 def type @type end |
Instance Method Details
#free ⇒ Object
Calculate free space
62 63 64 |
# File 'lib/druid_config/entities/node.rb', line 62 def free max_size - size end |
#uri ⇒ Object
Return the URI of this node
69 70 71 |
# File 'lib/druid_config/entities/node.rb', line 69 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 |