|
| 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 |
0 commit comments