riak-client 0.9.0.beta → 0.9.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile +10 -7
  2. data/Rakefile +21 -3
  3. data/erl_src/riak_kv_test_backend.beam +0 -0
  4. data/erl_src/riak_kv_test_backend.erl +29 -13
  5. data/lib/riak/bucket.rb +1 -1
  6. data/lib/riak/cache_store.rb +1 -1
  7. data/lib/riak/client.rb +119 -8
  8. data/lib/riak/client/beefcake/messages.rb +162 -0
  9. data/lib/riak/client/beefcake/object_methods.rb +92 -0
  10. data/lib/riak/client/beefcake_protobuffs_backend.rb +186 -0
  11. data/lib/riak/client/curb_backend.rb +10 -16
  12. data/lib/riak/client/excon_backend.rb +14 -18
  13. data/lib/riak/client/http_backend.rb +13 -13
  14. data/lib/riak/client/http_backend/object_methods.rb +1 -1
  15. data/lib/riak/client/http_backend/transport_methods.rb +6 -2
  16. data/lib/riak/client/net_http_backend.rb +33 -20
  17. data/lib/riak/client/protobuffs_backend.rb +103 -0
  18. data/lib/riak/client/pump.rb +44 -0
  19. data/lib/riak/failed_request.rb +58 -3
  20. data/lib/riak/locale/en.yml +11 -3
  21. data/lib/riak/map_reduce.rb +15 -6
  22. data/lib/riak/map_reduce/filter_builder.rb +4 -4
  23. data/lib/riak/test_server.rb +5 -1
  24. data/lib/riak/util/multipart.rb +30 -16
  25. data/lib/riak/util/multipart/stream_parser.rb +74 -0
  26. data/riak-client.gemspec +14 -12
  27. data/spec/fixtures/server.cert.crt +15 -0
  28. data/spec/fixtures/server.cert.key +15 -0
  29. data/spec/fixtures/test.pem +1 -0
  30. data/spec/integration/riak/http_backends_spec.rb +45 -0
  31. data/spec/integration/riak/protobuffs_backends_spec.rb +45 -0
  32. data/spec/integration/riak/test_server_spec.rb +2 -2
  33. data/spec/riak/bucket_spec.rb +4 -4
  34. data/spec/riak/client_spec.rb +209 -3
  35. data/spec/riak/excon_backend_spec.rb +8 -7
  36. data/spec/riak/http_backend/configuration_spec.rb +64 -0
  37. data/spec/riak/http_backend/object_methods_spec.rb +1 -1
  38. data/spec/riak/http_backend/transport_methods_spec.rb +129 -0
  39. data/spec/riak/http_backend_spec.rb +13 -1
  40. data/spec/riak/map_reduce/filter_builder_spec.rb +45 -0
  41. data/spec/riak/map_reduce/phase_spec.rb +149 -0
  42. data/spec/riak/map_reduce_spec.rb +5 -5
  43. data/spec/riak/net_http_backend_spec.rb +1 -0
  44. data/spec/riak/{object_spec.rb → robject_spec.rb} +1 -1
  45. data/spec/riak/stream_parser_spec.rb +66 -0
  46. data/spec/support/drb_mock_server.rb +2 -2
  47. data/spec/support/http_backend_implementation_examples.rb +27 -0
  48. data/spec/support/mock_server.rb +22 -1
  49. data/spec/support/unified_backend_examples.rb +255 -0
  50. metadata +43 -54
data/Gemfile CHANGED
@@ -1,22 +1,25 @@
1
- source :gemcutter
1
+ source :rubygems
2
2
 
3
3
  gem 'i18n'
4
4
  gem 'builder'
5
- gem 'rspec', "~>2.0.0"
5
+ gem 'rspec', "~>2.4.0"
6
6
  gem 'fakeweb', ">=1.2"
7
7
  gem 'rack', '>=1.0'
8
8
  gem 'rake'
9
9
  gem 'bundler'
10
- gem 'excon', "~>0.3.4"
10
+ gem 'excon', "~>0.5.7"
11
+ gem 'beefcake', '~>0.2.0'
11
12
 
12
- if defined? JRUBY_VERSION
13
- gem 'json'
14
- gem 'jruby-openssl'
15
- else
13
+ platforms :mri do
16
14
  gem 'curb', '>=0.6'
17
15
  gem 'yajl-ruby'
18
16
  end
19
17
 
18
+ platforms :jruby do
19
+ gem 'json'
20
+ gem 'jruby-openssl'
21
+ end
22
+
20
23
  group :integration do
21
24
  gem 'activesupport', '~>3.0'
22
25
  end
data/Rakefile CHANGED
@@ -9,13 +9,14 @@ gemspec = Gem::Specification.new do |gem|
9
9
  gem.email = "sean@basho.com"
10
10
  gem.homepage = "http://seancribbs.github.com/ripple"
11
11
  gem.authors = ["Sean Cribbs"]
12
- gem.add_development_dependency "rspec", "~>2.0.0"
12
+ gem.add_development_dependency "rspec", "~>2.4.0"
13
13
  gem.add_development_dependency "fakeweb", ">=1.2"
14
14
  gem.add_development_dependency "rack", ">=1.0"
15
15
  gem.add_development_dependency "curb", ">=0.6"
16
- gem.add_development_dependency "excon", "~>0.3.4"
16
+ gem.add_development_dependency "excon", "~>0.5.7"
17
17
  gem.add_dependency "i18n", ">=0.4.0"
18
18
  gem.add_dependency "builder", "~>2.1.2"
19
+ gem.add_dependency "beefcake", "~>0.2.0"
19
20
 
20
21
  gem.files = %W{
21
22
  erl_src/riak_kv_test_backend.beam
@@ -24,6 +25,9 @@ gemspec = Gem::Specification.new do |gem|
24
25
  lib/active_support/cache/riak_store.rb
25
26
  lib/riak/bucket.rb
26
27
  lib/riak/cache_store.rb
28
+ lib/riak/client/beefcake/messages.rb
29
+ lib/riak/client/beefcake/object_methods.rb
30
+ lib/riak/client/beefcake_protobuffs_backend.rb
27
31
  lib/riak/client/curb_backend.rb
28
32
  lib/riak/client/excon_backend.rb
29
33
  lib/riak/client/http_backend/configuration.rb
@@ -32,6 +36,8 @@ gemspec = Gem::Specification.new do |gem|
32
36
  lib/riak/client/http_backend/transport_methods.rb
33
37
  lib/riak/client/http_backend.rb
34
38
  lib/riak/client/net_http_backend.rb
39
+ lib/riak/client/protobuffs_backend.rb
40
+ lib/riak/client/pump.rb
35
41
  lib/riak/client.rb
36
42
  lib/riak/core_ext/blank.rb
37
43
  lib/riak/core_ext/extract_options.rb
@@ -56,6 +62,7 @@ gemspec = Gem::Specification.new do |gem|
56
62
  lib/riak/util/escape.rb
57
63
  lib/riak/util/fiber1.8.rb
58
64
  lib/riak/util/headers.rb
65
+ lib/riak/util/multipart/stream_parser.rb
59
66
  lib/riak/util/multipart.rb
60
67
  lib/riak/util/tcp_socket_extensions.rb
61
68
  lib/riak/util/translation.rb
@@ -66,7 +73,12 @@ gemspec = Gem::Specification.new do |gem|
66
73
  spec/fixtures/cat.jpg
67
74
  spec/fixtures/multipart-blank.txt
68
75
  spec/fixtures/multipart-with-body.txt
76
+ spec/fixtures/server.cert.crt
77
+ spec/fixtures/server.cert.key
78
+ spec/fixtures/test.pem
69
79
  spec/integration/riak/cache_store_spec.rb
80
+ spec/integration/riak/http_backends_spec.rb
81
+ spec/integration/riak/protobuffs_backends_spec.rb
70
82
  spec/integration/riak/test_server_spec.rb
71
83
  spec/riak/bucket_spec.rb
72
84
  spec/riak/client_spec.rb
@@ -74,14 +86,19 @@ gemspec = Gem::Specification.new do |gem|
74
86
  spec/riak/escape_spec.rb
75
87
  spec/riak/excon_backend_spec.rb
76
88
  spec/riak/headers_spec.rb
89
+ spec/riak/http_backend/configuration_spec.rb
77
90
  spec/riak/http_backend/object_methods_spec.rb
91
+ spec/riak/http_backend/transport_methods_spec.rb
78
92
  spec/riak/http_backend_spec.rb
79
93
  spec/riak/link_spec.rb
94
+ spec/riak/map_reduce/filter_builder_spec.rb
95
+ spec/riak/map_reduce/phase_spec.rb
80
96
  spec/riak/map_reduce_spec.rb
81
97
  spec/riak/multipart_spec.rb
82
98
  spec/riak/net_http_backend_spec.rb
83
- spec/riak/object_spec.rb
99
+ spec/riak/robject_spec.rb
84
100
  spec/riak/search_spec.rb
101
+ spec/riak/stream_parser_spec.rb
85
102
  spec/riak/walk_spec_spec.rb
86
103
  spec/spec_helper.rb
87
104
  spec/support/drb_mock_server.rb
@@ -89,6 +106,7 @@ gemspec = Gem::Specification.new do |gem|
89
106
  spec/support/mock_server.rb
90
107
  spec/support/mocks.rb
91
108
  spec/support/test_server.yml.example
109
+ spec/support/unified_backend_examples.rb
92
110
  }
93
111
 
94
112
  gem.test_files = gem.files.grep(/_spec\.rb$/)
Binary file
@@ -20,7 +20,8 @@
20
20
  %%
21
21
  %% -------------------------------------------------------------------
22
22
 
23
- % @doc riak_kv_test_backend is a Riak storage backend using ets that exposes a reset function for efficiently clearing stored data.
23
+ % @doc riak_kv_test_backend is a Riak storage backend using ets that
24
+ % exposes a reset function for efficiently clearing stored data.
24
25
 
25
26
  -module(riak_kv_test_backend).
26
27
  -behavior(riak_kv_backend).
@@ -34,29 +35,47 @@
34
35
  -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
35
36
  terminate/2, code_change/3]).
36
37
 
38
+
37
39
  % @type state() = term().
38
- -record(state, {t}).
40
+ -record(state, {t, p}).
39
41
 
40
42
  % @spec start(Partition :: integer(), Config :: proplist()) ->
41
43
  % {ok, state()} | {{error, Reason :: term()}, state()}
42
44
  start(Partition, _Config) ->
43
45
  gen_server:start_link(?MODULE, [Partition], []).
44
46
 
45
- % @spec reset() -> ok
47
+ % @spec reset() -> ok | {error, timeout}
46
48
  reset() ->
47
- Pids = lists:filter(fun(Item) ->
48
- lists:prefix("test_backend", atom_to_list(Item))
49
- end, registered()),
50
- [gen_server:call(Pid, reset) || Pid <- Pids],
51
- ok.
49
+ Pids = lists:foldl(fun(Item, Acc) ->
50
+ case lists:prefix("test_backend", atom_to_list(Item)) of
51
+ true -> [whereis(Item)|Acc];
52
+ _ -> Acc
53
+ end
54
+ end, [], registered()),
55
+ [gen_server:cast(Pid,{reset, self()})|| Pid <- Pids],
56
+ receive_reset(Pids).
57
+
58
+ receive_reset([]) -> ok;
59
+ receive_reset(Pids) ->
60
+ receive
61
+ {reset, Pid} ->
62
+ receive_reset(lists:delete(Pid, Pids))
63
+ after 1000 ->
64
+ {error, timeout}
65
+ end.
52
66
 
53
67
  %% @private
54
68
  init([Partition]) ->
55
69
  PName = list_to_atom("test_backend" ++ integer_to_list(Partition)),
70
+ P = list_to_atom(integer_to_list(Partition)),
56
71
  register(PName, self()),
57
- {ok, #state{t=ets:new(list_to_atom(integer_to_list(Partition)),[])}}.
72
+ {ok, #state{t=ets:new(P,[]), p=P}}.
58
73
 
59
74
  %% @private
75
+ handle_cast({reset,From}, State) ->
76
+ ets:delete_all_objects(State#state.t),
77
+ From ! {reset, self()},
78
+ {noreply, State};
60
79
  handle_cast(_, State) -> {noreply, State}.
61
80
 
62
81
  %% @private
@@ -76,10 +95,7 @@ handle_call(drop, _From, State) ->
76
95
  handle_call({fold, Fun0, Acc}, _From, State) ->
77
96
  Fun = fun({{B,K}, V}, AccIn) -> Fun0({B,K}, V, AccIn) end,
78
97
  Reply = ets:foldl(Fun, Acc, State#state.t),
79
- {reply, Reply, State};
80
- handle_call(reset, _From, State) ->
81
- ets:delete_all_objects(State#state.t),
82
- {reply, ok, State}.
98
+ {reply, Reply, State}.
83
99
 
84
100
  % @spec stop(state()) -> ok | {error, Reason :: term()}
85
101
  stop(SrvRef) -> gen_server:call(SrvRef,stop).
data/lib/riak/bucket.rb CHANGED
@@ -113,7 +113,7 @@ module Riak
113
113
  begin
114
114
  get(key, options)
115
115
  rescue Riak::FailedRequest => fr
116
- if fr.code.to_i == 404
116
+ if fr.not_found?
117
117
  new(key)
118
118
  else
119
119
  raise fr
@@ -77,7 +77,7 @@ module Riak
77
77
  begin
78
78
  bucket.get(key).data
79
79
  rescue Riak::FailedRequest => fr
80
- raise fr unless fr.code.to_i == 404
80
+ raise fr unless fr.not_found?
81
81
  nil
82
82
  end
83
83
  end
data/lib/riak/client.rb CHANGED
@@ -14,6 +14,7 @@
14
14
  require 'riak'
15
15
  require 'tempfile'
16
16
  require 'delegate'
17
+ require 'riak/failed_request'
17
18
 
18
19
  module Riak
19
20
  # A client connection to Riak.
@@ -21,26 +22,45 @@ module Riak
21
22
  include Util::Translation
22
23
  include Util::Escape
23
24
 
25
+ autoload :Pump, "riak/client/pump"
24
26
  autoload :HTTPBackend, "riak/client/http_backend"
25
27
  autoload :NetHTTPBackend, "riak/client/net_http_backend"
26
28
  autoload :CurbBackend, "riak/client/curb_backend"
27
29
  autoload :ExconBackend, "riak/client/excon_backend"
28
30
 
31
+ autoload :ProtobuffsBackend, "riak/client/protobuffs_backend"
32
+ autoload :BeefcakeProtobuffsBackend, "riak/client/beefcake_protobuffs_backend"
33
+
29
34
  # When using integer client IDs, the exclusive upper-bound of valid values.
30
35
  MAX_CLIENT_ID = 4294967296
31
36
 
37
+ # Array of valid protocols
38
+ PROTOCOLS = %w[http https pbc]
39
+
32
40
  # Regexp for validating hostnames, lifted from uri.rb in Ruby 1.8.6
33
41
  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
34
42
 
43
+ # @return [String] The protocol to use for the Riak endpoint
44
+ attr_reader :protocol
45
+
35
46
  # @return [String] The host or IP address for the Riak endpoint
36
47
  attr_reader :host
37
48
 
38
49
  # @return [Fixnum] The port of the Riak HTTP endpoint
39
50
  attr_reader :port
40
51
 
52
+ # @return [String] The user:pass for http basic authentication
53
+ attr_reader :basic_auth
54
+
41
55
  # @return [String] The internal client ID used by Riak to route responses
42
56
  attr_reader :client_id
43
57
 
58
+ # @return [Hash|nil] The SSL options that get built when using SSL
59
+ attr_reader :ssl_options
60
+
61
+ # @return [Hash|nil] The writer that will build valid SSL options from the provided config
62
+ attr_writer :ssl
63
+
44
64
  # @return [String] The URL path prefix to the "raw" HTTP endpoint
45
65
  attr_accessor :prefix
46
66
 
@@ -53,6 +73,9 @@ module Riak
53
73
  # @return [Symbol] The HTTP backend/client to use
54
74
  attr_accessor :http_backend
55
75
 
76
+ # @return [Symbol] The Protocol Buffers backend/client to use
77
+ attr_accessor :protobuffs_backend
78
+
56
79
  # Creates a client connection to Riak
57
80
  # @param [Hash] options configuration options for the client
58
81
  # @option options [String] :host ('127.0.0.1') The host or IP address for the Riak endpoint
@@ -61,19 +84,23 @@ module Riak
61
84
  # @option options [String] :mapred ('/mapred') The path to the map-reduce HTTP endpoint
62
85
  # @option options [Fixnum, String] :client_id (rand(MAX_CLIENT_ID)) The internal client ID used by Riak to route responses
63
86
  # @option options [String, Symbol] :http_backend (:NetHTTP) which HTTP backend to use
64
- # @raise [ArgumentError] raised if any options are invalid
87
+ # @option options [String, Symbol] :protobuffs_backend (:Beefcake) which Protocol Buffers backend to use
88
+ # @raise [ArgumentError] raised if any invalid options are given
65
89
  def initialize(options={})
66
- unless (options.keys - [:host, :port, :prefix, :client_id, :mapred, :luwak, :http_backend]).empty?
67
- raise ArgumentError, "invalid options"
90
+ unless (options.keys - [:protocol, :host, :port, :prefix, :client_id, :mapred, :luwak, :http_backend, :protobuffs_backend, :ssl, :basic_auth]).empty?
91
+ raise ArgumentError, t("invalid options")
68
92
  end
93
+ self.ssl = options[:ssl]
94
+ self.protocol = options[:protocol] || "http"
69
95
  self.host = options[:host] || "127.0.0.1"
70
- self.port = options[:port] || 8098
96
+ self.port = options[:port] || ((protocol == "pbc") ? 8087 : 8098)
71
97
  self.client_id = options[:client_id] || make_client_id
72
98
  self.prefix = options[:prefix] || "/riak/"
73
99
  self.mapred = options[:mapred] || "/mapred"
74
100
  self.luwak = options[:luwak] || "/luwak"
75
101
  self.http_backend = options[:http_backend] || :NetHTTP
76
- raise ArgumentError, t("missing_host_and_port") unless @host && @port
102
+ self.protobuffs_backend = options[:protobuffs_backend] || :Beefcake
103
+ self.basic_auth = options[:basic_auth] if options[:basic_auth]
77
104
  end
78
105
 
79
106
  # Set the client ID for this client. Must be a string or Fixnum value 0 =< value < MAX_CLIENT_ID.
@@ -91,6 +118,19 @@ module Riak
91
118
  end
92
119
  end
93
120
 
121
+ # Set the protocol of the Riak endpoint. Value must be in the
122
+ # Riak::Client::PROTOCOLS array.
123
+ # @raise [ArgumentError] if the protocol is not in PROTOCOLS
124
+ # @return [String] the protocol being assigned
125
+ def protocol=(value)
126
+ unless PROTOCOLS.include?(value.to_s)
127
+ raise ArgumentError, t("protocol_invalid", :invalid => value, :valid => PROTOCOLS.join(', '))
128
+ end
129
+ @ssl_options ||= {} if value === 'https'
130
+ @backend = nil
131
+ @protocol = value
132
+ end
133
+
94
134
  # Set the hostname of the Riak endpoint. Must be an IPv4, IPv6, or valid hostname
95
135
  # @param [String] value The host or IP address for the Riak endpoint
96
136
  # @raise [ArgumentError] if an invalid hostname is given
@@ -109,12 +149,34 @@ module Riak
109
149
  @port = value
110
150
  end
111
151
 
152
+ def basic_auth=(value)
153
+ raise ArgumentError, t("invalid_basic_auth") unless value.to_s.split(':').length === 2
154
+ @basic_auth = value
155
+ end
156
+
112
157
  # Sets the desired HTTP backend
113
158
  def http_backend=(value)
114
- @http = nil
159
+ @http, @backend = nil, nil
115
160
  @http_backend = value
116
161
  end
117
162
 
163
+ # Sets the desired Protocol Buffers backend
164
+ def protobuffs_backend=(value)
165
+ @protobuffs, @backend = nil, nil
166
+ @protobuffs_backend = value
167
+ end
168
+
169
+ # Enables or disables SSL on the client to be utilized by the HTTP Backends
170
+ def ssl=(value)
171
+ @ssl_options = Hash === value ? value : {}
172
+ value ? ssl_enable : ssl_disable
173
+ end
174
+
175
+ # Checks if the current protocol is https
176
+ def ssl_enabled?
177
+ protocol === 'https'
178
+ end
179
+
118
180
  # Automatically detects and returns an appropriate HTTP backend.
119
181
  # The HTTP backend is used internally by the Riak client, but can also
120
182
  # be used to access the server directly.
@@ -130,7 +192,41 @@ module Riak
130
192
  end
131
193
  end
132
194
 
133
- alias :backend :http
195
+ # Automatically detects and returns an appropriate Protocol
196
+ # Buffers backend. The Protocol Buffers backend is used
197
+ # internally by the Riak client but can also be used to access the
198
+ # server directly.
199
+ # @return [ProtobuffsBackend] the Protocol Buffers backend for
200
+ # this client
201
+ def protobuffs
202
+ @protobuffs ||= begin
203
+ klass = self.class.const_get("#{@protobuffs_backend}ProtobuffsBackend")
204
+ if klass.configured?
205
+ klass.new(self)
206
+ else
207
+ raise t('protobuffs_configuration', :backend => @protobuffs_backend)
208
+ end
209
+ end
210
+ end
211
+
212
+ # Returns a backend for operations that are protocol-independent.
213
+ # You can change which type of backend is used by setting the
214
+ # {#protocol}.
215
+ # @return [HTTPBackend,ProtobuffsBackend] an appropriate client backend
216
+ def backend
217
+ @backend ||= case @protocol.to_s
218
+ when /https?/i
219
+ http
220
+ when /pbc/i
221
+ protobuffs
222
+ end
223
+ end
224
+
225
+ # Pings the Riak server to check for liveness.
226
+ # @return [true,false] whether the Riak server is alive and reachable
227
+ def ping
228
+ backend.ping
229
+ end
134
230
 
135
231
  # Retrieves a bucket from Riak.
136
232
  # @param [String] bucket the bucket to retrieve
@@ -228,7 +324,7 @@ module Riak
228
324
 
229
325
  # @return [String] A representation suitable for IRB and debugging output.
230
326
  def inspect
231
- "#<Riak::Client #{http.root_uri.to_s}>"
327
+ "#<Riak::Client #{protocol}://#{host}:#{port}>"
232
328
  end
233
329
 
234
330
  private
@@ -240,6 +336,21 @@ module Riak
240
336
  Base64.encode64([n].pack("N")).chomp
241
337
  end
242
338
 
339
+ def ssl_enable
340
+ self.protocol = 'https'
341
+ @ssl_options[:pem] = File.read(@ssl_options[:pem_file]) if @ssl_options[:pem_file]
342
+ @ssl_options[:verify_mode] ||= "peer" if @ssl_options.stringify_keys.any? {|k,v| %w[pem ca_file ca_path].include?(k)}
343
+ @ssl_options[:verify_mode] ||= "none"
344
+ raise ArgumentError.new unless %w[none peer].include?(@ssl_options[:verify_mode])
345
+
346
+ @ssl_options
347
+ end
348
+
349
+ def ssl_disable
350
+ self.protocol = 'http'
351
+ @ssl_options = nil
352
+ end
353
+
243
354
  # @private
244
355
  class LuwakFile < DelegateClass(Tempfile)
245
356
  attr_accessor :original_filename, :content_type
@@ -0,0 +1,162 @@
1
+ # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'riak'
15
+ require 'riak/link'
16
+ require 'beefcake'
17
+
18
+ module Riak
19
+ class Client
20
+ # @private
21
+ class BeefcakeProtobuffsBackend
22
+ # Embedded messages
23
+ class RpbPair
24
+ include Beefcake::Message
25
+ required :key, :bytes, 1
26
+ optional :value, :bytes, 2
27
+ end
28
+
29
+ class RpbBucketProps
30
+ include Beefcake::Message
31
+ optional :n_val, :uint32, 1
32
+ optional :allow_mult, :bool, 2
33
+ end
34
+
35
+ class RpbLink
36
+ include Beefcake::Message
37
+ optional :bucket, :bytes, 1
38
+ optional :key, :bytes, 2
39
+ optional :tag, :bytes, 3
40
+ end
41
+
42
+ class RpbContent
43
+ include Beefcake::Message
44
+ required :value, :bytes, 1
45
+ optional :content_type, :bytes, 2
46
+ optional :charset, :bytes, 3
47
+ optional :content_encoding, :bytes, 4
48
+ optional :vtag, :bytes, 5
49
+ repeated :links, RpbLink, 6
50
+ optional :last_mod, :uint32, 7
51
+ optional :last_mod_usecs, :uint32, 8
52
+ repeated :usermeta, RpbPair, 9
53
+ end
54
+
55
+ # Primary messages
56
+ class RpbErrorResp
57
+ include Beefcake::Message
58
+ required :errmsg, :bytes, 1
59
+ required :errcode, :uint32, 2
60
+ end
61
+
62
+ class RpbGetClientIdResp
63
+ include Beefcake::Message
64
+ required :client_id, :bytes, 1
65
+ end
66
+
67
+ class RpbSetClientIdReq
68
+ include Beefcake::Message
69
+ required :client_id, :bytes, 1
70
+ end
71
+
72
+ class RpbGetServerInfoResp
73
+ include Beefcake::Message
74
+ optional :node, :bytes, 1
75
+ optional :server_version, :bytes, 2
76
+ end
77
+
78
+ class RpbGetReq
79
+ include Beefcake::Message
80
+ required :bucket, :bytes, 1
81
+ required :key, :bytes, 2
82
+ optional :r, :uint32, 3
83
+ end
84
+
85
+ class RpbGetResp
86
+ include Beefcake::Message
87
+ repeated :content, RpbContent, 1
88
+ optional :vclock, :bytes, 2
89
+ end
90
+
91
+ class RpbPutReq
92
+ include Beefcake::Message
93
+ required :bucket, :bytes, 1
94
+ required :key, :bytes, 2
95
+ optional :vclock, :bytes, 3
96
+ required :content, RpbContent, 4
97
+ optional :w, :uint32, 5
98
+ optional :dw, :uint32, 6
99
+ optional :return_body, :bool, 7
100
+ end
101
+
102
+ # Optional since it has the same structure as GetResp
103
+ # class RpbPutResp
104
+ # include Beefcake::Message
105
+ # repeated :content, RpbContent, 1
106
+ # optional :vclock, :bytes, 2
107
+ # end
108
+
109
+ class RpbDelReq
110
+ include Beefcake::Message
111
+ required :bucket, :bytes, 1
112
+ required :key, :bytes, 2
113
+ optional :rw, :uint32, 3
114
+ end
115
+
116
+ class RpbListBucketsResp
117
+ include Beefcake::Message
118
+ repeated :buckets, :bytes, 1
119
+ end
120
+
121
+ class RpbListKeysReq
122
+ include Beefcake::Message
123
+ required :bucket, :bytes, 1
124
+ end
125
+
126
+ class RpbListKeysResp
127
+ include Beefcake::Message
128
+ repeated :keys, :bytes, 1
129
+ optional :done, :bool, 2
130
+ end
131
+
132
+ class RpbGetBucketReq
133
+ include Beefcake::Message
134
+ required :bucket, :bytes, 1
135
+ end
136
+
137
+ class RpbGetBucketResp
138
+ include Beefcake::Message
139
+ required :props, RpbBucketProps, 1
140
+ end
141
+
142
+ class RpbSetBucketReq
143
+ include Beefcake::Message
144
+ required :bucket, :bytes, 1
145
+ required :props, RpbBucketProps, 2
146
+ end
147
+
148
+ class RpbMapRedReq
149
+ include Beefcake::Message
150
+ required :request, :bytes, 1
151
+ required :content_type, :bytes, 2
152
+ end
153
+
154
+ class RpbMapRedResp
155
+ include Beefcake::Message
156
+ optional :phase, :uint32, 1
157
+ optional :response, :bytes, 2
158
+ optional :done, :bool, 3
159
+ end
160
+ end
161
+ end
162
+ end