etzetera 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/etzetera/client.rb +34 -24
- data/lib/etzetera/version.rb +1 -1
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38612bce2ee17586f79f5cfd8d8c33c756e64092
|
4
|
+
data.tar.gz: dd6df3080f822e663f1c1fef03cafdfb569849d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 891492fc076d758d6745758615cd7bd61131dcdb3e09b0d65fec6dfe615013b66f11299a0989494bd76e9e4a767629a41f6ab11d77b263d58afd5e0a108cd58e
|
7
|
+
data.tar.gz: f3340a534150032db397a562fe4dec957335eb4d649bce6a14f6df5b98dd149698b272cd6299bae51a3a4ef8970e1faa3252bbf3f858ffdb7bcfeadf15462b0d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/etzetera/client.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'celluloid/io'
|
2
|
-
require 'time'
|
3
2
|
require 'multi_json'
|
4
3
|
|
5
4
|
module Etzetera
|
6
5
|
class Client
|
6
|
+
include Celluloid::Logger
|
7
7
|
include Celluloid::IO
|
8
|
+
|
8
9
|
API_VERSION = 'v2'.freeze
|
9
10
|
KEYS_PREFIX = "/#{API_VERSION}/keys".freeze
|
10
11
|
LOCK_PREFIX = "/mod/#{API_VERSION}/lock/".freeze
|
@@ -22,16 +23,15 @@ module Etzetera
|
|
22
23
|
def_opts = default_options.dup
|
23
24
|
|
24
25
|
opts = {}
|
25
|
-
opts[:headers]
|
26
|
-
opts[:response]
|
27
|
-
opts[:socket_class]
|
28
|
-
opts[:ssl_socket_class]
|
26
|
+
opts[:headers] = {:accept => 'application/json'}
|
27
|
+
opts[:response] = :object
|
28
|
+
opts[:socket_class] = Celluloid::IO::TCPSocket
|
29
|
+
opts[:ssl_socket_class] = Celluloid::IO::SSLSocket
|
29
30
|
|
30
31
|
@etcd_opts = {}
|
31
32
|
@etcd_opts[:election_timeout] = def_opts.delete(:election_timeout) {|key| 200}
|
32
33
|
@etcd_opts[:heartbeat_interval] = def_opts.delete(:heartbeat_interval) {|key| 50}
|
33
34
|
|
34
|
-
|
35
35
|
@default_options = ::HTTP::Options.new(opts.merge(def_opts))
|
36
36
|
end
|
37
37
|
|
@@ -61,15 +61,15 @@ module Etzetera
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def create(key, form, params = {})
|
64
|
-
request(:put, KEYS_PREFIX, key, form
|
64
|
+
request(:put, KEYS_PREFIX, key, :form => form, :params => params.merge({:prevExist => false}))
|
65
65
|
end
|
66
66
|
|
67
67
|
def update(key, form, params = {})
|
68
|
-
request(:put, KEYS_PREFIX, key, form
|
68
|
+
request(:put, KEYS_PREFIX, key, :form => form, :params => params.merge({:prevExist => true}))
|
69
69
|
end
|
70
70
|
|
71
71
|
def mkdir(dir)
|
72
|
-
request(:put, KEYS_PREFIX, dir, :params => {dir
|
72
|
+
request(:put, KEYS_PREFIX, dir, :params => {:dir => true})
|
73
73
|
end
|
74
74
|
|
75
75
|
def dir(dir, params = {})
|
@@ -131,37 +131,47 @@ module Etzetera
|
|
131
131
|
client = ::HTTP::Client.new(opts)
|
132
132
|
server = servers.first
|
133
133
|
retries = servers.count - 1
|
134
|
-
|
134
|
+
req = nil
|
135
|
+
|
135
136
|
begin
|
136
|
-
|
137
|
-
MultiJson.load(
|
137
|
+
req = client.request(verb, "#{server}#{prefix}#{path}")
|
138
|
+
response = MultiJson.load(req.body)
|
139
|
+
unless response['errorCode']
|
140
|
+
response
|
141
|
+
else
|
142
|
+
abort Error::CODES[response['errorCode']].new(response['message'])
|
143
|
+
end
|
138
144
|
rescue IOError => e
|
139
145
|
abort e if retries < 1
|
140
146
|
|
147
|
+
#sleep (@etcd_opts[:election_timeout] / 1000.0)
|
148
|
+
|
141
149
|
old_server = server
|
142
150
|
new_servers = servers.dup
|
143
151
|
new_servers.delete(old_server)
|
144
|
-
# Would be nice if you could get the host:port combination of the new leader
|
145
|
-
# Or maybe i haven't looked good enough ^^
|
152
|
+
# Would be nice if you could get the host:port combination of the new leader directly.
|
146
153
|
server = new_servers.sample
|
147
154
|
|
148
155
|
servers.swap!(servers.index(old_server), servers.index(server))
|
149
156
|
|
150
157
|
retries -= 1
|
151
158
|
|
152
|
-
#sleep (@etcd_opts[:election_timeout] / 1000.0)
|
153
159
|
retry
|
160
|
+
# etcd is inconsistent in the way it handles http responses
|
161
|
+
# instead of adopting their buggy behaviour (all 5** errors are text, 4** errors are json,
|
162
|
+
# but both respond with text/plain content-type) i just use exceptions for flow control :<
|
154
163
|
rescue MultiJson::LoadError => e
|
155
|
-
if
|
156
|
-
|
157
|
-
elsif
|
158
|
-
if
|
159
|
-
|
164
|
+
if req.code.between?(200, 299)
|
165
|
+
req.body.to_s
|
166
|
+
elsif req.code.between?(300, 399)
|
167
|
+
if req.headers['Location']
|
168
|
+
debug req.headers['Location']
|
169
|
+
request(verb, '', req.headers['Location'], opts)
|
160
170
|
end
|
161
|
-
elsif
|
162
|
-
abort Error::HttpClientError.new("#{
|
163
|
-
elsif
|
164
|
-
abort Error::HttpServerError.new("#{
|
171
|
+
elsif req.code.between?(400, 499)
|
172
|
+
abort Error::HttpClientError.new("#{req.reason}\n\t#{req.body}")
|
173
|
+
elsif req.code.between?(500, 599)
|
174
|
+
abort Error::HttpServerError.new("#{req.reason}\n\t#{req.body}")
|
165
175
|
else
|
166
176
|
abort Error::EtzeteraError.new(e)
|
167
177
|
end
|
data/lib/etzetera/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etzetera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hendrik
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
fESaRa24pr3CGd0AyltcRbKGfNpZfj1zfqWXrDUJj0Y1sOASd8+UZPmBFS2feJqy
|
32
32
|
het/fGFD7akMwHXIlNxNsg==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2014-03-
|
34
|
+
date: 2014-03-22 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: celluloid-io
|
@@ -128,3 +128,4 @@ signing_key:
|
|
128
128
|
specification_version: 4
|
129
129
|
summary: etcd ruby client
|
130
130
|
test_files: []
|
131
|
+
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|