Class: Elastomer::Client::Cluster
- Inherits:
-
Object
- Object
- Elastomer::Client::Cluster
- Defined in:
- lib/elastomer/client/cluster.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#get_aliases(params = {}) ⇒ Object
(also: #aliases)
Retrieve the current aliases.
-
#get_settings(params = {}) ⇒ Object
(also: #settings)
Cluster wide settings that have been modified via the update API.
-
#health(params = {}) ⇒ Object
Simple status on the health of the cluster.
-
#indices ⇒ Object
List all indices currently defined.
-
#initialize(client) ⇒ Cluster
constructor
Create a new cluster client for making API requests that pertain to the cluster health and management.
-
#nodes ⇒ Object
List all nodes currently part of the cluster.
-
#reroute(commands, params = {}) ⇒ Object
Explicitly execute a cluster reroute allocation command.
-
#shutdown(params = {}) ⇒ Object
Shutdown the entire cluster.
-
#state(params = {}) ⇒ Object
Comprehensive state information of the whole cluster.
-
#templates ⇒ Object
List all templates currently defined.
-
#update_aliases(actions, params = {}) ⇒ Object
Perform an aliases action on the cluster.
-
#update_settings(body, params = {}) ⇒ Object
Update cluster wide specific settings.
Constructor Details
#initialize(client) ⇒ Cluster
Create a new cluster client for making API requests that pertain to the cluster health and management.
client - Elastomer::Client used for HTTP requests to the server
16 17 18 |
# File 'lib/elastomer/client/cluster.rb', line 16 def initialize( client ) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
20 21 22 |
# File 'lib/elastomer/client/cluster.rb', line 20 def client @client end |
Instance Method Details
#get_aliases(params = {}) ⇒ Object Also known as: aliases
Retrieve the current aliases. An :index name can be given (or an array of index names) to get just the aliases for those indexes. You can also use the alias name here since it is acting the part of an index.
See www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
params - Parameters Hash
Examples
get_aliases
get_aliases( :index => 'users' )
Returns the response body as a Hash
125 126 127 128 |
# File 'lib/elastomer/client/cluster.rb', line 125 def get_aliases( params = {} ) response = client.get '{/index}/_aliases', params.merge(:action => 'cluster.get_aliases') response.body end |
#get_settings(params = {}) ⇒ Object Also known as: settings
Cluster wide settings that have been modified via the update API. See www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
params - Parameters Hash
Returns the response as a Hash
50 51 52 53 |
# File 'lib/elastomer/client/cluster.rb', line 50 def get_settings( params = {} ) response = client.get '/_cluster/settings', params.merge(:action => 'cluster.get_settings') response.body end |
#health(params = {}) ⇒ Object
Simple status on the health of the cluster. See www.elasticsearch.org/guide/reference/api/admin-cluster-health/
params - Parameters Hash
Returns the response as a Hash
28 29 30 31 |
# File 'lib/elastomer/client/cluster.rb', line 28 def health( params = {} ) response = client.get '/_cluster/health{/index}', params.merge(:action => 'cluster.health') response.body end |
#indices ⇒ Object
List all indices currently defined. This is just a convenience method around the ‘state` call that extracts and returns the indices section.
Returns the indices definitions as a Hash
183 184 185 186 187 188 189 190 |
# File 'lib/elastomer/client/cluster.rb', line 183 def indices h = state( :filter_blocks => true, :filter_nodes => true, :filter_routing_table => true ) h['metadata']['indices'] end |
#nodes ⇒ Object
List all nodes currently part of the cluster. This is just a convenience method around the ‘state` call that extracts and returns the nodes section.
Returns the nodes definitions as a Hash
197 198 199 200 201 202 203 204 |
# File 'lib/elastomer/client/cluster.rb', line 197 def nodes h = state( :filter_blocks => true, :filter_metadata => true, :filter_routing_table => true ) h['nodes'] end |
#reroute(commands, params = {}) ⇒ Object
Explicitly execute a cluster reroute allocation command. For example, a shard can be moved from one node to another explicitly, an allocation can be canceled, or an unassigned shard can be explicitly allocated on a specific node.
See www.elasticsearch.org/guide/reference/api/admin-cluster-reroute/
commands - A command Hash or an Array of command Hashes params - Parameters Hash
Examples
reroute(:move => { :index => 'test', :shard => 0, :from_node => 'node1', :to_node => 'node2' })
reroute([
{ :move => { :index => 'test', :shard => 0, :from_node => 'node1', :to_node => 'node2' }},
{ :allocate => { :index => 'test', :shard => 1, :node => 'node3' }}
])
Returns the response as a Hash
91 92 93 94 95 96 97 |
# File 'lib/elastomer/client/cluster.rb', line 91 def reroute( commands, params = {} ) commands = [commands] unless Array === commands body = {:commands => commands} response = client.post '/_cluster/reroute', params.merge(:body => body, :action => 'cluster.reroute') response.body end |
#shutdown(params = {}) ⇒ Object
Shutdown the entire cluster. See www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/
params - Parameters Hash
Returns the response as a Hash
105 106 107 108 |
# File 'lib/elastomer/client/cluster.rb', line 105 def shutdown( params = {} ) response = client.post '/_shutdown', params.merge(:action => 'cluster.shutdown') response.body end |
#state(params = {}) ⇒ Object
Comprehensive state information of the whole cluster. See www.elasticsearch.org/guide/reference/api/admin-cluster-state/
params - Parameters Hash
Returns the response as a Hash
39 40 41 42 |
# File 'lib/elastomer/client/cluster.rb', line 39 def state( params = {} ) response = client.get '/_cluster/state', params.merge(:action => 'cluster.state') response.body end |
#templates ⇒ Object
List all templates currently defined. This is just a convenience method around the ‘state` call that extracts and returns the templates section.
Returns the template definitions as a Hash
170 171 172 173 174 175 176 177 |
# File 'lib/elastomer/client/cluster.rb', line 170 def templates h = state( :filter_blocks => true, :filter_nodes => true, :filter_routing_table => true ) h['metadata']['templates'] end |
#update_aliases(actions, params = {}) ⇒ Object
Perform an aliases action on the cluster. We are just a teensy bit clever here in that a single action can be given or an array of actions. This API method will wrap the request in the appropriate => […] body construct.
See www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
actions - An action Hash or an Array of action Hashes params - Parameters Hash
Examples
update_aliases(:add => { :index => 'users-1', :alias => 'users' })
update_aliases([
{ :remove => { :index => 'users-1', :alias => 'users' }},
{ :add => { :index => 'users-2', :alias => 'users' }}
])
Returns the response body as a Hash
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/elastomer/client/cluster.rb', line 151 def update_aliases( actions, params = {} ) if actions.is_a?(Hash) && actions.key?(:actions) body = actions elsif actions.is_a?(Hash) # Array() on a Hash does not do what you think it does - that is why # we are explicitly wrapping the Hash via [actions] here. body = {:actions => [actions]} else body = {:actions => Array(actions)} end response = client.post '/_aliases', params.merge(:body => body, :action => 'cluster.update_aliases') response.body end |
#update_settings(body, params = {}) ⇒ Object
Update cluster wide specific settings. Settings updated can either be persistent (applied cross restarts) or transient (will not survive a full cluster restart).
See www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
body - The new settings as a Hash or a JSON encoded String params - Parameters Hash
Returns the response as a Hash
66 67 68 69 |
# File 'lib/elastomer/client/cluster.rb', line 66 def update_settings( body, params = {} ) response = client.put '/_cluster/settings', params.merge(:body => body, :action => 'cluster.update_settings') response.body end |