Skip to content

Commit 0a9d8d0

Browse files
committed
Create and assign model
1 parent 1b2dd4b commit 0a9d8d0

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.services.elasticsearch;
9+
10+
import org.elasticsearch.ResourceNotFoundException;
11+
import org.elasticsearch.action.ActionListener;
12+
import org.elasticsearch.inference.ChunkingSettings;
13+
import org.elasticsearch.inference.Model;
14+
import org.elasticsearch.inference.TaskType;
15+
import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction;
16+
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
17+
18+
public class ElasticDeployedModel extends ElasticsearchInternalModel {
19+
public ElasticDeployedModel(
20+
String inferenceEntityId,
21+
TaskType taskType,
22+
String service,
23+
ElserInternalServiceSettings serviceSettings,
24+
ElserMlNodeTaskSettings taskSettings,
25+
ChunkingSettings chunkingSettings
26+
) {
27+
super(inferenceEntityId, taskType, service, serviceSettings, taskSettings, chunkingSettings);
28+
}
29+
30+
@Override
31+
public ActionListener<CreateTrainedModelAssignmentAction.Response> getCreateTrainedModelAssignmentActionListener(Model model, ActionListener<Boolean> listener) {
32+
return new ActionListener<>() {
33+
@Override
34+
public void onResponse(CreateTrainedModelAssignmentAction.Response response) {
35+
listener.onResponse(Boolean.TRUE);
36+
}
37+
38+
@Override
39+
public void onFailure(Exception e) {
40+
if (ExceptionsHelper.unwrapCause(e) instanceof ResourceNotFoundException) {
41+
listener.onFailure(
42+
new ResourceNotFoundException(
43+
"Could not start the inference as the deploymend model [{0}] cannot be found."
44+
+ " Trained Models must be deployed before they can be started.",
45+
internalServiceSettings.modelId()
46+
)
47+
);
48+
return;
49+
}
50+
listener.onFailure(e);
51+
}
52+
};
53+
}
54+
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,16 @@ public void parseRequestConfig(
143143
String modelId = (String) serviceSettingsMap.get(ElasticsearchInternalServiceSettings.MODEL_ID);
144144
String deploymentId = (String) serviceSettingsMap.get(ElasticsearchInternalServiceSettings.DEPLOYMENT_ID);
145145
if (deploymentId != null) {
146-
validateAgainstDeployment(modelId, deploymentId, taskType, ) // TODO create model
146+
validateAgainstDeployment(modelId, deploymentId, taskType, modelListener.delegateFailureAndWrap((l, settings) -> {
147+
l.onResponse(new ElasticDeployedModel(
148+
inferenceEntityId,
149+
taskType,
150+
NAME,
151+
new ElserInternalServiceSettings(settings.build()),
152+
ElserMlNodeTaskSettings.DEFAULT,
153+
chunkingSettings
154+
));
155+
}));
147156
} else if (modelId == null) {
148157
if (OLD_ELSER_SERVICE_NAME.equals(serviceName)) {
149158
// TODO complete deprecation of null model ID

0 commit comments

Comments
 (0)