Move the policy class to xpack core module. (#41311)
This allows the transport client use this class in enrich APIs. Relates to #40997
This commit is contained in:
parent
d01c1f3ba0
commit
d99249c624
|
@ -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;
|
|
@ -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<MetaData.Custom>
|
|||
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 + "]");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<EnrichPolicy>
|
|||
|
||||
@Override
|
||||
protected EnrichPolicy doParseInstance(XContentParser parser) throws IOException {
|
||||
return EnrichPolicy.PARSER.parse(parser, null);
|
||||
return EnrichPolicy.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue