Skip to content

Commit da25a35

Browse files
authored
[ML] add timeout parameter for DELETE trained_models API (#79739)
DELETE trained models should allow timeout parameter to override the current default of 30s closes: #77070
1 parent 17727e5 commit da25a35

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/ml.delete_trained_model.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
}
2525
}
2626
]
27+
},
28+
"params":{
29+
"timeout":{
30+
"type":"time",
31+
"required":false,
32+
"description":"Controls the amount of time to wait for the model to be deleted.",
33+
"default": "30s"
34+
}
2735
}
2836
}
2937
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
*/
77
package org.elasticsearch.xpack.ml.rest.inference;
88

9+
import org.elasticsearch.action.support.master.AcknowledgedRequest;
910
import org.elasticsearch.client.node.NodeClient;
1011
import org.elasticsearch.core.RestApiVersion;
12+
import org.elasticsearch.core.TimeValue;
1113
import org.elasticsearch.rest.BaseRestHandler;
1214
import org.elasticsearch.rest.RestRequest;
1315
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -18,6 +20,7 @@
1820
import java.util.List;
1921

2022
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
23+
import static org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction.Request.TIMEOUT;
2124
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
2225

2326
public class RestDeleteTrainedModelAction extends BaseRestHandler {
@@ -39,6 +42,10 @@ public String getName() {
3942
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
4043
String modelId = restRequest.param(TrainedModelConfig.MODEL_ID.getPreferredName());
4144
DeleteTrainedModelAction.Request request = new DeleteTrainedModelAction.Request(modelId);
45+
if (restRequest.hasParam(TIMEOUT.getPreferredName())) {
46+
TimeValue timeout = restRequest.paramAsTime(TIMEOUT.getPreferredName(), AcknowledgedRequest.DEFAULT_ACK_TIMEOUT);
47+
request.timeout(timeout);
48+
}
4249
return channel -> client.execute(DeleteTrainedModelAction.INSTANCE, request, new RestToXContentListener<>(channel));
4350
}
4451
}

0 commit comments

Comments
 (0)