class ElastomerClient::Client::Snapshot

Attributes

client[R]
name[R]
repository[R]

Public Class Methods

new(client, repository = nil, name = nil) click to toggle source

Create a new snapshot object for making API requests that pertain to creating, restoring, deleting, and retrieving snapshots.

client - ElastomerClient::Client used for HTTP requests to the server repository - The name of the repository as a String. Cannot be nil if

snapshot name is not nil.

name - The name of the snapshot as a String

# File lib/elastomer_client/client/snapshot.rb, line 24
def initialize(client, repository = nil, name = nil)
  @client     = client
  # don't allow nil repository if snapshot name is not nil
  @repository = @client.assert_param_presence(repository, "repository name") unless repository.nil? && name.nil?
  @name       = @client.assert_param_presence(name, "snapshot name") unless name.nil?
end

Public Instance Methods

create(body = {}, params = {}) click to toggle source

Create the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot

body - The snapshot options as a Hash or a JSON encoded String params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer_client/client/snapshot.rb, line 58
def create(body = {}, params = {})
  response = client.put "/_snapshot/{repository}/{snapshot}", update_params(params, body:, action: "snapshot.create", rest_api: "snapshot.create")
  response.body
end
defaults() click to toggle source

Internal: Returns a Hash containing default parameters.

# File lib/elastomer_client/client/snapshot.rb, line 124
def defaults
  { repository:, snapshot: name }
end
delete(params = {}) click to toggle source

Delete the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot

params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer_client/client/snapshot.rb, line 105
def delete(params = {})
  response = client.delete "/_snapshot/{repository}/{snapshot}", update_params(params, action: "snapshot.delete", rest_api: "snapshot.delete")
  response.body
end
exist?(params = {})
Alias for: exists?
exists?(params = {}) click to toggle source

Check for the existence of the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot

params - Parameters Hash

Returns true if the snapshot exists

# File lib/elastomer_client/client/snapshot.rb, line 39
def exists?(params = {})
  response = client.get "/_snapshot/{repository}/{snapshot}", update_params(params, action: "snapshot.exists", rest_api: "snapshot.get")
  response.success?
rescue ElastomerClient::Client::Error => err
  if err.error && err.error.dig("root_cause", 0, "type") == "snapshot_missing_exception"
    false
  else
    raise err
  end
end
Also aliased as: exist?
get(params = {}) click to toggle source

Get snapshot progress information. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot

params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer_client/client/snapshot.rb, line 69
def get(params = {})
  # Set snapshot name or we'll get the repository instead
  snapshot = name || "_all"
  response = client.get "/_snapshot/{repository}/{snapshot}", update_params(params, snapshot:, action: "snapshot.get", rest_api: "snapshot.get")
  response.body
end
restore(body = {}, params = {}) click to toggle source

Restore the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot

body - The restore options as a Hash or a JSON encoded String params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer_client/client/snapshot.rb, line 94
def restore(body = {}, params = {})
  response = client.post "/_snapshot/{repository}/{snapshot}/_restore", update_params(params, body:, action: "snapshot.restore", rest_api: "snapshot.restore")
  response.body
end
status(params = {}) click to toggle source

Get detailed snapshot status. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot

params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer_client/client/snapshot.rb, line 82
def status(params = {})
  response = client.get "/_snapshot{/repository}{/snapshot}/_status", update_params(params, action: "snapshot.status", rest_api: "snapshot.status")
  response.body
end
update_params(params, overrides = nil) click to toggle source

Internal: Add default parameters to the ‘params` Hash and then apply `overrides` to the params if any are given.

params - Parameters Hash overrides - Optional parameter overrides as a Hash

Returns a new params Hash.

# File lib/elastomer_client/client/snapshot.rb, line 117
def update_params(params, overrides = nil)
  h = defaults.update params
  h.update overrides unless overrides.nil?
  h
end