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.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +0 -1
  4. data/{LICENSE → LICENSE.md} +0 -0
  5. data/README.markdown +211 -66
  6. data/RELEASE_NOTES.md +22 -47
  7. data/Rakefile +45 -0
  8. data/lib/riak.rb +1 -1
  9. data/lib/riak/bucket.rb +2 -2
  10. data/lib/riak/client.rb +22 -195
  11. data/lib/riak/client/beefcake/crdt_loader.rb +127 -0
  12. data/lib/riak/client/beefcake/crdt_operator.rb +222 -0
  13. data/lib/riak/client/beefcake/footer +4 -0
  14. data/lib/riak/client/beefcake/header +6 -0
  15. data/lib/riak/client/beefcake/message_codes.rb +29 -0
  16. data/lib/riak/client/beefcake/message_overlay.rb +61 -0
  17. data/lib/riak/client/beefcake/messages.rb +733 -371
  18. data/lib/riak/client/beefcake/object_methods.rb +1 -1
  19. data/lib/riak/client/beefcake/protocol.rb +105 -0
  20. data/lib/riak/client/beefcake/socket.rb +243 -0
  21. data/lib/riak/client/beefcake_protobuffs_backend.rb +262 -122
  22. data/lib/riak/client/node.rb +4 -75
  23. data/lib/riak/client/protobuffs_backend.rb +6 -14
  24. data/lib/riak/client/search.rb +0 -64
  25. data/lib/riak/client/yokozuna.rb +52 -0
  26. data/lib/riak/counter.rb +1 -1
  27. data/lib/riak/crdt.rb +21 -0
  28. data/lib/riak/crdt/base.rb +97 -0
  29. data/lib/riak/crdt/batch_counter.rb +19 -0
  30. data/lib/riak/crdt/batch_map.rb +41 -0
  31. data/lib/riak/crdt/counter.rb +71 -0
  32. data/lib/riak/crdt/inner_counter.rb +74 -0
  33. data/lib/riak/crdt/inner_flag.rb +42 -0
  34. data/lib/riak/crdt/inner_map.rb +53 -0
  35. data/lib/riak/crdt/inner_register.rb +26 -0
  36. data/lib/riak/crdt/inner_set.rb +95 -0
  37. data/lib/riak/crdt/map.rb +88 -0
  38. data/lib/riak/crdt/operation.rb +19 -0
  39. data/lib/riak/crdt/set.rb +156 -0
  40. data/lib/riak/crdt/typed_collection.rb +131 -0
  41. data/lib/riak/errors/base.rb +9 -0
  42. data/lib/riak/errors/connection_error.rb +44 -0
  43. data/lib/riak/errors/crdt_error.rb +18 -0
  44. data/lib/riak/errors/failed_request.rb +56 -0
  45. data/lib/riak/errors/protobuffs_error.rb +11 -0
  46. data/lib/riak/i18n.rb +2 -0
  47. data/lib/riak/json.rb +1 -1
  48. data/lib/riak/locale/en.yml +26 -1
  49. data/lib/riak/locale/fr.yml +0 -1
  50. data/lib/riak/map_reduce.rb +1 -1
  51. data/lib/riak/map_reduce/results.rb +1 -1
  52. data/lib/riak/multiget.rb +1 -2
  53. data/lib/riak/rcontent.rb +8 -3
  54. data/lib/riak/robject.rb +2 -8
  55. data/lib/riak/secondary_index.rb +4 -4
  56. data/lib/riak/serializers.rb +1 -1
  57. data/lib/riak/util/escape.rb +3 -5
  58. data/lib/riak/version.rb +1 -1
  59. data/lib/riak/walk_spec.rb +7 -3
  60. data/riak-client.gemspec +10 -8
  61. data/spec/fixtures/bitcask.txt +25 -0
  62. data/spec/integration/riak/bucket_types_spec.rb +61 -0
  63. data/spec/integration/riak/counters_spec.rb +17 -32
  64. data/spec/integration/riak/crdt_spec.rb +181 -0
  65. data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
  66. data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
  67. data/spec/integration/riak/protobuffs_backends_spec.rb +9 -26
  68. data/spec/integration/riak/security_spec.rb +94 -0
  69. data/spec/integration/riak/threading_spec.rb +24 -67
  70. data/spec/integration/yokozuna/index_spec.rb +61 -0
  71. data/spec/integration/yokozuna/queries_spec.rb +116 -0
  72. data/spec/integration/yokozuna/schema_spec.rb +49 -0
  73. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
  74. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +4 -4
  75. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
  76. data/spec/riak/beefcake_protobuffs_backend/socket_spec.rb +151 -0
  77. data/spec/riak/beefcake_protobuffs_backend_spec.rb +68 -106
  78. data/spec/riak/bucket_spec.rb +81 -77
  79. data/spec/riak/client_spec.rb +43 -340
  80. data/spec/riak/core_ext/to_param_spec.rb +2 -2
  81. data/spec/riak/counter_spec.rb +20 -20
  82. data/spec/riak/crdt/counter_spec.rb +52 -0
  83. data/spec/riak/crdt/inner_counter_spec.rb +21 -0
  84. data/spec/riak/crdt/inner_flag_spec.rb +39 -0
  85. data/spec/riak/crdt/inner_map_spec.rb +47 -0
  86. data/spec/riak/crdt/inner_register_spec.rb +40 -0
  87. data/spec/riak/crdt/inner_set_spec.rb +33 -0
  88. data/spec/riak/crdt/map_spec.rb +77 -0
  89. data/spec/riak/crdt/set_spec.rb +58 -0
  90. data/spec/riak/crdt/shared_examples.rb +74 -0
  91. data/spec/riak/crdt/typed_collection_spec.rb +231 -0
  92. data/spec/riak/escape_spec.rb +33 -37
  93. data/spec/riak/feature_detection_spec.rb +45 -45
  94. data/spec/riak/index_collection_spec.rb +12 -12
  95. data/spec/riak/link_spec.rb +34 -34
  96. data/spec/riak/list_buckets_spec.rb +7 -7
  97. data/spec/riak/map_reduce/filter_builder_spec.rb +6 -6
  98. data/spec/riak/map_reduce/phase_spec.rb +35 -35
  99. data/spec/riak/map_reduce_spec.rb +89 -87
  100. data/spec/riak/multiget_spec.rb +20 -15
  101. data/spec/riak/node_spec.rb +5 -152
  102. data/spec/riak/robject_spec.rb +95 -108
  103. data/spec/riak/search_spec.rb +17 -139
  104. data/spec/riak/secondary_index_spec.rb +49 -49
  105. data/spec/riak/serializers_spec.rb +9 -9
  106. data/spec/riak/stamp_spec.rb +9 -9
  107. data/spec/riak/walk_spec_spec.rb +46 -46
  108. data/spec/spec_helper.rb +14 -22
  109. data/spec/support/certs/README.md +13 -0
  110. data/spec/support/certs/ca.crt +22 -0
  111. data/spec/support/certs/client.crt +95 -0
  112. data/spec/support/certs/client.key +27 -0
  113. data/spec/support/certs/empty_ca.crt +21 -0
  114. data/spec/support/certs/server.crl +13 -0
  115. data/spec/support/certs/server.crt +95 -0
  116. data/spec/support/certs/server.key +27 -0
  117. data/spec/support/integration_setup.rb +1 -1
  118. data/spec/support/search_corpus_setup.rb +29 -8
  119. data/spec/support/test_client.rb +46 -0
  120. data/spec/support/test_client.yml.example +10 -0
  121. data/spec/support/unified_backend_examples.rb +104 -83
  122. data/spec/support/version_filter.rb +2 -2
  123. data/spec/support/wait_until.rb +14 -0
  124. metadata +134 -132
  125. data/erl_src/riak_kv_test014_backend.beam +0 -0
  126. data/erl_src/riak_kv_test014_backend.erl +0 -189
  127. data/erl_src/riak_kv_test_backend.beam +0 -0
  128. data/erl_src/riak_kv_test_backend.erl +0 -731
  129. data/erl_src/riak_search_test_backend.beam +0 -0
  130. data/erl_src/riak_search_test_backend.erl +0 -175
  131. data/lib/riak/client/excon_backend.rb +0 -172
  132. data/lib/riak/client/http_backend.rb +0 -413
  133. data/lib/riak/client/http_backend/bucket_streamer.rb +0 -15
  134. data/lib/riak/client/http_backend/chunked_json_streamer.rb +0 -42
  135. data/lib/riak/client/http_backend/configuration.rb +0 -227
  136. data/lib/riak/client/http_backend/key_streamer.rb +0 -15
  137. data/lib/riak/client/http_backend/object_methods.rb +0 -114
  138. data/lib/riak/client/http_backend/request_headers.rb +0 -34
  139. data/lib/riak/client/http_backend/transport_methods.rb +0 -201
  140. data/lib/riak/client/instrumentation.rb +0 -25
  141. data/lib/riak/client/net_http_backend.rb +0 -82
  142. data/lib/riak/cluster.rb +0 -151
  143. data/lib/riak/failed_request.rb +0 -81
  144. data/lib/riak/instrumentation.rb +0 -6
  145. data/lib/riak/node.rb +0 -40
  146. data/lib/riak/node/configuration.rb +0 -304
  147. data/lib/riak/node/console.rb +0 -133
  148. data/lib/riak/node/control.rb +0 -207
  149. data/lib/riak/node/defaults.rb +0 -85
  150. data/lib/riak/node/generation.rb +0 -127
  151. data/lib/riak/node/log.rb +0 -34
  152. data/lib/riak/node/version.rb +0 -29
  153. data/lib/riak/search.rb +0 -3
  154. data/lib/riak/test_server.rb +0 -89
  155. data/lib/riak/util/headers.rb +0 -32
  156. data/lib/riak/util/multipart.rb +0 -52
  157. data/lib/riak/util/multipart/stream_parser.rb +0 -62
  158. data/spec/fixtures/munchausen.txt +0 -1033
  159. data/spec/integration/riak/cluster_spec.rb +0 -88
  160. data/spec/integration/riak/http_backends_spec.rb +0 -180
  161. data/spec/integration/riak/node_spec.rb +0 -170
  162. data/spec/integration/riak/test_server_spec.rb +0 -57
  163. data/spec/riak/excon_backend_spec.rb +0 -102
  164. data/spec/riak/headers_spec.rb +0 -21
  165. data/spec/riak/http_backend/configuration_spec.rb +0 -273
  166. data/spec/riak/http_backend/object_methods_spec.rb +0 -243
  167. data/spec/riak/http_backend/transport_methods_spec.rb +0 -97
  168. data/spec/riak/http_backend_spec.rb +0 -367
  169. data/spec/riak/instrumentation_spec.rb +0 -167
  170. data/spec/riak/multipart_spec.rb +0 -23
  171. data/spec/riak/net_http_backend_spec.rb +0 -15
  172. data/spec/riak/stream_parser_spec.rb +0 -53
  173. data/spec/support/drb_mock_server.rb +0 -39
  174. data/spec/support/http_backend_implementation_examples.rb +0 -253
  175. data/spec/support/mock_server.rb +0 -81
  176. data/spec/support/mocks.rb +0 -4
  177. data/spec/support/riak_test.rb +0 -77
  178. data/spec/support/sometimes.rb +0 -46
  179. data/spec/support/test_server.rb +0 -61
  180. data/spec/support/test_server.yml.example +0 -14
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rubygems/package_task'
3
+ require 'yard'
3
4
  require 'rspec/core'
4
5
  require 'rspec/core/rake_task'
5
6
 
@@ -12,6 +13,17 @@ Gem::PackageTask.new(gemspec) do |pkg|
12
13
  pkg.need_tar = false
13
14
  end
14
15
 
16
+ YARD::Rake::YardocTask.new :doc do |doc|
17
+ doc.options = ["--markup markdown",
18
+ "--markup-provider=redcarpet",
19
+ "--charset utf-8",
20
+ '-',
21
+ 'lib/**/*.rb',
22
+ '*.md',
23
+ '*.markdown'
24
+ ].map{|e| e.split(' ')}.flatten
25
+ end
26
+
15
27
  task :gem => :gemspec
16
28
 
17
29
  desc %{Validate the gemspec file.}
@@ -70,3 +82,36 @@ RSpec::Core::RakeTask.new(:ci) do |spec|
70
82
  spec.rspec_opts = %w[--profile]
71
83
  end
72
84
  task :default => :ci
85
+
86
+
87
+ desc "Generate Protocol Buffers message definitions from riak_pb"
88
+ task :pb_defs => 'beefcake:pb_defs'
89
+
90
+ namespace :beefcake do
91
+ task :pb_defs => 'lib/riak/client/beefcake/messages.rb'
92
+
93
+ PROTO_FILES = %w{riak_kv riak_search riak_yokozuna riak_dt}
94
+ PROTO_TMP = PROTO_FILES.map{|f| "tmp/#{f}.pb.rb"}
95
+
96
+ task :clean do
97
+ sh "rm -rf tmp/riak_pb"
98
+ sh "rm -rf #{PROTO_TMP.join ' '}"
99
+ end
100
+
101
+
102
+ file 'lib/riak/client/beefcake/messages.rb' => PROTO_TMP do |t|
103
+ sh "cat lib/riak/client/beefcake/header tmp/riak.pb.rb #{t.prerequisites.join ' '} lib/riak/client/beefcake/footer > #{t.name}"
104
+ end
105
+
106
+ PROTO_FILES.each do |f|
107
+ file "tmp/#{f}.pb.rb" => 'tmp/riak_pb' do |t|
108
+ sh "protoc --beefcake_out tmp -I tmp/riak_pb/src tmp/riak_pb/src/#{f}.proto"
109
+ end
110
+ end
111
+
112
+ directory 'tmp/riak_pb' do
113
+ cd 'tmp' do
114
+ sh "git clone -b develop https://github.com/basho/riak_pb.git"
115
+ end
116
+ end
117
+ end
@@ -3,7 +3,7 @@ require 'riak/core_ext'
3
3
  require 'riak/client'
4
4
  require 'riak/map_reduce'
5
5
  require 'riak/util/translation'
6
- require 'riak/instrumentation'
6
+ require 'riak/crdt'
7
7
 
8
8
  # The Riak module contains all aspects of the client interface to
9
9
  # Riak.
@@ -2,7 +2,7 @@ require 'riak/util/translation'
2
2
  require 'riak/client'
3
3
  require 'riak/robject'
4
4
  require 'riak/counter'
5
- require 'riak/failed_request'
5
+ require 'riak/errors/failed_request'
6
6
 
7
7
  module Riak
8
8
  # Represents and encapsulates operations on a Riak bucket. You may retrieve a bucket
@@ -101,7 +101,7 @@ module Riak
101
101
  alias :[] :get
102
102
 
103
103
  # Retrieve multiple keys from this bucket.
104
- # @param [Array<String>] array of keys to fetch
104
+ # @param [Array<String>] keys array of keys to fetch
105
105
  # @return [Hash<String, Riak::RObject>] hash of keys to objects
106
106
  def get_many(keys)
107
107
  pairs = keys.map{|k| [self, k]}
@@ -4,13 +4,11 @@ require 'innertube'
4
4
  require 'riak'
5
5
  require 'riak/util/translation'
6
6
  require 'riak/util/escape'
7
- require 'riak/failed_request'
7
+ require 'riak/errors/failed_request'
8
8
  require 'riak/client/decaying'
9
9
  require 'riak/client/node'
10
10
  require 'riak/client/search'
11
- require 'riak/client/http_backend'
12
- require 'riak/client/net_http_backend'
13
- require 'riak/client/excon_backend'
11
+ require 'riak/client/yokozuna'
14
12
  require 'riak/client/protobuffs_backend'
15
13
  require 'riak/client/beefcake_protobuffs_backend'
16
14
  require 'riak/bucket'
@@ -28,14 +26,11 @@ module Riak
28
26
  # When using integer client IDs, the exclusive upper-bound of valid values.
29
27
  MAX_CLIENT_ID = 4294967296
30
28
 
31
- # Array of valid protocols
32
- PROTOCOLS = %w[http https pbc]
33
-
34
29
  # Regexp for validating hostnames, lifted from uri.rb in Ruby 1.8.6
35
30
  HOST_REGEX = /^(?:(?:(?:[a-zA-Z\d](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:(?:[a-fA-F\d]{1,4}:)*[a-fA-F\d]{1,4})?::(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))?)\])$/n
36
31
 
37
32
  # Valid constructor options.
38
- VALID_OPTIONS = [:protocol, :nodes, :client_id, :http_backend, :protobuffs_backend] | Node::VALID_OPTIONS
33
+ VALID_OPTIONS = [:nodes, :client_id, :protobuffs_backend, :authentication] | Node::VALID_OPTIONS
39
34
 
40
35
  # Network errors.
41
36
  NETWORK_ERRORS = [
@@ -52,21 +47,12 @@ module Riak
52
47
 
53
48
  Pool = ::Innertube::Pool
54
49
 
55
- # @return [String] The protocol to use for the Riak endpoint
56
- attr_reader :protocol
57
-
58
50
  # @return [Array] The set of Nodes this client can communicate with.
59
51
  attr_accessor :nodes
60
52
 
61
53
  # @return [String] The internal client ID used by Riak to route responses
62
54
  attr_reader :client_id
63
55
 
64
- # @return [Symbol] The HTTP backend/client to use
65
- attr_accessor :http_backend
66
-
67
- # @return [Client::Pool] A pool of HTTP connections
68
- attr_reader :http_pool
69
-
70
56
  # @return [Symbol] The Protocol Buffers backend/client to use
71
57
  attr_accessor :protobuffs_backend
72
58
 
@@ -76,23 +62,20 @@ module Riak
76
62
  # @return [Integer] The number of threads for multiget requests
77
63
  attr_reader :multiget_threads
78
64
 
65
+ # @return [Hash] The authentication information this client will use.
66
+ attr_reader :authentication
67
+
79
68
  # Creates a client connection to Riak
80
69
  # @param [Hash] options configuration options for the client
81
70
  # @option options [Array] :nodes A list of nodes this client connects to.
82
71
  # Each element of the list is a hash which is passed to Node.new, e.g.
83
- # {host: '127.0.0.1', pb_port: 1234, ...}.
72
+ # `{host: '127.0.0.1', pb_port: 1234, ...}`.
84
73
  # If no nodes are given, a single node is constructed from the remaining
85
74
  # options given to Client.new.
86
75
  # @option options [String] :host ('127.0.0.1') The host or IP address for the Riak endpoint
87
- # @option options [String] :protocol ('http') The protocol to use for connecting to a node backend
88
- # @option options [Fixnum] :http_port (8098) The port of the Riak HTTP endpoint
89
76
  # @option options [Fixnum] :pb_port (8087) The port of the Riak Protocol Buffers endpoint
90
- # @option options [String] :prefix ('/riak/') The URL path prefix to the main HTTP endpoint
91
- # @option options [String] :mapred ('/mapred') The path to the map-reduce HTTP endpoint
92
77
  # @option options [Fixnum, String] :client_id (rand(MAX_CLIENT_ID)) The internal client ID used by Riak to route responses
93
- # @option options [String, Symbol] :http_backend (:NetHTTP) which HTTP backend to use
94
78
  # @option options [String, Symbol] :protobuffs_backend (:Beefcake) which Protocol Buffers backend to use
95
- # @option options [Boolean, Hash] :ssl (nil) The SSL options to pass to each node or true for default options
96
79
  # @raise [ArgumentError] raised if any invalid options are given
97
80
  def initialize(options={})
98
81
  if options.include? :port
@@ -106,7 +89,7 @@ module Riak
106
89
  @nodes = (options[:nodes] || []).map do |n|
107
90
  Client::Node.new self, n
108
91
  end
109
- if @nodes.empty? or options[:host] or options[:http_port] or options[:pb_port]
92
+ if @nodes.empty? or options[:host] or options[:pb_port]
110
93
  @nodes |= [Client::Node.new(self, options)]
111
94
  end
112
95
 
@@ -115,42 +98,21 @@ module Riak
115
98
  lambda { |b| b.teardown }
116
99
  )
117
100
 
118
- @http_pool = Pool.new(
119
- method(:new_http_backend),
120
- lambda { |b| b.teardown }
121
- )
122
101
 
123
- self.protocol = options[:protocol] || "http"
124
- self.http_backend = options[:http_backend] || :NetHTTP
125
102
  self.protobuffs_backend = options[:protobuffs_backend] || :Beefcake
126
103
  self.client_id = options[:client_id] if options[:client_id]
127
- self.ssl = options[:ssl] if options[:ssl]
128
104
  self.multiget_threads = options[:multiget_threads]
105
+ @authentication = options[:authentication] && options[:authentication].symbolize_keys
129
106
  end
130
107
 
131
- # Yields a backend for operations that are protocol-independent.
132
- # You can change which type of backend is used by setting the
133
- # {#protocol}.
134
- # @yield [HTTPBackend,ProtobuffsBackend] an appropriate client backend
135
- def backend(&block)
136
- case @protocol.to_s
137
- when /https?/i
138
- http &block
139
- when /pbc/i
140
- protobuffs &block
141
- end
142
- end
143
-
144
- # Sets basic HTTP auth on all nodes.
145
- def basic_auth=(auth)
146
- @nodes.each do |node|
147
- node.basic_auth = auth
148
- end
149
- auth
108
+ # Is security enabled?
109
+ # @return [Boolean] whether or not a secure connection is being used
110
+ def security?
111
+ !!authentication
150
112
  end
151
113
 
152
114
  # Retrieves a bucket from Riak.
153
- # @param [String] bucket the bucket to retrieve
115
+ # @param [String] name the bucket to retrieve
154
116
  # @param [Hash] options options for retrieving the bucket
155
117
  # @option options [Boolean] :props (false) whether to retreive the bucket properties
156
118
  # @return [Bucket] the requested bucket
@@ -246,15 +208,6 @@ module Riak
246
208
  end
247
209
  end
248
210
 
249
- # Deletes a file stored via the "Luwak" interface
250
- # @param [String] filename the key/filename to delete
251
- def delete_file(filename)
252
- http do |h|
253
- h.delete_file(filename)
254
- end
255
- true
256
- end
257
-
258
211
  # Delete an object. See Bucket#delete
259
212
  def delete_object(bucket, key, options = {})
260
213
  backend do |b|
@@ -262,37 +215,10 @@ module Riak
262
215
  end
263
216
  end
264
217
 
265
- # Checks whether a file exists in "Luwak".
266
- # @param [String] key the key to check
267
- # @return [true, false] whether the key exists in "Luwak"
268
- def file_exists?(key)
269
- http do |h|
270
- h.file_exists?(key)
271
- end
272
- end
273
- alias :file_exist? :file_exists?
274
-
275
218
  # Bucket properties. See Bucket#props
276
- def get_bucket_props(bucket)
219
+ def get_bucket_props(bucket, options={ })
277
220
  backend do |b|
278
- b.get_bucket_props bucket
279
- end
280
- end
281
-
282
- # Retrieves a large file/IO object from Riak via the "Luwak"
283
- # interface. Streams the data to a temporary file unless a block
284
- # is given.
285
- # @param [String] filename the key/filename for the object
286
- # @return [IO, nil] the file (also having content_type and
287
- # original_filename accessors). The file will need to be
288
- # reopened to be read. nil will be returned if a block is given.
289
- # @yield [chunk] stream contents of the file through the
290
- # block. Passing the block will result in nil being returned
291
- # from the method.
292
- # @yieldparam [String] chunk a single chunk of the object's data
293
- def get_file(filename, &block)
294
- http do |h|
295
- h.get_file(filename, &block)
221
+ b.get_bucket_props bucket, options
296
222
  end
297
223
  end
298
224
 
@@ -316,31 +242,11 @@ module Riak
316
242
  end
317
243
  end
318
244
 
319
- # Yields an HTTPBackend.
320
- def http(&block)
321
- recover_from @http_pool, &block
322
- end
323
-
324
- # Sets the desired HTTP backend
325
- def http_backend=(value)
326
- @http_backend = value
327
- # Shut down existing connections using the old backend
328
- @http_pool.clear
329
- @http_backend
330
- end
331
-
332
245
  # @return [String] A representation suitable for IRB and debugging output.
333
246
  def inspect
334
247
  "#<Riak::Client #{nodes.inspect}>"
335
248
  end
336
249
 
337
- # Link-walk.
338
- def link_walk(object, specs)
339
- http do |h|
340
- h.link_walk object, specs
341
- end
342
- end
343
-
344
250
  # Retrieves a list of keys in the given bucket. See Bucket#keys
345
251
  def list_keys(bucket, options={}, &block)
346
252
  if block_given?
@@ -361,23 +267,6 @@ module Riak
361
267
  end
362
268
  end
363
269
 
364
- # Creates a new HTTP backend.
365
- # @return [HTTPBackend] An HTTP backend for a given node.
366
- def new_http_backend
367
- klass = self.class.const_get("#{@http_backend}Backend")
368
- if klass.configured?
369
- node = choose_node(
370
- @nodes.select do |n|
371
- n.http?
372
- end
373
- )
374
-
375
- klass.new(self, node)
376
- else
377
- raise t('http_configuration', :backend => @http_backend)
378
- end
379
- end
380
-
381
270
  # Creates a new protocol buffers backend.
382
271
  # @return [ProtobuffsBackend] the Protocol Buffers backend for
383
272
  # a given node.
@@ -413,6 +302,7 @@ module Riak
413
302
  def protobuffs(&block)
414
303
  recover_from @protobuffs_pool, &block
415
304
  end
305
+ alias :backend :protobuffs
416
306
 
417
307
  # Sets the desired Protocol Buffers backend
418
308
  def protobuffs_backend=(value)
@@ -422,33 +312,6 @@ module Riak
422
312
  @protobuffs_backend
423
313
  end
424
314
 
425
- # Set the protocol of the Riak endpoint. Value must be in the
426
- # Riak::Client::PROTOCOLS array.
427
- # @raise [ArgumentError] if the protocol is not in PROTOCOLS
428
- # @return [String] the protocol being assigned
429
- def protocol=(value)
430
- unless PROTOCOLS.include?(value.to_s)
431
- raise ArgumentError, t("protocol_invalid", :invalid => value, :valid => PROTOCOLS.join(', '))
432
- end
433
-
434
- #TODO
435
- @backend = nil
436
- @protocol = value
437
-
438
- case value
439
- when 'https'
440
- nodes.each do |node|
441
- node.ssl = true unless node.ssl_enabled?
442
- end
443
- when 'http'
444
- nodes.each do |node|
445
- node.ssl = false
446
- end
447
- end
448
-
449
- @protocol
450
- end
451
-
452
315
  # Takes a pool. Acquires a backend from the pool and yields it with
453
316
  # node-specific error recovery.
454
317
  def recover_from(pool)
@@ -496,27 +359,17 @@ module Riak
496
359
  end
497
360
 
498
361
  # Sets the properties on a bucket. See Bucket#props=
499
- def set_bucket_props(bucket, properties)
500
- # A bug in Beefcake is still giving us trouble with default booleans.
501
- # Until it is resolved, we'll use the HTTP backend.
502
- http do |b|
503
- b.set_bucket_props(bucket, properties)
362
+ def set_bucket_props(bucket, properties, type=nil)
363
+ backend do |b|
364
+ b.set_bucket_props(bucket, properties, type)
504
365
  end
505
366
  end
506
367
 
507
368
  # Clears the properties on a bucket. See Bucket#clear_props
508
369
  def clear_bucket_props(bucket)
509
- http do |b|
510
- b.clear_bucket_props(bucket)
511
- end
512
- end
513
-
514
- # Enables or disables SSL on all nodes, for HTTP backends.
515
- def ssl=(value)
516
- @nodes.each do |node|
517
- node.ssl = value
370
+ backend do |b|
371
+ b.reset_bucket_props(bucket)
518
372
  end
519
- value
520
373
  end
521
374
 
522
375
  # Exposes a {Stamp} object for use in generating unique
@@ -527,22 +380,6 @@ module Riak
527
380
  @stamp ||= Riak::Stamp.new(self)
528
381
  end
529
382
 
530
- # Stores a large file/IO-like object in Riak via the "Luwak" interface.
531
- # @overload store_file(filename, content_type, data)
532
- # Stores the file at the given key/filename
533
- # @param [String] filename the key/filename for the object
534
- # @param [String] content_type the MIME Content-Type for the data
535
- # @param [IO, String] data the contents of the file
536
- # @overload store_file(content_type, data)
537
- # Stores the file with a server-determined key/filename
538
- # @param [String] content_type the MIME Content-Type for the data
539
- # @param [String, #read] data the contents of the file
540
- # @return [String] the key/filename where the object was stored
541
- def store_file(*args)
542
- http do |h|
543
- h.store_file(*args)
544
- end
545
- end
546
383
 
547
384
  # Stores an object in Riak.
548
385
  def store_object(object, options = {})
@@ -568,15 +405,5 @@ module Riak
568
405
  n.ssl_disable
569
406
  end
570
407
  end
571
-
572
- # @private
573
- class LuwakFile < DelegateClass(Tempfile)
574
- attr_accessor :original_filename, :content_type
575
- alias :key :original_filename
576
- def initialize(fn)
577
- super(Tempfile.new(fn))
578
- @original_filename = fn
579
- end
580
- end
581
408
  end
582
409
  end
@@ -0,0 +1,127 @@
1
+ module Riak
2
+ class Client
3
+ class BeefcakeProtobuffsBackend
4
+
5
+ # Returns a new {CrdtLoader} for deserializing a protobuffs response full
6
+ # of CRDTs.
7
+ # @api private
8
+ def crdt_loader
9
+ return CrdtLoader.new self
10
+ end
11
+
12
+ # Loads, and deserializes CRDTs from protobuffs into Ruby hashes,
13
+ # sets, strings, and integers.
14
+ # @api private
15
+ class CrdtLoader
16
+ include Util::Translation
17
+
18
+ attr_reader :backend, :context
19
+
20
+ def initialize(backend)
21
+ @backend = backend
22
+ end
23
+
24
+ # Perform the protobuffs request and return a deserialized CRDT.
25
+ def load(bucket, key, bucket_type, options={})
26
+ bucket = bucket.name if bucket.is_a? ::Riak::Bucket
27
+ fetch_args = options.merge(
28
+ bucket: bucket,
29
+ key: key,
30
+ type: bucket_type
31
+ )
32
+ request = DtFetchReq.new fetch_args
33
+
34
+ response = backend.protocol do |p|
35
+ p.write :DtFetchReq, request
36
+ p.expect :DtFetchResp, DtFetchResp
37
+ end
38
+
39
+ @context = response.context
40
+ rubyfy response
41
+ end
42
+
43
+ private
44
+ # Convert the protobuffs response into low-level Ruby objects.
45
+ def rubyfy(response)
46
+ return nil_rubyfy(response.type) if response.value.nil?
47
+ case response.type
48
+ when DtFetchResp::DataType::COUNTER
49
+ response.value.counter_value
50
+ when DtFetchResp::DataType::SET
51
+ ::Set.new response.value.set_value
52
+ when DtFetchResp::DataType::MAP
53
+ rubyfy_map response.value.map_value
54
+ end
55
+ end
56
+
57
+ # Convert a top-level map into a Ruby {Hash} of hashes.
58
+ def rubyfy_map(map_value)
59
+ accum = {
60
+ counters: {},
61
+ flags: {},
62
+ maps: {},
63
+ registers: {},
64
+ sets: {}
65
+ }
66
+
67
+ rubyfy_map_contents map_value, accum
68
+ end
69
+
70
+ # Convert a map inside another map into a Ruby {Hash}.
71
+ def rubyfy_inner_map(accum, map_value)
72
+ destination = accum[:maps][map_value.field.name]
73
+ if destination.nil?
74
+ destination = accum[:maps][map_value.field.name] = {
75
+ counters: {},
76
+ flags: {},
77
+ maps: {},
78
+ registers: {},
79
+ sets: {}
80
+ }
81
+ end
82
+
83
+ rubyfy_map_contents map_value.map_value, destination
84
+ end
85
+
86
+ # Load the contents of a map into Ruby hashes.
87
+ def rubyfy_map_contents(map_value, destination)
88
+ return destination if map_value.nil?
89
+ map_value.each do |inner_mv|
90
+ case inner_mv.field.type
91
+ when MapField::MapFieldType::COUNTER
92
+ destination[:counters][inner_mv.field.name] = inner_mv.counter_value
93
+ when MapField::MapFieldType::FLAG
94
+ destination[:flags][inner_mv.field.name] = inner_mv.flag_value
95
+ when MapField::MapFieldType::MAP
96
+ rubyfy_inner_map destination, inner_mv
97
+ when MapField::MapFieldType::REGISTER
98
+ destination[:registers][inner_mv.field.name] = inner_mv.register_value
99
+ when MapField::MapFieldType::SET
100
+ destination[:sets][inner_mv.field.name] = ::Set.new inner_mv.set_value
101
+ end
102
+ end
103
+
104
+ return destination
105
+ end
106
+
107
+ # Sometimes a CRDT is empty, provide a sane default.
108
+ def nil_rubyfy(type)
109
+ case type
110
+ when DtFetchResp::DataType::COUNTER
111
+ 0
112
+ when DtFetchResp::DataType::SET
113
+ ::Set.new
114
+ when DtFetchResp::DataType::MAP
115
+ {
116
+ counters: {},
117
+ flags: {},
118
+ maps: {},
119
+ registers: {},
120
+ sets: {},
121
+ }
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end