Skip to content

Commit 692c356

Browse files
committed
self-review
1 parent 430dbd4 commit 692c356

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

modules/data-streams/src/test/java/org/elasticsearch/datastreams/MetadataIndexTemplateServiceTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
3535
import org.elasticsearch.test.ESSingleNodeTestCase;
3636

37-
import java.time.Instant;
3837
import java.util.ArrayList;
3938
import java.util.Collections;
4039
import java.util.List;
@@ -217,8 +216,7 @@ private MetadataIndexTemplateService getMetadataIndexTemplateService() {
217216
xContentRegistry(),
218217
EmptySystemIndices.INSTANCE,
219218
indexSettingProviders,
220-
DataStreamGlobalRetentionSettings.create(ClusterSettings.createBuiltInClusterSettings()),
221-
Instant::now
219+
DataStreamGlobalRetentionSettings.create(ClusterSettings.createBuiltInClusterSettings())
222220
);
223221
}
224222

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.component_template/20_tracking.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ setup:
1919
number_of_shards: 1
2020
created_date: "2025-07-04T12:50:48.415Z"
2121
- match: { status: 400 }
22-
- match: { error.reason: "Validation Failed: 1: Provided a pipeline property which is managed by the system: created_date.;" }
22+
- match: { error.reason: "Validation Failed: 1: Provided a template property which is managed by the system: created_date;" }
2323

2424
---
2525
"Test PUT setting modified_date":
@@ -33,7 +33,7 @@ setup:
3333
number_of_shards: 1
3434
modified_date: "2025-07-04T12:50:48.415Z"
3535
- match: { status: 400 }
36-
- match: { error.reason: "Validation Failed: 1: Provided a pipeline property which is managed by the system: modified_date.;" }
36+
- match: { error.reason: "Validation Failed: 1: Provided a template property which is managed by the system: modified_date;" }
3737

3838
---
3939
"Test update preserves created_date but updates modified_date":
@@ -53,6 +53,7 @@ setup:
5353
- set: { component_templates.0.component_template.modified_date: first_modified }
5454
- match: { $first_created: "/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/" }
5555
- match: { $first_modified: "/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/" }
56+
- match: { $first_created: $first_modified }
5657

5758
- do:
5859
cluster.put_component_template:
@@ -66,7 +67,5 @@ setup:
6667
cluster.get_component_template:
6768
name: test_tracking
6869
- set: { component_templates.0.component_template.created_date: second_created }
69-
- set: { component_templates.0.component_template.modified_date: second_modified }
7070
- match: { $second_created: $first_created }
71-
- gt: { $second_modified: $first_modified }
7271

server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutComponentTemplateAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ public ActionRequestValidationException validate() {
8181
}
8282
if (componentTemplate.createdDateMillis().isPresent()) {
8383
validationException = addValidationError(
84-
"Provided a pipeline property which is managed by the system: created_date.",
84+
"Provided a template property which is managed by the system: created_date",
8585
validationException
8686
);
8787
}
8888
if (componentTemplate.modifiedDateMillis().isPresent()) {
8989
validationException = addValidationError(
90-
"Provided a pipeline property which is managed by the system: modified_date.",
90+
"Provided a template property which is managed by the system: modified_date",
9191
validationException
9292
);
9393
}

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.elasticsearch.xcontent.NamedXContentRegistry;
5858

5959
import java.io.IOException;
60+
import java.time.Instant;
6061
import java.time.InstantSource;
6162
import java.util.ArrayList;
6263
import java.util.Arrays;
@@ -187,6 +188,30 @@ public void onFailure(Exception e) {
187188

188189
@Inject
189190
public MetadataIndexTemplateService(
191+
ClusterService clusterService,
192+
MetadataCreateIndexService metadataCreateIndexService,
193+
IndicesService indicesService,
194+
IndexScopedSettings indexScopedSettings,
195+
NamedXContentRegistry xContentRegistry,
196+
SystemIndices systemIndices,
197+
IndexSettingProviders indexSettingProviders,
198+
DataStreamGlobalRetentionSettings globalRetentionSettings
199+
) {
200+
this(
201+
clusterService,
202+
metadataCreateIndexService,
203+
indicesService,
204+
indexScopedSettings,
205+
xContentRegistry,
206+
systemIndices,
207+
indexSettingProviders,
208+
globalRetentionSettings,
209+
Instant::now
210+
);
211+
}
212+
213+
// constructor allowing for injection of InstantSource/time for testing
214+
MetadataIndexTemplateService(
190215
ClusterService clusterService,
191216
MetadataCreateIndexService metadataCreateIndexService,
192217
IndicesService indicesService,

server/src/main/java/org/elasticsearch/node/NodeConstruction.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@
228228
import java.io.Closeable;
229229
import java.io.IOException;
230230
import java.io.UncheckedIOException;
231-
import java.time.Instant;
232-
import java.time.InstantSource;
233231
import java.util.ArrayList;
234232
import java.util.Arrays;
235233
import java.util.Collection;
@@ -1302,7 +1300,6 @@ public Map<String, String> queryFields() {
13021300
b.bind(ShutdownPrepareService.class).toInstance(shutdownPrepareService);
13031301
b.bind(OnlinePrewarmingService.class).toInstance(onlinePrewarmingService);
13041302
b.bind(MergeMetrics.class).toInstance(mergeMetrics);
1305-
b.bind(InstantSource.class).toInstance(Instant::now);
13061303
});
13071304

13081305
if (ReadinessService.enabled(environment)) {
@@ -1658,8 +1655,7 @@ private List<ReservedProjectStateHandler<?>> buildReservedProjectStateHandlers(
16581655
xContentRegistry,
16591656
systemIndices,
16601657
indexSettingProviders,
1661-
globalRetentionSettings,
1662-
Instant::now
1658+
globalRetentionSettings
16631659
);
16641660
reservedStateHandlers.add(new ReservedComposableIndexTemplateAction(templateService, settingsModule.getIndexScopedSettings()));
16651661

server/src/test/java/org/elasticsearch/action/admin/indices/template/reservedstate/ReservedComposableIndexTemplateActionTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.junit.Before;
5555

5656
import java.io.IOException;
57-
import java.time.Instant;
5857
import java.util.Collections;
5958
import java.util.Map;
6059
import java.util.Set;
@@ -106,8 +105,7 @@ public void setup() throws IOException {
106105
mock(NamedXContentRegistry.class),
107106
mock(SystemIndices.class),
108107
new IndexSettingProviders(Set.of()),
109-
globalRetentionSettings,
110-
Instant::now
108+
globalRetentionSettings
111109
);
112110
}
113111

@@ -898,8 +896,7 @@ public void testTemplatesWithReservedPrefix() throws Exception {
898896
mock(NamedXContentRegistry.class),
899897
mock(SystemIndices.class),
900898
new IndexSettingProviders(Set.of()),
901-
globalRetentionSettings,
902-
Instant::now
899+
globalRetentionSettings
903900
);
904901

905902
ClusterState state = ClusterState.builder(new ClusterName("elasticsearch"))

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,8 +2852,7 @@ private static List<Throwable> putTemplate(NamedXContentRegistry xContentRegistr
28522852
xContentRegistry,
28532853
EmptySystemIndices.INSTANCE,
28542854
new IndexSettingProviders(Set.of()),
2855-
DataStreamGlobalRetentionSettings.create(ClusterSettings.createBuiltInClusterSettings()),
2856-
Instant::now
2855+
DataStreamGlobalRetentionSettings.create(ClusterSettings.createBuiltInClusterSettings())
28572856
);
28582857

28592858
final List<Throwable> throwables = new ArrayList<>();

0 commit comments

Comments
 (0)