Skip to content

Commit 418240d

Browse files
committed
[API] Adds infer, start and stop trained model deployment to ML API (Experimental)
1 parent 86eca5d commit 418240d

File tree

6 files changed

+294
-0
lines changed

6 files changed

+294
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 MachineLearning
21+
module Actions
22+
# Evaluate a trained model.
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :model_id The ID of the model to perform inference on
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-infer-trained-model-deployment.html
32+
#
33+
def infer_trained_model_deployment(arguments = {})
34+
raise ArgumentError, "Required argument 'model_id' missing" unless arguments[:model_id]
35+
36+
headers = arguments.delete(:headers) || {}
37+
38+
arguments = arguments.clone
39+
40+
_model_id = arguments.delete(:model_id)
41+
42+
method = Elasticsearch::API::HTTP_POST
43+
path = "_ml/trained_models/#{Utils.__listify(_model_id)}/deployment/_infer"
44+
params = {}
45+
46+
body = nil
47+
perform_request(method, path, params, body, headers).body
48+
end
49+
end
50+
end
51+
end
52+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 MachineLearning
21+
module Actions
22+
# Start a trained model deployment.
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :model_id The ID of the model to deploy
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-start-trained-model-deployment.html
32+
#
33+
def start_trained_model_deployment(arguments = {})
34+
raise ArgumentError, "Required argument 'model_id' missing" unless arguments[:model_id]
35+
36+
headers = arguments.delete(:headers) || {}
37+
38+
arguments = arguments.clone
39+
40+
_model_id = arguments.delete(:model_id)
41+
42+
method = Elasticsearch::API::HTTP_POST
43+
path = "_ml/trained_models/#{Utils.__listify(_model_id)}/deployment/_start"
44+
params = {}
45+
46+
body = nil
47+
perform_request(method, path, params, body, headers).body
48+
end
49+
end
50+
end
51+
end
52+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 MachineLearning
21+
module Actions
22+
# Stop a trained model deployment.
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :model_id The ID of the model to undeploy
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-trained-model-deployment.html
32+
#
33+
def stop_trained_model_deployment(arguments = {})
34+
raise ArgumentError, "Required argument 'model_id' missing" unless arguments[:model_id]
35+
36+
headers = arguments.delete(:headers) || {}
37+
38+
arguments = arguments.clone
39+
40+
_model_id = arguments.delete(:model_id)
41+
42+
method = Elasticsearch::API::HTTP_POST
43+
path = "_ml/trained_models/#{Utils.__listify(_model_id)}/deployment/_stop"
44+
params = {}
45+
46+
body = nil
47+
perform_request(method, path, params, body, headers).body
48+
end
49+
end
50+
end
51+
end
52+
end
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::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
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::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::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)