From ad54405e7d1c01020b1fa7d3e921e14d2213e563 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 22 Oct 2019 07:41:26 +0200 Subject: [PATCH] Fail with a better error when if there are no ingest nodes (#48272) when executing enrich execute policy api. --- .../action/TransportExecuteEnrichPolicyAction.java | 6 ++++++ .../xpack/enrich/EnrichMultiNodeIT.java | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/TransportExecuteEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/TransportExecuteEnrichPolicyAction.java index 7402c2daef6e7..23d756f3a83a4 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/TransportExecuteEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/TransportExecuteEnrichPolicyAction.java @@ -62,6 +62,12 @@ protected ExecuteEnrichPolicyAction.Response read(StreamInput in) throws IOExcep @Override protected void masterOperation(Task task, ExecuteEnrichPolicyAction.Request request, ClusterState state, ActionListener listener) { + if (state.getNodes().getIngestNodes().isEmpty()) { + // if we don't fail here then reindex will fail with a more complicated error. + // (EnrichPolicyRunner uses a pipeline with reindex) + throw new IllegalStateException("no ingest nodes in this cluster"); + } + if (request.isWaitForCompletion()) { executor.runPolicy(request, new ActionListener<>() { @Override diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java index 1b19958ee2ad5..63b92cea674b6 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMultiNodeIT.java @@ -119,6 +119,19 @@ public void testEnrichDedicatedIngestNode() { enrich(keys, ingestOnlyNode); } + public void testEnrichNoIngestNodes() { + Settings settings = Settings.builder() + .put(Node.NODE_MASTER_SETTING.getKey(), true) + .put(Node.NODE_DATA_SETTING.getKey(), true) + .put(Node.NODE_INGEST_SETTING.getKey(), false) + .build(); + internalCluster().startNode(settings); + + createSourceIndex(64); + Exception e = expectThrows(IllegalStateException.class, EnrichMultiNodeIT::createAndExecutePolicy); + assertThat(e.getMessage(), equalTo("no ingest nodes in this cluster")); + } + private static void enrich(List keys, String coordinatingNode) { int numDocs = 256; BulkRequest bulkRequest = new BulkRequest("my-index");