overriaktion 0.0.1.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,228 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://dont.overriak.com/riak_clusters.json
6
+ body: !!null
7
+ headers:
8
+ authorization:
9
+ - key
10
+ response: !ruby/struct:VCR::Response
11
+ status: !ruby/struct:VCR::ResponseStatus
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ server:
16
+ - nginx/0.7.67
17
+ date:
18
+ - Sat, 29 Oct 2011 23:26:08 GMT
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ connection:
22
+ - keep-alive
23
+ status:
24
+ - 200 OK
25
+ x-ua-compatible:
26
+ - IE=Edge,chrome=1
27
+ etag:
28
+ - ! '"61ddb7b66cd8ba45d1d6f485ee612aaa"'
29
+ cache-control:
30
+ - must-revalidate, private, max-age=0
31
+ x-runtime:
32
+ - '0.330417'
33
+ x-rack-cache:
34
+ - miss
35
+ content-length:
36
+ - '113'
37
+ x-varnish:
38
+ - '604933869'
39
+ age:
40
+ - '0'
41
+ via:
42
+ - 1.1 varnish
43
+ body: ! '[{"created_at":"2011-10-10T03:31:34Z","id":1,"name":"Localhost","updated_at":"2011-10-10T03:31:34Z","user_id":1}]'
44
+ http_version: '1.1'
45
+ - !ruby/struct:VCR::HTTPInteraction
46
+ request: !ruby/struct:VCR::Request
47
+ method: :get
48
+ uri: http://dont.overriak.com:80/riak_clusters/1.json
49
+ body: !!null
50
+ headers:
51
+ authorization:
52
+ - key
53
+ response: !ruby/struct:VCR::Response
54
+ status: !ruby/struct:VCR::ResponseStatus
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ server:
59
+ - nginx/0.7.67
60
+ date:
61
+ - Sun, 30 Oct 2011 01:20:59 GMT
62
+ content-type:
63
+ - application/json; charset=utf-8
64
+ connection:
65
+ - keep-alive
66
+ status:
67
+ - 200 OK
68
+ last-modified:
69
+ - Sun, 16 Oct 2011 17:52:50 GMT
70
+ cache-control:
71
+ - must-revalidate, private, max-age=0
72
+ x-ua-compatible:
73
+ - IE=Edge,chrome=1
74
+ x-runtime:
75
+ - '0.493222'
76
+ x-rack-cache:
77
+ - miss
78
+ content-length:
79
+ - '111'
80
+ x-varnish:
81
+ - '607689642'
82
+ age:
83
+ - '0'
84
+ via:
85
+ - 1.1 varnish
86
+ body: ! '{"created_at":"2011-10-10T03:31:34Z","id":1,"name":"Localhost","updated_at":"2011-10-10T03:31:34Z","user_id":1}'
87
+ http_version: '1.1'
88
+ - !ruby/struct:VCR::HTTPInteraction
89
+ request: !ruby/struct:VCR::Request
90
+ method: :get
91
+ uri: http://dont.overriak.com:80/riak_clusters/1/riak_nodes.json
92
+ body: !!null
93
+ headers:
94
+ authorization:
95
+ - key
96
+ response: !ruby/struct:VCR::Response
97
+ status: !ruby/struct:VCR::ResponseStatus
98
+ code: 200
99
+ message: OK
100
+ headers:
101
+ server:
102
+ - nginx/0.7.67
103
+ date:
104
+ - Sun, 30 Oct 2011 01:22:24 GMT
105
+ content-type:
106
+ - application/json; charset=utf-8
107
+ connection:
108
+ - keep-alive
109
+ status:
110
+ - 200 OK
111
+ x-ua-compatible:
112
+ - IE=Edge,chrome=1
113
+ etag:
114
+ - ! '"d54d934f198a4ccb635b0d164caafa44"'
115
+ cache-control:
116
+ - must-revalidate, private, max-age=0
117
+ x-runtime:
118
+ - '0.473296'
119
+ x-rack-cache:
120
+ - miss
121
+ content-length:
122
+ - '159'
123
+ x-varnish:
124
+ - '311653851'
125
+ age:
126
+ - '0'
127
+ via:
128
+ - 1.1 varnish
129
+ body: ! '[{"created_at":"2011-10-10T03:31:41Z","id":1,"ip_address":"127.0.0.1","port":"8098","riak_cluster_id":1,"updated_at":"2011-10-10T21:14:14Z","username":"root"}]'
130
+ http_version: '1.1'
131
+ - !ruby/struct:VCR::HTTPInteraction
132
+ request: !ruby/struct:VCR::Request
133
+ method: :get
134
+ uri: http://dont.overriak.com:80/riak_clusters/1/riak_nodes/1.json
135
+ body: !!null
136
+ headers:
137
+ authorization:
138
+ - key
139
+ response: !ruby/struct:VCR::Response
140
+ status: !ruby/struct:VCR::ResponseStatus
141
+ code: 200
142
+ message: OK
143
+ headers:
144
+ server:
145
+ - nginx/0.7.67
146
+ date:
147
+ - Sun, 30 Oct 2011 01:22:25 GMT
148
+ content-type:
149
+ - application/json; charset=utf-8
150
+ connection:
151
+ - keep-alive
152
+ status:
153
+ - 200 OK
154
+ last-modified:
155
+ - Sun, 16 Oct 2011 17:52:50 GMT
156
+ cache-control:
157
+ - must-revalidate, private, max-age=0
158
+ x-ua-compatible:
159
+ - IE=Edge,chrome=1
160
+ x-runtime:
161
+ - '0.168479'
162
+ x-rack-cache:
163
+ - miss
164
+ content-length:
165
+ - '157'
166
+ x-varnish:
167
+ - '1809353273'
168
+ age:
169
+ - '0'
170
+ via:
171
+ - 1.1 varnish
172
+ body: ! '{"created_at":"2011-10-10T03:31:41Z","id":1,"ip_address":"127.0.0.1","port":"8098","riak_cluster_id":1,"updated_at":"2011-10-10T21:14:14Z","username":"root"}'
173
+ http_version: '1.1'
174
+ - !ruby/struct:VCR::HTTPInteraction
175
+ request: !ruby/struct:VCR::Request
176
+ method: :post
177
+ uri: http://dont.overriak.com:80/samples?id=1&sample=response
178
+ body: !!null
179
+ headers:
180
+ authorization:
181
+ - '1'
182
+ response: !ruby/struct:VCR::Response
183
+ status: !ruby/struct:VCR::ResponseStatus
184
+ code: 200
185
+ message: OK
186
+ headers:
187
+ server:
188
+ - nginx/0.7.67
189
+ date:
190
+ - Tue, 01 Nov 2011 03:41:53 GMT
191
+ content-type:
192
+ - text/html; charset=utf-8
193
+ connection:
194
+ - keep-alive
195
+ status:
196
+ - 200 OK
197
+ content-length:
198
+ - '728'
199
+ x-runtime:
200
+ - '0.223045'
201
+ x-rack-cache:
202
+ - invalidate, pass
203
+ body: !!null
204
+ http_version: '1.1'
205
+ - !ruby/struct:VCR::HTTPInteraction
206
+ request: !ruby/struct:VCR::Request
207
+ method: :get
208
+ uri: http://127.0.0.1:8098/stats
209
+ body: !!null
210
+ headers: !!null
211
+ response: !ruby/struct:VCR::Response
212
+ status: !ruby/struct:VCR::ResponseStatus
213
+ code: 200
214
+ message: OK
215
+ headers:
216
+ vary:
217
+ - Accept, Accept-Encoding
218
+ server:
219
+ - MochiWeb/1.1 WebMachine/1.7.3 (participate in the frantic)
220
+ date:
221
+ - Tue, 01 Nov 2011 03:59:40 GMT
222
+ content-type:
223
+ - application/json
224
+ content-length:
225
+ - '1840'
226
+ body: ! '{"vnode_gets":0,"vnode_puts":0,"read_repairs":0,"vnode_gets_total":9243,"vnode_puts_total":2694,"node_gets":0,"node_gets_total":3081,"node_get_fsm_time_mean":"undefined","node_get_fsm_time_median":"undefined","node_get_fsm_time_95":"undefined","node_get_fsm_time_99":"undefined","node_get_fsm_time_100":"undefined","node_puts":0,"node_puts_total":898,"node_put_fsm_time_mean":"undefined","node_put_fsm_time_median":"undefined","node_put_fsm_time_95":"undefined","node_put_fsm_time_99":"undefined","node_put_fsm_time_100":"undefined","read_repairs_total":0,"cpu_nprocs":665,"cpu_avg1":100,"cpu_avg5":56,"cpu_avg15":38,"mem_total":3947307008.0,"mem_allocated":2930966528.0,"nodename":"riak@127.0.0.1","connected_nodes":[],"sys_driver_version":"1.5","sys_global_heaps_size":0,"sys_heap_type":"private","sys_logical_processors":4,"sys_otp_release":"R13B04","sys_process_count":213,"sys_smp_support":true,"sys_system_version":"Erlang
227
+ R13B04 (erts-5.7.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:64] [kernel-poll:true]","sys_system_architecture":"x86_64-pc-linux-gnu","sys_threads_enabled":true,"sys_thread_pool_size":64,"sys_wordsize":8,"ring_members":["riak@127.0.0.1"],"ring_num_partitions":64,"ring_ownership":"[{''riak@127.0.0.1'',64}]","ring_creation_size":64,"storage_backend":"riak_kv_bitcask_backend","pbc_connects_total":0,"pbc_connects":0,"pbc_active":0,"cluster_info_version":"1.0.0","luwak_version":"1.0.0","skerl_version":"1.0.0","riak_kv_version":"0.14.0","riak_core_version":"0.14.0","bitcask_version":"1.1.5","luke_version":"0.2.3","webmachine_version":"1.8.0","mochiweb_version":"1.7.1","erlang_js_version":"0.5.0","runtime_tools_version":"1.8.3","crypto_version":"1.6.4","os_mon_version":"2.2.5","riak_err_version":"1.0.0","sasl_version":"2.1.9","stdlib_version":"1.16.5","kernel_version":"2.13.5","executing_mappers":0}'
228
+ http_version: '1.1'
@@ -0,0 +1,44 @@
1
+ require 'overriaktion/version'
2
+ require 'overriaktion/vcr'
3
+
4
+ require 'singleton'
5
+ require 'httparty'
6
+ require 'json'
7
+
8
+ module Overriaktion
9
+ autoload :Client, "overriaktion/client"
10
+ autoload :Request, "overriaktion/request"
11
+
12
+ autoload :Configuration, "overriaktion/configuration"
13
+
14
+ autoload :Model, "overriaktion/model"
15
+ autoload :RiakCluster, "overriaktion/riak_cluster"
16
+ autoload :RiakNode, "overriaktion/riak_node"
17
+
18
+ autoload :EndPoints, "overriaktion/end_points"
19
+
20
+ autoload :CLI, "overriaktion/cli"
21
+
22
+ autoload :Sample, "overriaktion/sample"
23
+
24
+ class << self
25
+ def new(options = {})
26
+ Client.instance.tap do |instance|
27
+ instance.configure do |config|
28
+ options.each_pair do |key, value|
29
+ config.send("#{key}=".to_sym, value)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def method_missing(method, *args, &block)
36
+ return super unless new.respond_to?(method)
37
+ new.send(method, *args, &block)
38
+ end
39
+
40
+ def respond_to?(method, include_private=false)
41
+ new.respond_to?(method, include_private) || super(method, include_private)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ module Overriaktion
2
+ class CLI
3
+ attr_accessor :client
4
+
5
+ def initialize(api_key)
6
+ @client = Overriaktion.new(:api_key => api_key)
7
+ end
8
+
9
+ # Dispatcher
10
+ #
11
+
12
+ def dispatch(operation, cluster_name, node_uri)
13
+ case operation
14
+ when 'list'
15
+ list(cluster_name)
16
+ when 'sample'
17
+ sample(cluster_name, node_uri)
18
+ else
19
+ puts "'#{operation}' is not a valid operation"
20
+ end
21
+ end
22
+
23
+ def self.dispatch(api_key, operation, cluster_name, node_uri)
24
+ if client = self.new(api_key)
25
+ client.dispatch(operation, cluster_name, node_uri)
26
+ end
27
+ end
28
+
29
+ # Dispatch mechanisms
30
+ #
31
+
32
+ def list(cluster_name)
33
+ @client.riak_clusters.each do |cluster|
34
+ puts "#{cluster}"
35
+
36
+ cluster.riak_nodes.each do |node|
37
+ puts " - #{node}"
38
+ end
39
+ end
40
+ end
41
+
42
+ def sample(cluster_name, node_uri)
43
+ if riak_node = @client.riak_node_by_cluster_name_and_node_uri(cluster_name, node_uri)
44
+ retval = riak_node.sample
45
+ end
46
+
47
+ puts "OK"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,47 @@
1
+ module Overriaktion
2
+ class Client
3
+ include Singleton
4
+
5
+ def request
6
+ Request.new
7
+ end
8
+
9
+ def configure
10
+ yield configuration
11
+ end
12
+
13
+ def configuration
14
+ Configuration.instance
15
+ end
16
+
17
+ def riak_clusters
18
+ response = request.get("/riak_clusters.json")
19
+ response.map { |riak_cluster| RiakCluster.new(riak_cluster) }
20
+ end
21
+
22
+ def riak_cluster(riak_cluster_id)
23
+ response = request.get("/riak_clusters/#{riak_cluster_id}.json")
24
+ RiakCluster.new(response)
25
+ end
26
+
27
+ def riak_nodes(riak_cluster_id)
28
+ response = request.get("/riak_clusters/#{riak_cluster_id}/riak_nodes.json")
29
+ response.map { |riak_node| RiakNode.new(riak_node) }
30
+ end
31
+
32
+ def riak_node(riak_cluster_id, riak_node_id)
33
+ response = request.get("/riak_clusters/#{riak_cluster_id}/riak_nodes/#{riak_node_id}.json")
34
+ RiakNode.new(response)
35
+ end
36
+
37
+ def create_sample(riak_node_id, sample)
38
+ request.post("/samples", { :id => riak_node_id, :sample => sample })
39
+ end
40
+
41
+ def riak_node_by_cluster_name_and_node_uri(cluster_name, node_uri)
42
+ if cluster = riak_clusters.detect { |cluster| cluster.name == cluster_name }
43
+ node = cluster.riak_nodes.detect { |node| node.to_s == node_uri }
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,18 @@
1
+ module Overriaktion
2
+ class Configuration
3
+ include Singleton
4
+
5
+ VALID_ATTRIBUTES = [:api_key, :api_host]
6
+
7
+ attr_accessor *VALID_ATTRIBUTES
8
+
9
+ def api_host
10
+ @api_host || EndPoints::DEFAULT
11
+ end
12
+
13
+ def self.method_missing(method, *args, &block)
14
+ return super unless instance.respond_to?(method)
15
+ instance.send(method, *args, &block)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Overriaktion
2
+ module EndPoints
3
+ DEFAULT = "dont.overriak.com"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ module Overriaktion
2
+ class Model < Hash
3
+ attr_accessor :client
4
+
5
+ def initialize(options = {})
6
+ options.each_pair do |key, value|
7
+ self[key.to_sym] = value
8
+ end
9
+
10
+ @client = Client.instance
11
+ end
12
+
13
+ def method_missing(method, *params)
14
+ method = method.to_sym
15
+ return self[method] if self.keys.collect(&:to_sym).include?(method)
16
+ super
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module Overriaktion
2
+ class Request
3
+ extend Forwardable
4
+
5
+ def_delegators :configuration, :api_key, :api_host
6
+
7
+ def configuration
8
+ Configuration.instance
9
+ end
10
+
11
+ include HTTParty
12
+
13
+ def initialize
14
+ if api_key
15
+ self.class.headers 'Authorization' => api_key
16
+ end
17
+ self.class.format :json
18
+ self.class.base_uri api_host
19
+ end
20
+
21
+ def get(uri)
22
+ self.class.get(uri)
23
+ end
24
+
25
+ def post(uri, query)
26
+ self.class.post(uri, :query => query)
27
+ end
28
+ end
29
+ end