Class: DruidConfig::Entities::DataSource

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

Overview

Init a DataSource

Constant Summary collapse

DEFAULT_DATASOURCE =

Name of default datasource

'_default'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#pop_uri, #query_overlord, #secure_query, #stash_uri

Constructor Details

#initialize(metadata, load_status) ⇒ DataSource

Initialize a DataSource



21
22
23
24
25
26
27
28
29
# File 'lib/druid_config/entities/data_source.rb', line 21

def initialize(, load_status)
  @name = ['name']
  @properties = ['properties']
  @load_status = load_status
  # Set end point for HTTParty
  self.class.base_uri(
    "#{DruidConfig.client.coordinator}"\
    "druid/coordinator/#{DruidConfig::Version::API_VERSION}")
end

Instance Attribute Details

#load_statusObject (readonly)

Returns the value of attribute load_status.



13
14
15
# File 'lib/druid_config/entities/data_source.rb', line 13

def load_status
  @load_status
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/druid_config/entities/data_source.rb', line 13

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



13
14
15
# File 'lib/druid_config/entities/data_source.rb', line 13

def properties
  @properties
end

Instance Method Details

#destroy(interval = nil) ⇒ Hash?

Destroy the current data source. Becareful, this action will remove the data associated to the data source

Parameters:

  • interval (String) (defaults to: nil)

    Optional parameter to define the interval to destroy the data associated to the data source. By default, it will destroy all data.

Returns:

  • (Hash, nil)

    Hash with error or nil



69
70
71
72
73
74
75
76
77
78
# File 'lib/druid_config/entities/data_source.rb', line 69

def destroy(interval = nil)
  interval = all_interval unless interval
  # Disable data source
  disable
  # Execute kill task
  secure_query do
    self.class.delete(
      "/datasources/#{@name}?kill=true&interval=#{interval}")
  end
end

#disableObject

Disable the current data source



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

def disable
  secure_query do
    self.class.delete("/datasources/#{@name}")
  end
end

#enableObject

Enable the current data source



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

def enable
  secure_query do
    self.class.post("/datasources/#{@name}")
  end
end

#history_rules(interval) ⇒ Object



158
159
160
161
162
163
# File 'lib/druid_config/entities/data_source.rb', line 158

def history_rules(interval)
  secure_query do
    self.class.get("/rules/#{@name}/history"\
                   "?interval=#{interval}")
  end
end

#infoObject

The following methods are referenced to Druid API. To check the funcionality about it, please go to Druid documentation:

druid.io/docs/0.8.1/design/coordinator.html



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

def info
  secure_query do
    @info ||= self.class.get("/datasources/#{@name}")
  end
end

#interval(interval, params = '') ⇒ Object



90
91
92
93
94
95
# File 'lib/druid_config/entities/data_source.rb', line 90

def interval(interval, params = '')
  secure_query do
    self.class.get("/datasources/#{@name}/intervals/#{interval}"\
                   "?#{params}")
  end
end

#intervals(params = '') ⇒ Object

Intervals




84
85
86
87
88
# File 'lib/druid_config/entities/data_source.rb', line 84

def intervals(params = '')
  secure_query do
    self.class.get("/datasources/#{@name}/intervals?#{params}")
  end
end

#rules(params = '') ⇒ Object

Rules




118
119
120
121
122
123
124
125
126
127
# File 'lib/druid_config/entities/data_source.rb', line 118

def rules(params = '')
  return @rules if @rules
  @rules = DruidConfig::Entities::RuleCollection.new
  secure_query do
    self.class.get("/rules/#{@name}?#{params}").each do |rule|
      @rules << DruidConfig::Entities::Rule.parse(rule)
    end
  end
  @rules
end

#save_rulesObject

Save current rules

Returns:

Boolean indicating the status of the request



154
155
156
# File 'lib/druid_config/entities/data_source.rb', line 154

def save_rules
  post_rules(rules)
end

#segment(segment) ⇒ Object



108
109
110
# File 'lib/druid_config/entities/data_source.rb', line 108

def segment(segment)
  segments.select { |s| s.id == segment }
end

#segmentsObject

Segments and Tiers




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

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

#tiersObject



112
113
114
# File 'lib/druid_config/entities/data_source.rb', line 112

def tiers
  info['tiers']
end

#update_rules(new_rules) ⇒ Object

Apply given rules to the datasource

Paremeters:

rules

RuleCollection of rules

Returns:

Boolean indicating the status of the request



139
140
141
142
143
144
145
146
# File 'lib/druid_config/entities/data_source.rb', line 139

def update_rules(new_rules)
  if post_rules(new_rules)
    @rules = new_rules
    true
  else
    false
  end
end