Skip to content

Commit

Permalink
[HLRC] Ignore unknown fields in responses of CCR APIs (#36821)
Browse files Browse the repository at this point in the history
Otherwise hlrc fails if new fields are introduced in ccr api responses
in future versions.
  • Loading branch information
martijnvg committed Jan 10, 2019
1 parent 93c7722 commit d62a353
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public final class AutoFollowStats {
static final ParseField LAST_SEEN_METADATA_VERSION = new ParseField("last_seen_metadata_version");

@SuppressWarnings("unchecked")
static final ConstructingObjectParser<AutoFollowStats, Void> STATS_PARSER = new ConstructingObjectParser<>("auto_follow_stats",
static final ConstructingObjectParser<AutoFollowStats, Void> STATS_PARSER = new ConstructingObjectParser<>(
"auto_follow_stats",
true,
args -> new AutoFollowStats(
(Long) args[0],
(Long) args[1],
Expand All @@ -63,11 +65,13 @@ public final class AutoFollowStats {
private static final ConstructingObjectParser<Map.Entry<String, ElasticsearchException>, Void> AUTO_FOLLOW_EXCEPTIONS_PARSER =
new ConstructingObjectParser<>(
"auto_follow_stats_errors",
true,
args -> new AbstractMap.SimpleEntry<>((String) args[0], (ElasticsearchException) args[1]));

private static final ConstructingObjectParser<Map.Entry<String, AutoFollowedCluster>, Void> AUTO_FOLLOWED_CLUSTERS_PARSER =
new ConstructingObjectParser<>(
"auto_followed_clusters",
true,
args -> new AbstractMap.SimpleEntry<>((String) args[0], new AutoFollowedCluster((Long) args[1], (Long) args[2])));

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public final class CcrStatsResponse {
static final ParseField AUTO_FOLLOW_STATS_FIELD = new ParseField("auto_follow_stats");
static final ParseField FOLLOW_STATS_FIELD = new ParseField("follow_stats");

private static final ConstructingObjectParser<CcrStatsResponse, Void> PARSER = new ConstructingObjectParser<>("indices",
private static final ConstructingObjectParser<CcrStatsResponse, Void> PARSER = new ConstructingObjectParser<>(
"indices",
true,
args -> {
AutoFollowStats autoFollowStats = (AutoFollowStats) args[0];
IndicesFollowStats indicesFollowStats = (IndicesFollowStats) args[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public final class GetAutoFollowPatternResponse {
static final ParseField PATTERN_FIELD = new ParseField("pattern");

private static final ConstructingObjectParser<Map.Entry<String, Pattern>, Void> ENTRY_PARSER = new ConstructingObjectParser<>(
"get_auto_follow_pattern_response", args -> new AbstractMap.SimpleEntry<>((String) args[0], (Pattern) args[1]));
"get_auto_follow_pattern_response", true, args -> new AbstractMap.SimpleEntry<>((String) args[0], (Pattern) args[1]));

static {
ENTRY_PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME_FIELD);
ENTRY_PARSER.declareObject(ConstructingObjectParser.constructorArg(), Pattern.PARSER, PATTERN_FIELD);
}

private static final ConstructingObjectParser<GetAutoFollowPatternResponse, Void> PARSER = new ConstructingObjectParser<>(
"get_auto_follow_pattern_response", args -> {
"get_auto_follow_pattern_response", true, args -> {
@SuppressWarnings("unchecked")
List<Map.Entry<String, Pattern>> entries = (List<Map.Entry<String, Pattern>>) args[0];
return new GetAutoFollowPatternResponse(new TreeMap<>(entries.stream()
Expand Down Expand Up @@ -92,7 +92,7 @@ public static class Pattern extends FollowConfig {

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<Pattern, Void> PARSER = new ConstructingObjectParser<>(
"pattern", args -> new Pattern((String) args[0], (List<String>) args[1], (String) args[2]));
"pattern", true, args -> new Pattern((String) args[0], (List<String>) args[1], (String) args[2]));

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.REMOTE_CLUSTER_FIELD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class IndicesFollowStats {
private static final ConstructingObjectParser<Tuple<String, List<ShardFollowStats>>, Void> ENTRY_PARSER =
new ConstructingObjectParser<>(
"entry",
true,
args -> {
String index = (String) args[0];
@SuppressWarnings("unchecked")
Expand All @@ -54,7 +55,9 @@ public final class IndicesFollowStats {
ENTRY_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), ShardFollowStats.PARSER, SHARDS_FIELD);
}

static final ConstructingObjectParser<IndicesFollowStats, Void> PARSER = new ConstructingObjectParser<>("indices",
static final ConstructingObjectParser<IndicesFollowStats, Void> PARSER = new ConstructingObjectParser<>(
"indices",
true,
args -> {
@SuppressWarnings("unchecked")
List<Tuple<String, List<ShardFollowStats>>> entries = (List<Tuple<String, List<ShardFollowStats>>>) args[0];
Expand Down Expand Up @@ -116,6 +119,7 @@ public static final class ShardFollowStats {
static final ConstructingObjectParser<ShardFollowStats, Void> PARSER =
new ConstructingObjectParser<>(
"shard-follow-stats",
true,
args -> new ShardFollowStats(
(String) args[0],
(String) args[1],
Expand Down Expand Up @@ -152,6 +156,7 @@ public static final class ShardFollowStats {
static final ConstructingObjectParser<Map.Entry<Long, Tuple<Integer, ElasticsearchException>>, Void> READ_EXCEPTIONS_ENTRY_PARSER =
new ConstructingObjectParser<>(
"shard-follow-stats-read-exceptions-entry",
true,
args -> new AbstractMap.SimpleEntry<>((long) args[0], Tuple.tuple((Integer) args[1], (ElasticsearchException)args[2])));

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class PutFollowResponse {
static final ParseField INDEX_FOLLOWING_STARTED = new ParseField("index_following_started");

private static final ConstructingObjectParser<PutFollowResponse, Void> PARSER = new ConstructingObjectParser<>(
"put_follow_response", args -> new PutFollowResponse((boolean) args[0], (boolean) args[1], (boolean) args[2]));
"put_follow_response", true, args -> new PutFollowResponse((boolean) args[0], (boolean) args[1], (boolean) args[2]));

static {
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), FOLLOW_INDEX_CREATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testFromXContent() throws IOException {
CcrStatsResponseTests::createTestInstance,
CcrStatsResponseTests::toXContent,
CcrStatsResponse::fromXContent)
.supportsUnknownFields(false)
.supportsUnknownFields(true)
.assertEqualsConsumer(CcrStatsResponseTests::assertEqualInstances)
.assertToXContentEquivalence(false)
.test();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testFromXContent() throws IOException {
FollowStatsResponseTests::createTestInstance,
FollowStatsResponseTests::toXContent,
FollowStatsResponse::fromXContent)
.supportsUnknownFields(false)
.supportsUnknownFields(true)
.assertEqualsConsumer(FollowStatsResponseTests::assertEqualInstances)
.assertToXContentEquivalence(false)
.test();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testFromXContent() throws IOException {
this::createTestInstance,
GetAutoFollowPatternResponseTests::toXContent,
GetAutoFollowPatternResponse::fromXContent)
.supportsUnknownFields(false)
.supportsUnknownFields(true)
.test();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class PutFollowRequestTests extends AbstractXContentTestCase<PutFollowRequest> {

private static final ConstructingObjectParser<PutFollowRequest, Void> PARSER = new ConstructingObjectParser<>("test_parser",
(args) -> new PutFollowRequest((String) args[0], (String) args[1], (String) args[2]));
true, (args) -> new PutFollowRequest((String) args[0], (String) args[1], (String) args[2]));

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.REMOTE_CLUSTER_FIELD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testFromXContent() throws IOException {
this::createTestInstance,
PutFollowResponseTests::toXContent,
PutFollowResponse::fromXContent)
.supportsUnknownFields(false)
.supportsUnknownFields(true)
.test();
}

Expand Down

0 comments on commit d62a353

Please sign in to comment.