Skip to content

Commit e15eafd

Browse files
committed
Address review comments
1 parent a3350b8 commit e15eafd

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/InferenceProcessor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.ingest.IngestDocument;
1212
import org.elasticsearch.ingest.Processor;
1313

14-
import java.util.HashMap;
1514
import java.util.Map;
1615
import java.util.concurrent.ConcurrentHashMap;
1716
import java.util.function.BiConsumer;
@@ -43,8 +42,7 @@ public void execute(IngestDocument ingestDocument, BiConsumer<IngestDocument, Ex
4342

4443
@Override
4544
public IngestDocument execute(IngestDocument ingestDocument) {
46-
assert false : "The async override of execute() must be used";
47-
return null;
45+
throw new UnsupportedOperationException("The async override execute(document, handler) must be used");
4846
}
4947

5048
@Override
@@ -54,11 +52,11 @@ public String getType() {
5452

5553
public static final class Factory implements Processor.Factory {
5654

57-
private Map<String, Model> loadedModels;
58-
private Map<String, ModelLoader> modelLoaders;
55+
private final Map<String, Model> loadedModels;
56+
private final Map<String, ModelLoader> modelLoaders;
5957

6058
public Factory(Map<String, ModelLoader> modelLoaders) {
61-
loadedModels = new ConcurrentHashMap<>();
59+
this.loadedModels = new ConcurrentHashMap<>();
6260
this.modelLoaders = modelLoaders;
6361
}
6462

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/Model.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface Model {
2020
* be called either with the updated (or new) document or an {@code Exception}.
2121
*
2222
* @param document Document to infer on
23-
* @param handler The handler must be called
23+
* @param handler The handler that must be called
2424
*/
2525
void infer(IngestDocument document, BiConsumer<IngestDocument, Exception> handler);
2626
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ModelLoader.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
public interface ModelLoader {
1212
/**
13-
* Load the model with the given {@code modelId} and {@code config}
13+
* Load the model with the given {@code modelId} and {@code config}.
14+
*
15+
* Model specific config should can read from {@code config} and should
16+
* be removed from the map e.g with the use of {@link org.elasticsearch.ingest.ConfigurationUtils}
17+
*
1418
*
1519
* @param modelId The Id of the model to load
1620
* @param processorTag The ingest processor tag
@@ -22,9 +26,12 @@ public interface ModelLoader {
2226

2327
/**
2428
* Inference processors must remove their configuration from the {@code config} map.
25-
* For the case when a model has already been loaded
29+
* In the case when a model has already been loaded and {@link #load(String, String, boolean, Map)}
30+
* will not be called this use this method to strip the model specific config from the map.
2631
*
27-
* This method should be used when {@link #load(String, String, boolean, Map)} isn't.
32+
* This method should only be used if {@link #load(String, String, boolean, Map)} isn't
33+
* called on the same {@code config} as {@link #load(String, String, boolean, Map)} will
34+
* also remove the processor's configuration from the map.
2835
*
2936
* @param processorTag The ingest processor tag
3037
* @param config The ingest pipeline config

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/sillymodel/SillyModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SillyModel implements Model {
2020

2121
private static final String TARGET_FIELD = "hotdog_or_not";
2222

23-
private Random random;
23+
private final Random random;
2424

2525
public SillyModel() {
2626
random = Randomness.get();

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/sillymodel/SillyModelLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void consumeConfiguration(String processorTag, Map<String, Object> config
5858
}
5959

6060

61-
public void load(String id, String index, ActionListener<Model> listener) {
61+
private void load(String id, String index, ActionListener<Model> listener) {
6262
client.prepareGet(index, null, id).execute(ActionListener.wrap(
6363
response -> {
6464
if (response.isExists()) {

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/InferenceProcessorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ public class InferenceProcessorTests extends ESTestCase {
2323

2424
public void testFactory() throws Exception {
2525
String processorTag = randomAlphaOfLength(10);
26+
String modelType = "test";
2627

2728
Model mockModel = mock(Model.class);
2829
ModelLoader mockLoader = mock(ModelLoader.class);
2930
when(mockLoader.load(eq("k2"), eq(processorTag), eq(false), any())).thenReturn(mockModel);
3031

31-
InferenceProcessor.Factory factory = new InferenceProcessor.Factory(Map.of("test", mockLoader));
32+
InferenceProcessor.Factory factory = new InferenceProcessor.Factory(Collections.singletonMap(modelType, mockLoader));
3233

3334
Map<String, Object> config = new HashMap<>();
3435
config.put("model_id", "k2");
35-
config.put("model_type", "test");
36+
config.put("model_type", modelType);
3637

3738
InferenceProcessor processor = factory.create(Collections.emptyMap(), processorTag, config);
3839
assertThat(processor.getTag(), equalTo(processorTag));

0 commit comments

Comments
 (0)