From d99249c62461c690a70405ec5eefc4e663851b0d Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 17 Apr 2019 17:54:10 +0200 Subject: [PATCH] Move the policy class to xpack core module. (#41311) This allows the transport client use this class in enrich APIs. Relates to #40997 --- .../elasticsearch/xpack/core}/enrich/EnrichPolicy.java | 9 +++++++-- .../org/elasticsearch/xpack/enrich/EnrichMetadata.java | 3 ++- .../java/org/elasticsearch/xpack/enrich/EnrichStore.java | 1 + .../elasticsearch/xpack/enrich/EnrichMetadataTests.java | 1 + .../elasticsearch/xpack/enrich/EnrichPolicyTests.java | 3 ++- .../org/elasticsearch/xpack/enrich/EnrichStoreTests.java | 1 + 6 files changed, 14 insertions(+), 4 deletions(-) rename x-pack/plugin/{enrich/src/main/java/org/elasticsearch/xpack => core/src/main/java/org/elasticsearch/xpack/core}/enrich/EnrichPolicy.java (95%) diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java similarity index 95% rename from x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicy.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java index ceb3be91af1..06d74222b17 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicy.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.enrich; +package org.elasticsearch.xpack.core.enrich; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; @@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; @@ -28,7 +29,7 @@ import java.util.Objects; public final class EnrichPolicy implements Writeable, ToXContentFragment { static final String EXACT_MATCH_TYPE = "exact_match"; - static final String[] SUPPORTED_POLICY_TYPES = new String[]{EXACT_MATCH_TYPE}; + public static final String[] SUPPORTED_POLICY_TYPES = new String[]{EXACT_MATCH_TYPE}; static final ParseField TYPE = new ParseField("type"); static final ParseField QUERY = new ParseField("query"); @@ -64,6 +65,10 @@ public final class EnrichPolicy implements Writeable, ToXContentFragment { PARSER.declareString(ConstructingObjectParser.constructorArg(), SCHEDULE); } + public static EnrichPolicy fromXContent(XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } + private final String type; private final QuerySource query; private final String indexPattern; diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichMetadata.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichMetadata.java index 6548fc6514b..c791d2debd5 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichMetadata.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichMetadata.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.xpack.core.XPackPlugin; +import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import java.io.IOException; import java.util.Collections; @@ -47,7 +48,7 @@ public final class EnrichMetadata extends AbstractNamedDiffable if (token == XContentParser.Token.FIELD_NAME) { fieldName = p.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { - patterns.put(fieldName, EnrichPolicy.PARSER.parse(p, c)); + patterns.put(fieldName, EnrichPolicy.fromXContent(p)); } else { throw new ElasticsearchParseException("unexpected token [" + token + "]"); } diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichStore.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichStore.java index 918dd9c8fd4..11b973e72cf 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichStore.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichStore.java @@ -9,6 +9,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import java.util.HashMap; import java.util.Map; diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMetadataTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMetadataTests.java index 93efcd35b47..a0474b1216b 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMetadataTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichMetadataTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractSerializingTestCase; +import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import java.io.IOException; import java.util.HashMap; diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyTests.java index 3cfd7ee60d8..ad0ab6005be 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.test.AbstractSerializingTestCase; +import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -29,7 +30,7 @@ public class EnrichPolicyTests extends AbstractSerializingTestCase @Override protected EnrichPolicy doParseInstance(XContentParser parser) throws IOException { - return EnrichPolicy.PARSER.parse(parser, null); + return EnrichPolicy.fromXContent(parser); } @Override diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichStoreTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichStoreTests.java index 43dfc31ceb9..529acbcdfdb 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichStoreTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichStoreTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.enrich; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference;