Skip to content

Commit f786483

Browse files
committed
[XPACK] Adds ml.get_model_snapshot_upgrade_stats
1 parent 6586ee0 commit f786483

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
# Gets stats for anomaly detection job model snapshot upgrades that are in progress.
24+
#
25+
# @option arguments [String] :job_id The ID of the job. May be a wildcard, comma separated list or `_all`.
26+
# @option arguments [String] :snapshot_id The ID of the snapshot. May be a wildcard, comma separated list or `_all`.
27+
# @option arguments [Boolean] :allow_no_match Whether to ignore if a wildcard expression matches no jobs or no snapshots. (This includes the `_all` string.)
28+
# @option arguments [Hash] :headers Custom HTTP headers
29+
#
30+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.16/ml-get-job-model-snapshot-upgrade-stats.html
31+
#
32+
def get_model_snapshot_upgrade_stats(arguments = {})
33+
raise ArgumentError, "Required argument 'job_id' missing" unless arguments[:job_id]
34+
raise ArgumentError, "Required argument 'snapshot_id' missing" unless arguments[:snapshot_id]
35+
36+
headers = arguments.delete(:headers) || {}
37+
38+
arguments = arguments.clone
39+
40+
_job_id = arguments.delete(:job_id)
41+
42+
_snapshot_id = arguments.delete(:snapshot_id)
43+
44+
method = Elasticsearch::API::HTTP_GET
45+
path = "_ml/anomaly_detectors/#{Elasticsearch::API::Utils.__listify(_job_id)}/model_snapshots/#{Elasticsearch::API::Utils.__listify(_snapshot_id)}/_upgrade/_stats"
46+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
47+
48+
body = nil
49+
perform_request(method, path, params, body, headers).body
50+
end
51+
52+
# Register this action with its valid params when the module is loaded.
53+
#
54+
# @since 6.2.0
55+
ParamsRegistry.register(:get_model_snapshot_upgrade_stats, [
56+
:allow_no_match
57+
].freeze)
58+
end
59+
end
60+
end
61+
end
62+
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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#ml.get_model_snapshot_upgrade_stats' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'_ml/anomaly_detectors/foo/model_snapshots/bar/_upgrade/_stats',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(
33+
client_double.machine_learning.get_model_snapshot_upgrade_stats(job_id: 'foo', snapshot_id: 'bar')
34+
).to eq({})
35+
end
36+
37+
let(:client) do
38+
Class.new { include Elasticsearch::XPack::API }.new
39+
end
40+
41+
context 'when a job_id is not provided' do
42+
it 'raises an exception' do
43+
expect {
44+
client.machine_learning.get_model_snapshot_upgrade_stats(snapshot_id: 'foo')
45+
}.to raise_exception(ArgumentError)
46+
end
47+
end
48+
49+
context 'when a snapshot_id is not provided' do
50+
it 'raises an exception' do
51+
expect {
52+
client.machine_learning.get_model_snapshot_upgrade_stats(job_id: 'foo')
53+
}.to raise_exception(ArgumentError)
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)