Skip to content

Commit 1dd46b1

Browse files
committed
[API] Adds snapshot.clone endpoint
1 parent 0d045a7 commit 1dd46b1

File tree

2 files changed

+133
-0
lines changed
  • elasticsearch-api

2 files changed

+133
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Snapshot
21+
module Actions
22+
# Clones indices from one snapshot into another snapshot in the same repository.
23+
#
24+
# @option arguments [String] :repository A repository name
25+
# @option arguments [String] :snapshot The name of the snapshot to clone from
26+
# @option arguments [String] :target_snapshot The name of the cloned snapshot to create
27+
# @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
28+
# @option arguments [Hash] :headers Custom HTTP headers
29+
# @option arguments [Hash] :body The snapshot clone definition (*Required*)
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html
32+
#
33+
def clone(arguments = {})
34+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
35+
raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
36+
raise ArgumentError, "Required argument 'snapshot' missing" unless arguments[:snapshot]
37+
raise ArgumentError, "Required argument 'target_snapshot' missing" unless arguments[:target_snapshot]
38+
39+
headers = arguments.delete(:headers) || {}
40+
41+
arguments = arguments.clone
42+
43+
_repository = arguments.delete(:repository)
44+
45+
_snapshot = arguments.delete(:snapshot)
46+
47+
_target_snapshot = arguments.delete(:target_snapshot)
48+
49+
method = Elasticsearch::API::HTTP_PUT
50+
path = "_snapshot/#{Utils.__listify(_repository)}/#{Utils.__listify(_snapshot)}/_clone/#{Utils.__listify(_target_snapshot)}"
51+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
52+
53+
body = arguments[:body]
54+
perform_request(method, path, params, body, headers).body
55+
end
56+
57+
# Register this action with its valid params when the module is loaded.
58+
#
59+
# @since 6.2.0
60+
ParamsRegistry.register(:clone, [
61+
:master_timeout
62+
].freeze)
63+
end
64+
end
65+
end
66+
end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.snapshot#clone' do
21+
let(:expected_args) do
22+
[
23+
'PUT',
24+
'_snapshot/foo/bar/_clone/snapshot',
25+
{},
26+
{},
27+
{}
28+
]
29+
end
30+
31+
let(:client) do
32+
Class.new { include Elasticsearch::API }.new
33+
end
34+
35+
it 'requires the :body argument' do
36+
expect {
37+
client.snapshot.clone(snapshot: 'bar')
38+
}.to raise_exception(ArgumentError)
39+
end
40+
41+
it 'requires the :repository argument' do
42+
expect {
43+
client.snapshot.clone(snapshot: 'foo', body: {})
44+
}.to raise_exception(ArgumentError)
45+
end
46+
47+
it 'requires the :snapshot argument' do
48+
expect {
49+
client.snapshot.clone(repository: 'foo', body: {})
50+
}.to raise_exception(ArgumentError)
51+
end
52+
53+
it 'requires the :target_snapshot argument' do
54+
expect {
55+
client.snapshot.clone(repository: 'foo', body: {}, snapshot: 'bar')
56+
}.to raise_exception(ArgumentError)
57+
end
58+
59+
it 'performs the request' do
60+
expect(client_double.snapshot.clone(
61+
repository: 'foo',
62+
snapshot: 'bar',
63+
body: {},
64+
target_snapshot: 'snapshot'
65+
)).to eq({})
66+
end
67+
end

0 commit comments

Comments
 (0)