Skip to content

Commit cfd8394

Browse files
committed
[API] Adds ml.[infer,start,stop]trained_model_deployment
1 parent 4df83ea commit cfd8394

File tree

6 files changed

+318
-0
lines changed

6 files changed

+318
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
# Evaluate a trained model.
24+
# This functionality is Experimental and may be changed or removed
25+
# completely in a future release. Elastic will take a best effort approach
26+
# to fix any issues, but experimental features are not subject to the
27+
# support SLA of official GA features.
28+
#
29+
# @option arguments [String] :model_id The ID of the model to perform inference on
30+
# @option arguments [Time] :timeout Controls the time to wait for the inference result
31+
# @option arguments [Hash] :headers Custom HTTP headers
32+
#
33+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/ml-df-analytics-apis.html
34+
#
35+
def infer_trained_model_deployment(arguments = {})
36+
raise ArgumentError, "Required argument 'model_id' missing" unless arguments[:model_id]
37+
38+
headers = arguments.delete(:headers) || {}
39+
40+
arguments = arguments.clone
41+
42+
_model_id = arguments.delete(:model_id)
43+
44+
method = Elasticsearch::API::HTTP_POST
45+
path = "_ml/trained_models/#{Elasticsearch::API::Utils.__listify(_model_id)}/deployment/_infer"
46+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments,
47+
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(:infer_trained_model_deployment, [
57+
:timeout
58+
].freeze)
59+
end
60+
end
61+
end
62+
end
63+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
# Start a trained model deployment.
24+
# This functionality is Experimental and may be changed or removed
25+
# completely in a future release. Elastic will take a best effort approach
26+
# to fix any issues, but experimental features are not subject to the
27+
# support SLA of official GA features.
28+
#
29+
# @option arguments [String] :model_id The ID of the model to deploy
30+
# @option arguments [Time] :timeout Controls the time to wait until the model is deployed
31+
# @option arguments [Hash] :headers Custom HTTP headers
32+
#
33+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/ml-df-analytics-apis.html
34+
#
35+
def start_trained_model_deployment(arguments = {})
36+
raise ArgumentError, "Required argument 'model_id' missing" unless arguments[:model_id]
37+
38+
headers = arguments.delete(:headers) || {}
39+
40+
arguments = arguments.clone
41+
42+
_model_id = arguments.delete(:model_id)
43+
44+
method = Elasticsearch::API::HTTP_POST
45+
path = "_ml/trained_models/#{Elasticsearch::API::Utils.__listify(_model_id)}/deployment/_start"
46+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments,
47+
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(:start_trained_model_deployment, [
57+
:timeout
58+
].freeze)
59+
end
60+
end
61+
end
62+
end
63+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
# Stop a trained model deployment.
24+
# This functionality is Experimental and may be changed or removed
25+
# completely in a future release. Elastic will take a best effort approach
26+
# to fix any issues, but experimental features are not subject to the
27+
# support SLA of official GA features.
28+
#
29+
# @option arguments [String] :model_id The ID of the model to undeploy
30+
# @option arguments [Hash] :headers Custom HTTP headers
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/ml-df-analytics-apis.html
33+
#
34+
def stop_trained_model_deployment(arguments = {})
35+
raise ArgumentError, "Required argument 'model_id' missing" unless arguments[:model_id]
36+
37+
headers = arguments.delete(:headers) || {}
38+
39+
arguments = arguments.clone
40+
41+
_model_id = arguments.delete(:model_id)
42+
43+
method = Elasticsearch::API::HTTP_POST
44+
path = "_ml/trained_models/#{Elasticsearch::API::Utils.__listify(_model_id)}/deployment/_stop"
45+
params = {}
46+
47+
body = nil
48+
perform_request(method, path, params, body, headers).body
49+
end
50+
end
51+
end
52+
end
53+
end
54+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.infer_trained_model_deployment' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
'_ml/trained_models/foo/deployment/_infer',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.ml.infer_trained_model_deployment(model_id: 'foo')).to eq({})
33+
end
34+
35+
let(:client) do
36+
Class.new { include Elasticsearch::XPack::API }.new
37+
end
38+
39+
context 'when a model_id is not provided' do
40+
it 'raises an exception' do
41+
expect {
42+
client.ml.infer_trained_model_deployment
43+
}.to raise_exception(ArgumentError)
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.start_trained_model_deployment' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
'_ml/trained_models/foo/deployment/_start',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.ml.start_trained_model_deployment(model_id: 'foo')).to eq({})
33+
end
34+
35+
let(:client) do
36+
Class.new { include Elasticsearch::XPack::API }.new
37+
end
38+
39+
context 'when a model_id is not provided' do
40+
it 'raises an exception' do
41+
expect {
42+
client.ml.start_trained_model_deployment
43+
}.to raise_exception(ArgumentError)
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.stop_trained_model_deployment' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
'_ml/trained_models/foo/deployment/_stop',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.ml.stop_trained_model_deployment(model_id: 'foo')).to eq({})
33+
end
34+
35+
let(:client) do
36+
Class.new { include Elasticsearch::XPack::API }.new
37+
end
38+
39+
context 'when a model_id is not provided' do
40+
it 'raises an exception' do
41+
expect {
42+
client.ml.stop_trained_model_deployment
43+
}.to raise_exception(ArgumentError)
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)