Skip to content

Commit eb2af92

Browse files
Reuse existing deployment ID retrieval logic
1 parent d30f07f commit eb2af92

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportUpdateInferenceModelAction.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.cluster.block.ClusterBlockLevel;
2222
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
2323
import org.elasticsearch.cluster.service.ClusterService;
24+
import org.elasticsearch.common.Strings;
2425
import org.elasticsearch.common.util.concurrent.EsExecutors;
2526
import org.elasticsearch.common.xcontent.XContentHelper;
2627
import org.elasticsearch.inference.InferenceService;
@@ -50,6 +51,7 @@
5051
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
5152
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
5253
import org.elasticsearch.xpack.inference.registry.ModelRegistry;
54+
import org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalModel;
5355
import org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalService;
5456
import org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalServiceSettings;
5557

@@ -255,7 +257,7 @@ private void updateInClusterEndpoint(
255257
ActionListener<Boolean> listener
256258
) throws IOException {
257259
// The model we are trying to update must have a trained model associated with it if it is an in-cluster deployment
258-
var deploymentId = getDeploymentIdForInClusterEndpoint(request.getInferenceEntityId(), existingParsedModel);
260+
var deploymentId = getDeploymentIdForInClusterEndpoint(existingParsedModel);
259261
throwIfTrainedModelDoesntExist(request.getInferenceEntityId(), deploymentId);
260262

261263
Map<String, Object> serviceSettings = request.getContentAsSettings().serviceSettings();
@@ -293,15 +295,18 @@ private boolean isInClusterService(String name) {
293295
return List.of(ElasticsearchInternalService.NAME, ElasticsearchInternalService.OLD_ELSER_SERVICE_NAME).contains(name);
294296
}
295297

296-
private String getDeploymentIdForInClusterEndpoint(String inferenceEntityId, Model model) {
297-
var serviceSettings = model.getConfigurations().getServiceSettings();
298-
if (serviceSettings instanceof ElasticsearchInternalServiceSettings) {
299-
var deploymentId = ((ElasticsearchInternalServiceSettings) serviceSettings).getDeploymentId();
300-
if (deploymentId != null) {
301-
return deploymentId;
302-
}
298+
private String getDeploymentIdForInClusterEndpoint(Model model) {
299+
if (model instanceof ElasticsearchInternalModel esModel) {
300+
return esModel.mlNodeDeploymentId();
301+
} else {
302+
throw new IllegalStateException(
303+
Strings.format(
304+
"Cannot update inference endpoint [%s]. Class [%s] is not an Elasticsearch internal model",
305+
model.getInferenceEntityId(),
306+
model.getClass().getSimpleName()
307+
)
308+
);
303309
}
304-
return inferenceEntityId;
305310
}
306311

307312
private void throwIfTrainedModelDoesntExist(String inferenceEntityId, String deploymentId) throws ElasticsearchStatusException {

0 commit comments

Comments
 (0)