|
@@ -427,9 +427,9 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
ComponentTemplate componentTemplate = new ComponentTemplate(template, 1L, new HashMap<>());
|
|
|
project = metadataIndexTemplateService.addComponentTemplate(project, false, "foo", componentTemplate);
|
|
|
|
|
|
- ComponentTemplate foo = project.componentTemplates().get("foo");
|
|
|
- ComponentTemplate expectedFoo = new ComponentTemplate(template, 1L, Map.of(), null, 0L, 0L);
|
|
|
- assertThat(foo, equalTo(expectedFoo));
|
|
|
+ ComponentTemplate actualTemplateFoo = project.componentTemplates().get("foo");
|
|
|
+ ComponentTemplate expectedTemplateFoo = new ComponentTemplate(template, 1L, Map.of(), null, 0L, 0L);
|
|
|
+ assertThat(actualTemplateFoo, equalTo(expectedTemplateFoo));
|
|
|
|
|
|
ProjectMetadata throwState = ProjectMetadata.builder(project).build();
|
|
|
IllegalArgumentException e = expectThrows(
|
|
@@ -533,8 +533,8 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
ComposableIndexTemplate template = ComposableIndexTemplateTests.randomInstance();
|
|
|
project = metadataIndexTemplateService.addIndexTemplateV2(project, false, "foo", template);
|
|
|
|
|
|
- assertNotNull(project.templatesV2().get("foo"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("foo"), template);
|
|
|
+ final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
|
|
|
|
|
|
ComposableIndexTemplate newTemplate = randomValueOtherThanMany(
|
|
|
t -> Objects.equals(template.priority(), t.priority()),
|
|
@@ -558,16 +558,16 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
ComposableIndexTemplate template = ComposableIndexTemplateTests.randomInstance();
|
|
|
project = metadataIndexTemplateService.addIndexTemplateV2(project, false, "foo", template);
|
|
|
|
|
|
- assertNotNull(project.templatesV2().get("foo"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("foo"), template);
|
|
|
+ final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
|
|
|
|
|
|
List<String> patterns = new ArrayList<>(template.indexPatterns());
|
|
|
patterns.add("new-pattern");
|
|
|
template = template.toBuilder().indexPatterns(patterns).build();
|
|
|
project = metadataIndexTemplateService.addIndexTemplateV2(project, false, "foo", template);
|
|
|
|
|
|
- assertNotNull(project.templatesV2().get("foo"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("foo"), template);
|
|
|
+ final ComposableIndexTemplate updatedExpectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(2L).build();
|
|
|
+ assertTemplatesEqual(updatedExpectedTemplateFoo, project.templatesV2().get("foo"));
|
|
|
}
|
|
|
|
|
|
public void testRemoveIndexTemplateV2() throws Exception {
|
|
@@ -581,8 +581,8 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
assertThat(e.getMessage(), equalTo("index_template [foo] missing"));
|
|
|
|
|
|
ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", template);
|
|
|
- assertNotNull(project.templatesV2().get("foo"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("foo"), template);
|
|
|
+ final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
|
|
|
|
|
|
ProjectMetadata updatedState = MetadataIndexTemplateService.innerRemoveIndexTemplateV2(project, "foo");
|
|
|
assertNull(updatedState.templatesV2().get("foo"));
|
|
@@ -598,7 +598,8 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
ProjectMetadata project = metadataIndexTemplateService.addIndexTemplateV2(initialProject, false, "foo", template);
|
|
|
assertThat(project.templatesV2().get("foo"), notNullValue());
|
|
|
|
|
|
- assertTemplatesEqual(project.templatesV2().get("foo"), template);
|
|
|
+ final ComposableIndexTemplate expectedTemplateFoo = template.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
|
|
|
|
|
|
Exception e = expectThrows(
|
|
|
IndexTemplateMissingException.class,
|
|
@@ -620,12 +621,12 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", fooTemplate);
|
|
|
project = service.addIndexTemplateV2(project, false, "bar", barTemplate);
|
|
|
project = service.addIndexTemplateV2(project, false, "baz", bazTemplate);
|
|
|
- assertNotNull(project.templatesV2().get("foo"));
|
|
|
- assertNotNull(project.templatesV2().get("bar"));
|
|
|
- assertNotNull(project.templatesV2().get("baz"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("foo"), fooTemplate);
|
|
|
- assertTemplatesEqual(project.templatesV2().get("bar"), barTemplate);
|
|
|
- assertTemplatesEqual(project.templatesV2().get("baz"), bazTemplate);
|
|
|
+ final ComposableIndexTemplate expectedTemplateFoo = fooTemplate.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ final ComposableIndexTemplate expectedTemplateBar = barTemplate.toBuilder().createdDate(2L).modifiedDate(2L).build();
|
|
|
+ final ComposableIndexTemplate expectedTemplateBaz = bazTemplate.toBuilder().createdDate(4L).modifiedDate(4L).build();
|
|
|
+ assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
|
|
|
+ assertTemplatesEqual(expectedTemplateBar, project.templatesV2().get("bar"));
|
|
|
+ assertTemplatesEqual(expectedTemplateBaz, project.templatesV2().get("baz"));
|
|
|
|
|
|
ProjectMetadata updatedState = MetadataIndexTemplateService.innerRemoveIndexTemplateV2(project, "foo", "baz");
|
|
|
assertNull(updatedState.templatesV2().get("foo"));
|
|
@@ -653,12 +654,13 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
);
|
|
|
assertThat(e.getMessage(), equalTo("index_template [b*,k*,*] missing"));
|
|
|
|
|
|
- assertNotNull(project.templatesV2().get("foo"));
|
|
|
- assertNotNull(project.templatesV2().get("bar"));
|
|
|
- assertNotNull(project.templatesV2().get("baz"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("foo"), fooTemplate);
|
|
|
- assertTemplatesEqual(project.templatesV2().get("bar"), barTemplate);
|
|
|
- assertTemplatesEqual(project.templatesV2().get("baz"), bazTemplate);
|
|
|
+ final ComposableIndexTemplate expectedTemplateFoo = fooTemplate.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ final ComposableIndexTemplate expectedTemplateBar = barTemplate.toBuilder().createdDate(2L).modifiedDate(2L).build();
|
|
|
+ final ComposableIndexTemplate expectedTemplateBaz = bazTemplate.toBuilder().createdDate(4L).modifiedDate(4L).build();
|
|
|
+
|
|
|
+ assertTemplatesEqual(expectedTemplateFoo, project.templatesV2().get("foo"));
|
|
|
+ assertTemplatesEqual(expectedTemplateBar, project.templatesV2().get("bar"));
|
|
|
+ assertTemplatesEqual(expectedTemplateBaz, project.templatesV2().get("baz"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -681,8 +683,8 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
+ "take precedence during new index creation"
|
|
|
);
|
|
|
|
|
|
- assertNotNull(project.templatesV2().get("v2-template"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("v2-template"), v2Template);
|
|
|
+ final ComposableIndexTemplate expectedV2Template = v2Template.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ assertTemplatesEqual(expectedV2Template, project.templatesV2().get("v2-template"));
|
|
|
}
|
|
|
|
|
|
public void testPutGlobalV2TemplateWhichResolvesIndexHiddenSetting() throws Exception {
|
|
@@ -832,8 +834,8 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
+ "take precedence during new index creation"
|
|
|
);
|
|
|
|
|
|
- assertNotNull(project.templatesV2().get("v2-template"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("v2-template"), v2Template);
|
|
|
+ final ComposableIndexTemplate expectedV2Template = v2Template.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ assertTemplatesEqual(expectedV2Template, project.templatesV2().get("v2-template"));
|
|
|
|
|
|
// Now try to update the existing v1-template
|
|
|
|
|
@@ -872,8 +874,8 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
+ "take precedence during new index creation"
|
|
|
);
|
|
|
|
|
|
- assertNotNull(project.templatesV2().get("v2-template"));
|
|
|
- assertTemplatesEqual(project.templatesV2().get("v2-template"), v2Template);
|
|
|
+ final ComposableIndexTemplate expectedV2 = v2Template.toBuilder().createdDate(0L).modifiedDate(0L).build();
|
|
|
+ assertTemplatesEqual(expectedV2, project.templatesV2().get("v2-template"));
|
|
|
|
|
|
// Now try to update the existing v1-template
|
|
|
|
|
@@ -1932,15 +1934,36 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
|
|
|
ProjectMetadata result = innerRemoveComponentTemplate(projectMetadata, "foo");
|
|
|
// created_date and modified_date come from monotonically increasing clock
|
|
|
- ComponentTemplate expectedBar = new ComponentTemplate(bar.template(), bar.version(), bar.metadata(), bar.deprecated(), 1L, 1L);
|
|
|
- ComponentTemplate expectedBaz = new ComponentTemplate(baz.template(), baz.version(), baz.metadata(), baz.deprecated(), 2L, 2L);
|
|
|
+ ComponentTemplate expectedTemplateBar = new ComponentTemplate(
|
|
|
+ bar.template(),
|
|
|
+ bar.version(),
|
|
|
+ bar.metadata(),
|
|
|
+ bar.deprecated(),
|
|
|
+ 1L,
|
|
|
+ 1L
|
|
|
+ );
|
|
|
+ ComponentTemplate expectedTemplateBaz = new ComponentTemplate(
|
|
|
+ baz.template(),
|
|
|
+ baz.version(),
|
|
|
+ baz.metadata(),
|
|
|
+ baz.deprecated(),
|
|
|
+ 2L,
|
|
|
+ 2L
|
|
|
+ );
|
|
|
assertThat(result.componentTemplates().get("foo"), nullValue());
|
|
|
- assertThat(result.componentTemplates().get("bar"), equalTo(expectedBar));
|
|
|
- assertThat(result.componentTemplates().get("baz"), equalTo(expectedBaz));
|
|
|
+ assertThat(result.componentTemplates().get("bar"), equalTo(expectedTemplateBar));
|
|
|
+ assertThat(result.componentTemplates().get("baz"), equalTo(expectedTemplateBaz));
|
|
|
|
|
|
result = innerRemoveComponentTemplate(projectMetadata, "bar", "baz");
|
|
|
- ComponentTemplate expectedFoo = new ComponentTemplate(foo.template(), foo.version(), foo.metadata(), foo.deprecated(), 0L, 0L);
|
|
|
- assertThat(result.componentTemplates().get("foo"), equalTo(expectedFoo));
|
|
|
+ ComponentTemplate expectedTemplateFoo = new ComponentTemplate(
|
|
|
+ foo.template(),
|
|
|
+ foo.version(),
|
|
|
+ foo.metadata(),
|
|
|
+ foo.deprecated(),
|
|
|
+ 0L,
|
|
|
+ 0L
|
|
|
+ );
|
|
|
+ assertThat(result.componentTemplates().get("foo"), equalTo(expectedTemplateFoo));
|
|
|
assertThat(result.componentTemplates().get("bar"), nullValue());
|
|
|
assertThat(result.componentTemplates().get("baz"), nullValue());
|
|
|
|
|
@@ -1954,7 +1977,7 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
|
|
|
result = innerRemoveComponentTemplate(projectMetadata, "b*");
|
|
|
assertThat(result.componentTemplates().size(), equalTo(1));
|
|
|
- assertThat(result.componentTemplates().get("foo"), equalTo(expectedFoo));
|
|
|
+ assertThat(result.componentTemplates().get("foo"), equalTo(expectedTemplateFoo));
|
|
|
|
|
|
e = expectThrows(ResourceNotFoundException.class, () -> innerRemoveComponentTemplate(projectMetadata, "foo", "b*"));
|
|
|
assertThat(e.getMessage(), equalTo("b*"));
|
|
@@ -2826,6 +2849,85 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
assertThat(newTemplate.modifiedDateMillis().orElseThrow(), is(1L));
|
|
|
}
|
|
|
|
|
|
+ public void testIndexTemplateNoOpDoesNotChangeTracking() throws Exception {
|
|
|
+ final String name = "test-template";
|
|
|
+ final ProjectId projectId = randomProjectIdOrDefault();
|
|
|
+ final Template template = new Template(Settings.builder().put("index.number_of_shards", 1).build(), null, null);
|
|
|
+ final MetadataIndexTemplateService service = getMetadataIndexTemplateService();
|
|
|
+
|
|
|
+ // create template
|
|
|
+ final ComposableIndexTemplate indexTemplate = ComposableIndexTemplate.builder()
|
|
|
+ .indexPatterns(List.of("test-*"))
|
|
|
+ .template(template)
|
|
|
+ .priority(1L)
|
|
|
+ .build();
|
|
|
+ final ProjectMetadata initialMetadata = ProjectMetadata.builder(projectId).build();
|
|
|
+ final ProjectMetadata updatedMetadata = service.addIndexTemplateV2(initialMetadata, false, name, indexTemplate);
|
|
|
+ final ComposableIndexTemplate addedTemplate = updatedMetadata.templatesV2().get(name);
|
|
|
+ assertThat(addedTemplate.createdDateMillis().orElseThrow(), is(0L));
|
|
|
+ assertThat(addedTemplate.modifiedDateMillis().orElseThrow(), is(0L));
|
|
|
+
|
|
|
+ // update template which should result in NOP
|
|
|
+ final ProjectMetadata sameMetadata = service.addIndexTemplateV2(updatedMetadata, false, name, indexTemplate);
|
|
|
+ assertThat(sameMetadata, sameInstance(updatedMetadata));
|
|
|
+ final ComposableIndexTemplate unchangedTemplate = sameMetadata.templatesV2().get(name);
|
|
|
+ assertThat(unchangedTemplate.createdDateMillis().orElseThrow(), is(0L));
|
|
|
+ assertThat(unchangedTemplate.modifiedDateMillis().orElseThrow(), is(0L));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testIndexTemplateUpdateWithoutExistingTracking() throws Exception {
|
|
|
+ final String name = "test-template";
|
|
|
+ final ProjectId projectId = randomProjectIdOrDefault();
|
|
|
+ final MetadataIndexTemplateService service = getMetadataIndexTemplateService();
|
|
|
+ final ComposableIndexTemplate initialTemplate = ComposableIndexTemplate.builder()
|
|
|
+ .indexPatterns(List.of("test-*"))
|
|
|
+ .template(new Template(Settings.builder().put("index.number_of_shards", 1).build(), null, null))
|
|
|
+ .priority(1L)
|
|
|
+ .build();
|
|
|
+ final ProjectMetadata initialMetadata = ProjectMetadata.builder(projectId).put(name, initialTemplate).build();
|
|
|
+
|
|
|
+ final ComposableIndexTemplate updateTemplate = ComposableIndexTemplate.builder()
|
|
|
+ .indexPatterns(List.of("test-*"))
|
|
|
+ .template(new Template(Settings.builder().put("index.number_of_shards", 2).build(), null, null))
|
|
|
+ .priority(1L)
|
|
|
+ .build();
|
|
|
+ final ProjectMetadata afterCreateMetadata = service.addIndexTemplateV2(initialMetadata, false, name, updateTemplate);
|
|
|
+
|
|
|
+ final ComposableIndexTemplate newTemplate = afterCreateMetadata.templatesV2().get(name);
|
|
|
+ assertTrue(newTemplate.createdDateMillis().isEmpty());
|
|
|
+ assertThat(newTemplate.modifiedDateMillis().orElseThrow(), is(0L));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testIndexTemplateUpdateChangesModifiedDate() throws Exception {
|
|
|
+ final String name = "test-template";
|
|
|
+ final ProjectId projectId = randomProjectIdOrDefault();
|
|
|
+ final MetadataIndexTemplateService service = getMetadataIndexTemplateService();
|
|
|
+ final ProjectMetadata initialMetadata = ProjectMetadata.builder(projectId).build();
|
|
|
+ final Template template = new Template(Settings.builder().put("index.number_of_shards", 1).build(), null, null);
|
|
|
+
|
|
|
+ // create template
|
|
|
+ final ComposableIndexTemplate indexTemplate = ComposableIndexTemplate.builder()
|
|
|
+ .indexPatterns(List.of("test-*"))
|
|
|
+ .template(template)
|
|
|
+ .priority(1L)
|
|
|
+ .build();
|
|
|
+ final ProjectMetadata afterCreateMetadata = service.addIndexTemplateV2(initialMetadata, false, name, indexTemplate);
|
|
|
+ final ComposableIndexTemplate addedTemplate = afterCreateMetadata.templatesV2().get(name);
|
|
|
+ assertThat(addedTemplate.createdDateMillis().orElseThrow(), is(0L));
|
|
|
+ assertThat(addedTemplate.modifiedDateMillis().orElseThrow(), is(0L));
|
|
|
+
|
|
|
+ // update template
|
|
|
+ final ComposableIndexTemplate updatedIndexTemplate = ComposableIndexTemplate.builder()
|
|
|
+ .indexPatterns(List.of("test-*"))
|
|
|
+ .template(template)
|
|
|
+ .priority(2L)
|
|
|
+ .build();
|
|
|
+ final ProjectMetadata afterUpdateMetadata = service.addIndexTemplateV2(afterCreateMetadata, false, name, updatedIndexTemplate);
|
|
|
+ final ComposableIndexTemplate newTemplate = afterUpdateMetadata.templatesV2().get(name);
|
|
|
+ assertThat(newTemplate.createdDateMillis().orElseThrow(), is(0L));
|
|
|
+ assertThat(newTemplate.modifiedDateMillis().orElseThrow(), is(2L));
|
|
|
+ }
|
|
|
+
|
|
|
private static List<Throwable> putTemplate(NamedXContentRegistry xContentRegistry, PutRequest request) {
|
|
|
ThreadPool testThreadPool = mock(ThreadPool.class);
|
|
|
when(testThreadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
|
|
@@ -2923,7 +3025,7 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public static void assertTemplatesEqual(ComposableIndexTemplate actual, ComposableIndexTemplate expected) {
|
|
|
- assertEquals(actual, expected);
|
|
|
+ public static void assertTemplatesEqual(ComposableIndexTemplate expected, ComposableIndexTemplate actual) {
|
|
|
+ assertThat(actual, equalTo(expected));
|
|
|
}
|
|
|
}
|