Skip to content

Commit f56f430

Browse files
Revert start model deployment being in TransportPutInferenceModelAction
1 parent 770b6ce commit f56f430

File tree

2 files changed

+78
-16
lines changed

2 files changed

+78
-16
lines changed

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,19 @@ private void parseAndStoreModel(
191191
ActionListener<Model> storeModelListener = listener.delegateFailureAndWrap(
192192
(delegate, verifiedModel) -> modelRegistry.storeModel(
193193
verifiedModel,
194-
ActionListener.wrap(
195-
r -> listener.onResponse(new PutInferenceModelAction.Response(verifiedModel.getConfigurations())),
196-
e -> {
197-
if (e.getCause() instanceof StrictDynamicMappingException
198-
&& e.getCause().getMessage().contains("chunking_settings")) {
199-
delegate.onFailure(
200-
new ElasticsearchStatusException(
201-
"One or more nodes in your cluster does not support chunking_settings. "
202-
+ "Please update all nodes in your cluster to the latest version to use chunking_settings.",
203-
RestStatus.BAD_REQUEST
204-
)
205-
);
206-
} else {
207-
delegate.onFailure(e);
208-
}
194+
ActionListener.wrap(r -> startInferenceEndpoint(service, timeout, verifiedModel, delegate), e -> {
195+
if (e.getCause() instanceof StrictDynamicMappingException && e.getCause().getMessage().contains("chunking_settings")) {
196+
delegate.onFailure(
197+
new ElasticsearchStatusException(
198+
"One or more nodes in your cluster does not support chunking_settings. "
199+
+ "Please update all nodes in your cluster to the latest version to use chunking_settings.",
200+
RestStatus.BAD_REQUEST
201+
)
202+
);
203+
} else {
204+
delegate.onFailure(e);
209205
}
210-
),
206+
}),
211207
timeout
212208
)
213209
);
@@ -224,6 +220,19 @@ private void parseAndStoreModel(
224220
service.parseRequestConfig(inferenceEntityId, taskType, config, parsedModelListener);
225221
}
226222

223+
private void startInferenceEndpoint(
224+
InferenceService service,
225+
TimeValue timeout,
226+
Model model,
227+
ActionListener<PutInferenceModelAction.Response> listener
228+
) {
229+
if (skipValidationAndStart) {
230+
listener.onResponse(new PutInferenceModelAction.Response(model.getConfigurations()));
231+
} else {
232+
service.start(model, timeout, listener.map(started -> new PutInferenceModelAction.Response(model.getConfigurations())));
233+
}
234+
}
235+
227236
private Map<String, Object> requestToMap(PutInferenceModelAction.Request request) throws IOException {
228237
try (
229238
XContentParser parser = XContentHelper.createParser(

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/validation/ElasticsearchInternalServiceModelValidatorTests.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,33 @@ public void testValidate_ElandTextEmbeddingModelValidationSucceedsAndDimensionsS
178178
);
179179
}
180180

181+
public void testValidate_ElandTextEmbeddingAndValidationReturnsInvalidResultsType() {
182+
var dimensions = randomIntBetween(1, 10);
183+
var mockInferenceServiceResults = mock(InferenceServiceResults.class);
184+
when(mockInferenceServiceResults.getWriteableName()).thenReturn(randomAlphaOfLength(10));
185+
CustomElandEmbeddingModel customElandEmbeddingModel = createCustomElandEmbeddingModel(true, dimensions);
186+
187+
doAnswer(ans -> {
188+
ActionListener<InferenceServiceResults> responseListener = ans.getArgument(3);
189+
responseListener.onResponse(mockInferenceServiceResults);
190+
return null;
191+
}).when(mockServiceIntegrationValidator).validate(eq(mockInferenceService), any(), eq(TIMEOUT), any());
192+
193+
underTest.validate(mockInferenceService, customElandEmbeddingModel, TIMEOUT, mockActionListener);
194+
195+
verify(mockServiceIntegrationValidator).validate(eq(mockInferenceService), any(), eq(TIMEOUT), any());
196+
verify(mockActionListener).delegateFailureAndWrap(any());
197+
verify(mockActionListener).onFailure(any(ElasticsearchStatusException.class));
198+
verify(mockInferenceServiceResults).getWriteableName();
199+
verifyNoMoreInteractions(
200+
mockServiceIntegrationValidator,
201+
mockInferenceService,
202+
mockCustomElandEmbeddingModel,
203+
mockActionListener,
204+
mockInferenceServiceResults
205+
);
206+
}
207+
181208
public void testValidate_ElandTextEmbeddingModelDimensionsNotSetByUser() {
182209
var dimensions = randomIntBetween(1, 10);
183210
var mockInferenceServiceResults = mock(TextEmbeddingResults.class);
@@ -211,6 +238,32 @@ public void testValidate_ElandTextEmbeddingModelDimensionsNotSetByUser() {
211238
);
212239
}
213240

241+
public void testValidate_ElandTextEmbeddingModelAndEmbeddingSizeRetrievalThrowsException() {
242+
var mockInferenceServiceResults = mock(TextEmbeddingResults.class);
243+
when(mockInferenceServiceResults.getFirstEmbeddingSize()).thenThrow(ElasticsearchStatusException.class);
244+
CustomElandEmbeddingModel customElandEmbeddingModel = createCustomElandEmbeddingModel(false, null);
245+
246+
doAnswer(ans -> {
247+
ActionListener<InferenceServiceResults> responseListener = ans.getArgument(3);
248+
responseListener.onResponse(mockInferenceServiceResults);
249+
return null;
250+
}).when(mockServiceIntegrationValidator).validate(eq(mockInferenceService), any(), eq(TIMEOUT), any());
251+
252+
underTest.validate(mockInferenceService, customElandEmbeddingModel, TIMEOUT, mockActionListener);
253+
254+
verify(mockServiceIntegrationValidator).validate(eq(mockInferenceService), any(), eq(TIMEOUT), any());
255+
verify(mockActionListener).delegateFailureAndWrap(any());
256+
verify(mockActionListener).onFailure(any(ElasticsearchStatusException.class));
257+
verify(mockInferenceServiceResults).getFirstEmbeddingSize();
258+
verifyNoMoreInteractions(
259+
mockServiceIntegrationValidator,
260+
mockInferenceService,
261+
mockCustomElandEmbeddingModel,
262+
mockActionListener,
263+
mockInferenceServiceResults
264+
);
265+
}
266+
214267
private CustomElandEmbeddingModel createCustomElandEmbeddingModel(boolean areDimensionsSetByUser, Integer dimensions) {
215268
var mockServiceSettings = mock(CustomElandInternalTextEmbeddingServiceSettings.class);
216269
when(mockServiceSettings.modelId()).thenReturn(randomAlphaOfLength(10));

0 commit comments

Comments
 (0)