Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.cluster.metadata.ComponentTemplate;
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.Nullable;
Expand Down Expand Up @@ -197,13 +196,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
builder.field(NAME.getPreferredName(), componentTemplate.getKey());
builder.field(COMPONENT_TEMPLATE.getPreferredName());
componentTemplate.getValue()
.toXContent(
builder,
DataStreamLifecycle.maybeAddEffectiveRetentionParams(params),
rolloverConfiguration,
globalRetention
);
componentTemplate.getValue().toXContent(builder, params, rolloverConfiguration);
builder.endObject();
}
builder.endArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.Nullable;
Expand Down Expand Up @@ -196,13 +195,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
builder.field(NAME.getPreferredName(), indexTemplate.getKey());
builder.field(INDEX_TEMPLATE.getPreferredName());
indexTemplate.getValue()
.toXContent(
builder,
DataStreamLifecycle.maybeAddEffectiveRetentionParams(params),
rolloverConfiguration,
globalRetention
);
indexTemplate.getValue().toXContent(builder, params, rolloverConfiguration);
builder.endObject();
}
builder.endArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration;
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -121,12 +120,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
if (this.resolvedTemplate != null) {
builder.field(TEMPLATE.getPreferredName());
this.resolvedTemplate.toXContent(
builder,
DataStreamLifecycle.maybeAddEffectiveRetentionParams(params),
rolloverConfiguration,
globalRetention
);
this.resolvedTemplate.toXContent(builder, params, rolloverConfiguration);
}
if (this.overlappingTemplates != null) {
builder.startArray(OVERLAPPING.getPreferredName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,17 @@ public String toString() {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return toXContent(builder, params, null, null);
return toXContent(builder, params, null);
}

/**
* Converts the component template to XContent and passes the RolloverConditions, when provided, to the template.
*/
public XContentBuilder toXContent(
XContentBuilder builder,
Params params,
@Nullable RolloverConfiguration rolloverConfiguration,
@Nullable DataStreamGlobalRetention globalRetention
) throws IOException {
public XContentBuilder toXContent(XContentBuilder builder, Params params, @Nullable RolloverConfiguration rolloverConfiguration)
throws IOException {
builder.startObject();
builder.field(TEMPLATE.getPreferredName());
this.template.toXContent(builder, params, rolloverConfiguration, globalRetention);
this.template.toXContent(builder, params, rolloverConfiguration);
if (this.version != null) {
builder.field(VERSION.getPreferredName(), this.version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,19 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return toXContent(builder, params, null, null);
return toXContent(builder, params, null);
}

/**
* Converts the composable index template to XContent and passes the RolloverConditions, when provided, to the template.
*/
public XContentBuilder toXContent(
XContentBuilder builder,
Params params,
@Nullable RolloverConfiguration rolloverConfiguration,
@Nullable DataStreamGlobalRetention globalRetention
) throws IOException {
public XContentBuilder toXContent(XContentBuilder builder, Params params, @Nullable RolloverConfiguration rolloverConfiguration)
throws IOException {
builder.startObject();
builder.stringListField(INDEX_PATTERNS.getPreferredName(), this.indexPatterns);
if (this.template != null) {
builder.field(TEMPLATE.getPreferredName());
this.template.toXContent(builder, params, rolloverConfiguration, globalRetention);
this.template.toXContent(builder, params, rolloverConfiguration);
}
if (this.componentTemplates != null) {
builder.stringListField(COMPOSED_OF.getPreferredName(), this.componentTemplates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,14 @@ public String toString() {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return toXContent(builder, params, null, null);
return toXContent(builder, params, null);
}

/**
* Converts the template to XContent and passes the RolloverConditions, when provided, to the lifecycle.
*/
public XContentBuilder toXContent(
XContentBuilder builder,
Params params,
@Nullable RolloverConfiguration rolloverConfiguration,
@Nullable DataStreamGlobalRetention globalRetention
) throws IOException {
public XContentBuilder toXContent(XContentBuilder builder, Params params, @Nullable RolloverConfiguration rolloverConfiguration)
throws IOException {
builder.startObject();
if (this.settings != null) {
builder.startObject(SETTINGS.getPreferredName());
Expand Down Expand Up @@ -254,7 +250,7 @@ public XContentBuilder toXContent(
}
if (this.lifecycle != null) {
builder.field(LIFECYCLE.getPreferredName());
lifecycle.toXContent(builder, params, rolloverConfiguration, globalRetention);
lifecycle.toXContent(builder, params, rolloverConfiguration, null);
}
builder.endObject();
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,20 @@ public void testXContentSerializationWithRolloverAndEffectiveRetention() throws
RolloverConfiguration rolloverConfiguration = RolloverConfigurationTests.randomRolloverConditions();
DataStreamGlobalRetention globalRetention = DataStreamGlobalRetentionTests.randomGlobalRetention();
ToXContent.Params withEffectiveRetention = new ToXContent.MapParams(DataStreamLifecycle.INCLUDE_EFFECTIVE_RETENTION_PARAMS);
template.toXContent(builder, withEffectiveRetention, rolloverConfiguration, globalRetention);
template.toXContent(builder, withEffectiveRetention, rolloverConfiguration);
String serialized = Strings.toString(builder);
assertThat(serialized, containsString("rollover"));
for (String label : rolloverConfiguration.resolveRolloverConditions(lifecycle.getEffectiveDataRetention(globalRetention))
.getConditions()
.keySet()) {
assertThat(serialized, containsString(label));
}
// We check that even if there was no retention provided by the user, the global retention applies
/*
* A template does not have a global retention and the lifecycle has no retention, so there will be no data_retention or
* effective_retention.
*/
assertThat(serialized, not(containsString("data_retention")));
if (globalRetention.getDefaultRetention() != null || globalRetention.getMaxRetention() != null) {
assertThat(serialized, containsString("effective_retention"));
} else {
assertThat(serialized, not(containsString("effective_retention")));
}
assertThat(serialized, not(containsString("effective_retention")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,20 @@ public void testXContentSerializationWithRolloverAndEffectiveRetention() throws
RolloverConfiguration rolloverConfiguration = RolloverConfigurationTests.randomRolloverConditions();
DataStreamGlobalRetention globalRetention = DataStreamGlobalRetentionTests.randomGlobalRetention();
ToXContent.Params withEffectiveRetention = new ToXContent.MapParams(DataStreamLifecycle.INCLUDE_EFFECTIVE_RETENTION_PARAMS);
template.toXContent(builder, withEffectiveRetention, rolloverConfiguration, globalRetention);
template.toXContent(builder, withEffectiveRetention, rolloverConfiguration);
String serialized = Strings.toString(builder);
assertThat(serialized, containsString("rollover"));
for (String label : rolloverConfiguration.resolveRolloverConditions(lifecycle.getEffectiveDataRetention(globalRetention))
.getConditions()
.keySet()) {
assertThat(serialized, containsString(label));
}
// We check that even if there was no retention provided by the user, the global retention applies
/*
* A template does not have a global retention and the lifecycle has no retention, so there will be no data_retention or
* effective_retention.
*/
assertThat(serialized, not(containsString("data_retention")));
if (globalRetention.getDefaultRetention() != null || globalRetention.getMaxRetention() != null) {
assertThat(serialized, containsString("effective_retention"));
} else {
assertThat(serialized, not(containsString("effective_retention")));
}
assertThat(serialized, not(containsString("effective_retention")));
}
}

Expand Down