use of org.graylog2.indexer.IgnoreIndexTemplate in project graylog2-server by Graylog2.
the class IndicesIT method createThrowingIndexMappingFactory.
private IndexMappingFactory createThrowingIndexMappingFactory(IndexSetConfig indexSetConfig) {
final IndexMappingFactory indexMappingFactory = mock(IndexMappingFactory.class);
when(indexMappingFactory.createIndexMapping(any())).thenThrow(new IgnoreIndexTemplate(true, "Reason", indexSetConfig.indexPrefix(), indexSetConfig.indexTemplateName(), indexSetConfig.indexTemplateType().orElse(null)));
return indexMappingFactory;
}
use of org.graylog2.indexer.IgnoreIndexTemplate in project graylog2-server by Graylog2.
the class IndicesTest method ensureIndexTemplate_IfIndexTemplateDoesntExistOnIgnoreIndexTemplateAndFailOnMissingTemplateIsTrue_thenExceptionThrown.
@Test
public void ensureIndexTemplate_IfIndexTemplateDoesntExistOnIgnoreIndexTemplateAndFailOnMissingTemplateIsTrue_thenExceptionThrown() {
when(indexMappingFactory.createIndexMapping(any())).thenThrow(new IgnoreIndexTemplate(true, "Reasom", "test", "test-template", null));
when(indicesAdapter.indexTemplateExists("test-template")).thenReturn(false);
assertThatCode(() -> underTest.ensureIndexTemplate(indexSetConfig("test", "test-template", "custom"))).isExactlyInstanceOf(IndexTemplateNotFoundException.class).hasMessage("No index template with name 'test-template' (type - 'custom') found in Elasticsearch");
}
use of org.graylog2.indexer.IgnoreIndexTemplate in project graylog2-server by Graylog2.
the class IndicesTest method ensureIndexTemplate_IfIndexTemplateDoesntExistOnIgnoreIndexTemplateAndFailOnMissingTemplateIsFalse_thenNoExceptionThrown.
@Test
public void ensureIndexTemplate_IfIndexTemplateDoesntExistOnIgnoreIndexTemplateAndFailOnMissingTemplateIsFalse_thenNoExceptionThrown() {
when(indexMappingFactory.createIndexMapping(any())).thenThrow(new IgnoreIndexTemplate(false, "Reasom", "test", "test-template", null));
assertThatCode(() -> underTest.ensureIndexTemplate(indexSetConfig("test", "test-template", "custom"))).doesNotThrowAnyException();
}
use of org.graylog2.indexer.IgnoreIndexTemplate in project graylog2-server by Graylog2.
the class IndicesTest method ensureIndexTemplate_IfIndexTemplateExistsOnIgnoreIndexTemplate_thenNoExceptionThrown.
@Test
public void ensureIndexTemplate_IfIndexTemplateExistsOnIgnoreIndexTemplate_thenNoExceptionThrown() {
when(indexMappingFactory.createIndexMapping(any())).thenThrow(new IgnoreIndexTemplate(true, "Reasom", "test", "test-template", null));
when(indicesAdapter.indexTemplateExists("test-template")).thenReturn(true);
assertThatCode(() -> underTest.ensureIndexTemplate(indexSetConfig("test", "test-template", "custom"))).doesNotThrowAnyException();
}
use of org.graylog2.indexer.IgnoreIndexTemplate in project graylog2-server by Graylog2.
the class Indices method ensureIndexTemplate.
public void ensureIndexTemplate(IndexSet indexSet) {
final IndexSetConfig indexSetConfig = indexSet.getConfig();
final String templateName = indexSetConfig.indexTemplateName();
try {
final Map<String, Object> template = buildTemplate(indexSet, indexSetConfig);
if (indicesAdapter.ensureIndexTemplate(templateName, template)) {
LOG.info("Successfully ensured index template {}", templateName);
} else {
LOG.warn("Failed to create index template {}", templateName);
}
} catch (IgnoreIndexTemplate e) {
LOG.warn(e.getMessage());
if (e.isFailOnMissingTemplate() && !indicesAdapter.indexTemplateExists(templateName)) {
throw new IndexTemplateNotFoundException(f("No index template with name '%s' (type - '%s') found in Elasticsearch", templateName, indexSetConfig.indexTemplateType().orElse(null)));
}
}
}
Aggregations