Skip to content

Commit

Permalink
[ML] add timeout parameter for DELETE trained_models API (elastic#79739)
Browse files Browse the repository at this point in the history
DELETE trained models should allow timeout parameter to override the current default of 30s

closes: elastic#77070
  • Loading branch information
benwtrent authored and Adam Locke committed Oct 28, 2021
1 parent 39d0d7b commit 422d061
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
}
}
]
},
"params":{
"timeout":{
"type":"time",
"required":false,
"description":"Controls the amount of time to wait for the model to be deleted.",
"default": "30s"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/
package org.elasticsearch.xpack.ml.rest.inference;

import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -18,6 +20,7 @@
import java.util.List;

import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction.Request.TIMEOUT;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;

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

0 comments on commit 422d061

Please sign in to comment.