Skip to content

Commit

Permalink
[API] Added the "Snapshot Status" API
Browse files Browse the repository at this point in the history
  • Loading branch information
karmi committed Apr 10, 2014
1 parent 3d0725a commit 0473545
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Actions
# @option arguments [Boolean] :wait_for_completion Whether the request should block and wait until
# the operation has completed
#
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html#_snapshot
#
def create(arguments={})
raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Actions
# @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
# @option arguments [Time] :timeout Explicit operation timeout
#
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html#_repositories
#
def create_repository(arguments={})
raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Actions
# @example Restore a specific index under a different name
#
# client.snapshot.restore repository: 'my-backups',
# snapshot: 'snapshot-5',
# snapshot: 'snapshot-1',
# body: {
# rename_pattern: "^(.*)$",
# rename_replacement: "restored_$1"
Expand Down
40 changes: 40 additions & 0 deletions elasticsearch-api/lib/elasticsearch/api/actions/snapshot/status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Elasticsearch
module API
module Snapshot
module Actions

# Return information about a running snapshot
#
# @example Return information about all currently running snapshots
#
# client.snapshot.status repository: 'my-backups', human: true
#
# @example Return information about a specific snapshot
#
# client.snapshot.status repository: 'my-backups', human: true
#
# @option arguments [String] :repository A repository name
# @option arguments [List] :snapshot A comma-separated list of snapshot names
# @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
#
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html#_snapshot_status
#
def status(arguments={})
valid_params = [
:master_timeout ]

repository = arguments.delete(:repository)
snapshot = arguments.delete(:snapshot)

method = 'GET'

path = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__escape(snapshot), '_status')
params = Utils.__validate_and_extract_params arguments, valid_params
body = nil

perform_request(method, path, params, body).body
end
end
end
end
end
38 changes: 38 additions & 0 deletions elasticsearch-api/test/unit/snapshot/status_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'test_helper'

module Elasticsearch
module Test
class SnapshotStatusTest < ::Test::Unit::TestCase

context "Snapshot: Status" do
subject { FakeClient.new }

should "perform correct request" do
subject.expects(:perform_request).with do |method, url, params, body|
assert_equal 'GET', method
assert_equal '_snapshot/_status', url
assert_equal Hash.new, params
assert_nil body
true
end.returns(FakeResponse.new)

subject.snapshot.status
end

should "encode repository and snapshot" do
subject.expects(:perform_request).with do |method, url, params, body|
assert_equal 'GET', method
assert_equal '_snapshot/foo/bar/_status', url
assert_equal Hash.new, params
assert_equal nil, body
true
end.returns(FakeResponse.new)

subject.snapshot.status :repository => 'foo', :snapshot => 'bar'
end

end

end
end
end

0 comments on commit 0473545

Please sign in to comment.