|
@@ -17,7 +17,10 @@ import org.elasticsearch.common.collect.Iterators;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
|
|
|
+import org.elasticsearch.xcontent.ConstructingObjectParser;
|
|
|
+import org.elasticsearch.xcontent.ParseField;
|
|
|
import org.elasticsearch.xcontent.ToXContent;
|
|
|
+import org.elasticsearch.xcontent.XContentParser;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.EnumSet;
|
|
@@ -32,6 +35,14 @@ public class StreamsMetadata extends AbstractNamedDiffable<Metadata.ProjectCusto
|
|
|
|
|
|
public static final String TYPE = "streams";
|
|
|
public static final StreamsMetadata EMPTY = new StreamsMetadata(false);
|
|
|
+ private static final ParseField LOGS_ENABLED = new ParseField("logs_enabled");
|
|
|
+ private static final ConstructingObjectParser<StreamsMetadata, Void> PARSER = new ConstructingObjectParser<>(TYPE, false, args -> {
|
|
|
+ boolean logsEnabled = (boolean) args[0];
|
|
|
+ return new StreamsMetadata(logsEnabled);
|
|
|
+ });
|
|
|
+ static {
|
|
|
+ PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), LOGS_ENABLED);
|
|
|
+ }
|
|
|
|
|
|
public boolean logsEnabled;
|
|
|
|
|
@@ -79,7 +90,9 @@ public class StreamsMetadata extends AbstractNamedDiffable<Metadata.ProjectCusto
|
|
|
|
|
|
@Override
|
|
|
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
|
|
|
- return Iterators.concat(ChunkedToXContentHelper.chunk((builder, bParams) -> builder.field("logs_enabled", logsEnabled)));
|
|
|
+ return Iterators.concat(
|
|
|
+ ChunkedToXContentHelper.chunk((builder, bParams) -> builder.field(LOGS_ENABLED.getPreferredName(), logsEnabled))
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -95,4 +108,8 @@ public class StreamsMetadata extends AbstractNamedDiffable<Metadata.ProjectCusto
|
|
|
public int hashCode() {
|
|
|
return Objects.hashCode(logsEnabled);
|
|
|
}
|
|
|
+
|
|
|
+ public static StreamsMetadata fromXContent(XContentParser parser) throws IOException {
|
|
|
+ return PARSER.parse(parser, null);
|
|
|
+ }
|
|
|
}
|