couchbase-jruby-client 0.2.2-java → 1.0.4-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +103 -0
  3. data/.ruby-version +1 -1
  4. data/Rakefile +13 -2
  5. data/couchbase-jruby-client.gemspec +7 -6
  6. data/lib/couchbase/bucket.rb +11 -338
  7. data/lib/couchbase/cluster.rb +10 -88
  8. data/lib/couchbase/configuration.rb +39 -0
  9. data/lib/couchbase/design_doc.rb +18 -73
  10. data/lib/couchbase/document.rb +34 -0
  11. data/lib/couchbase/error.rb +0 -35
  12. data/lib/couchbase/operations.rb +60 -40
  13. data/lib/couchbase/version.rb +1 -1
  14. data/lib/couchbase/view.rb +55 -345
  15. data/lib/couchbase.rb +37 -141
  16. data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
  17. data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
  18. data/lib/jars/rxjava-1.0.8.jar +0 -0
  19. data/lib/jars/rxjruby-0.0.1.jar +0 -0
  20. data/test/{test_cas.rb → helper.rb} +15 -10
  21. data/test/test_bucket.rb +14 -228
  22. data/test/test_cluster.rb +1 -29
  23. data/test/test_configuration.rb +51 -0
  24. data/test/test_couchbase.rb +28 -28
  25. data/test/test_design_doc.rb +29 -0
  26. data/test/test_document.rb +51 -0
  27. data/test/test_operations.rb +49 -0
  28. data/test/test_view.rb +62 -116
  29. metadata +43 -125
  30. data/lib/couchbase/async/callback.rb +0 -38
  31. data/lib/couchbase/async/queue.rb +0 -26
  32. data/lib/couchbase/async.rb +0 -32
  33. data/lib/couchbase/constants.rb +0 -29
  34. data/lib/couchbase/operations/arithmetic.rb +0 -290
  35. data/lib/couchbase/operations/delete.rb +0 -115
  36. data/lib/couchbase/operations/design_docs.rb +0 -99
  37. data/lib/couchbase/operations/fetch.rb +0 -33
  38. data/lib/couchbase/operations/get.rb +0 -303
  39. data/lib/couchbase/operations/stats.rb +0 -42
  40. data/lib/couchbase/operations/store.rb +0 -463
  41. data/lib/couchbase/operations/touch.rb +0 -140
  42. data/lib/couchbase/operations/unlock.rb +0 -209
  43. data/lib/couchbase/operations/utils.rb +0 -68
  44. data/lib/couchbase/query.rb +0 -76
  45. data/lib/couchbase/result.rb +0 -60
  46. data/lib/couchbase/transcoder.rb +0 -81
  47. data/lib/couchbase/utils.rb +0 -62
  48. data/lib/couchbase/view_row.rb +0 -227
  49. data/lib/jars/commons-codec-1.5.jar +0 -0
  50. data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
  51. data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
  52. data/lib/jars/couchbase-client-1.3.2.jar +0 -0
  53. data/lib/jars/httpcore-4.3.1.jar +0 -0
  54. data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
  55. data/lib/jars/jettison-1.1.jar +0 -0
  56. data/lib/jars/netty-3.5.5.Final.jar +0 -0
  57. data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
  58. data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
  59. data/lib/jars/spymemcached-2.10.5.jar +0 -0
  60. data/tasks/benchmark.rake +0 -6
  61. data/tasks/test.rake +0 -36
  62. data/tasks/util.rake +0 -21
  63. data/test/mock.rb +0 -85
  64. data/test/profile/.gitignore +0 -1
  65. data/test/profile/.jrubyrc +0 -722
  66. data/test/profile/Gemfile +0 -7
  67. data/test/profile/benchmark.rb +0 -177
  68. data/test/profile/profile.rb +0 -59
  69. data/test/setup.rb +0 -74
  70. data/test/test_arithmetic.rb +0 -155
  71. data/test/test_async.rb +0 -24
  72. data/test/test_couchbase_rails_cache_store.rb +0 -341
  73. data/test/test_delete.rb +0 -139
  74. data/test/test_design_docs.rb +0 -67
  75. data/test/test_errors.rb +0 -74
  76. data/test/test_fetch.rb +0 -71
  77. data/test/test_format.rb +0 -142
  78. data/test/test_get.rb +0 -363
  79. data/test/test_query.rb +0 -23
  80. data/test/test_result.rb +0 -15
  81. data/test/test_stats.rb +0 -44
  82. data/test/test_store.rb +0 -203
  83. data/test/test_touch.rb +0 -90
  84. data/test/test_unlock.rb +0 -89
  85. data/test/test_utils.rb +0 -67
  86. data/test/test_version.rb +0 -28
  87. data/test/test_view_row.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ec71506555414ea67468af719e184392afa4704
4
- data.tar.gz: 74653b08496b561fcf60bae9c03a836c47acff4c
3
+ metadata.gz: 97f6ffc94c3d26dea77d88c7f57145ac9b8b061b
4
+ data.tar.gz: 5f969c7a83b8c5a62e2cd003f05182ddb9977091
5
5
  SHA512:
6
- metadata.gz: 5bbc04e04898e8505bc3ffd4ce5223c2ab2f13a0200c4c7eae0ddd3eb8ca61797f1f9e3b244f1aaff7c862c0e108e00469345c42e1420e137ffb5d2992c7ab9e
7
- data.tar.gz: dfa98216f38e6ce0d8282ef7befe1bc85a2efe5332692df1f113e12d1d94a2e1332784f31e0fa5c9f9b28750ca895f1515461afff9abc062f1ad0b3150b1ec98
6
+ metadata.gz: 9a04e21b82c3af1c422378f161d0102a5996788a1aa556f59e01618228643208acafe712e53e456bea8ead32cd35d3734b383b90c3c3bf9f06b2dfb73d2ac4e5
7
+ data.tar.gz: 52babb42001362e77794530e70113985b0fc08229c96c3beb1fd3b3a8602df6d8d9b16092f3de09543046be8da1a2295531a243682ca032f189a8f416f03dd24
data/.rubocop.yml ADDED
@@ -0,0 +1,103 @@
1
+ AllCops:
2
+ Includes:
3
+ - '**/Gemfile'
4
+ - '**/Rakefile'
5
+
6
+ Style/EmptyLinesAroundClassBody:
7
+ Enabled: false
8
+
9
+ Style/EmptyLinesAroundModuleBody:
10
+ Enabled: false
11
+
12
+ Style/ModuleFunction:
13
+ Enabled: false
14
+
15
+ Metrics/AbcSize:
16
+ Enabled: true
17
+ Max: 20
18
+
19
+ # Avoid long parameter lists
20
+ ParameterLists:
21
+ Max: 3
22
+ CountKeywordArgs: true
23
+
24
+ MethodLength:
25
+ CountComments: false
26
+ Max: 15 # TODO: lower to 15
27
+
28
+ ClassLength:
29
+ CountComments: false
30
+ Max: 132 # TODO: lower to 100
31
+
32
+ CyclomaticComplexity:
33
+ Max: 6 # TODO: lower to 6
34
+
35
+ # Avoid more than `Max` levels of nesting.
36
+ BlockNesting:
37
+ Max: 3
38
+
39
+ # Align with the style guide.
40
+ CollectionMethods:
41
+ PreferredMethods:
42
+ collect: 'map'
43
+ inject: 'reduce'
44
+ find_all: 'select'
45
+
46
+ AccessModifierIndentation:
47
+ Enabled: false
48
+
49
+ # Limit line length
50
+ LineLength:
51
+ Enabled: false
52
+
53
+ # Disable documentation checking until a class needs to be documented once
54
+ Documentation:
55
+ Enabled: false
56
+
57
+ # Not all trivial readers/writers can be defined with attr_* methods
58
+ TrivialAccessors:
59
+ Enabled: false
60
+
61
+ # Enforce Ruby 1.8-compatible hash syntax
62
+ # HashSyntax:
63
+ # EnforcedStyle: hash_rockets
64
+
65
+ # No spaces inside hash literals
66
+ # SpaceInsideHashLiteralBraces:
67
+ # EnforcedStyle: no_space
68
+
69
+ Style/MultilineOperationIndentation:
70
+ Enabled: true
71
+ EnforcedStyle: indented
72
+
73
+ # Allow dots at the end of lines
74
+ DotPosition:
75
+ Enabled: false
76
+
77
+ # Don't require magic comment at the top of every file
78
+ Encoding:
79
+ Enabled: false
80
+
81
+ # Enforce outdenting of access modifiers (i.e. public, private, protected)
82
+ # AccessModifierIndentation:
83
+ # EnforcedStyle: outdent
84
+
85
+ EmptyLinesAroundAccessModifier:
86
+ Enabled: true
87
+
88
+ # Align ends correctly
89
+ EndAlignment:
90
+ AlignWith: variable
91
+
92
+ # Indentation of when/else
93
+ # CaseIndentation:
94
+ # IndentWhenRelativeTo: end
95
+ # IndentOneStep: false
96
+
97
+ # Use the old lambda literal syntax
98
+ # Lambda:
99
+ # Enabled: false
100
+
101
+ # Semicolon:
102
+ # Exclude:
103
+ # - 'spec/support/'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- jruby-1.7.11
1
+ jruby-1.7.21@cb-client
data/Rakefile CHANGED
@@ -1,5 +1,16 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
2
3
 
3
- Dir['tasks/*.rake'].sort.each { |f| load f }
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
4
9
 
5
- task :default => :test
10
+ task default: :test
11
+
12
+ task :pry do
13
+ require 'couchbase'
14
+ require 'pry'
15
+ Pry.start
16
+ end
@@ -19,13 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
  s.require_paths = ['lib']
21
21
 
22
- s.add_runtime_dependency 'multi_json', '>= 1.0'
23
- s.add_runtime_dependency 'thread_safe', '>= 0.1.2'
22
+ s.add_runtime_dependency 'multi_json'
23
+ # s.add_runtime_dependency 'jbundler'
24
+ # s.requirements << "jar 'com.couchbase:java-client', '2.1.1'"
24
25
 
25
- s.add_development_dependency 'bundler', '>= 1.3'
26
+ s.add_development_dependency 'bundler'
26
27
  s.add_development_dependency 'rake'
27
- s.add_development_dependency 'minitest', '>= 5.1.0'
28
- s.add_development_dependency 'jrjackson', '>= 0.2.3'
28
+ s.add_development_dependency 'minitest'
29
+ s.add_development_dependency 'jrjackson'
29
30
  s.add_development_dependency 'pry'
30
- s.add_development_dependency 'mocha'
31
+ s.add_development_dependency 'rubocop'
31
32
  end
@@ -16,357 +16,30 @@
16
16
  #
17
17
 
18
18
  module Couchbase
19
-
20
19
  class Bucket
21
-
22
- java_import java.io.IOException
23
- java_import java.net.SocketAddress
24
- java_import java.net.URI
25
- java_import java.net.URISyntaxException
26
- java_import java.util.ArrayList
27
- java_import java.util.LinkedList
28
- java_import java.util.List
29
- java_import java.util.concurrent.Future
30
- java_import java.util.concurrent.TimeUnit
31
- java_import com.couchbase.client.CouchbaseClient
32
- java_import com.couchbase.client.CouchbaseConnectionFactory
33
- java_import com.couchbase.client.CouchbaseConnectionFactoryBuilder
34
-
35
20
  include Couchbase::Operations
36
- include Couchbase::Async
37
-
38
- attr_accessor :quiet, :hostname, :port, :pool, :bucket, :username,
39
- :password, :default_ttl, :timeout, :default_format,
40
- :default_arithmetic_init, :transcoder, :transcoders
41
-
42
- attr_reader :client, :key_prefix, :default_format
43
-
44
- DEFAULT_OPTIONS = {
45
- type: nil,
46
- quiet: false,
47
- hostname: 'localhost',
48
- port: 8091,
49
- pool: 'default',
50
- bucket: 'default',
51
- password: '',
52
- engine: nil,
53
- default_ttl: 0,
54
- default_arithmetic_init: 0,
55
- default_flags: 0,
56
- default_format: :document,
57
- default_observe_timeout: 2_500_000,
58
- on_error: nil,
59
- on_connect: nil,
60
- timeout: 0,
61
- environment: nil,
62
- key_prefix: nil,
63
- node_list: nil,
64
- destroying: 0,
65
- connected: 0,
66
- on_connect_proc: nil,
67
- connected: false
68
- }.freeze
69
-
70
- # Initialize new Bucket.
71
- #
72
- # @since 1.0.0
73
- #
74
- # @overload initialize(url, options = {})
75
- # Initialize bucket using URI of the cluster and options. It is possible
76
- # to override some parts of URI using the options keys (e.g. :host or
77
- # :port)
78
- #
79
- # @param [String] url The full URL of management API of the cluster.
80
- # @param [Hash] options The options for connection. See options definition
81
- # below.
82
- #
83
- # @overload initialize(options = {})
84
- # Initialize bucket using options only.
85
- #
86
- # @param [Hash] options The options for operation for connection
87
- # @option options [Array] :node_list (nil) the list of nodes to connect
88
- # to. If specified it takes precedence over +:host+ option. The list
89
- # must be array of strings in form of host names or host names with
90
- # ports (in first case port 8091 will be used, see examples).
91
- # @option options [String] :host ("localhost") the hostname or IP address
92
- # of the node
93
- # @option options [Fixnum] :port (8091) the port of the managemenent API
94
- # @option options [String] :pool ("default") the pool name
95
- # @option options [String] :bucket ("default") the bucket name
96
- # @option options [Fixnum] :default_ttl (0) the TTL used by default during
97
- # storing key-value pairs.
98
- # @option options [Fixnum] :default_flags (0) the default flags.
99
- # @option options [Symbol] :default_format (:document) the format, which
100
- # will be used for values by default. Note that changing format will
101
- # amend flags. (see {Bucket#default_format})
102
- # @option options [String] :username (nil) the user name to connect to the
103
- # cluster. Used to authenticate on management API. The username could
104
- # be skipped for protected buckets, the bucket name will be used
105
- # instead.
106
- # @option options [String] :password (nil) the password of the user.
107
- # @option options [true, false] :quiet (false) the flag controlling if raising
108
- # exception when the client executes operations on non-existent keys. If it
109
- # is +true+ it will raise {Couchbase::Error::NotFound} exceptions. The
110
- # default behaviour is to return +nil+ value silently (might be useful in
111
- # Rails cache).
112
- # @option options [Symbol] :environment (:production) the mode of the
113
- # connection. Currently it influences only on design documents set. If
114
- # the environment is +:development+, you will able to get design
115
- # documents with 'dev_' prefix, otherwise (in +:production+ mode) the
116
- # library will hide them from you.
117
- # @option options [String] :key_prefix (nil) the prefix string which will
118
- # be prepended to each key before sending out, and sripped before
119
- # returning back to the application.
120
- # @option options [Fixnum] :timeout (2500000) the timeout for IO
121
- # operations (in microseconds)
122
- # @option options [Fixnum, true] :default_arithmetic_init (0) the default
123
- # initial value for arithmetic operations. Setting this option to any
124
- # non positive number forces creation missing keys with given default
125
- # value. Setting it to +true+ will use zero as initial value. (see
126
- # {Bucket#incr} and {Bucket#decr}).
127
- # @option options [Symbol] :engine (:default) the IO engine to use
128
- # Currently following engines are supported:
129
- # :default :: Built-in engine (multi-thread friendly)
130
- # :libevent :: libevent IO plugin from libcouchbase (optional)
131
- # :libev :: libev IO plugin from libcouchbase (optional)
132
- # :eventmachine :: EventMachine plugin (builtin, but requires EM gem and ruby 1.9+)
133
- #
134
- # @example Initialize connection using default options
135
- # Couchbase.new
136
- #
137
- # @example Select custom bucket
138
- # Couchbase.new(:bucket => 'foo')
139
- # Couchbase.new('http://localhost:8091/pools/default/buckets/foo')
140
- #
141
- # @example Connect to protected bucket
142
- # Couchbase.new(:bucket => 'protected', :username => 'protected', :password => 'secret')
143
- # Couchbase.new('http://localhost:8091/pools/default/buckets/protected',
144
- # :username => 'protected', :password => 'secret')
145
- #
146
- # @example Use list of nodes, in case some nodes might be dead
147
- # Couchbase.new(:node_list => ['example.com:8091', 'example.org:8091', 'example.net'])
148
- #
149
- # @raise [Couchbase::Error::BucketNotFound] if there is no such bucket to
150
- # connect to
151
- #
152
- # @raise [Couchbase::Error::Connect] if the socket wasn't accessible
153
- # (doesn't accept connections or doesn't respond in time)
154
- #
155
- # @return [Bucket]
156
- #
157
- def initialize(url = nil, options = {})
158
- url_options = expand_url_options(url)
159
-
160
- options = Couchbase.normalize_connection_options(options)
161
-
162
- connection_options = DEFAULT_OPTIONS.merge(url_options).merge(options)
163
-
164
- connection_options.each_pair do |key, value|
165
- instance_variable_set("@#{key}", value)
166
- end
167
-
168
- self.password = '' if self.password.nil?
169
-
170
- @transcoders = {
171
- document: Transcoder::Document.new,
172
- marshal: Transcoder::Marshal.new,
173
- plain: Transcoder::Plain.new
174
- }
175
-
176
- connect
177
- end
178
-
179
- def quiet?
180
- !!quiet
181
- end
182
-
183
- def host
184
- hostname
185
- end
186
-
187
- def connect
188
- uris = expand_node_list
189
-
190
- begin
191
- builder = CouchbaseConnectionFactoryBuilder.new
192
- builder.setTranscoder(transcoder)
193
- connection_factory = builder.buildCouchbaseConnection(uris, bucket.to_java_string, password.to_java_string)
194
- @client = CouchbaseClient.new(connection_factory)
195
- @connected = true
196
- rescue Java::ComCouchbaseClientVbucket::ConfigurationException => e
197
- fail Couchbase::Error::Auth, "Couchbase configurations are incorrect: #{e.to_s}"
198
- rescue java.net.ConnectException => e
199
- fail Couchbase::Error::Connect, e.to_s
200
- end
201
-
202
- self
203
- end
204
- alias_method :reconnect, :connect
205
21
 
206
- def authority
207
- "#{hostname}:#{port}"
208
- end
209
-
210
- def base_url
211
- "http://#{authority}/pools"
212
- end
213
-
214
- def url
215
- "http://#{authority}/pools/#{pool}/buckets/#{bucket}/"
216
- end
217
-
218
- def connected?
219
- @connected
220
- end
221
-
222
- def disconnect
223
- if connected? && @client.shutdown(3, TimeUnit::SECONDS)
224
- @client = nil
225
- @connection_factory = nil
226
- @connected = false
227
- else
228
- fail Couchbase::Error::Connect
229
- end
230
- end
231
-
232
- def transcoder
233
- transcoders[default_format]
234
- end
22
+ attr_reader :bucket
235
23
 
236
- def on_connect(&block)
237
- @on_connect = block
24
+ def initialize(bucket)
25
+ @bucket = bucket
238
26
  end
239
27
 
240
- def on_error(&block)
241
- @on_error = block
28
+ def async
29
+ @bucket.async
242
30
  end
243
31
 
244
- def version
245
- {}.tap do |hash|
246
- @client.getVersions.to_hash.each_pair do |ip, ver|
247
- hash[ip.to_s] = ver
248
- end
249
- end
32
+ def save_design_doc(name, design_doc, development = false)
33
+ design_doc = DesignDoc.new(name, design_doc)
34
+ @bucket.bucket_manager.upsert_design_document(design_doc.create, development)
250
35
  end
251
36
 
252
- # Compare and swap value.
253
- #
254
- # @since 1.0.0
255
- #
256
- # Reads a key's value from the server and yields it to a block. Replaces
257
- # the key's value with the result of the block as long as the key hasn't
258
- # been updated in the meantime, otherwise raises
259
- # {Couchbase::Error::KeyExists}. CAS stands for "compare and swap", and
260
- # avoids the need for manual key mutexing. Read more info here:
261
- #
262
- # In asynchronous mode it will yield result twice, first for
263
- # {Bucket#get} with {Result#operation} equal to +:get+ and
264
- # second time for {Bucket#set} with {Result#operation} equal to +:set+.
265
- #
266
- # @see http://couchbase.com/docs/memcached-api/memcached-api-protocol-text_cas.html
267
- #
268
- # @param [String, Symbol] key
269
- #
270
- # @param [Hash] options the options for "swap" part
271
- # @option options [Fixnum] :ttl (self.default_ttl) the time to live of this key
272
- # @option options [Symbol] :format (self.default_format) format of the value
273
- # @option options [Fixnum] :flags (self.default_flags) flags for this key
274
- #
275
- # @yieldparam [Object, Result] value old value in synchronous mode and
276
- # +Result+ object in asynchronous mode.
277
- # @yieldreturn [Object] new value.
278
- #
279
- # @raise [Couchbase::Error::KeyExists] if the key was updated before the the
280
- # code in block has been completed (the CAS value has been changed).
281
- # @raise [ArgumentError] if the block is missing for async mode
282
- #
283
- # @example Implement append to JSON encoded value
284
- #
285
- # c.default_format = :document
286
- # c.set("foo", {"bar" => 1})
287
- # c.cas("foo") do |val|
288
- # val["baz"] = 2
289
- # val
290
- # end
291
- # c.get("foo") #=> {"bar" => 1, "baz" => 2}
292
- #
293
- # @example Append JSON encoded value asynchronously
294
- #
295
- # c.default_format = :document
296
- # c.set("foo", {"bar" => 1})
297
- # c.run do
298
- # c.cas("foo") do |val|
299
- # case val.operation
300
- # when :get
301
- # val["baz"] = 2
302
- # val
303
- # when :set
304
- # # verify all is ok
305
- # puts "error: #{ret.error.inspect}" unless ret.success?
306
- # end
307
- # end
308
- # end
309
- # c.get("foo") #=> {"bar" => 1, "baz" => 2}
310
- #
311
- # @return [Fixnum] the CAS of new value
312
- def cas(key, options = {})
313
- val, flags, ver = get(key, :extended => true)
314
- val = yield(val) # get new value from caller
315
- set(key, val, options.merge(:cas => ver))
37
+ def query(design_doc, view)
38
+ View.new(design_doc, view, self)
316
39
  end
317
- alias :compare_and_swap :cas
318
40
 
319
- # Delete contents of the bucket
320
- #
321
- # @see http://www.couchbase.com/docs/couchbase-manual-2.0/restapi-flushing-bucket.html
322
- #
323
- # @since 1.2.0.beta
324
- #
325
- # @yieldparam [Result] ret the object with +error+, +status+ and +operation+
326
- # attributes.
327
- #
328
- # @raise [Couchbase::Error::Protocol] in case of an error is
329
- # encountered. Check {Couchbase::Error::Base#status} for detailed code.
330
- #
331
- # @return [true] always return true (see raise section)
332
- #
333
- # @example Simple flush the bucket
334
- # c.flush #=> true
335
- #
336
41
  def flush
337
- async_flush.get
42
+ bucket.bucket_manager.flush
338
43
  end
339
-
340
- def async_flush
341
- @client.flush
342
- end
343
-
344
- private
345
-
346
- def path_to_pool_and_bucket(path)
347
- {}
348
- end
349
-
350
- def expand_url_options(url)
351
- if url.is_a? String
352
- fail ArgumentError.new unless url =~ /^http:\/\//
353
- uri = URI.new(url)
354
- { hostname: uri.host, port: uri.port }.merge(path_to_pool_and_bucket(uri.path))
355
- elsif url.nil?
356
- {}
357
- else
358
- url
359
- end
360
- end
361
-
362
- def expand_node_list
363
- if @node_list
364
- Array(@node_list).map { |n| URI.new(n) }
365
- else
366
- Array(URI.new(base_url))
367
- end
368
- end
369
-
370
44
  end
371
-
372
45
  end
@@ -1,5 +1,5 @@
1
- # Author:: Couchbase <info@couchbase.com>
2
- # Copyright:: 2011, 2012 Couchbase, Inc.
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,100 +17,22 @@
17
17
 
18
18
  module Couchbase
19
19
 
20
- class ClusterError < Error::Base; end
21
-
22
20
  class Cluster
23
21
 
24
- java_import java.net.URI
25
- java_import com.couchbase.client.clustermanager.BucketType
26
- java_import com.couchbase.client.clustermanager.FlushResponse
27
- java_import com.couchbase.client.clustermanager.AuthType
28
-
29
- # Establish connection to the cluster for administration
30
- #
31
- # @param [Hash] options The connection parameter
32
- # @option options [String] :username The username
33
- # @option options [String] :password The password
34
- # @option options [String] :pool ("default") The pool name
35
- # @option options [String] :hostname ("localhost") The hostname
36
- # @option options [String] :port (8091) The port
37
- def initialize(options)
38
- if options[:username].nil? || options[:password].nil?
39
- raise ArgumentError, "username and password mandatory to connect to the cluster"
40
- end
22
+ java_import com.couchbase.client.java.CouchbaseCluster
41
23
 
42
- options = {
43
- hostname: 'localhost',
44
- port: 8091
45
- }.merge(options)
24
+ attr_reader :cluster
46
25
 
47
- cluster_uri = "http://#{options[:hostname]}:#{options[:port]}"
48
-
49
- uri_list = Array(URI.new(cluster_uri))
50
- @manager = Java::ComCouchbaseClient::ClusterManager.new(uri_list, options[:username], options[:password])
26
+ def initialize(hosts = 'localhost')
27
+ @cluster = CouchbaseCluster.create(hosts)
51
28
  end
52
29
 
53
- # List available buckets
54
- def list_buckets
55
- @manager.listBuckets
30
+ def open_bucket(name = 'default', password = '')
31
+ Bucket.new(@cluster.open_bucket(name, password))
56
32
  end
57
33
 
58
- # Delete the data bucket
59
- #
60
- # @param [String] name The name of the bucket
61
- # @param [Hash] options
62
- def delete_bucket(bucket)
63
- @manager.deleteBucket(bucket)
64
- end
65
-
66
- # Create data bucket
67
- #
68
- # @param [String] name The name of the bucket
69
- # @param [Hash] options The bucket parameters
70
- # @option options [String] :bucket_type ("couchbase") The type of the
71
- # bucket. Possible values are "memcached" and "couchbase".
72
- # @option options [Fixnum] :ram_quota (100) The RAM quota in megabytes.
73
- # @option options [Fixnum] :replica_number (1) The number of replicas of
74
- # each document
75
- # @option options [String] :auth_type ("sasl") The authentication type.
76
- # Possible values are "sasl" and "none". Note you should specify free
77
- # port for "none"
78
- # @option options [Fixnum] :proxy_port The port for moxi
79
- def create_bucket(name, options = {})
80
- ram_quota = options[:ram_quota] || 100
81
- replicas = options[:replica_number] || 0
82
- flush = options.fetch(:flush) { true }
83
- password = options[:password]
84
- proxy_port = options[:proxy_port]
85
- auth_type = options[:auth_type] || 'sasl'
86
- bucket_type = options[:bucket_type] == 'memcached' ? BucketType::MEMCACHED : BucketType::COUCHBASE
87
-
88
- if name == 'default'
89
- @manager.createDefaultBucket(bucket_type, ram_quota, replicas, flush)
90
- elsif auth == 'sasl'
91
- @manager.createPortBucket(bucket_type, name, ram_quota, replicas, proxy_port, flush)
92
- else
93
- @manager.createNamedBucket(bucket_type, name, ram_quota, replicas, password, flush)
94
- end
95
- true
96
- rescue Java::JavaLang::RuntimeException => e
97
- raise ClusterError, e
98
- end
99
-
100
- def flush_bucket(bucket)
101
- @manager.flushBucket(bucket) == FlushResponse::OK
102
- end
103
-
104
- def update_bucket(name, options)
105
- # implement
106
- end
107
-
108
- def self.manage(cluster_uri, username, password, &block)
109
- manager = new(cluster_uri, username, password)
110
- yield manager
111
- ensure
112
- manager.shutdown
34
+ def disconnect
35
+ @cluster.disconnect
113
36
  end
114
37
  end
115
-
116
38
  end
@@ -0,0 +1,39 @@
1
+ module Couchbase
2
+
3
+ class Configuration
4
+
5
+ DEFAULT_CONFIG = {
6
+ host: 'localhost',
7
+ bucket: 'default',
8
+ password: ''
9
+ }
10
+
11
+ Bucket = Struct.new(:name, :password)
12
+
13
+ attr_accessor :hosts, :buckets
14
+
15
+ def initialize(config = {})
16
+ config = DEFAULT_CONFIG.merge(symbolize_keys(config))
17
+ @hosts = Array(config[:hosts] || config[:host] || config[:hostname])
18
+
19
+ if config[:buckets]
20
+ @buckets = config[:buckets].map do |b|
21
+ b = symbolize_keys(b)
22
+ Bucket.new(b[:name], b[:password])
23
+ end
24
+ else
25
+ @buckets = [Bucket.new(config[:bucket], config[:password])]
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def symbolize_keys(old_hash)
32
+ {}.tap do |hash|
33
+ old_hash.each_pair do |key, value|
34
+ hash[key.to_sym] = value
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end