Class: Couchbase::Cluster

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cluster

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

#create_bucket(name, options = {}) ⇒ Object

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. Minimum 0, maximum 3.

  • :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

  • :replica_index (true, false) — default: true

    Disable or enable indexes for bucket replicas

  • :flush_enabled (true, false) — default: false

    Enables the 'flush all' functionality on the specified bucket.

  • :parallel_db_and_view_compaction (true, false) — default: false

    Indicates whether database and view files on disk can be compacted simultaneously


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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/couchbase/cluster.rb', line 58

def create_bucket(name, options = {})
  defaults = {
    :type => "couchbase",
    :ram_quota => 100,
    :replica_number => 1,
    :auth_type => "sasl",
    :sasl_password => "",
    :proxy_port => nil,
    :flush_enabled => false,
    :replica_index => true,
    :parallel_db_and_view_compaction => false
  }
  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]
  params["flushEnabled"] = !!options[:flush_enabled]
  params["replicaIndex"] = !!options[:replica_index]
  params["parallelDBAndViewCompaction"] = !!options[:parallel_db_and_view_compaction]
  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

#delete_bucket(name, options = {}) ⇒ Object

Delete the data bucket

Parameters:

  • name (String)

    The name of the bucket

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

102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/couchbase/cluster.rb', line 102

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