|
@@ -28,7 +28,6 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.ingest.IngestMetadata;
|
|
|
import org.elasticsearch.ingest.PipelineConfiguration;
|
|
|
-import org.elasticsearch.license.XPackLicenseState;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
|
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.ClassificationConfig;
|
|
@@ -51,7 +50,6 @@ import static org.mockito.Mockito.when;
|
|
|
public class InferenceProcessorFactoryTests extends ESTestCase {
|
|
|
|
|
|
private Client client;
|
|
|
- private XPackLicenseState licenseState;
|
|
|
private ClusterService clusterService;
|
|
|
|
|
|
@Before
|
|
@@ -68,8 +66,6 @@ public class InferenceProcessorFactoryTests extends ESTestCase {
|
|
|
ClusterService.USER_DEFINED_METADATA,
|
|
|
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING)));
|
|
|
clusterService = new ClusterService(settings, clusterSettings, tp);
|
|
|
- licenseState = mock(XPackLicenseState.class);
|
|
|
- when(licenseState.checkFeature(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true);
|
|
|
}
|
|
|
|
|
|
public void testNumInferenceProcessors() throws Exception {
|
|
@@ -209,15 +205,10 @@ public class InferenceProcessorFactoryTests extends ESTestCase {
|
|
|
Collections.singletonMap(RegressionConfig.NAME.getPreferredName(), Collections.emptyMap()));
|
|
|
}};
|
|
|
|
|
|
- try {
|
|
|
- processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, regression);
|
|
|
- fail("Should not have successfully created");
|
|
|
- } catch (ElasticsearchException ex) {
|
|
|
- assertThat(ex.getMessage(),
|
|
|
- equalTo("Configuration [regression] requires minimum node version [7.6.0] (current minimum node version [7.5.0]"));
|
|
|
- } catch (Exception ex) {
|
|
|
- fail(ex.getMessage());
|
|
|
- }
|
|
|
+ ElasticsearchException ex = expectThrows(ElasticsearchException.class,
|
|
|
+ () -> processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, regression));
|
|
|
+ assertThat(ex.getMessage(),
|
|
|
+ equalTo("Configuration [regression] requires minimum node version [7.6.0] (current minimum node version [7.5.0]"));
|
|
|
|
|
|
Map<String, Object> classification = new HashMap<>() {{
|
|
|
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
|
|
@@ -227,15 +218,26 @@ public class InferenceProcessorFactoryTests extends ESTestCase {
|
|
|
Collections.singletonMap(ClassificationConfig.NUM_TOP_CLASSES.getPreferredName(), 1)));
|
|
|
}};
|
|
|
|
|
|
- try {
|
|
|
- processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, classification);
|
|
|
- fail("Should not have successfully created");
|
|
|
- } catch (ElasticsearchException ex) {
|
|
|
- assertThat(ex.getMessage(),
|
|
|
- equalTo("Configuration [classification] requires minimum node version [7.6.0] (current minimum node version [7.5.0]"));
|
|
|
- } catch (Exception ex) {
|
|
|
- fail(ex.getMessage());
|
|
|
- }
|
|
|
+ ex = expectThrows(ElasticsearchException.class,
|
|
|
+ () -> processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, classification));
|
|
|
+ assertThat(ex.getMessage(),
|
|
|
+ equalTo("Configuration [classification] requires minimum node version [7.6.0] (current minimum node version [7.5.0]"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testCreateProcessorWithEmptyConfigNotSupportedOnOldNode() throws IOException {
|
|
|
+ InferenceProcessor.Factory processorFactory = new InferenceProcessor.Factory(client,
|
|
|
+ clusterService,
|
|
|
+ Settings.EMPTY);
|
|
|
+ processorFactory.accept(builderClusterStateWithModelReferences(Version.V_7_5_0, "model1"));
|
|
|
+
|
|
|
+ Map<String, Object> minimalConfig = new HashMap<>() {{
|
|
|
+ put(InferenceProcessor.MODEL_ID, "my_model");
|
|
|
+ put(InferenceProcessor.TARGET_FIELD, "result");
|
|
|
+ }};
|
|
|
+
|
|
|
+ ElasticsearchException ex = expectThrows(ElasticsearchException.class,
|
|
|
+ () -> processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, minimalConfig));
|
|
|
+ assertThat(ex.getMessage(), equalTo("[inference_config] required property is missing"));
|
|
|
}
|
|
|
|
|
|
public void testCreateProcessor() {
|
|
@@ -251,11 +253,8 @@ public class InferenceProcessorFactoryTests extends ESTestCase {
|
|
|
Collections.singletonMap(RegressionConfig.NAME.getPreferredName(), Collections.emptyMap()));
|
|
|
}};
|
|
|
|
|
|
- try {
|
|
|
- processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, regression);
|
|
|
- } catch (Exception ex) {
|
|
|
- fail(ex.getMessage());
|
|
|
- }
|
|
|
+ processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, regression);
|
|
|
+
|
|
|
|
|
|
Map<String, Object> classification = new HashMap<>() {{
|
|
|
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
|
|
@@ -265,11 +264,33 @@ public class InferenceProcessorFactoryTests extends ESTestCase {
|
|
|
Collections.singletonMap(ClassificationConfig.NUM_TOP_CLASSES.getPreferredName(), 1)));
|
|
|
}};
|
|
|
|
|
|
- try {
|
|
|
- processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, classification);
|
|
|
- } catch (Exception ex) {
|
|
|
- fail(ex.getMessage());
|
|
|
- }
|
|
|
+ processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, classification);
|
|
|
+
|
|
|
+ Map<String, Object> mininmal = new HashMap<>() {{
|
|
|
+ put(InferenceProcessor.MODEL_ID, "my_model");
|
|
|
+ put(InferenceProcessor.TARGET_FIELD, "result");
|
|
|
+ }};
|
|
|
+
|
|
|
+ processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, mininmal);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testCreateProcessorWithDuplicateFields() {
|
|
|
+ InferenceProcessor.Factory processorFactory = new InferenceProcessor.Factory(client,
|
|
|
+ clusterService,
|
|
|
+ Settings.EMPTY);
|
|
|
+
|
|
|
+ Map<String, Object> regression = new HashMap<>() {{
|
|
|
+ put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
|
|
|
+ put(InferenceProcessor.MODEL_ID, "my_model");
|
|
|
+ put(InferenceProcessor.TARGET_FIELD, "ml");
|
|
|
+ put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap(RegressionConfig.NAME.getPreferredName(),
|
|
|
+ Collections.singletonMap(RegressionConfig.RESULTS_FIELD.getPreferredName(), "warning")));
|
|
|
+ }};
|
|
|
+
|
|
|
+ Exception ex = expectThrows(Exception.class, () ->
|
|
|
+ processorFactory.create(Collections.emptyMap(), "my_inference_processor", null, regression));
|
|
|
+ assertThat(ex.getMessage(), equalTo("Invalid inference config. " +
|
|
|
+ "More than one field is configured as [warning]"));
|
|
|
}
|
|
|
|
|
|
private static ClusterState buildClusterState(Metadata metadata) {
|