-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
In addition to creating and re-assigning model aliases, users should be able to delete existing and unused model aliases.
- Loading branch information
Showing
14 changed files
with
469 additions
and
3 deletions.
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.