riak-client 1.4.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +0 -1
- data/{LICENSE → LICENSE.md} +0 -0
- data/README.markdown +211 -66
- data/RELEASE_NOTES.md +22 -47
- data/Rakefile +45 -0
- data/lib/riak.rb +1 -1
- data/lib/riak/bucket.rb +2 -2
- data/lib/riak/client.rb +22 -195
- data/lib/riak/client/beefcake/crdt_loader.rb +127 -0
- data/lib/riak/client/beefcake/crdt_operator.rb +222 -0
- data/lib/riak/client/beefcake/footer +4 -0
- data/lib/riak/client/beefcake/header +6 -0
- data/lib/riak/client/beefcake/message_codes.rb +29 -0
- data/lib/riak/client/beefcake/message_overlay.rb +61 -0
- data/lib/riak/client/beefcake/messages.rb +733 -371
- data/lib/riak/client/beefcake/object_methods.rb +1 -1
- data/lib/riak/client/beefcake/protocol.rb +105 -0
- data/lib/riak/client/beefcake/socket.rb +243 -0
- data/lib/riak/client/beefcake_protobuffs_backend.rb +262 -122
- data/lib/riak/client/node.rb +4 -75
- data/lib/riak/client/protobuffs_backend.rb +6 -14
- data/lib/riak/client/search.rb +0 -64
- data/lib/riak/client/yokozuna.rb +52 -0
- data/lib/riak/counter.rb +1 -1
- data/lib/riak/crdt.rb +21 -0
- data/lib/riak/crdt/base.rb +97 -0
- data/lib/riak/crdt/batch_counter.rb +19 -0
- data/lib/riak/crdt/batch_map.rb +41 -0
- data/lib/riak/crdt/counter.rb +71 -0
- data/lib/riak/crdt/inner_counter.rb +74 -0
- data/lib/riak/crdt/inner_flag.rb +42 -0
- data/lib/riak/crdt/inner_map.rb +53 -0
- data/lib/riak/crdt/inner_register.rb +26 -0
- data/lib/riak/crdt/inner_set.rb +95 -0
- data/lib/riak/crdt/map.rb +88 -0
- data/lib/riak/crdt/operation.rb +19 -0
- data/lib/riak/crdt/set.rb +156 -0
- data/lib/riak/crdt/typed_collection.rb +131 -0
- data/lib/riak/errors/base.rb +9 -0
- data/lib/riak/errors/connection_error.rb +44 -0
- data/lib/riak/errors/crdt_error.rb +18 -0
- data/lib/riak/errors/failed_request.rb +56 -0
- data/lib/riak/errors/protobuffs_error.rb +11 -0
- data/lib/riak/i18n.rb +2 -0
- data/lib/riak/json.rb +1 -1
- data/lib/riak/locale/en.yml +26 -1
- data/lib/riak/locale/fr.yml +0 -1
- data/lib/riak/map_reduce.rb +1 -1
- data/lib/riak/map_reduce/results.rb +1 -1
- data/lib/riak/multiget.rb +1 -2
- data/lib/riak/rcontent.rb +8 -3
- data/lib/riak/robject.rb +2 -8
- data/lib/riak/secondary_index.rb +4 -4
- data/lib/riak/serializers.rb +1 -1
- data/lib/riak/util/escape.rb +3 -5
- data/lib/riak/version.rb +1 -1
- data/lib/riak/walk_spec.rb +7 -3
- data/riak-client.gemspec +10 -8
- data/spec/fixtures/bitcask.txt +25 -0
- data/spec/integration/riak/bucket_types_spec.rb +61 -0
- data/spec/integration/riak/counters_spec.rb +17 -32
- data/spec/integration/riak/crdt_spec.rb +181 -0
- data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
- data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
- data/spec/integration/riak/protobuffs_backends_spec.rb +9 -26
- data/spec/integration/riak/security_spec.rb +94 -0
- data/spec/integration/riak/threading_spec.rb +24 -67
- data/spec/integration/yokozuna/index_spec.rb +61 -0
- data/spec/integration/yokozuna/queries_spec.rb +116 -0
- data/spec/integration/yokozuna/schema_spec.rb +49 -0
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +4 -4
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
- data/spec/riak/beefcake_protobuffs_backend/socket_spec.rb +151 -0
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +68 -106
- data/spec/riak/bucket_spec.rb +81 -77
- data/spec/riak/client_spec.rb +43 -340
- data/spec/riak/core_ext/to_param_spec.rb +2 -2
- data/spec/riak/counter_spec.rb +20 -20
- data/spec/riak/crdt/counter_spec.rb +52 -0
- data/spec/riak/crdt/inner_counter_spec.rb +21 -0
- data/spec/riak/crdt/inner_flag_spec.rb +39 -0
- data/spec/riak/crdt/inner_map_spec.rb +47 -0
- data/spec/riak/crdt/inner_register_spec.rb +40 -0
- data/spec/riak/crdt/inner_set_spec.rb +33 -0
- data/spec/riak/crdt/map_spec.rb +77 -0
- data/spec/riak/crdt/set_spec.rb +58 -0
- data/spec/riak/crdt/shared_examples.rb +74 -0
- data/spec/riak/crdt/typed_collection_spec.rb +231 -0
- data/spec/riak/escape_spec.rb +33 -37
- data/spec/riak/feature_detection_spec.rb +45 -45
- data/spec/riak/index_collection_spec.rb +12 -12
- data/spec/riak/link_spec.rb +34 -34
- data/spec/riak/list_buckets_spec.rb +7 -7
- data/spec/riak/map_reduce/filter_builder_spec.rb +6 -6
- data/spec/riak/map_reduce/phase_spec.rb +35 -35
- data/spec/riak/map_reduce_spec.rb +89 -87
- data/spec/riak/multiget_spec.rb +20 -15
- data/spec/riak/node_spec.rb +5 -152
- data/spec/riak/robject_spec.rb +95 -108
- data/spec/riak/search_spec.rb +17 -139
- data/spec/riak/secondary_index_spec.rb +49 -49
- data/spec/riak/serializers_spec.rb +9 -9
- data/spec/riak/stamp_spec.rb +9 -9
- data/spec/riak/walk_spec_spec.rb +46 -46
- data/spec/spec_helper.rb +14 -22
- data/spec/support/certs/README.md +13 -0
- data/spec/support/certs/ca.crt +22 -0
- data/spec/support/certs/client.crt +95 -0
- data/spec/support/certs/client.key +27 -0
- data/spec/support/certs/empty_ca.crt +21 -0
- data/spec/support/certs/server.crl +13 -0
- data/spec/support/certs/server.crt +95 -0
- data/spec/support/certs/server.key +27 -0
- data/spec/support/integration_setup.rb +1 -1
- data/spec/support/search_corpus_setup.rb +29 -8
- data/spec/support/test_client.rb +46 -0
- data/spec/support/test_client.yml.example +10 -0
- data/spec/support/unified_backend_examples.rb +104 -83
- data/spec/support/version_filter.rb +2 -2
- data/spec/support/wait_until.rb +14 -0
- metadata +134 -132
- data/erl_src/riak_kv_test014_backend.beam +0 -0
- data/erl_src/riak_kv_test014_backend.erl +0 -189
- data/erl_src/riak_kv_test_backend.beam +0 -0
- data/erl_src/riak_kv_test_backend.erl +0 -731
- data/erl_src/riak_search_test_backend.beam +0 -0
- data/erl_src/riak_search_test_backend.erl +0 -175
- data/lib/riak/client/excon_backend.rb +0 -172
- data/lib/riak/client/http_backend.rb +0 -413
- data/lib/riak/client/http_backend/bucket_streamer.rb +0 -15
- data/lib/riak/client/http_backend/chunked_json_streamer.rb +0 -42
- data/lib/riak/client/http_backend/configuration.rb +0 -227
- data/lib/riak/client/http_backend/key_streamer.rb +0 -15
- data/lib/riak/client/http_backend/object_methods.rb +0 -114
- data/lib/riak/client/http_backend/request_headers.rb +0 -34
- data/lib/riak/client/http_backend/transport_methods.rb +0 -201
- data/lib/riak/client/instrumentation.rb +0 -25
- data/lib/riak/client/net_http_backend.rb +0 -82
- data/lib/riak/cluster.rb +0 -151
- data/lib/riak/failed_request.rb +0 -81
- data/lib/riak/instrumentation.rb +0 -6
- data/lib/riak/node.rb +0 -40
- data/lib/riak/node/configuration.rb +0 -304
- data/lib/riak/node/console.rb +0 -133
- data/lib/riak/node/control.rb +0 -207
- data/lib/riak/node/defaults.rb +0 -85
- data/lib/riak/node/generation.rb +0 -127
- data/lib/riak/node/log.rb +0 -34
- data/lib/riak/node/version.rb +0 -29
- data/lib/riak/search.rb +0 -3
- data/lib/riak/test_server.rb +0 -89
- data/lib/riak/util/headers.rb +0 -32
- data/lib/riak/util/multipart.rb +0 -52
- data/lib/riak/util/multipart/stream_parser.rb +0 -62
- data/spec/fixtures/munchausen.txt +0 -1033
- data/spec/integration/riak/cluster_spec.rb +0 -88
- data/spec/integration/riak/http_backends_spec.rb +0 -180
- data/spec/integration/riak/node_spec.rb +0 -170
- data/spec/integration/riak/test_server_spec.rb +0 -57
- data/spec/riak/excon_backend_spec.rb +0 -102
- data/spec/riak/headers_spec.rb +0 -21
- data/spec/riak/http_backend/configuration_spec.rb +0 -273
- data/spec/riak/http_backend/object_methods_spec.rb +0 -243
- data/spec/riak/http_backend/transport_methods_spec.rb +0 -97
- data/spec/riak/http_backend_spec.rb +0 -367
- data/spec/riak/instrumentation_spec.rb +0 -167
- data/spec/riak/multipart_spec.rb +0 -23
- data/spec/riak/net_http_backend_spec.rb +0 -15
- data/spec/riak/stream_parser_spec.rb +0 -53
- data/spec/support/drb_mock_server.rb +0 -39
- data/spec/support/http_backend_implementation_examples.rb +0 -253
- data/spec/support/mock_server.rb +0 -81
- data/spec/support/mocks.rb +0 -4
- data/spec/support/riak_test.rb +0 -77
- data/spec/support/sometimes.rb +0 -46
- data/spec/support/test_server.rb +0 -61
- data/spec/support/test_server.yml.example +0 -14
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'riak/util/escape'
|
2
|
-
require 'riak/json'
|
3
|
-
|
4
|
-
module Riak
|
5
|
-
class Client
|
6
|
-
class HTTPBackend
|
7
|
-
class ChunkedJsonStreamer
|
8
|
-
include Util::Escape
|
9
|
-
|
10
|
-
def initialize(block)
|
11
|
-
@buffer = ""
|
12
|
-
@block = block
|
13
|
-
end
|
14
|
-
|
15
|
-
def accept(chunk)
|
16
|
-
@buffer << chunk
|
17
|
-
consume
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_proc
|
21
|
-
method(:accept).to_proc
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
def consume
|
26
|
-
while @buffer =~ /\}\{/
|
27
|
-
stream($~.pre_match + '}')
|
28
|
-
@buffer = '{' + $~.post_match
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def stream(str)
|
33
|
-
obj = JSON.parse(str) rescue nil
|
34
|
-
if obj && get_values(obj)
|
35
|
-
@block.call get_values(obj).map(&method(:maybe_unescape))
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
@@ -1,227 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'riak/failed_request'
|
3
|
-
require 'riak/client/http_backend'
|
4
|
-
require 'riak/link'
|
5
|
-
|
6
|
-
module Riak
|
7
|
-
class Client
|
8
|
-
class HTTPBackend
|
9
|
-
# Riak 0.14 provides a root URL that enumerates all of the
|
10
|
-
# HTTP endpoints and their paths. This module adds methods to
|
11
|
-
# auto-discover those endpoints via the root URL. It also adds
|
12
|
-
# methods for generating URL paths for specific resources.
|
13
|
-
module Configuration
|
14
|
-
# @return [URI] a URL path to the "ping" resource
|
15
|
-
def ping_path
|
16
|
-
path(riak_kv_wm_ping)
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [URI] a URL path to the "stats" resource
|
20
|
-
def stats_path
|
21
|
-
path(riak_kv_wm_stats)
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [URI] a URL path to the "mapred" resource
|
25
|
-
# @param options [Hash] query parameters, e.g. chunked=true
|
26
|
-
def mapred_path(options={})
|
27
|
-
path(riak_kv_wm_mapred, options)
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [URI] a URL path for the "buckets list" resource
|
31
|
-
def bucket_list_path(options={})
|
32
|
-
if options[:stream] && new_scheme?
|
33
|
-
options.delete :stream
|
34
|
-
path(riak_kv_wm_buckets, options.merge(buckets: 'stream'))
|
35
|
-
elsif new_scheme?
|
36
|
-
path(riak_kv_wm_buckets, options.merge(:buckets => true))
|
37
|
-
else
|
38
|
-
path(riak_kv_wm_raw, options.merge(:buckets => true))
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# @return [URI] a URL path for the "bucket properties"
|
43
|
-
# resource
|
44
|
-
# @param [String] bucket the bucket name
|
45
|
-
def bucket_properties_path(bucket, options={})
|
46
|
-
if new_scheme?
|
47
|
-
path(riak_kv_wm_buckets, escape(bucket), "props", options)
|
48
|
-
else
|
49
|
-
path(riak_kv_wm_raw, escape(bucket), options.merge(:props => true, :keys => false))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# @return [URI] a URL path for the "list keys" resource
|
54
|
-
# @param [String] bucket the bucket whose keys to list
|
55
|
-
# @param [Hash] options query parameters, e.g. keys=stream
|
56
|
-
def key_list_path(bucket, options={:keys => true})
|
57
|
-
if new_scheme?
|
58
|
-
path(riak_kv_wm_buckets, escape(bucket), "keys", options)
|
59
|
-
else
|
60
|
-
path(riak_kv_wm_raw, escape(bucket), options.merge(:props => false))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# @return [URI] a URL path for the "object" resource
|
65
|
-
# @param [String] bucket the bucket of the object
|
66
|
-
# @param [String,nil] key the key of the object, or nil for a
|
67
|
-
# server-assigned key when using POST
|
68
|
-
def object_path(bucket, key, options={})
|
69
|
-
key = escape(key) if key
|
70
|
-
if new_scheme?
|
71
|
-
path([riak_kv_wm_buckets, escape(bucket), "keys", key, options].compact)
|
72
|
-
else
|
73
|
-
path([riak_kv_wm_raw, escape(bucket), key, options].compact)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# @return [URI] a URL path for the "counter" resource
|
78
|
-
# @param [String] bucket the bucket of the counter
|
79
|
-
# @param [String] key the key of the counter
|
80
|
-
def counter_path(bucket, key, options={})
|
81
|
-
path([
|
82
|
-
riak_kv_wm_buckets,
|
83
|
-
escape(bucket),
|
84
|
-
"counters",
|
85
|
-
escape(key),
|
86
|
-
options
|
87
|
-
].compact)
|
88
|
-
end
|
89
|
-
|
90
|
-
# @return [URI] a URL path for the "link-walking" resource
|
91
|
-
# @param [String] bucket the bucket of the origin object
|
92
|
-
# @param [String] key the key of the origin object
|
93
|
-
# @param [Array<WalkSpec>] specs a list of walk specifications
|
94
|
-
# to traverse
|
95
|
-
def link_walk_path(bucket, key, specs)
|
96
|
-
specs = specs.map {|s| s.to_s }
|
97
|
-
if new_scheme?
|
98
|
-
path(riak_kv_wm_buckets, escape(bucket), "keys", escape(key), *specs)
|
99
|
-
else
|
100
|
-
path(riak_kv_wm_link_walker, escape(bucket), escape(key), *specs)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# @return [URI] a URL path for the "index range query"
|
105
|
-
# resource
|
106
|
-
# @param [String] bucket the bucket whose index to query
|
107
|
-
# @param [String] index the name of the index to query
|
108
|
-
# @param [String,Integer] start the start of the range
|
109
|
-
# @param [String,Integer] finish the end of the range
|
110
|
-
def index_range_path(bucket, index, start, finish, options={})
|
111
|
-
raise t('indexes_unsupported') unless new_scheme?
|
112
|
-
path(riak_kv_wm_buckets, escape(bucket), "index", escape(index), escape(start.to_s), escape(finish.to_s), options)
|
113
|
-
end
|
114
|
-
|
115
|
-
# @return [URI] a URL path for the "index range query"
|
116
|
-
# resource
|
117
|
-
# @param [String] bucket the bucket whose index to query
|
118
|
-
# @param [String] index the name of the index to query
|
119
|
-
# @param [String,Integer] start the start of the range
|
120
|
-
# @param [String,Integer] finish the end of the range
|
121
|
-
def index_eq_path(bucket, index, value, options={})
|
122
|
-
raise t('indexes_unsupported') unless new_scheme?
|
123
|
-
path(riak_kv_wm_buckets, escape(bucket), "index", escape(index), escape(value.to_s), options)
|
124
|
-
end
|
125
|
-
|
126
|
-
# @return [URI] a URL path for a Solr query resource
|
127
|
-
# @param [String] index the index to query
|
128
|
-
# @param [String] query the Lucene-style query string
|
129
|
-
# @param [Hash] options additional query options
|
130
|
-
def solr_select_path(index, query, options={})
|
131
|
-
raise t('search_unsupported') unless riak_solr_searcher_wm
|
132
|
-
options = {"q" => query, "wt" => "json"}.merge(options)
|
133
|
-
if index
|
134
|
-
path(riak_solr_searcher_wm, index, 'select', options)
|
135
|
-
else
|
136
|
-
path(riak_solr_searcher_wm, 'select', options)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# @return [URI] a URL path for a Solr update resource
|
141
|
-
# @param [String] index the index to update
|
142
|
-
def solr_update_path(index)
|
143
|
-
raise t('search_unsupported') unless riak_solr_indexer_wm
|
144
|
-
if index
|
145
|
-
path(riak_solr_indexer_wm, index, 'update')
|
146
|
-
else
|
147
|
-
path(riak_solr_indexer_wm, 'update')
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
# @return [URI] a URL path for the Luwak interface
|
152
|
-
def luwak_path(key)
|
153
|
-
raise t('luwak_unsupported') unless luwak_wm_file
|
154
|
-
if key
|
155
|
-
path(luwak_wm_file, escape(key))
|
156
|
-
else
|
157
|
-
path(luwak_wm_file)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
private
|
162
|
-
def server_config
|
163
|
-
@server_config ||= {}.tap do |hash|
|
164
|
-
begin
|
165
|
-
response = get(200, path("/"))
|
166
|
-
Link.parse(response[:headers]['link'].first).each {|l| hash[l.tag.intern] ||= l.url }
|
167
|
-
rescue Riak::FailedRequest
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def new_scheme?
|
173
|
-
!riak_kv_wm_buckets.nil?
|
174
|
-
end
|
175
|
-
|
176
|
-
def get_server_version
|
177
|
-
begin
|
178
|
-
# Attempt to grab the server version from the stats resource
|
179
|
-
stats = send(:stats)
|
180
|
-
stats['riak_kv_version']
|
181
|
-
rescue FailedRequest
|
182
|
-
# If stats is disabled, we can't assume the Riak version
|
183
|
-
# is >= 1.1. However, we can assume the new URL scheme is
|
184
|
-
# at least version 1.0.
|
185
|
-
new_scheme? ? "1.0.0" : "0.14.0"
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def riak_kv_wm_buckets
|
190
|
-
server_config[:riak_kv_wm_buckets]
|
191
|
-
end
|
192
|
-
|
193
|
-
def riak_kv_wm_raw
|
194
|
-
server_config[:riak_kv_wm_raw] || node.http_paths[:prefix]
|
195
|
-
end
|
196
|
-
|
197
|
-
def riak_kv_wm_link_walker
|
198
|
-
server_config[:riak_kv_wm_link_walker] || node.http_paths[:prefix]
|
199
|
-
end
|
200
|
-
|
201
|
-
def riak_kv_wm_mapred
|
202
|
-
server_config[:riak_kv_wm_mapred] || node.http_paths[:mapred]
|
203
|
-
end
|
204
|
-
|
205
|
-
def riak_kv_wm_ping
|
206
|
-
server_config[:riak_kv_wm_ping] || "/ping"
|
207
|
-
end
|
208
|
-
|
209
|
-
def riak_kv_wm_stats
|
210
|
-
server_config[:riak_kv_wm_stats] || "/stats"
|
211
|
-
end
|
212
|
-
|
213
|
-
def riak_solr_searcher_wm
|
214
|
-
server_config[:riak_solr_searcher_wm]
|
215
|
-
end
|
216
|
-
|
217
|
-
def riak_solr_indexer_wm
|
218
|
-
server_config[:riak_solr_indexer_wm]
|
219
|
-
end
|
220
|
-
|
221
|
-
def luwak_wm_file
|
222
|
-
server_config[:luwak_wm_file]
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'set'
|
3
|
-
require 'time'
|
4
|
-
require 'riak/client/http_backend'
|
5
|
-
require 'riak/robject'
|
6
|
-
require 'riak/link'
|
7
|
-
require 'riak/util/multipart'
|
8
|
-
|
9
|
-
module Riak
|
10
|
-
class Client
|
11
|
-
class HTTPBackend
|
12
|
-
# Methods for assisting with the handling of {RObject}s present
|
13
|
-
# in HTTP requests and responses.
|
14
|
-
module ObjectMethods
|
15
|
-
# HTTP header hash that will be sent along when reloading the object
|
16
|
-
# @return [Hash] hash of HTTP headers
|
17
|
-
def reload_headers(robject)
|
18
|
-
{}.tap do |h|
|
19
|
-
h['If-None-Match'] = robject.etag if robject.etag.present?
|
20
|
-
h['If-Modified-Since'] = robject.last_modified.httpdate if robject.last_modified.present?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# HTTP header hash that will be sent along when storing the object
|
25
|
-
# @return [Hash] hash of HTTP Headers
|
26
|
-
def store_headers(robject)
|
27
|
-
{}.tap do |hash|
|
28
|
-
hash["Content-Type"] = robject.content_type
|
29
|
-
hash["X-Riak-Vclock"] = robject.vclock if robject.vclock
|
30
|
-
if robject.prevent_stale_writes && robject.etag.present?
|
31
|
-
hash["If-Match"] = robject.etag
|
32
|
-
elsif robject.prevent_stale_writes
|
33
|
-
hash["If-None-Match"] = "*"
|
34
|
-
end
|
35
|
-
unless robject.links.blank?
|
36
|
-
hash["Link"] = robject.links.reject {|l| l.rel == "up" }.map {|l| l.to_s(new_scheme?) }.join(", ")
|
37
|
-
end
|
38
|
-
unless robject.meta.blank?
|
39
|
-
robject.meta.each do |k,v|
|
40
|
-
hash["X-Riak-Meta-#{k}"] = v.to_s
|
41
|
-
end
|
42
|
-
end
|
43
|
-
unless robject.indexes.blank?
|
44
|
-
robject.indexes.each do |k,v|
|
45
|
-
hash["X-Riak-Index-#{k}"] = v.to_a.sort.map {|i| i.to_s }.join(", ")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Load object data from an HTTP response
|
52
|
-
# @param [Hash] response a response from {Riak::Client::HTTPBackend}
|
53
|
-
def load_object(robject, response)
|
54
|
-
extract_header(robject, response, "location", :key) {|v| URI.unescape(v.match(%r{.*/(.*?)(\?.*)?$})[1]) }
|
55
|
-
extract_header(robject, response, "x-riak-vclock", :vclock)
|
56
|
-
case response[:code] && response[:code].to_i
|
57
|
-
when 304
|
58
|
-
# Resulted from a reload, don't modify anything
|
59
|
-
when 300
|
60
|
-
robject.siblings = extract_siblings(robject, response[:body], response[:headers]['content-type'].first)
|
61
|
-
else
|
62
|
-
robject.siblings = [ load_content(response, RContent.new(robject)) ]
|
63
|
-
end
|
64
|
-
robject.conflict? ? robject.attempt_conflict_resolution : robject
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
def extract_header(robject, response, name, attribute=nil, &block)
|
69
|
-
extract_if_present(robject, response[:headers], name, attribute) do |value|
|
70
|
-
block ? block.call(value[0]) : value[0]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def extract_if_present(robject, hash, key, attribute=nil)
|
75
|
-
if hash[key].present?
|
76
|
-
attribute ||= key
|
77
|
-
value = block_given? ? yield(hash[key]) : hash[key]
|
78
|
-
robject.send("#{attribute}=", value)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def extract_siblings(robject, data, content_type)
|
83
|
-
Util::Multipart.parse(data, Util::Multipart.extract_boundary(content_type)).map do |part|
|
84
|
-
RContent.new(robject) do |sibling|
|
85
|
-
load_content(part, sibling)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def load_content(response, rcontent)
|
91
|
-
extract_header(rcontent, response, "link", :links) {|v| Set.new(Link.parse(v)) }
|
92
|
-
extract_header(rcontent, response, "etag", :etag)
|
93
|
-
extract_header(rcontent, response, "last-modified", :last_modified) {|v| Time.httpdate(v) }
|
94
|
-
extract_header(rcontent, response, "content-type", :content_type)
|
95
|
-
rcontent.meta = response[:headers].inject({}) do |h,(k,v)|
|
96
|
-
if k =~ /x-riak-meta-(.*)/i
|
97
|
-
h[$1] = v
|
98
|
-
end
|
99
|
-
h
|
100
|
-
end
|
101
|
-
rcontent.indexes = response[:headers].inject(Hash.new {|h,k| h[k] = Set.new }) do |h,(k,v)|
|
102
|
-
if k =~ /x-riak-index-((?:.*)_(?:int|bin))$/i
|
103
|
-
key = $1
|
104
|
-
h[key].merge Array(v).map {|vals| vals.split(/,\s*/).map {|i| key =~ /int$/ ? i.to_i : i } }.flatten
|
105
|
-
end
|
106
|
-
h
|
107
|
-
end
|
108
|
-
rcontent.raw_data = response[:body] if response[:body].present?
|
109
|
-
rcontent
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'riak/util/headers'
|
3
|
-
|
4
|
-
module Riak
|
5
|
-
class Client
|
6
|
-
class HTTPBackend
|
7
|
-
# @private
|
8
|
-
class RequestHeaders < Riak::Util::Headers
|
9
|
-
alias each each_capitalized
|
10
|
-
|
11
|
-
def initialize(hash)
|
12
|
-
initialize_http_header(hash)
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_a
|
16
|
-
[].tap do |arr|
|
17
|
-
each_capitalized do |k,v|
|
18
|
-
arr << "#{k}: #{v}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_hash
|
24
|
-
{}.tap do |hash|
|
25
|
-
each_capitalized do |k,v|
|
26
|
-
hash[k] ||= []
|
27
|
-
hash[k] << v
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|