diff --git a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java index 02027b1f633d2..f7415b438dfae 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.cluster.metadata.ProjectId; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.ReleasableBytesReference; import org.elasticsearch.common.io.stream.StreamInput; @@ -130,6 +131,7 @@ record Parsed(Pipeline pipeline, List documents, boolean verbose static final String SIMULATED_PIPELINE_ID = "_simulate_pipeline"; static Parsed parseWithPipelineId( + ProjectId projectId, String pipelineId, Map config, boolean verbose, @@ -139,7 +141,7 @@ static Parsed parseWithPipelineId( if (pipelineId == null) { throw new IllegalArgumentException("param [pipeline] is null"); } - Pipeline pipeline = ingestService.getPipeline(pipelineId); + Pipeline pipeline = ingestService.getPipeline(projectId, pipelineId); if (pipeline == null) { throw new IllegalArgumentException("pipeline [" + pipelineId + "] does not exist"); } diff --git a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineTransportAction.java b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineTransportAction.java index 6b2b96fb76402..6d2f2d8044388 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineTransportAction.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineTransportAction.java @@ -17,6 +17,7 @@ import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.common.Randomness; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.util.concurrent.EsExecutors; @@ -49,6 +50,7 @@ public class SimulatePipelineTransportAction extends HandledTransportAction random = ThreadLocal.withInitial(Randomness::get); @@ -58,7 +60,8 @@ public SimulatePipelineTransportAction( ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters, - IngestService ingestService + IngestService ingestService, + ProjectResolver projectResolver ) { super( SimulatePipelineAction.NAME, @@ -70,6 +73,7 @@ public SimulatePipelineTransportAction( this.ingestService = ingestService; this.executionService = new SimulateExecutionService(threadPool); this.transportService = transportService; + this.projectResolver = projectResolver; this.ingestNodeTransportActionTimeout = INGEST_NODE_TRANSPORT_ACTION_TIMEOUT.get(ingestService.getClusterService().getSettings()); ingestService.getClusterService() .getClusterSettings() @@ -96,9 +100,11 @@ protected void doExecute(Task task, SimulatePipelineRequest request, ActionListe } try { if (discoveryNodes.getLocalNode().isIngestNode()) { + final var projectId = projectResolver.getProjectId(); final SimulatePipelineRequest.Parsed simulateRequest; if (request.getId() != null) { simulateRequest = SimulatePipelineRequest.parseWithPipelineId( + projectId, request.getId(), source, request.isVerbose(), diff --git a/server/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java b/server/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java index 391c258b6f098..575c3e87dfcd7 100644 --- a/server/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java +++ b/server/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java @@ -44,6 +44,8 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -61,7 +63,7 @@ public void init() throws IOException { (factories, tag, description, config) -> processor ); ingestService = mock(IngestService.class); - when(ingestService.getPipeline(SIMULATED_PIPELINE_ID)).thenReturn(pipeline); + when(ingestService.getPipeline(any(), eq(SIMULATED_PIPELINE_ID))).thenReturn(pipeline); when(ingestService.getProcessorFactories()).thenReturn(registry); } @@ -89,7 +91,9 @@ public void testParseUsingPipelineStore() throws Exception { expectedDocs.add(expectedDoc); } + var projectId = randomProjectIdOrDefault(); SimulatePipelineRequest.Parsed actualRequest = SimulatePipelineRequest.parseWithPipelineId( + projectId, SIMULATED_PIPELINE_ID, requestContent, false, @@ -213,24 +217,40 @@ public void testParseWithProvidedPipeline() throws Exception { } public void testNullPipelineId() { + var projectId = randomProjectIdOrDefault(); Map requestContent = new HashMap<>(); List> docs = new ArrayList<>(); requestContent.put(Fields.DOCS, docs); Exception e = expectThrows( IllegalArgumentException.class, - () -> SimulatePipelineRequest.parseWithPipelineId(null, requestContent, false, ingestService, RestApiVersion.current()) + () -> SimulatePipelineRequest.parseWithPipelineId( + projectId, + null, + requestContent, + false, + ingestService, + RestApiVersion.current() + ) ); assertThat(e.getMessage(), equalTo("param [pipeline] is null")); } public void testNonExistentPipelineId() { + var projectId = randomProjectIdOrDefault(); String pipelineId = randomAlphaOfLengthBetween(1, 10); Map requestContent = new HashMap<>(); List> docs = new ArrayList<>(); requestContent.put(Fields.DOCS, docs); Exception e = expectThrows( IllegalArgumentException.class, - () -> SimulatePipelineRequest.parseWithPipelineId(pipelineId, requestContent, false, ingestService, RestApiVersion.current()) + () -> SimulatePipelineRequest.parseWithPipelineId( + projectId, + pipelineId, + requestContent, + false, + ingestService, + RestApiVersion.current() + ) ); assertThat(e.getMessage(), equalTo("pipeline [" + pipelineId + "] does not exist")); }