Class: DruidConfig::Entities::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/druid_config/entities/worker.rb

Overview

Worker class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ Worker

Initialize it with received info

Parameters:

metadata

Hash with returned metadata from Druid



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/druid_config/entities/worker.rb', line 18

def initialize()
  @host, @port = ['worker']['host'].split(':')
  @ip = ['worker']['ip']
  @capacity = ['worker']['capacity']
  @version = ['worker']['version']
  @last_completed_task_time = ['lastCompletedTaskTime']
  @running_tasks = ['runningTasks'].map do |task|
    DruidConfig::Entities::Task.new(
      task,
      DruidConfig::Entities::Task::STATUS[:running],
      created_time: task['createdTime'],
      query_insertion_time: task['queueInsertionTime'])
  end
  @capacity_used = ['currCapacityUsed']
end

Instance Attribute Details

#capacityObject (readonly)

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def capacity
  @capacity
end

#capacity_usedObject (readonly) Also known as: used

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def capacity_used
  @capacity_used
end

#hostObject (readonly)

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def host
  @host
end

#ipObject (readonly)

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def ip
  @ip
end

#last_completed_task_timeObject (readonly)

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def last_completed_task_time
  @last_completed_task_time
end

#portObject (readonly)

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def port
  @port
end

#running_tasksObject (readonly)

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def running_tasks
  @running_tasks
end

#versionObject (readonly)

Readers



8
9
10
# File 'lib/druid_config/entities/worker.rb', line 8

def version
  @version
end

Instance Method Details

#freeObject

Return free capacity



39
40
41
42
# File 'lib/druid_config/entities/worker.rb', line 39

def free
  return @free if @free
  @free = (capacity - capacity_used) > 0 ? (capacity - capacity_used) : 0
end

#uriObject

Return the uri of the worker



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

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

#used_percentObject

Return capacity used



47
48
49
50
# File 'lib/druid_config/entities/worker.rb', line 47

def used_percent
  return 0 unless @capacity && @capacity != 0
  ((@capacity_used.to_f / @capacity) * 100).round(2)
end