-
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
Changes from 4 commits
c2046a0
9ddcfb4
464f620
e03fed4
6d75073
4412969
3313a19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[role="xpack"] | ||
[testenv="platinum"] | ||
[[delete-trained-models-aliases]] | ||
= Delete Trained Models Aliases API | ||
[subs="attributes"] | ||
++++ | ||
<titleabbrev>Delete Trained Models Aliases</titleabbrev> | ||
++++ | ||
|
||
Deletes a trained models 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 trained models. | ||
|
||
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] |
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); | ||
} | ||
|
||
} | ||
} |
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)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ protected void masterOperation(Task task, | |
ActionListener<AcknowledgedResponse> listener) { | ||
String id = request.getId(); | ||
IngestMetadata currentIngestMetadata = state.metadata().custom(IngestMetadata.TYPE); | ||
Set<String> referencedModels = getReferencedModelKeys(currentIngestMetadata); | ||
Set<String> referencedModels = getReferencedModelKeys(currentIngestMetadata, ingestService); | ||
|
||
if (referencedModels.contains(id)) { | ||
listener.onFailure(new ElasticsearchStatusException("Cannot delete model [{}] as it is still referenced by ingest processors", | ||
|
@@ -142,7 +142,7 @@ public ClusterState execute(final ClusterState currentState) { | |
}); | ||
} | ||
|
||
private Set<String> getReferencedModelKeys(IngestMetadata ingestMetadata) { | ||
static Set<String> getReferencedModelKeys(IngestMetadata ingestMetadata, IngestService ingestService) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 |
||
Set<String> allReferencedModelKeys = new HashSet<>(); | ||
if (ingestMetadata == null) { | ||
return allReferencedModelKeys; | ||
|
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.
Is it "model's" possessive or singular "Deletes a trained model alias"
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.
definitely