Class: Riak::Cluster
- Includes:
- Util::Translation
- Defined in:
- lib/riak/cluster.rb
Overview
Generates and controls a cluster of Node instances for use in development or testing on a single machine.
Instance Attribute Summary collapse
-
#configuration ⇒ Hash
readonly
The cluster configuration.
-
#nodes ⇒ Array<Node>
readonly
The member Nodes of this cluster.
-
#root ⇒ Pathname
readonly
The root directory of the cluster.
Instance Method Summary collapse
-
#attach ⇒ Array<Riak::Node::Console>
Attaches to the console on all nodes, returning a list of Node::Console objects.
-
#create ⇒ Object
Generates all nodes in the cluster.
-
#destroy ⇒ Object
Removes all nodes in the cluster and the root, and freezes the object.
-
#drop ⇒ Object
Drops all data from the cluster without destroying the nodes.
-
#exist? ⇒ true, false
Whether the cluster has been created.
- #initialize(config = {}) ⇒ Cluster constructor
-
#join ⇒ Object
Joins the nodes together into a cluster.
-
#js_reload ⇒ Object
Forces the cluster nodes to restart/reload their JavaScript VMs, effectively reloading any user-provided code.
-
#reboot ⇒ Object
Reboots all nodes in the cluster.
-
#recreate ⇒ Object
Removes and recreates the cluster.
-
#restart ⇒ Object
Restarts all nodes in the cluster (without exiting the Erlang runtime).
-
#start ⇒ Object
Starts all nodes in the cluster.
-
#started? ⇒ Boolean
Is the cluster started?.
-
#stop ⇒ Object
Stops all nodes in the cluster.
-
#stopped? ⇒ Boolean
Is the cluster stopped?.
-
#with_console {|console| ... } ⇒ Object
Executes the given block on each node against the node’s console.
Methods included from Util::Translation
Constructor Details
#initialize(config = {}) ⇒ Cluster
Creates a Riak::Cluster of Nodes.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/riak/cluster.rb', line 28 def initialize(config={}) raise ArgumentError, t('source_and_root_required') unless config[:source] && config[:root] @configuration = config @count = config.delete(:count) || 4 @min_port = config.delete(:min_port) || 9000 @root = Pathname.new(config.delete(:root)) @nodes = [] = "#{rand(100000).to_s}_#{rand(1000000).to_s}" @count.times do |i| nodes << Riak::Node.new(config.merge(:min_port => @min_port + (i * 3), :root => @root + (i+1).to_s, :cookie => )) end end |
Instance Attribute Details
#configuration ⇒ Hash (readonly)
Returns the cluster configuration.
14 15 16 |
# File 'lib/riak/cluster.rb', line 14 def configuration @configuration end |
#nodes ⇒ Array<Node> (readonly)
Returns the member Nodes of this cluster.
11 12 13 |
# File 'lib/riak/cluster.rb', line 11 def nodes @nodes end |
#root ⇒ Pathname (readonly)
Returns the root directory of the cluster.
17 18 19 |
# File 'lib/riak/cluster.rb', line 17 def root @root end |
Instance Method Details
#attach ⇒ Array<Riak::Node::Console>
Attaches to the console on all nodes, returning a list of Node::Console objects.
108 109 110 111 112 113 114 115 116 |
# File 'lib/riak/cluster.rb', line 108 def attach nodes.map do |n| begin n.attach rescue ArgumentError, SystemCallError nil end end end |
#create ⇒ Object
Generates all nodes in the cluster.
49 50 51 52 53 54 |
# File 'lib/riak/cluster.rb', line 49 def create unless exist? root.mkpath unless root.exist? nodes.each {|n| n.create } end end |
#destroy ⇒ Object
Removes all nodes in the cluster and the root, and freezes the object.
58 59 60 61 62 |
# File 'lib/riak/cluster.rb', line 58 def destroy nodes.each {|n| n.destroy } root.rmtree if root.exist? freeze end |
#drop ⇒ Object
Drops all data from the cluster without destroying the nodes.
72 73 74 |
# File 'lib/riak/cluster.rb', line 72 def drop nodes.each {|n| n.drop } end |
#exist? ⇒ true, false
Returns whether the cluster has been created.
44 45 46 |
# File 'lib/riak/cluster.rb', line 44 def exist? root.directory? && nodes.all? {|n| n.exist? } end |
#join ⇒ Object
This method relies on cluster membership changes present in the 1.0 series of Riak, and is NOT safe on 0.14 and earlier.
Joins the nodes together into a cluster.
145 146 147 148 149 |
# File 'lib/riak/cluster.rb', line 145 def join claimant = nodes.first.name # Not really the claimant, just a # node to join to nodes[1..-1].each {|n| n.join(claimant) unless n.peers.include?(claimant) } end |
#js_reload ⇒ Object
Forces the cluster nodes to restart/reload their JavaScript VMs, effectively reloading any user-provided code.
99 100 101 |
# File 'lib/riak/cluster.rb', line 99 def js_reload nodes.each {|n| n.js_reload } end |
#reboot ⇒ Object
Reboots all nodes in the cluster
93 94 95 |
# File 'lib/riak/cluster.rb', line 93 def reboot nodes.each {|n| n.reboot } end |
#recreate ⇒ Object
Removes and recreates the cluster.
65 66 67 68 69 |
# File 'lib/riak/cluster.rb', line 65 def recreate stop unless stopped? root.rmtree if root.exist? create end |
#restart ⇒ Object
Restarts all nodes in the cluster (without exiting the Erlang runtime)
88 89 90 |
# File 'lib/riak/cluster.rb', line 88 def restart nodes.each {|n| n.restart } end |
#start ⇒ Object
Starts all nodes in the cluster.
77 78 79 |
# File 'lib/riak/cluster.rb', line 77 def start nodes.each {|n| n.start } end |
#started? ⇒ Boolean
Is the cluster started?
132 133 134 |
# File 'lib/riak/cluster.rb', line 132 def started? nodes.all? {|n| n.started? } end |
#stop ⇒ Object
Stops all nodes in the cluster.
82 83 84 |
# File 'lib/riak/cluster.rb', line 82 def stop nodes.each {|n| n.stop } end |
#stopped? ⇒ Boolean
Is the cluster stopped?
137 138 139 |
# File 'lib/riak/cluster.rb', line 137 def stopped? nodes.all? {|n| n.stopped? } end |
#with_console {|console| ... } ⇒ Object
Executes the given block on each node against the node’s console. You could use this to send Erlang commands to all nodes in the cluster.
125 126 127 128 129 |
# File 'lib/riak/cluster.rb', line 125 def with_console(&block) nodes.each do |n| n.with_console(&block) end end |