From 1d5ab06f6e2238f61389a5f48c288e268e9e7b9a Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Wed, 29 May 2024 14:34:47 -0400 Subject: [PATCH] Moving shared pieces to core --- .../ml/utils/InferenceProcessorConstants.java | 20 +++ .../InferenceProcessorInfoExtractor.java | 39 ++++- .../InferenceProcessorInfoExtractorTests.java | 11 +- ...ransportDeleteInferenceEndpointAction.java | 2 +- .../InferenceProcessorInfoExtractor.java | 158 ----------------- .../InferenceProcessorInfoExtractorTests.java | 161 ------------------ .../ml/integration/TestFeatureResetIT.java | 2 +- .../xpack/ml/MachineLearning.java | 2 +- .../TransportDeleteTrainedModelAction.java | 2 +- ...ransportDeleteTrainedModelAliasAction.java | 2 +- .../TransportGetTrainedModelsStatsAction.java | 2 +- ...sportStopTrainedModelDeploymentAction.java | 2 +- .../inference/ingest/InferenceProcessor.java | 12 +- 13 files changed, 73 insertions(+), 342 deletions(-) create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorConstants.java rename x-pack/plugin/{ml/src/main/java/org/elasticsearch/xpack => core/src/main/java/org/elasticsearch/xpack/core}/ml/utils/InferenceProcessorInfoExtractor.java (82%) rename x-pack/plugin/{ml/src/test/java/org/elasticsearch/xpack => core/src/test/java/org/elasticsearch/xpack/core}/ml/utils/InferenceProcessorInfoExtractorTests.java (96%) delete mode 100644 x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractor.java delete mode 100644 x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractorTests.java diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorConstants.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorConstants.java new file mode 100644 index 0000000000000..7222f20784bb7 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorConstants.java @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.core.ml.utils; + +/** + * Provides access to constants for core, ml, and inference plugins + */ +public class InferenceProcessorConstants { + public static final String TYPE = "inference"; + public static final String TARGET_FIELD = "target_field"; + public static final String FIELD_MAP = "field_map"; + public static final String INFERENCE_CONFIG = "inference_config"; + + private InferenceProcessorConstants() {} +} diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/utils/InferenceProcessorInfoExtractor.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorInfoExtractor.java similarity index 82% rename from x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/utils/InferenceProcessorInfoExtractor.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorInfoExtractor.java index fe16cc4c59bed..1be495a8a82f5 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/utils/InferenceProcessorInfoExtractor.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorInfoExtractor.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.ml.utils; +package org.elasticsearch.xpack.core.ml.utils; import org.apache.lucene.util.Counter; import org.elasticsearch.cluster.ClusterState; @@ -16,6 +16,7 @@ import org.elasticsearch.transport.Transports; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -24,13 +25,11 @@ import static org.elasticsearch.inference.InferenceResults.MODEL_ID_RESULTS_FIELD; import static org.elasticsearch.ingest.Pipeline.PROCESSORS_KEY; -import static org.elasticsearch.xpack.ml.inference.ingest.InferenceProcessor.TYPE; /** * Utilities for extracting information around inference processors from IngestMetadata */ public final class InferenceProcessorInfoExtractor { - private static final String FOREACH_PROCESSOR_NAME = "foreach"; // Any more than 10 nestings of processors, we stop searching for inference processor definitions private static final int MAX_INFERENCE_PROCESSOR_SEARCH_RECURSIONS = 10; @@ -131,6 +130,38 @@ public static Map> pipelineIdsByResource(ClusterState state, return pipelineIdsByModelIds; } + /** + * @param state Current {@link ClusterState} + * @return a map from Model or Deployment IDs or Aliases to each pipeline referencing them. + */ + @SuppressWarnings("unchecked") + public static Set pipelineIdsForResource(ClusterState state, Set ids) { + assert Transports.assertNotTransportThread("non-trivial nested loops over cluster state structures"); + Set pipelineIds = new HashSet<>(); + Metadata metadata = state.metadata(); + if (metadata == null) { + return pipelineIds; + } + IngestMetadata ingestMetadata = metadata.custom(IngestMetadata.TYPE); + if (ingestMetadata == null) { + return pipelineIds; + } + ingestMetadata.getPipelines().forEach((pipelineId, configuration) -> { + Map configMap = configuration.getConfigAsMap(); + List> processorConfigs = ConfigurationUtils.readList(null, null, configMap, PROCESSORS_KEY); + for (Map processorConfigWithKey : processorConfigs) { + for (Map.Entry entry : processorConfigWithKey.entrySet()) { + addModelsAndPipelines(entry.getKey(), pipelineId, (Map) entry.getValue(), pam -> { + if (ids.contains(pam.modelIdOrAlias)) { + pipelineIds.add(pipelineId); + } + }, 0); + } + } + }); + return pipelineIds; + } + @SuppressWarnings("unchecked") private static void addModelsAndPipelines( String processorType, @@ -146,7 +177,7 @@ private static void addModelsAndPipelines( if (processorType == null || processorDefinition == null) { return; } - if (TYPE.equals(processorType)) { + if (InferenceProcessorConstants.TYPE.equals(processorType)) { String modelId = (String) processorDefinition.get(MODEL_ID_RESULTS_FIELD); if (modelId != null) { handler.accept(new PipelineAndModel(pipelineId, modelId)); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/utils/InferenceProcessorInfoExtractorTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorInfoExtractorTests.java similarity index 96% rename from x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/utils/InferenceProcessorInfoExtractorTests.java rename to x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorInfoExtractorTests.java index 488c974cc27bb..a5d823fc2144f 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/utils/InferenceProcessorInfoExtractorTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/InferenceProcessorInfoExtractorTests.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.ml.utils; +package org.elasticsearch.xpack.core.ml.utils; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -23,7 +23,6 @@ import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xpack.core.ml.inference.trainedmodel.RegressionConfig; -import org.elasticsearch.xpack.ml.inference.ingest.InferenceProcessor; import java.io.IOException; import java.net.InetAddress; @@ -217,15 +216,15 @@ private static Map forEachProcessorWithInference(String modelId) } private static Map inferenceProcessorForModel(String modelId) { - return Collections.singletonMap(InferenceProcessor.TYPE, new HashMap<>() { + return Collections.singletonMap(InferenceProcessorConstants.TYPE, new HashMap<>() { { put(InferenceResults.MODEL_ID_RESULTS_FIELD, modelId); put( - InferenceProcessor.INFERENCE_CONFIG, + InferenceProcessorConstants.INFERENCE_CONFIG, Collections.singletonMap(RegressionConfig.NAME.getPreferredName(), Collections.emptyMap()) ); - put(InferenceProcessor.TARGET_FIELD, "new_field"); - put(InferenceProcessor.FIELD_MAP, Collections.singletonMap("source", "dest")); + put(InferenceProcessorConstants.TARGET_FIELD, "new_field"); + put(InferenceProcessorConstants.FIELD_MAP, Collections.singletonMap("source", "dest")); } }); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportDeleteInferenceEndpointAction.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportDeleteInferenceEndpointAction.java index 957b6ace128f6..7d47578c42474 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportDeleteInferenceEndpointAction.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportDeleteInferenceEndpointAction.java @@ -30,9 +30,9 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.inference.action.DeleteInferenceEndpointAction; +import org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor; import org.elasticsearch.xpack.inference.common.InferenceExceptions; import org.elasticsearch.xpack.inference.registry.ModelRegistry; -import org.elasticsearch.xpack.inference.utils.InferenceProcessorInfoExtractor; import java.util.Set; diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractor.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractor.java deleted file mode 100644 index bf504f4f4432b..0000000000000 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractor.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.xpack.inference.utils; - -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.ingest.ConfigurationUtils; -import org.elasticsearch.ingest.IngestMetadata; -import org.elasticsearch.ingest.Pipeline; -import org.elasticsearch.transport.Transports; - -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; - -import static org.elasticsearch.inference.InferenceResults.MODEL_ID_RESULTS_FIELD; -import static org.elasticsearch.ingest.Pipeline.PROCESSORS_KEY; - -/** - * Utilities for extracting information around inference processors from IngestMetadata - *

- * this class was duplicated from org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor - */ - -public final class InferenceProcessorInfoExtractor { - - public static final String TYPE = "inference"; - private static final String FOREACH_PROCESSOR_NAME = "foreach"; - // Any more than 10 nestings of processors, we stop searching for inference processor definitions - private static final int MAX_INFERENCE_PROCESSOR_SEARCH_RECURSIONS = 10; - - private InferenceProcessorInfoExtractor() {} - - /** - * @param ingestMetadata The ingestMetadata of current {@link ClusterState} - * @return The set of model IDs referenced by inference processors - */ - @SuppressWarnings("unchecked") - public static Set getModelIdsFromInferenceProcessors(IngestMetadata ingestMetadata) { - if (ingestMetadata == null) { - return Set.of(); - } - - Set modelIds = new LinkedHashSet<>(); - ingestMetadata.getPipelines().forEach((pipelineId, configuration) -> { - Map configMap = configuration.getConfigAsMap(); - List> processorConfigs = ConfigurationUtils.readList(null, null, configMap, PROCESSORS_KEY); - for (Map processorConfigWithKey : processorConfigs) { - for (Map.Entry entry : processorConfigWithKey.entrySet()) { - addModelsAndPipelines( - entry.getKey(), - pipelineId, - (Map) entry.getValue(), - pam -> modelIds.add(pam.modelIdOrAlias()), - 0 - ); - } - } - }); - return modelIds; - } - - /** - * @param state Current {@link ClusterState} - * @return a map from Model or Deployment IDs or Aliases to each pipeline referencing them. - */ - @SuppressWarnings("unchecked") - public static Set pipelineIdsForResource(ClusterState state, Set ids) { - assert Transports.assertNotTransportThread("non-trivial nested loops over cluster state structures"); - Set pipelineIds = new HashSet<>(); - Metadata metadata = state.metadata(); - if (metadata == null) { - return pipelineIds; - } - IngestMetadata ingestMetadata = metadata.custom(IngestMetadata.TYPE); - if (ingestMetadata == null) { - return pipelineIds; - } - ingestMetadata.getPipelines().forEach((pipelineId, configuration) -> { - Map configMap = configuration.getConfigAsMap(); - List> processorConfigs = ConfigurationUtils.readList(null, null, configMap, PROCESSORS_KEY); - for (Map processorConfigWithKey : processorConfigs) { - for (Map.Entry entry : processorConfigWithKey.entrySet()) { - addModelsAndPipelines(entry.getKey(), pipelineId, (Map) entry.getValue(), pam -> { - if (ids.contains(pam.modelIdOrAlias)) { - pipelineIds.add(pipelineId); - } - }, 0); - } - } - }); - return pipelineIds; - } - - @SuppressWarnings("unchecked") - private static void addModelsAndPipelines( - String processorType, - String pipelineId, - Map processorDefinition, - Consumer handler, - int level - ) { - // arbitrary, but we must limit this somehow - if (level > MAX_INFERENCE_PROCESSOR_SEARCH_RECURSIONS) { - return; - } - if (processorType == null || processorDefinition == null) { - return; - } - if (TYPE.equals(processorType)) { - String modelId = (String) processorDefinition.get(MODEL_ID_RESULTS_FIELD); - if (modelId != null) { - handler.accept(new PipelineAndModel(pipelineId, modelId)); - } - return; - } - if (FOREACH_PROCESSOR_NAME.equals(processorType)) { - Map innerProcessor = (Map) processorDefinition.get("processor"); - if (innerProcessor != null) { - // a foreach processor should only have a SINGLE nested processor. Iteration is for simplicity's sake. - for (Map.Entry innerProcessorWithName : innerProcessor.entrySet()) { - addModelsAndPipelines( - innerProcessorWithName.getKey(), - pipelineId, - (Map) innerProcessorWithName.getValue(), - handler, - level + 1 - ); - } - } - return; - } - if (processorDefinition.containsKey(Pipeline.ON_FAILURE_KEY)) { - List> onFailureConfigs = ConfigurationUtils.readList( - null, - null, - processorDefinition, - Pipeline.ON_FAILURE_KEY - ); - onFailureConfigs.stream() - .flatMap(map -> map.entrySet().stream()) - .forEach( - entry -> addModelsAndPipelines(entry.getKey(), pipelineId, (Map) entry.getValue(), handler, level + 1) - ); - } - } - - private record PipelineAndModel(String pipelineId, String modelIdOrAlias) {} - -} diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractorTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractorTests.java deleted file mode 100644 index 20d305b8ad8ad..0000000000000 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/utils/InferenceProcessorInfoExtractorTests.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.xpack.inference.utils; - -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.node.DiscoveryNodeUtils; -import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.common.util.Maps; -import org.elasticsearch.inference.InferenceResults; -import org.elasticsearch.ingest.IngestMetadata; -import org.elasticsearch.ingest.PipelineConfiguration; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentFactory; -import org.elasticsearch.xcontent.XContentType; -import org.elasticsearch.xpack.core.ml.inference.trainedmodel.RegressionConfig; - -import java.io.IOException; -import java.net.InetAddress; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static org.hamcrest.Matchers.equalTo; - -public class InferenceProcessorInfoExtractorTests extends ESTestCase { - /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - - public void testGetModelIdsFromInferenceProcessors() throws IOException { - String modelId1 = "trained_model_1"; - String modelId2 = "trained_model_2"; - String modelId3 = "trained_model_3"; - Set expectedModelIds = new HashSet<>(Arrays.asList(modelId1, modelId2, modelId3)); - - ClusterState clusterState = buildClusterStateWithModelReferences(2, modelId1, modelId2, modelId3); - IngestMetadata ingestMetadata = clusterState.metadata().custom(IngestMetadata.TYPE); - Set actualModelIds = InferenceProcessorInfoExtractor.getModelIdsFromInferenceProcessors(ingestMetadata); - - assertThat(actualModelIds, equalTo(expectedModelIds)); - } - - public void testGetModelIdsFromInferenceProcessorsWhenNull() throws IOException { - - Set expectedModelIds = new HashSet<>(Arrays.asList()); - - ClusterState clusterState = buildClusterStateWithModelReferences(0); - IngestMetadata ingestMetadata = clusterState.metadata().custom(IngestMetadata.TYPE); - Set actualModelIds = InferenceProcessorInfoExtractor.getModelIdsFromInferenceProcessors(ingestMetadata); - - assertThat(actualModelIds, equalTo(expectedModelIds)); - } - - private static PipelineConfiguration newConfigurationWithOutInferenceProcessor(int i) throws IOException { - try ( - XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() - .map( - Collections.singletonMap( - "processors", - Collections.singletonList(Collections.singletonMap("not_inference", Collections.emptyMap())) - ) - ) - ) { - return new PipelineConfiguration("pipeline_without_model_" + i, BytesReference.bytes(xContentBuilder), XContentType.JSON); - } - } - - private static ClusterState buildClusterState(Metadata metadata) { - return ClusterState.builder(new ClusterName("_name")).metadata(metadata).build(); - } - - private static ClusterState buildClusterStateWithModelReferences(int numPipelineReferences, String... modelId) throws IOException { - Map configurations = Maps.newMapWithExpectedSize(modelId.length); - for (String id : modelId) { - for (int i = 0; i < numPipelineReferences; i++) { - configurations.put( - "pipeline_with_model_" + id + i, - randomBoolean() ? newConfigurationWithInferenceProcessor(id) : newConfigurationWithForeachProcessorProcessor(id) - ); - } - - } - int numPipelinesWithoutModel = randomInt(5); - for (int i = 0; i < numPipelinesWithoutModel; i++) { - configurations.put("pipeline_without_model_" + i, newConfigurationWithOutInferenceProcessor(i)); - } - IngestMetadata ingestMetadata = new IngestMetadata(configurations); - - return ClusterState.builder(new ClusterName("_name")) - .metadata(Metadata.builder().putCustom(IngestMetadata.TYPE, ingestMetadata)) - .nodes( - DiscoveryNodes.builder() - .add(DiscoveryNodeUtils.create("min_node", new TransportAddress(InetAddress.getLoopbackAddress(), 9300))) - .add(DiscoveryNodeUtils.create("current_node", new TransportAddress(InetAddress.getLoopbackAddress(), 9302))) - .add(DiscoveryNodeUtils.create("_node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9304))) - .localNodeId("_node_id") - .masterNodeId("_node_id") - ) - .build(); - } - - private static PipelineConfiguration newConfigurationWithInferenceProcessor(String modelId) throws IOException { - try ( - XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() - .map(Collections.singletonMap("processors", Collections.singletonList(inferenceProcessorForModel(modelId)))) - ) { - return new PipelineConfiguration("pipeline_with_model_" + modelId, BytesReference.bytes(xContentBuilder), XContentType.JSON); - } - } - - private static PipelineConfiguration newConfigurationWithForeachProcessorProcessor(String modelId) throws IOException { - try ( - XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() - .map(Collections.singletonMap("processors", Collections.singletonList(forEachProcessorWithInference(modelId)))) - ) { - return new PipelineConfiguration("pipeline_with_model_" + modelId, BytesReference.bytes(xContentBuilder), XContentType.JSON); - } - } - - private static Map forEachProcessorWithInference(String modelId) { - return Collections.singletonMap("foreach", new HashMap<>() { - { - put("field", "foo"); - put("processor", inferenceProcessorForModel(modelId)); - } - }); - } - - public static final String TYPE = "inference"; - public static final String INFERENCE_CONFIG = "inference_config"; - public static final String TARGET_FIELD = "target_field"; - public static final String FIELD_MAP = "field_map"; - - private static Map inferenceProcessorForModel(String modelId) { - return Collections.singletonMap(TYPE, new HashMap<>() { - { - put(InferenceResults.MODEL_ID_RESULTS_FIELD, modelId); - put(INFERENCE_CONFIG, Collections.singletonMap(RegressionConfig.NAME.getPreferredName(), Collections.emptyMap())); - put(TARGET_FIELD, "new_field"); - put(FIELD_MAP, Collections.singletonMap("source", "dest")); - } - }); - } - -} diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/TestFeatureResetIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/TestFeatureResetIT.java index 7158e494bee68..19dad8db8ef01 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/TestFeatureResetIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/TestFeatureResetIT.java @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import static org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor.countInferenceProcessors; import static org.elasticsearch.xpack.ml.integration.ClassificationIT.KEYWORD_FIELD; import static org.elasticsearch.xpack.ml.integration.MlNativeDataFrameAnalyticsIntegTestCase.buildAnalytics; import static org.elasticsearch.xpack.ml.integration.PyTorchModelIT.BASE_64_ENCODED_MODEL; @@ -55,7 +56,6 @@ import static org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase.createScheduledJob; import static org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase.getDataCounts; import static org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase.indexDocs; -import static org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor.countInferenceProcessors; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 48cf92f4cab10..6fdc4e73e184f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -475,7 +475,7 @@ import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; import static org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX; import static org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX; -import static org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor.countInferenceProcessors; +import static org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor.countInferenceProcessors; public class MachineLearning extends Plugin implements diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAction.java index 168a81ba554dc..1be5a765d1735 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAction.java @@ -42,9 +42,9 @@ import org.elasticsearch.xpack.core.ml.inference.ModelAliasMetadata; import org.elasticsearch.xpack.core.ml.inference.assignment.TrainedModelAssignmentMetadata; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; +import org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor; import org.elasticsearch.xpack.ml.inference.persistence.TrainedModelProvider; import org.elasticsearch.xpack.ml.notifications.InferenceAuditor; -import org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor; import java.util.ArrayList; import java.util.HashMap; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAliasAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAliasAction.java index 78ac4bc11d17a..2a4b3ea70a57f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAliasAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteTrainedModelAliasAction.java @@ -33,8 +33,8 @@ import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ml.action.DeleteTrainedModelAliasAction; import org.elasticsearch.xpack.core.ml.inference.ModelAliasMetadata; +import org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor; import org.elasticsearch.xpack.ml.notifications.InferenceAuditor; -import org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor; import java.util.HashMap; import java.util.Locale; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsAction.java index eeab3d461661b..12a8e7aadee46 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsAction.java @@ -74,7 +74,7 @@ import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; -import static org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor.pipelineIdsByResource; +import static org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor.pipelineIdsByResource; public class TransportGetTrainedModelsStatsAction extends TransportAction< GetTrainedModelsStatsAction.Request, diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStopTrainedModelDeploymentAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStopTrainedModelDeploymentAction.java index 10027cbd0d6bc..dc95d548c5f1b 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStopTrainedModelDeploymentAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStopTrainedModelDeploymentAction.java @@ -36,10 +36,10 @@ import org.elasticsearch.xpack.core.ml.inference.assignment.TrainedModelAssignmentMetadata; import org.elasticsearch.xpack.core.ml.job.messages.Messages; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; +import org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor; import org.elasticsearch.xpack.ml.inference.assignment.TrainedModelAssignmentClusterService; import org.elasticsearch.xpack.ml.inference.deployment.TrainedModelDeploymentTask; import org.elasticsearch.xpack.ml.notifications.InferenceAuditor; -import org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor; import java.util.List; import java.util.Objects; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessor.java index e0df2fb77fdd6..6b14e60c00247 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessor.java @@ -55,9 +55,10 @@ import org.elasticsearch.xpack.core.ml.inference.trainedmodel.ZeroShotClassificationConfigUpdate; import org.elasticsearch.xpack.core.ml.job.messages.Messages; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; +import org.elasticsearch.xpack.core.ml.utils.InferenceProcessorConstants; +import org.elasticsearch.xpack.core.ml.utils.InferenceProcessorInfoExtractor; import org.elasticsearch.xpack.ml.inference.loadingservice.LocalModel; import org.elasticsearch.xpack.ml.notifications.InferenceAuditor; -import org.elasticsearch.xpack.ml.utils.InferenceProcessorInfoExtractor; import java.util.ArrayList; import java.util.Collections; @@ -85,16 +86,15 @@ public class InferenceProcessor extends AbstractProcessor { Setting.Property.NodeScope ); - public static final String TYPE = "inference"; // this value is hardcoded in - // org.elasticsearch.xpack.inference.utils.InferenceProcessorInfoExtractor + public static final String TYPE = InferenceProcessorConstants.TYPE; public static final String MODEL_ID = "model_id"; - public static final String INFERENCE_CONFIG = "inference_config"; + public static final String INFERENCE_CONFIG = InferenceProcessorConstants.INFERENCE_CONFIG; public static final String IGNORE_MISSING = "ignore_missing"; // target field style mappings - public static final String TARGET_FIELD = "target_field"; + public static final String TARGET_FIELD = InferenceProcessorConstants.TARGET_FIELD; public static final String FIELD_MAPPINGS = "field_mappings"; - public static final String FIELD_MAP = "field_map"; + public static final String FIELD_MAP = InferenceProcessorConstants.FIELD_MAP; private static final String DEFAULT_TARGET_FIELD = "ml.inference"; // input field config