|
21 | 21 | import org.elasticsearch.cluster.block.ClusterBlockLevel; |
22 | 22 | import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; |
23 | 23 | import org.elasticsearch.cluster.service.ClusterService; |
| 24 | +import org.elasticsearch.common.Strings; |
24 | 25 | import org.elasticsearch.common.util.concurrent.EsExecutors; |
25 | 26 | import org.elasticsearch.common.xcontent.XContentHelper; |
26 | 27 | import org.elasticsearch.inference.InferenceService; |
|
50 | 51 | import org.elasticsearch.xpack.core.ml.job.messages.Messages; |
51 | 52 | import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; |
52 | 53 | import org.elasticsearch.xpack.inference.registry.ModelRegistry; |
| 54 | +import org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalModel; |
53 | 55 | import org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalService; |
54 | 56 | import org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalServiceSettings; |
55 | 57 |
|
@@ -255,7 +257,7 @@ private void updateInClusterEndpoint( |
255 | 257 | ActionListener<Boolean> listener |
256 | 258 | ) throws IOException { |
257 | 259 | // 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); |
259 | 261 | throwIfTrainedModelDoesntExist(request.getInferenceEntityId(), deploymentId); |
260 | 262 |
|
261 | 263 | Map<String, Object> serviceSettings = request.getContentAsSettings().serviceSettings(); |
@@ -293,15 +295,18 @@ private boolean isInClusterService(String name) { |
293 | 295 | return List.of(ElasticsearchInternalService.NAME, ElasticsearchInternalService.OLD_ELSER_SERVICE_NAME).contains(name); |
294 | 296 | } |
295 | 297 |
|
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 | + ); |
303 | 309 | } |
304 | | - return inferenceEntityId; |
305 | 310 | } |
306 | 311 |
|
307 | 312 | private void throwIfTrainedModelDoesntExist(String inferenceEntityId, String deploymentId) throws ElasticsearchStatusException { |
|
0 commit comments