-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] add new delete trained model aliases API #69195
Merged
benwtrent
merged 7 commits into
elastic:master
from
benwtrent:feature/ml-delete-trained-model-alias
Feb 18, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c2046a0
[ML] add new delete trained model aliases API
benwtrent 9ddcfb4
fixing test
benwtrent 464f620
revert bad code
benwtrent e03fed4
Merge branch 'master' into feature/ml-delete-trained-model-alias
elasticmachine 6d75073
Merge remote-tracking branch 'upstream/master' into feature/ml-delete…
benwtrent 4412969
Merge branch 'feature/ml-delete-trained-model-alias' of github.com:be…
benwtrent 3313a19
addressing PR comments
benwtrent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
docs/reference/ml/df-analytics/apis/delete-trained-models-aliases.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[role="xpack"] | ||
[testenv="platinum"] | ||
[[delete-trained-models-aliases]] | ||
= Delete Trained Model Aliases API | ||
[subs="attributes"] | ||
++++ | ||
<titleabbrev>Delete Trained Model Aliases</titleabbrev> | ||
++++ | ||
|
||
Deletes a trained model alias. | ||
|
||
beta::[] | ||
|
||
[[ml-delete-trained-models-aliases-request]] | ||
== {api-request-title} | ||
|
||
`DELETE _ml/trained_models/<model_id>/model_aliases/<model_alias>` | ||
|
||
|
||
[[ml-delete-trained-models-aliases-prereq]] | ||
== {api-prereq-title} | ||
|
||
If the {es} {security-features} are enabled, you must have the following | ||
built-in roles and privileges: | ||
|
||
* `machine_learning_admin` | ||
|
||
For more information, see <<built-in-roles>>, <<security-privileges>>, and | ||
{ml-docs-setup-privileges}. | ||
|
||
[[ml-delete-trained-models-aliases-desc]] | ||
== {api-description-title} | ||
|
||
This API deletes an existing model alias that refers to a trained model. | ||
|
||
If the model alias is missing or refers to a model other than the one identified by | ||
the `model_id`, this API will return an error. | ||
|
||
[[ml-delete-trained-models-aliases-path-params]] | ||
== {api-path-parms-title} | ||
|
||
`model_id`:: | ||
(Required, string) | ||
The trained model ID to which the model alias refers. | ||
|
||
`model_alias`:: | ||
(Required, string) | ||
The model alias to delete. | ||
|
||
[[ml-delete-trained-models-aliases-example]] | ||
== {api-examples-title} | ||
|
||
[[ml-delete-trained-models-aliases-example-delete]] | ||
=== Deleting a model alias | ||
|
||
The following example shows how to delete a model alias for a trained model ID. | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
DELETE _ml/trained_models/flight-delay-prediction-1574775339910/model_aliases/flight_delay_model | ||
-------------------------------------------------- | ||
// TEST[skip:setup kibana sample data] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...e/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteTrainedModelAliasAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig; | ||
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
|
||
public class DeleteTrainedModelAliasAction extends ActionType<AcknowledgedResponse> { | ||
|
||
public static final DeleteTrainedModelAliasAction INSTANCE = new DeleteTrainedModelAliasAction(); | ||
public static final String NAME = "cluster:admin/xpack/ml/inference/model_aliases/delete"; | ||
|
||
private DeleteTrainedModelAliasAction() { | ||
super(NAME, AcknowledgedResponse::readFrom); | ||
} | ||
|
||
public static class Request extends AcknowledgedRequest<Request> { | ||
|
||
public static final String MODEL_ALIAS = "model_alias"; | ||
|
||
private final String modelAlias; | ||
private final String modelId; | ||
|
||
public Request(String modelAlias, String modelId) { | ||
this.modelAlias = ExceptionsHelper.requireNonNull(modelAlias, MODEL_ALIAS); | ||
this.modelId = ExceptionsHelper.requireNonNull(modelId, TrainedModelConfig.MODEL_ID); | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
this.modelAlias = in.readString(); | ||
this.modelId = in.readString(); | ||
} | ||
|
||
public String getModelAlias() { | ||
return modelAlias; | ||
} | ||
|
||
public String getModelId() { | ||
return modelId; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(modelAlias); | ||
out.writeString(modelId); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Request request = (Request) o; | ||
return Objects.equals(modelAlias, request.modelAlias) | ||
&& Objects.equals(modelId, request.modelId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(modelAlias, modelId); | ||
} | ||
|
||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ava/org/elasticsearch/xpack/core/ml/action/DeleteTrainedModelAliasActionRequestTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
import org.elasticsearch.xpack.core.ml.action.DeleteTrainedModelAliasAction.Request; | ||
|
||
|
||
public class DeleteTrainedModelAliasActionRequestTests extends AbstractWireSerializingTestCase<Request> { | ||
|
||
@Override | ||
protected Request createTestInstance() { | ||
return new Request(randomAlphaOfLength(10), randomAlphaOfLength(10)); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<Request> instanceReader() { | ||
return Request::new; | ||
} | ||
|
||
public void testCtor() { | ||
expectThrows(Exception.class, () -> new Request(null, randomAlphaOfLength(10))); | ||
expectThrows(Exception.class, () -> new Request(randomAlphaOfLength(10), null)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is used also in the transport delete trained model alias class to gather all the referenced models to make sure a model alias is not used by a pipeline