From da3bab375a5b8751e55b0d810d7f6c31e06f8041 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Mon, 10 Jun 2024 10:30:13 +0300 Subject: [PATCH 01/10] Introduce data stream options and failure store configuration classes --- .../metadata/DataStreamFailureStore.java | 88 ++++++++++++++++++ .../cluster/metadata/DataStreamOptions.java | 91 +++++++++++++++++++ .../metadata/DataStreamFailureStoreTests.java | 42 +++++++++ .../metadata/DataStreamOptionsTests.java | 44 +++++++++ 4 files changed, 265 insertions(+) create mode 100644 server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java create mode 100644 server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java create mode 100644 server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java create mode 100644 server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java new file mode 100644 index 0000000000000..bfcbbb1f87d0d --- /dev/null +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java @@ -0,0 +1,88 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.cluster.metadata; + +import org.elasticsearch.cluster.Diff; +import org.elasticsearch.cluster.SimpleDiffable; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.core.Nullable; +import org.elasticsearch.xcontent.ConstructingObjectParser; +import org.elasticsearch.xcontent.ParseField; +import org.elasticsearch.xcontent.ToXContentObject; +import org.elasticsearch.xcontent.XContentBuilder; +import org.elasticsearch.xcontent.XContentParser; + +import java.io.IOException; + +/** + * Holds the data stream failure store metadata that enable or disable the failure store of a data stream. Currently, it + * supports the following configurations: + * - enabled + */ +public record DataStreamFailureStore(boolean enabled) implements SimpleDiffable, ToXContentObject { + + public static final ParseField ENABLED_FIELD = new ParseField("enabled"); + + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "failure_store", + false, + (args, unused) -> new DataStreamFailureStore((Boolean) args[0]) + ); + + static { + PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), ENABLED_FIELD); + } + + public DataStreamFailureStore() { + this(true); + } + + public DataStreamFailureStore(@Nullable Boolean enabled) { + this(enabled == null || enabled); + } + + public static DataStreamFailureStore read(StreamInput in) throws IOException { + return new DataStreamFailureStore(in.readBoolean()); + } + + /** + * Returns true, if this data stream lifecycle configuration is enabled and false otherwise + */ + public boolean isEnabled() { + return enabled; + } + + public static Diff readDiffFrom(StreamInput in) throws IOException { + return SimpleDiffable.readDiffFrom(DataStreamFailureStore::read, in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeBoolean(enabled); + } + + @Override + public String toString() { + return Strings.toString(this, true, true); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.field(ENABLED_FIELD.getPreferredName(), enabled); + builder.endObject(); + return builder; + } + + public static DataStreamFailureStore fromXContent(XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } +} diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java new file mode 100644 index 0000000000000..86c239f0ffa85 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java @@ -0,0 +1,91 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.cluster.metadata; + +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.cluster.Diff; +import org.elasticsearch.cluster.SimpleDiffable; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.core.Nullable; +import org.elasticsearch.xcontent.ConstructingObjectParser; +import org.elasticsearch.xcontent.ObjectParser; +import org.elasticsearch.xcontent.ParseField; +import org.elasticsearch.xcontent.ToXContentObject; +import org.elasticsearch.xcontent.XContentBuilder; +import org.elasticsearch.xcontent.XContentParser; + +import java.io.IOException; + +/** + * Holds data stream dedicated configuration options such as failure store, (in the future lifecycle). Currently, it + * supports the following configurations: + * - failure store + */ +public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) implements SimpleDiffable, ToXContentObject { + + public static final ParseField OPTIONS_FIELD = new ParseField("options"); + + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "options", + false, + (args, unused) -> new DataStreamOptions((DataStreamFailureStore) args[0]) + ); + + static { + PARSER.declareField( + ConstructingObjectParser.optionalConstructorArg(), + (p, c) -> DataStreamFailureStore.fromXContent(p), + OPTIONS_FIELD, + ObjectParser.ValueType.OBJECT_OR_NULL + ); + } + + public DataStreamOptions() { + this(null); + } + public static DataStreamOptions read(StreamInput in) throws IOException { + return new DataStreamOptions(in.readOptionalWriteable(DataStreamFailureStore::read)); + } + + @Nullable + public DataStreamFailureStore getFailureStore() { + return failureStore; + } + + public static Diff readDiffFrom(StreamInput in) throws IOException { + return SimpleDiffable.readDiffFrom(DataStreamOptions::read, in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeOptionalWriteable(failureStore); + } + + @Override + public String toString() { + return Strings.toString(this, true, true); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + if (failureStore != null) { + builder.field(OPTIONS_FIELD.getPreferredName()); + builder.value(failureStore); + } + builder.endObject(); + return builder; + } + + public static DataStreamOptions fromXContent(XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } +} diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java new file mode 100644 index 0000000000000..f150696f5988b --- /dev/null +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java @@ -0,0 +1,42 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.cluster.metadata; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractXContentSerializingTestCase; +import org.elasticsearch.xcontent.XContentParser; + +import java.io.IOException; + +public class DataStreamFailureStoreTests extends AbstractXContentSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return DataStreamFailureStore::read; + } + + @Override + protected DataStreamFailureStore createTestInstance() { + return randomFailureStore(); + } + + @Override + protected DataStreamFailureStore mutateInstance(DataStreamFailureStore instance) throws IOException { + return new DataStreamFailureStore(instance.isEnabled() == false); + } + + @Override + protected DataStreamFailureStore doParseInstance(XContentParser parser) throws IOException { + return DataStreamFailureStore.fromXContent(parser); + } + + static DataStreamFailureStore randomFailureStore() { + return new DataStreamFailureStore(randomBoolean() ? null : randomBoolean()); + } +} diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java new file mode 100644 index 0000000000000..3debf3c9eba6c --- /dev/null +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java @@ -0,0 +1,44 @@ + /* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.cluster.metadata; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractXContentSerializingTestCase; +import org.elasticsearch.xcontent.XContentParser; + +import java.io.IOException; + +public class DataStreamOptionsTests extends AbstractXContentSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return DataStreamOptions::read; + } + + @Override + protected DataStreamOptions createTestInstance() { + return new DataStreamOptions(randomBoolean() ? null : DataStreamFailureStoreTests.randomFailureStore()); + } + + @Override + protected DataStreamOptions mutateInstance(DataStreamOptions instance) throws IOException { + var failureStore = instance.getFailureStore(); + if (failureStore == null) { + failureStore = DataStreamFailureStoreTests.randomFailureStore(); + } else { + failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.isEnabled() == false); + } + return new DataStreamOptions(failureStore); + } + + @Override + protected DataStreamOptions doParseInstance(XContentParser parser) throws IOException { + return DataStreamOptions.fromXContent(parser); + } +} From 6352d2e12957016443bf5b72d88ecf2d8b05da1c Mon Sep 17 00:00:00 2001 From: gmarouli Date: Mon, 10 Jun 2024 11:06:08 +0300 Subject: [PATCH 02/10] Fix format --- .../cluster/metadata/DataStreamOptions.java | 9 ++++++--- .../cluster/metadata/DataStreamOptionsTests.java | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java index 86c239f0ffa85..9166ba61b7e99 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.metadata; -import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.SimpleDiffable; import org.elasticsearch.common.Strings; @@ -29,7 +28,10 @@ * supports the following configurations: * - failure store */ -public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) implements SimpleDiffable, ToXContentObject { +public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) + implements + SimpleDiffable, + ToXContentObject { public static final ParseField OPTIONS_FIELD = new ParseField("options"); @@ -43,7 +45,7 @@ public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) i PARSER.declareField( ConstructingObjectParser.optionalConstructorArg(), (p, c) -> DataStreamFailureStore.fromXContent(p), - OPTIONS_FIELD, + OPTIONS_FIELD, ObjectParser.ValueType.OBJECT_OR_NULL ); } @@ -51,6 +53,7 @@ public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) i public DataStreamOptions() { this(null); } + public static DataStreamOptions read(StreamInput in) throws IOException { return new DataStreamOptions(in.readOptionalWriteable(DataStreamFailureStore::read)); } diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java index 3debf3c9eba6c..a8f43845bb92c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java @@ -1,10 +1,10 @@ - /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ +/* +* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +* or more contributor license agreements. Licensed under the Elastic License +* 2.0 and the Server Side Public License, v 1; you may not use this file except +* in compliance with, at your election, the Elastic License 2.0 or the Server +* Side Public License, v 1. +*/ package org.elasticsearch.cluster.metadata; From 9e41720f6e8bd9500911d3fc6b05f75b62e0cdbb Mon Sep 17 00:00:00 2001 From: gmarouli Date: Mon, 10 Jun 2024 11:25:56 +0300 Subject: [PATCH 03/10] Fix license --- .../cluster/metadata/DataStreamOptionsTests.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java index a8f43845bb92c..185bdaa1a24e7 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java @@ -1,10 +1,10 @@ /* -* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -* or more contributor license agreements. Licensed under the Elastic License -* 2.0 and the Server Side Public License, v 1; you may not use this file except -* in compliance with, at your election, the Elastic License 2.0 or the Server -* Side Public License, v 1. -*/ + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ package org.elasticsearch.cluster.metadata; From 9f19c4aa9fdb522e5f958caae08a386ac4a462c7 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Mon, 10 Jun 2024 15:54:48 +0300 Subject: [PATCH 04/10] Remove unnecessary getter --- .../cluster/metadata/DataStreamFailureStore.java | 7 ------- .../cluster/metadata/DataStreamFailureStoreTests.java | 2 +- .../cluster/metadata/DataStreamOptionsTests.java | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java index bfcbbb1f87d0d..eefb7c5af95bd 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java @@ -53,13 +53,6 @@ public static DataStreamFailureStore read(StreamInput in) throws IOException { return new DataStreamFailureStore(in.readBoolean()); } - /** - * Returns true, if this data stream lifecycle configuration is enabled and false otherwise - */ - public boolean isEnabled() { - return enabled; - } - public static Diff readDiffFrom(StreamInput in) throws IOException { return SimpleDiffable.readDiffFrom(DataStreamFailureStore::read, in); } diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java index f150696f5988b..945be74711743 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java @@ -28,7 +28,7 @@ protected DataStreamFailureStore createTestInstance() { @Override protected DataStreamFailureStore mutateInstance(DataStreamFailureStore instance) throws IOException { - return new DataStreamFailureStore(instance.isEnabled() == false); + return new DataStreamFailureStore(instance.enabled() == false); } @Override diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java index 185bdaa1a24e7..8a7cf2329b863 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java @@ -32,7 +32,7 @@ protected DataStreamOptions mutateInstance(DataStreamOptions instance) throws IO if (failureStore == null) { failureStore = DataStreamFailureStoreTests.randomFailureStore(); } else { - failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.isEnabled() == false); + failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.enabled() == false); } return new DataStreamOptions(failureStore); } From 47cca1354d31b552a84c917d117c047348bb2d9d Mon Sep 17 00:00:00 2001 From: gmarouli Date: Mon, 10 Jun 2024 19:42:24 +0300 Subject: [PATCH 05/10] Fix wrong field name --- .../elasticsearch/cluster/metadata/DataStreamOptions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java index 9166ba61b7e99..a0849e1603fc2 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java @@ -33,7 +33,7 @@ public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) SimpleDiffable, ToXContentObject { - public static final ParseField OPTIONS_FIELD = new ParseField("options"); + public static final ParseField FAILURE_STORE_FIELD = new ParseField("failure_store"); public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "options", @@ -45,7 +45,7 @@ public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) PARSER.declareField( ConstructingObjectParser.optionalConstructorArg(), (p, c) -> DataStreamFailureStore.fromXContent(p), - OPTIONS_FIELD, + FAILURE_STORE_FIELD, ObjectParser.ValueType.OBJECT_OR_NULL ); } @@ -81,7 +81,7 @@ public String toString() { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (failureStore != null) { - builder.field(OPTIONS_FIELD.getPreferredName()); + builder.field(FAILURE_STORE_FIELD.getPreferredName()); builder.value(failureStore); } builder.endObject(); From 4fcd3af8ddc5a6ba9f86cf915301b7c6c17faf91 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Tue, 11 Jun 2024 09:54:06 +0300 Subject: [PATCH 06/10] Add lifecycle to show how they combine --- .../cluster/metadata/DataStreamOptions.java | 29 +++++++++++++------ .../metadata/DataStreamOptionsTests.java | 24 +++++++++++---- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java index a0849e1603fc2..d7b7b7adc5458 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java @@ -26,22 +26,30 @@ /** * Holds data stream dedicated configuration options such as failure store, (in the future lifecycle). Currently, it * supports the following configurations: + * - lifecycle * - failure store */ -public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) +public record DataStreamOptions(@Nullable DataStreamLifecycle lifecycle, @Nullable DataStreamFailureStore failureStore) implements SimpleDiffable, ToXContentObject { + public static final ParseField LIFECYCLE_FIELD = new ParseField("lifecycle"); public static final ParseField FAILURE_STORE_FIELD = new ParseField("failure_store"); public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "options", false, - (args, unused) -> new DataStreamOptions((DataStreamFailureStore) args[0]) + (args, unused) -> new DataStreamOptions((DataStreamLifecycle) args[0], (DataStreamFailureStore) args[1]) ); static { + PARSER.declareField( + ConstructingObjectParser.optionalConstructorArg(), + (p, c) -> DataStreamLifecycle.fromXContent(p), + LIFECYCLE_FIELD, + ObjectParser.ValueType.OBJECT_OR_NULL + ); PARSER.declareField( ConstructingObjectParser.optionalConstructorArg(), (p, c) -> DataStreamFailureStore.fromXContent(p), @@ -51,16 +59,14 @@ public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) } public DataStreamOptions() { - this(null); + this(null, null); } public static DataStreamOptions read(StreamInput in) throws IOException { - return new DataStreamOptions(in.readOptionalWriteable(DataStreamFailureStore::read)); - } - - @Nullable - public DataStreamFailureStore getFailureStore() { - return failureStore; + return new DataStreamOptions( + in.readOptionalWriteable(DataStreamLifecycle::new), + in.readOptionalWriteable(DataStreamFailureStore::read) + ); } public static Diff readDiffFrom(StreamInput in) throws IOException { @@ -69,6 +75,7 @@ public static Diff readDiffFrom(StreamInput in) throws IOExce @Override public void writeTo(StreamOutput out) throws IOException { + out.writeOptionalWriteable(lifecycle); out.writeOptionalWriteable(failureStore); } @@ -80,6 +87,10 @@ public String toString() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + if (lifecycle != null) { + builder.field(LIFECYCLE_FIELD.getPreferredName()); + builder.value(lifecycle); + } if (failureStore != null) { builder.field(FAILURE_STORE_FIELD.getPreferredName()); builder.value(failureStore); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java index 8a7cf2329b863..4412b98cba9e4 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java @@ -23,18 +23,30 @@ protected Writeable.Reader instanceReader() { @Override protected DataStreamOptions createTestInstance() { - return new DataStreamOptions(randomBoolean() ? null : DataStreamFailureStoreTests.randomFailureStore()); + return new DataStreamOptions( + randomBoolean() ? null : DataStreamLifecycleTests.randomLifecycle(), + randomBoolean() ? null : DataStreamFailureStoreTests.randomFailureStore() + ); } @Override protected DataStreamOptions mutateInstance(DataStreamOptions instance) throws IOException { - var failureStore = instance.getFailureStore(); - if (failureStore == null) { - failureStore = DataStreamFailureStoreTests.randomFailureStore(); + var lifecycle = instance.lifecycle(); + var failureStore = instance.failureStore(); + if (randomBoolean()) { + if (lifecycle == null) { + lifecycle = DataStreamLifecycleTests.randomLifecycle(); + } else { + lifecycle = randomBoolean() ? null : randomValueOtherThan(lifecycle, DataStreamLifecycleTests::randomLifecycle); + } } else { - failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.enabled() == false); + if (failureStore == null) { + failureStore = DataStreamFailureStoreTests.randomFailureStore(); + } else { + failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.enabled() == false); + } } - return new DataStreamOptions(failureStore); + return new DataStreamOptions(lifecycle, failureStore); } @Override From fbc03be1b8ee32673e6c0ee9c1515b3faa8c2314 Mon Sep 17 00:00:00 2001 From: Mary Gouseti Date: Fri, 14 Jun 2024 12:42:55 +0300 Subject: [PATCH 07/10] Update server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java Co-authored-by: Niels Bauman <33722607+nielsbauman@users.noreply.github.com> --- .../elasticsearch/cluster/metadata/DataStreamOptions.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java index d7b7b7adc5458..1bb7136c6cce4 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java @@ -88,12 +88,10 @@ public String toString() { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (lifecycle != null) { - builder.field(LIFECYCLE_FIELD.getPreferredName()); - builder.value(lifecycle); + builder.field(LIFECYCLE_FIELD.getPreferredName(), lifecycle); } if (failureStore != null) { - builder.field(FAILURE_STORE_FIELD.getPreferredName()); - builder.value(failureStore); + builder.field(FAILURE_STORE_FIELD.getPreferredName(), failureStore); } builder.endObject(); return builder; From a0453dcdfaf544928c1f88f02f3b0c105b4ffce4 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Mon, 17 Jun 2024 11:21:22 +0300 Subject: [PATCH 08/10] Review comments --- .../cluster/metadata/DataStreamFailureStore.java | 7 +------ .../cluster/metadata/DataStreamFailureStoreTests.java | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java index eefb7c5af95bd..4c2fedddcbbf8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.core.Nullable; import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.ToXContentObject; @@ -34,7 +33,7 @@ public record DataStreamFailureStore(boolean enabled) implements SimpleDiffable< public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "failure_store", false, - (args, unused) -> new DataStreamFailureStore((Boolean) args[0]) + (args, unused) -> new DataStreamFailureStore(args[0] == null || (Boolean) args[0]) ); static { @@ -45,10 +44,6 @@ public DataStreamFailureStore() { this(true); } - public DataStreamFailureStore(@Nullable Boolean enabled) { - this(enabled == null || enabled); - } - public static DataStreamFailureStore read(StreamInput in) throws IOException { return new DataStreamFailureStore(in.readBoolean()); } diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java index 945be74711743..fe3621a705f2a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java @@ -37,6 +37,6 @@ protected DataStreamFailureStore doParseInstance(XContentParser parser) throws I } static DataStreamFailureStore randomFailureStore() { - return new DataStreamFailureStore(randomBoolean() ? null : randomBoolean()); + return new DataStreamFailureStore(randomBoolean()); } } From dd769d06170d056608f36271cc5cb18ed486bbe9 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Wed, 19 Jun 2024 13:04:59 +0300 Subject: [PATCH 09/10] Use constructor instead of static method. --- .../cluster/metadata/DataStreamFailureStore.java | 6 +++--- .../cluster/metadata/DataStreamOptions.java | 9 +++------ .../cluster/metadata/DataStreamFailureStoreTests.java | 2 +- .../cluster/metadata/DataStreamOptionsTests.java | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java index 4c2fedddcbbf8..d647956e752a3 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java @@ -44,12 +44,12 @@ public DataStreamFailureStore() { this(true); } - public static DataStreamFailureStore read(StreamInput in) throws IOException { - return new DataStreamFailureStore(in.readBoolean()); + public DataStreamFailureStore(StreamInput in) throws IOException { + this(in.readBoolean()); } public static Diff readDiffFrom(StreamInput in) throws IOException { - return SimpleDiffable.readDiffFrom(DataStreamFailureStore::read, in); + return SimpleDiffable.readDiffFrom(DataStreamFailureStore::new, in); } @Override diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java index 1bb7136c6cce4..c65e7f3d58f3d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java @@ -62,15 +62,12 @@ public DataStreamOptions() { this(null, null); } - public static DataStreamOptions read(StreamInput in) throws IOException { - return new DataStreamOptions( - in.readOptionalWriteable(DataStreamLifecycle::new), - in.readOptionalWriteable(DataStreamFailureStore::read) - ); + public DataStreamOptions(StreamInput in) throws IOException { + this(in.readOptionalWriteable(DataStreamLifecycle::new), in.readOptionalWriteable(DataStreamFailureStore::new)); } public static Diff readDiffFrom(StreamInput in) throws IOException { - return SimpleDiffable.readDiffFrom(DataStreamOptions::read, in); + return SimpleDiffable.readDiffFrom(DataStreamOptions::new, in); } @Override diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java index fe3621a705f2a..f5334f903af6b 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreTests.java @@ -18,7 +18,7 @@ public class DataStreamFailureStoreTests extends AbstractXContentSerializingTest @Override protected Writeable.Reader instanceReader() { - return DataStreamFailureStore::read; + return DataStreamFailureStore::new; } @Override diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java index 4412b98cba9e4..9f3abd0881dde 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java @@ -18,7 +18,7 @@ public class DataStreamOptionsTests extends AbstractXContentSerializingTestCase< @Override protected Writeable.Reader instanceReader() { - return DataStreamOptions::read; + return DataStreamOptions::new; } @Override From a26bb6dbe514f21c7c38162f59951fae2af61aa7 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Wed, 4 Sep 2024 19:04:33 +0300 Subject: [PATCH 10/10] Remove lifecycle from the data stream options --- .../cluster/metadata/DataStreamOptions.java | 29 +++++++------------ .../metadata/DataStreamOptionsTests.java | 26 +++++------------ 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java index c65e7f3d58f3d..9c7d2a986fa48 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java @@ -26,30 +26,22 @@ /** * Holds data stream dedicated configuration options such as failure store, (in the future lifecycle). Currently, it * supports the following configurations: - * - lifecycle * - failure store */ -public record DataStreamOptions(@Nullable DataStreamLifecycle lifecycle, @Nullable DataStreamFailureStore failureStore) +public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore) implements SimpleDiffable, ToXContentObject { - public static final ParseField LIFECYCLE_FIELD = new ParseField("lifecycle"); public static final ParseField FAILURE_STORE_FIELD = new ParseField("failure_store"); public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "options", false, - (args, unused) -> new DataStreamOptions((DataStreamLifecycle) args[0], (DataStreamFailureStore) args[1]) + (args, unused) -> new DataStreamOptions((DataStreamFailureStore) args[0]) ); static { - PARSER.declareField( - ConstructingObjectParser.optionalConstructorArg(), - (p, c) -> DataStreamLifecycle.fromXContent(p), - LIFECYCLE_FIELD, - ObjectParser.ValueType.OBJECT_OR_NULL - ); PARSER.declareField( ConstructingObjectParser.optionalConstructorArg(), (p, c) -> DataStreamFailureStore.fromXContent(p), @@ -59,20 +51,24 @@ public record DataStreamOptions(@Nullable DataStreamLifecycle lifecycle, @Nullab } public DataStreamOptions() { - this(null, null); + this(null); } - public DataStreamOptions(StreamInput in) throws IOException { - this(in.readOptionalWriteable(DataStreamLifecycle::new), in.readOptionalWriteable(DataStreamFailureStore::new)); + public static DataStreamOptions read(StreamInput in) throws IOException { + return new DataStreamOptions(in.readOptionalWriteable(DataStreamFailureStore::new)); + } + + @Nullable + public DataStreamFailureStore getFailureStore() { + return failureStore; } public static Diff readDiffFrom(StreamInput in) throws IOException { - return SimpleDiffable.readDiffFrom(DataStreamOptions::new, in); + return SimpleDiffable.readDiffFrom(DataStreamOptions::read, in); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeOptionalWriteable(lifecycle); out.writeOptionalWriteable(failureStore); } @@ -84,9 +80,6 @@ public String toString() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - if (lifecycle != null) { - builder.field(LIFECYCLE_FIELD.getPreferredName(), lifecycle); - } if (failureStore != null) { builder.field(FAILURE_STORE_FIELD.getPreferredName(), failureStore); } diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java index 9f3abd0881dde..8a7cf2329b863 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamOptionsTests.java @@ -18,35 +18,23 @@ public class DataStreamOptionsTests extends AbstractXContentSerializingTestCase< @Override protected Writeable.Reader instanceReader() { - return DataStreamOptions::new; + return DataStreamOptions::read; } @Override protected DataStreamOptions createTestInstance() { - return new DataStreamOptions( - randomBoolean() ? null : DataStreamLifecycleTests.randomLifecycle(), - randomBoolean() ? null : DataStreamFailureStoreTests.randomFailureStore() - ); + return new DataStreamOptions(randomBoolean() ? null : DataStreamFailureStoreTests.randomFailureStore()); } @Override protected DataStreamOptions mutateInstance(DataStreamOptions instance) throws IOException { - var lifecycle = instance.lifecycle(); - var failureStore = instance.failureStore(); - if (randomBoolean()) { - if (lifecycle == null) { - lifecycle = DataStreamLifecycleTests.randomLifecycle(); - } else { - lifecycle = randomBoolean() ? null : randomValueOtherThan(lifecycle, DataStreamLifecycleTests::randomLifecycle); - } + var failureStore = instance.getFailureStore(); + if (failureStore == null) { + failureStore = DataStreamFailureStoreTests.randomFailureStore(); } else { - if (failureStore == null) { - failureStore = DataStreamFailureStoreTests.randomFailureStore(); - } else { - failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.enabled() == false); - } + failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.enabled() == false); } - return new DataStreamOptions(lifecycle, failureStore); + return new DataStreamOptions(failureStore); } @Override