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
@@ -1,201 +0,0 @@
1
-
2
- require 'base64'
3
- require 'uri'
4
- require 'riak/client'
5
- require 'riak/util/headers'
6
-
7
- module Riak
8
- class Client
9
- class HTTPBackend
10
- # Methods related to performing HTTP requests in a consistent
11
- # fashion across multiple client libraries. HTTP/1.1 verbs are
12
- # presented as methods.
13
- module TransportMethods
14
- # Performs a HEAD request to the specified resource on the Riak server.
15
- # @param [Fixnum, Array] expect the expected HTTP response code(s) from Riak
16
- # @param [String, Array<String,Hash>] resource a relative path or array of path segments and optional query params Hash that will be joined to the root URI
17
- # @overload head(expect, *resource)
18
- # @overload head(expect, *resource, headers)
19
- # Send the request with custom headers
20
- # @param [Hash] headers custom headers to send with the request
21
- # @return [Hash] response data, containing only the :headers and :code keys
22
- # @raise [FailedRequest] if the response code doesn't match the expected response
23
- def head(expect, resource, headers={})
24
- headers = default_headers.merge(headers)
25
- perform(:head, resource, headers, expect)
26
- end
27
-
28
- # Performs a GET request to the specified resource on the Riak server.
29
- # @param [Fixnum, Array] expect the expected HTTP response code(s) from Riak
30
- # @param [String, Array<String,Hash>] resource a relative path or array of path segments and optional query params Hash that will be joined to the root URI
31
- # @overload get(expect, *resource)
32
- # @overload get(expect, *resource, headers)
33
- # Send the request with custom headers
34
- # @param [Hash] headers custom headers to send with the request
35
- # @overload get(expect, *resource, headers={})
36
- # Stream the response body through the supplied block
37
- # @param [Hash] headers custom headers to send with the request
38
- # @yield [chunk] yields successive chunks of the response body as strings
39
- # @return [Hash] response data, containing only the :headers and :code keys
40
- # @return [Hash] response data, containing :headers, :body, and :code keys
41
- # @raise [FailedRequest] if the response code doesn't match the expected response
42
- def get(expect, resource, headers={}, &block)
43
- headers = default_headers.merge(headers)
44
- perform(:get, resource, headers, expect, &block)
45
- end
46
-
47
- # Performs a PUT request to the specified resource on the Riak server.
48
- # @param [Fixnum, Array] expect the expected HTTP response code(s) from Riak
49
- # @param [String, Array<String,Hash>] resource a relative path or array of path segments and optional query params Hash that will be joined to the root URI
50
- # @param [String] body the request body to send to the server
51
- # @overload put(expect, *resource, body)
52
- # @overload put(expect, *resource, body, headers)
53
- # Send the request with custom headers
54
- # @param [Hash] headers custom headers to send with the request
55
- # @overload put(expect, *resource, body, headers={})
56
- # Stream the response body through the supplied block
57
- # @param [Hash] headers custom headers to send with the request
58
- # @yield [chunk] yields successive chunks of the response body as strings
59
- # @return [Hash] response data, containing only the :headers and :code keys
60
- # @return [Hash] response data, containing :headers, :code, and :body keys
61
- # @raise [FailedRequest] if the response code doesn't match the expected response
62
- def put(expect, resource, body, headers={}, &block)
63
- headers = default_headers.merge(headers)
64
- verify_body!(body)
65
- perform(:put, resource, headers, expect, body, &block)
66
- end
67
-
68
- # Performs a POST request to the specified resource on the Riak server.
69
- # @param [Fixnum, Array] expect the expected HTTP response code(s) from Riak
70
- # @param [String, Array<String>] resource a relative path or array of path segments that will be joined to the root URI
71
- # @param [String] body the request body to send to the server
72
- # @overload post(expect, *resource, body)
73
- # @overload post(expect, *resource, body, headers)
74
- # Send the request with custom headers
75
- # @param [Hash] headers custom headers to send with the request
76
- # @overload post(expect, *resource, body, headers={})
77
- # Stream the response body through the supplied block
78
- # @param [Hash] headers custom headers to send with the request
79
- # @yield [chunk] yields successive chunks of the response body as strings
80
- # @return [Hash] response data, containing only the :headers and :code keys
81
- # @return [Hash] response data, containing :headers, :code and :body keys
82
- # @raise [FailedRequest] if the response code doesn't match the expected response
83
- def post(expect, resource, body, headers={}, &block)
84
- headers = default_headers.merge(headers)
85
- verify_body!(body)
86
- perform(:post, resource, headers, expect, body, &block)
87
- end
88
-
89
- # Performs a DELETE request to the specified resource on the Riak server.
90
- # @param [Fixnum, Array] expect the expected HTTP response code(s) from Riak
91
- # @param [String, Array<String,Hash>] resource a relative path or array of path segments and optional query params Hash that will be joined to the root URI
92
- # @overload delete(expect, *resource)
93
- # @overload delete(expect, *resource, headers)
94
- # Send the request with custom headers
95
- # @param [Hash] headers custom headers to send with the request
96
- # @overload delete(expect, *resource, headers={})
97
- # Stream the response body through the supplied block
98
- # @param [Hash] headers custom headers to send with the request
99
- # @yield [chunk] yields successive chunks of the response body as strings
100
- # @return [Hash] response data, containing only the :headers and :code keys
101
- # @return [Hash] response data, containing :headers, :code and :body keys
102
- # @raise [FailedRequest] if the response code doesn't match the expected response
103
- def delete(expect, resource, headers={}, &block)
104
- headers = default_headers.merge(headers)
105
- perform(:delete, resource, headers, expect, &block)
106
- end
107
-
108
- # Executes requests according to the underlying HTTP client library semantics.
109
- # @abstract Subclasses must implement this internal method to perform HTTP requests
110
- # according to the API of their HTTP libraries.
111
- # @param [Symbol] method one of :head, :get, :post, :put, :delete
112
- # @param [URI] uri the HTTP URI to request
113
- # @param [Hash] headers headers to send along with the request
114
- # @param [Fixnum, Array] expect the expected response code(s)
115
- # @param [String, #read] body the PUT or POST request body
116
- # @return [Hash] response data, containing :headers, :code and :body keys. Only :headers and :code should be present when the body is streamed or the method is :head.
117
- # @yield [chunk] if the method is not :head, successive chunks of the response body will be yielded as strings
118
- # @raise [NotImplementedError] if a subclass does not implement this method
119
- def perform(method, uri, headers, expect, body=nil)
120
- raise NotImplementedError
121
- end
122
-
123
- # Default header hash sent with every request, based on settings in the client
124
- # @return [Hash] headers that will be merged with user-specified headers on every request
125
- def default_headers
126
- {
127
- "Accept" => "multipart/mixed, application/json;q=0.7, */*;q=0.5",
128
- "X-Riak-ClientId" => client_id
129
- }.merge(basic_auth_header)
130
- end
131
-
132
- def client_id
133
- value = @client.client_id
134
- case value
135
- when Integer
136
- b64encode(value)
137
- when String
138
- value
139
- end
140
- end
141
-
142
- def basic_auth_header
143
- @node.basic_auth ? {"Authorization" => "Basic #{Base64::encode64(@node.basic_auth)}"} : {}
144
- end
145
-
146
- # @return [URI] The calculated root URI for the Riak HTTP endpoint
147
- def root_uri
148
- protocol = node.ssl_enabled? ? "https" : "http"
149
- URI.parse("#{protocol}://#{node.host}:#{node.http_port}")
150
- end
151
-
152
- # Calculates an absolute URI from a relative path specification
153
- # @param [Array<String,Hash>] segments a relative path or sequence of path segments and optional query params Hash that will be joined to the root URI
154
- # @return [URI] an absolute URI for the resource
155
- def path(*segments)
156
- segments = segments.flatten
157
- query = segments.extract_options!.to_param
158
- root_uri.merge(segments.join("/").gsub(/\/+/, "/").sub(/^\//, '')).tap do |uri|
159
- uri.query = query if query.present?
160
- end
161
- end
162
-
163
- # Checks the expected response codes against the actual response code. Use internally when
164
- # implementing {#perform}.
165
- # @param [String, Fixnum, Array<String,Fixnum>] expected the expected response code(s)
166
- # @param [String, Fixnum] actual the received response code
167
- # @return [Boolean] whether the actual response code is acceptable given the expectations
168
- def valid_response?(expected, actual)
169
- Array(expected).map(&:to_i).include?(actual.to_i)
170
- end
171
-
172
- # Checks whether a combination of the HTTP method, response code, and block should
173
- # result in returning the :body in the response hash. Use internally when implementing {#perform}.
174
- # @param [Symbol] method the HTTP method
175
- # @param [String, Fixnum] code the received response code
176
- # @param [Boolean] has_block whether a streaming block was passed to {#perform}. Pass block_given? to this parameter.
177
- # @return [Boolean] whether to return the body in the response hash
178
- def return_body?(method, code, has_block)
179
- method != :head && !valid_response?([204,205,304], code) && !has_block
180
- end
181
-
182
- # Checks whether the submitted body is valid. That is, it must
183
- # be a String or respond to the 'read' method.
184
- # @param [String, #read] body the body
185
- # @raise [ArgumentError] if the body is of invalid type
186
- def verify_body!(body)
187
- raise ArgumentError, t('request_body_type') unless String === body || body.respond_to?(:read)
188
- end
189
-
190
- private
191
- def response_headers
192
- Thread.current[:response_headers] ||= Riak::Util::Headers.new
193
- end
194
-
195
- def b64encode(n)
196
- Base64.encode64([n].pack("N")).chomp
197
- end
198
- end
199
- end
200
- end
201
- end
@@ -1,25 +0,0 @@
1
- class Riak::Client
2
- include Instrumentable
3
-
4
- client_payload = {protocol: :protocol, client_id: :client_id}
5
-
6
- instrument_method :buckets, 'riak.list_buckets', client_payload
7
- instrument_method :list_buckets, 'riak.list_buckets', client_payload
8
- instrument_method :list_keys, 'riak.list_keys', client_payload
9
- instrument_method :set_bucket_props, 'riak.set_bucket_props', client_payload
10
- instrument_method :get_bucket_props, 'riak.get_bucket_props', client_payload
11
- instrument_method :clear_bucket_props, 'riak.clear_bucket_props', client_payload
12
- instrument_method :get_index, 'riak.get_index', client_payload
13
- instrument_method :store_object, 'riak.store_object', client_payload
14
- instrument_method :get_object, 'riak.get_object', client_payload
15
- instrument_method :reload_object, 'riak.reload_object', client_payload
16
- instrument_method :delete_object, 'riak.delete_object', client_payload
17
- instrument_method :store_file, 'riak.store_file', client_payload
18
- instrument_method :get_file, 'riak.get_file', client_payload
19
- instrument_method :delete_file, 'riak.delete_file', client_payload
20
- instrument_method :file_exists?, 'riak.file_exists', client_payload
21
- instrument_method :file_exist?, 'riak.file_exists', client_payload
22
- instrument_method :link_walk, 'riak.link_walk', client_payload
23
- instrument_method :mapred, 'riak.map_reduce', client_payload
24
- instrument_method :ping, 'riak.ping', client_payload
25
- end
@@ -1,82 +0,0 @@
1
- require 'riak/client/http_backend'
2
- require 'riak/failed_request'
3
-
4
- module Riak
5
- class Client
6
- # Uses the Ruby standard library Net::HTTP to connect to Riak.
7
- # Conforms to the Riak::Client::HTTPBackend interface.
8
- class NetHTTPBackend < HTTPBackend
9
- def self.configured?
10
- begin
11
- require 'net/http'
12
- require 'openssl'
13
- true
14
- rescue LoadError, NameError
15
- false
16
- end
17
- end
18
-
19
- # Sets the read_timeout applied to Net::HTTP connections
20
- # Increase this if you have very long request times.
21
- def self.read_timeout=(timeout)
22
- @read_timeout = timeout
23
- end
24
-
25
- def self.read_timeout
26
- @read_timeout ||= 4096
27
- end
28
-
29
- # Net::HTTP doesn't use persistent connections, so there's no
30
- # work to do here.
31
- def teardown; end
32
-
33
- private
34
- def perform(method, uri, headers, expect, data=nil) #:nodoc:
35
- http = Net::HTTP.new(uri.host, uri.port)
36
- http.read_timeout = self.class.read_timeout
37
- configure_ssl(http) if @node.ssl_enabled?
38
-
39
- request = Net::HTTP.const_get(method.to_s.capitalize).new(uri.request_uri, headers)
40
- if String === data
41
- request.body = data
42
- elsif data.respond_to?(:read)
43
- case
44
- when data.respond_to?(:stat) # IO#stat
45
- request.content_length = data.stat.size
46
- when data.respond_to?(:size) # Some IO-like objects
47
- request.content_length = data.size
48
- else
49
- request['Transfer-Encoding'] = 'chunked'
50
- end
51
- request.body_stream = data
52
- end
53
-
54
- {}.tap do |result|
55
- http.start # Fixes Ruby < 1.8.7p315
56
- http.request(request) do |response|
57
- unless valid_response?(expect, response.code)
58
- raise Riak::HTTPFailedRequest.new(method, expect, response.code.to_i, response.to_hash, response.body)
59
- end
60
-
61
- result.merge!({:headers => response.to_hash, :code => response.code.to_i})
62
- response.read_body {|chunk| yield chunk } if block_given?
63
- if return_body?(method, response.code, block_given?)
64
- result[:body] = response.body
65
- end
66
- end
67
- end
68
- end
69
-
70
- def configure_ssl(http)
71
- http.use_ssl = true
72
- http.verify_mode = OpenSSL::SSL.const_get("VERIFY_#{@node.ssl_options[:verify_mode].upcase}")
73
- if @node.ssl_options[:pem]
74
- http.cert = OpenSSL::X509::Certificate.new(@node.ssl_options[:pem])
75
- http.key = OpenSSL::PKey::RSA.new(@node.ssl_options[:pem], @node.ssl_options[:pem_password])
76
- end
77
- http.ca_file = @node.ssl_options[:ca_file] if @node.ssl_options[:ca_file]
78
- http.ca_path = @node.ssl_options[:ca_path] if @node.ssl_options[:ca_path]
79
- end
80
- end
81
- end
82
- end
@@ -1,151 +0,0 @@
1
- require 'pathname'
2
- require 'riak/node'
3
- require 'riak/util/translation'
4
-
5
- module Riak
6
- # Generates and controls a cluster of {Riak::Node} instances for use
7
- # in development or testing on a single machine.
8
- class Cluster
9
- include Util::Translation
10
- # @return [Array<Node>] the member Nodes of this cluster
11
- attr_reader :nodes
12
-
13
- # @return [Hash] the cluster configuration
14
- attr_reader :configuration
15
-
16
- # @return [Pathname] the root directory of the cluster
17
- attr_reader :root
18
-
19
- # Creates a {Cluster} of {Node}s.
20
- # @param [Hash] config the configuration for the cluster
21
- # @option config [Fixnum] :count the number of nodes to create
22
- # @option config [String] :source path to the Riak bin/ directory.
23
- # See {Node#source}.
24
- # @option config [String] :root path to where the nodes will be
25
- # generated.
26
- # @option config [Fixnum] :min_port the base port number from
27
- # which nodes will claim IP ports for HTTP, PB, handoff.
28
- def initialize(config={})
29
- raise ArgumentError, t('source_and_root_required') unless config[:source] && config[:root]
30
- @configuration = config
31
- @count = config.delete(:count) || 4
32
- @min_port = config.delete(:min_port) || 9000
33
- @root = Pathname.new(config.delete(:root))
34
- @nodes = []
35
- cookie = "#{rand(100000).to_s}_#{rand(1000000).to_s}"
36
- @count.times do |i|
37
- nodes << Riak::Node.new(config.merge(:min_port => @min_port + (i * 3),
38
- :root => @root + (i+1).to_s,
39
- :cookie => cookie))
40
- end
41
- end
42
-
43
- # @return [true,false] whether the cluster has been created
44
- def exist?
45
- root.directory? && nodes.all? {|n| n.exist? }
46
- end
47
-
48
- # Generates all nodes in the cluster.
49
- def create
50
- unless exist?
51
- root.mkpath unless root.exist?
52
- nodes.each {|n| n.create }
53
- end
54
- end
55
-
56
- # Removes all nodes in the cluster and the root, and freezes the
57
- # object.
58
- def destroy
59
- nodes.each {|n| n.destroy }
60
- root.rmtree if root.exist?
61
- freeze
62
- end
63
-
64
- # Removes and recreates the cluster.
65
- def recreate
66
- stop unless stopped?
67
- root.rmtree if root.exist?
68
- create
69
- end
70
-
71
- # Drops all data from the cluster without destroying the nodes.
72
- def drop
73
- nodes.each {|n| n.drop }
74
- end
75
-
76
- # Starts all nodes in the cluster.
77
- def start
78
- nodes.each {|n| n.start }
79
- end
80
-
81
- # Stops all nodes in the cluster.
82
- def stop
83
- nodes.each {|n| n.stop }
84
- end
85
-
86
- # Restarts all nodes in the cluster (without exiting the Erlang
87
- # runtime)
88
- def restart
89
- nodes.each {|n| n.restart }
90
- end
91
-
92
- # Reboots all nodes in the cluster
93
- def reboot
94
- nodes.each {|n| n.reboot }
95
- end
96
-
97
- # Forces the cluster nodes to restart/reload their JavaScript VMs,
98
- # effectively reloading any user-provided code.
99
- def js_reload
100
- nodes.each {|n| n.js_reload }
101
- end
102
-
103
- # Attaches to the console on all nodes, returning a list of
104
- # {Riak::Node::Console} objects.
105
- # @return [Array<Riak::Node::Console>] consoles for all running
106
- # nodes, with nil for nodes that aren't running or otherwise
107
- # fail to connect
108
- def attach
109
- nodes.map do |n|
110
- begin
111
- n.attach
112
- rescue ArgumentError, SystemCallError
113
- nil
114
- end
115
- end
116
- end
117
-
118
- # Executes the given block on each node against the node's
119
- # console. You could use this to send Erlang commands to all nodes
120
- # in the cluster.
121
- # @yield [console] A block of commands to be run against the
122
- # console
123
- # @yieldparam [Riak::Node::Console] console A console manager for
124
- # sending commands to the current node in the iteration
125
- def with_console(&block)
126
- nodes.each do |n|
127
- n.with_console(&block)
128
- end
129
- end
130
-
131
- # Is the cluster started?
132
- def started?
133
- nodes.all? {|n| n.started? }
134
- end
135
-
136
- # Is the cluster stopped?
137
- def stopped?
138
- nodes.all? {|n| n.stopped? }
139
- end
140
-
141
- # Joins the nodes together into a cluster.
142
- # @note This method relies on cluster membership changes present
143
- # in the 1.0 series of Riak, and is NOT safe on 0.14 and
144
- # earlier.
145
- def join
146
- claimant = nodes.first.name # Not really the claimant, just a
147
- # node to join to
148
- nodes[1..-1].each {|n| n.join(claimant) unless n.peers.include?(claimant) }
149
- end
150
- end
151
- end