Skip to content

Commit 48cdc6e

Browse files
committed
[XPACK] Adds ml.upgrade_job_snapshot
1 parent 6616885 commit 48cdc6e

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 XPack
20+
module API
21+
module MachineLearning
22+
module Actions
23+
# Upgrades a given job snapshot to the current major version.
24+
#
25+
# @option arguments [String] :job_id The ID of the job
26+
# @option arguments [String] :snapshot_id The ID of the snapshot
27+
# @option arguments [Time] :timeout How long should the API wait for the job to be opened and the old snapshot to be loaded.
28+
# @option arguments [Boolean] :wait_for_completion Should the request wait until the task is complete before responding to the caller. Default is false.
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/ml-upgrade-job-model-snapshot.html
32+
#
33+
def upgrade_job_snapshot(arguments = {})
34+
raise ArgumentError, "Required argument 'job_id' missing" unless arguments[:job_id]
35+
raise ArgumentError, "Required argument 'snapshot_id' missing" unless arguments[:snapshot_id]
36+
37+
headers = arguments.delete(:headers) || {}
38+
39+
arguments = arguments.clone
40+
41+
_job_id = arguments.delete(:job_id)
42+
43+
_snapshot_id = arguments.delete(:snapshot_id)
44+
45+
method = Elasticsearch::API::HTTP_POST
46+
path = "_ml/anomaly_detectors/#{Elasticsearch::API::Utils.__listify(_job_id)}/model_snapshots/#{Elasticsearch::API::Utils.__listify(_snapshot_id)}/_upgrade"
47+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
48+
49+
body = nil
50+
perform_request(method, path, params, body, headers).body
51+
end
52+
53+
# Register this action with its valid params when the module is loaded.
54+
#
55+
# @since 6.2.0
56+
ParamsRegistry.register(:upgrade_job_snapshot, [
57+
:timeout,
58+
:wait_for_completion
59+
].freeze)
60+
end
61+
end
62+
end
63+
end
64+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackMlUpdateJobSnapshotTest < Minitest::Test
23+
24+
context "XPack MachineLearning: Upgrade job snapshot" do
25+
subject { FakeClient.new }
26+
27+
should "perform correct request" do
28+
subject.expects(:perform_request).with do |method, url, params, body|
29+
assert_equal 'POST', method
30+
assert_equal "_ml/anomaly_detectors/foo/model_snapshots/bar/_upgrade", url
31+
assert_equal Hash.new, params
32+
assert_equal nil, body
33+
true
34+
end.returns(FakeResponse.new)
35+
36+
subject.xpack.ml.upgrade_job_snapshot(job_id: 'foo', snapshot_id: 'bar')
37+
end
38+
39+
end
40+
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)