class DruidConfig::Entities::Node

Node class

Attributes

host[R]

Readers

max_size[R]

Readers

port[R]

Readers

priority[R]

Readers

segments_to_drop_count[R]

Readers

segments_to_drop_size[R]

Readers

segments_to_load_count[R]

Readers

segments_to_load_size[R]

Readers

size[R]

Readers

tier[R]

Readers

type[R]

Readers

used[R]

Readers

Public Class Methods

new(metadata, queue) click to toggle source

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

# File lib/druid_config/entities/node.rb, line 25
def initialize(metadata, queue)
  @host, @port = metadata['host'].split(':')
  @max_size = metadata['maxSize']
  @type = metadata['type'].to_sym
  @tier = metadata['tier']
  @priority = metadata['priority']
  @size = metadata['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

Public Instance Methods

free() click to toggle source

Calculate free space

# 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() click to toggle source

Return all segments of this node

# 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() click to toggle source

Return all segments of this node

# 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() click to toggle source

Get segments to drop

# 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() click to toggle source

Get segments to load

# 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() click to toggle source

Return the URI of this node

# File lib/druid_config/entities/node.rb, line 110
def uri
  "#{@host}:#{@port}"
end
used_percent() click to toggle source

Calculate the percent of used space

# 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

Private Instance Methods

queue() click to toggle source

Get load queue for this node

# File lib/druid_config/entities/node.rb, line 119
def queue
  secure_query do
    self.class.get('/loadqueue?full')
      .select { |k, _| k == uri }.values.first
  end
end