Class: Couchbase::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/cluster.rb

Instance Method Summary (collapse)

Constructor Details

- (Cluster) initialize(options = {})

Establish connection to the cluster for administration

Parameters:

  • options (Hash) (defaults to: {})

    The connection parameter

Options Hash (options):

  • :username (String)

    The username

  • :password (String)

    The password

  • :pool (String) — default: "default"

    The pool name

  • :hostname (String) — default: "localhost"

    The hostname

  • :port (String) — default: 8091

    The port



30
31
32
33
34
35
# File 'lib/couchbase/cluster.rb', line 30

def initialize(options = {})
  if options[:username].nil? || options[:password].nil?
    raise ArgumentError, "username and password mandatory to connect to the cluster"
  end
  @connection = Bucket.new(options.merge(:type => :cluster))
end

Instance Method Details

- (Object) create_bucket(name, options = {})

Create data bucket

Parameters:

  • name (String)

    The name of the bucket

  • options (Hash) (defaults to: {})

    The bucket parameters

Options Hash (options):

  • :bucket_type (String) — default: "couchbase"

    The type of the bucket. Possible values are "memcached" and "couchbase".

  • :ram_quota (Fixnum) — default: 100

    The RAM quota in megabytes.

  • :replica_number (Fixnum) — default: 1

    The number of replicas of each document

  • :auth_type (String) — default: "sasl"

    The authentication type. Possible values are "sasl" and "none". Note you should specify free port for "none"

  • :proxy_port (Fixnum)

    The port for moxi



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/couchbase/cluster.rb', line 50

def create_bucket(name, options = {})
  defaults = {
    :type => "couchbase",
    :ram_quota => 100,
    :replica_number => 1,
    :auth_type => "sasl",
    :sasl_password => "",
    :proxy_port => nil
  }
  options = defaults.merge(options)
  params = {"name" => name}
  params["bucketType"] = options[:type]
  params["ramQuotaMB"] = options[:ram_quota]
  params["replicaNumber"] = options[:replica_number]
  params["authType"] = options[:auth_type]
  params["saslPassword"] = options[:sasl_password]
  params["proxyPort"] = options[:proxy_port]
  payload = Utils.encode_params(params.reject!{|k, v| v.nil?})
  request = @connection.make_http_request("/pools/default/buckets",
                                          :content_type => "application/x-www-form-urlencoded",
                                          :type => :management,
                                          :method => :post,
                                          :extended => true,
                                          :body => payload)
  response = nil
  request.on_body do |r|
    response = r
    response.instance_variable_set("@operation", :create_bucket)
    yield(response) if block_given?
  end
  request.continue
  response
end

- (Object) delete_bucket(name, options = {})

Delete the data bucket

Parameters:

  • name (String)

    The name of the bucket

  • options (Hash) (defaults to: {})


88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/couchbase/cluster.rb', line 88

def delete_bucket(name, options = {})
  request = @connection.make_http_request("/pools/default/buckets/#{name}",
                                          :type => :management,
                                          :method => :delete,
                                          :extended => true)
  response = nil
  request.on_body do |r|
    response = r
    response.instance_variable_set("@operation", :delete_bucket)
    yield(response) if block_given?
  end
  request.continue
  response
end