ruby-druid 0.1.9 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'liquid-ext'
6
- gem 'ripl'
7
- gem 'terminal-table'
8
-
9
- group :test, :development do
10
- gem 'liquid-development'
11
- gem 'webmock'
12
- end
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "liquid/tasks"
data/bin/dripl DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'liquid/boot'
5
-
6
- def zookeeper(value)
7
- @zk_uri = value
8
- end
9
-
10
- def uri(value)
11
- puts "using 'uri' in the config is deprecated, use 'zookeeper' instead"
12
- zookeeper value
13
- end
14
-
15
- def source(value)
16
- @source = value
17
- end
18
-
19
- def options(value)
20
- @options = value
21
- end
22
-
23
- begin
24
- driplrc = File.read(File.join(File.expand_path("../..", __FILE__), '.driplrc'))
25
- rescue
26
- puts "You need to create a .driplrc, take a look at dot_driplrc_example"
27
- exit 1
28
- end
29
-
30
- instance_eval(driplrc)
31
-
32
- unless @zk_uri || (@options && @options[:static_setup])
33
- puts "Your .driplrc is incomplete, please fix"
34
- exit 1
35
- end
36
-
37
- require 'druid/console'
38
- Druid::Console.new(@zk_uri, @source, @options)
@@ -1,12 +0,0 @@
1
- ## your zookeeper config. For static scenarios (i.e. ssh tunnels) see options
2
- ##
3
- # zookeeper "localhost:2181/druid"
4
-
5
- ## using options, you can disable zookeeper lookup
6
- ## options[:static_setup], the key is the source name, the value is the brokers post uri
7
- ##
8
- # options :static_setup => { 'example/events' => 'http://localhost:8080/druid/v2/' }
9
-
10
- ## dripl will default to use the first available data source. use this to override
11
- ##
12
- # source "example/events"
@@ -1,74 +0,0 @@
1
- require 'active_support/time'
2
- require 'ap'
3
- require 'forwardable'
4
- require 'irb'
5
- require 'ripl'
6
- require 'terminal-table'
7
-
8
- require 'druid'
9
-
10
- Ripl::Shell.class_eval do
11
- def format_query_result(result, query)
12
- include_timestamp = query.properties[:granularity] != 'all'
13
-
14
- keys = result.empty? ? [] : result.last.keys
15
- grouped_result = result.group_by(&:timestamp)
16
-
17
- Terminal::Table.new(:headings => keys) do
18
- grouped_result.each do |timestamp, rows|
19
- if include_timestamp
20
- add_row :separator unless timestamp == result.first.timestamp
21
- add_row [{ :value => timestamp, :colspan => keys.length }]
22
- add_row :separator
23
- end
24
- rows.each {|row| add_row keys.map {|key| row[key] } }
25
- end
26
- end
27
- end
28
-
29
- def format_result(result)
30
- if result.is_a?(Druid::Query)
31
- start = Time.now.to_f
32
- puts format_query_result(result.send, result)
33
- puts "Response Time: #{(Time.now.to_f - start).round(3)}s"
34
- else
35
- ap(result)
36
- end
37
- end
38
- end
39
-
40
- module Druid
41
- class Console
42
-
43
- extend Forwardable
44
-
45
- def initialize(uri, source, options)
46
- @uri, @source, @options = uri, source, options
47
- Ripl.start(binding: binding)
48
- end
49
-
50
- def client
51
- @client ||= Druid::Client.new(@uri, @options)
52
- @source ||= @client.data_sources[0]
53
- @client
54
- end
55
-
56
- def source
57
- client.data_source(@source)
58
- end
59
-
60
- def dimensions
61
- source.dimensions
62
- end
63
-
64
- def metrics
65
- source.metrics
66
- end
67
-
68
- def query
69
- client.query(@source)
70
- end
71
-
72
- def_delegators :query, :group_by, :sum, :long_sum, :double_sum, :count, :postagg, :interval, :granularity, :filter, :time_series, :topn
73
- end
74
- end
@@ -1,32 +0,0 @@
1
- module Druid
2
-
3
- class ResponseRow
4
- (instance_methods + private_instance_methods).each do |method|
5
- unless method.to_s =~ /^(__|object_id|initialize)/
6
- undef_method method
7
- end
8
- end
9
-
10
- attr_reader :timestamp
11
- attr_reader :row
12
-
13
- def initialize(row)
14
- @timestamp = row['timestamp']
15
- @row = row['event'] || row['result']
16
- end
17
-
18
- def method_missing(name, *args, &block)
19
- @row.send name, *args, &block
20
- end
21
-
22
- def to_s
23
- "#{@timestamp.to_s}:#{@row.to_s}"
24
- end
25
-
26
- def inspect
27
- "#{@timestamp.inspect}:#{@row.inspect}"
28
- end
29
-
30
- end
31
-
32
- end
@@ -1,19 +0,0 @@
1
- module Druid
2
- module Serializable
3
- def to_hash
4
- {}
5
- end
6
-
7
- def to_s
8
- to_hash.to_s
9
- end
10
-
11
- def as_json(*a)
12
- to_hash
13
- end
14
-
15
- def to_json(*a)
16
- to_hash.to_json(*a)
17
- end
18
- end
19
- end
@@ -1,129 +0,0 @@
1
- require 'zk'
2
- require 'json'
3
- require 'rest_client'
4
-
5
- module Druid
6
-
7
- class ZooHandler
8
- def initialize(uri, opts = {})
9
- @zk = ZK.new uri, :chroot => :check
10
- @registry = Hash.new {|hash,key| hash[key] = Array.new }
11
- @discovery_path = opts[:discovery_path] || '/discoveryPath'
12
- @watched_services = Hash.new
13
-
14
- init_zookeeper
15
- end
16
-
17
- def init_zookeeper
18
- @zk.on_expired_session do
19
- init_zookeeper
20
- end
21
-
22
- @zk.register(@discovery_path, :only => :child) do |event|
23
- check_services
24
- end
25
-
26
- check_services
27
- end
28
-
29
- def close!
30
- @zk.close!
31
- end
32
-
33
- def check_services
34
- zk_services = @zk.children @discovery_path, :watch => true
35
-
36
- #remove deprecated services
37
- (services - zk_services).each do |old_service|
38
- @registry.delete old_service
39
- if @watched_services.include? old_service
40
- @watched_services.delete(old_service).unregister
41
- end
42
- end
43
-
44
- zk_services.each do |service|
45
- check_service service unless @watched_services.include? service
46
- end
47
- end
48
-
49
- def check_service(service)
50
- unless @watched_services.include? service
51
- watchPath = "#{@discovery_path}/#{service}"
52
- @watched_services[service] = @zk.register(watchPath, :only => :child) do |event|
53
- old_handler = @watched_services.delete(service)
54
- if old_handler
55
- old_handler.unregister
56
- end
57
- check_service service
58
- end
59
-
60
- known = @registry[service].map{ |node| node[:name] } rescue []
61
- live = @zk.children(watchPath, :watch => true)
62
-
63
- # copy the unchanged entries
64
- new_list = @registry[service].select{ |node| live.include? node[:name] } rescue []
65
-
66
- # verify the new entries to be living brokers
67
- (live - known).each do |name|
68
- info = @zk.get "#{watchPath}/#{name}"
69
- node = JSON.parse(info[0])
70
- uri = "http://#{node['address']}:#{node['port']}/druid/v2/"
71
-
72
- begin
73
- check_uri = "#{uri}datasources/"
74
-
75
- check = RestClient::Request.execute({
76
- :method => :get,
77
- :url => check_uri,
78
- :timeout => 5,
79
- :open_timeout => 5
80
- })
81
-
82
- if check.code == 200
83
- new_list.push({
84
- :name => name,
85
- :uri => uri,
86
- :data_sources => JSON.parse(check.to_str)
87
- })
88
- else
89
- end
90
- rescue
91
- end
92
- end
93
-
94
- if !new_list.empty?
95
- # poor mans load balancing
96
- @registry[service] = new_list.shuffle
97
- else
98
- # don't show services w/o active brokers
99
- @registry.delete service
100
- end
101
- end
102
- end
103
-
104
- def services
105
- @registry.keys
106
- end
107
-
108
- def data_sources
109
- result = Hash.new { |hash, key| hash[key] = [] }
110
-
111
- @registry.each do |service, brokers|
112
- brokers.each do |broker|
113
- broker[:data_sources].each do |data_source|
114
- result["#{service}/#{data_source}"] << broker[:uri]
115
- end
116
- end
117
- end
118
- result.each do |source, uris|
119
- result[source] = uris.sample if uris.respond_to?(:sample)
120
- end
121
-
122
- result
123
- end
124
-
125
- def to_s
126
- @registry.to_s
127
- end
128
- end
129
- end