Search in sources :

Example 1 with IgnoreIndexTemplate

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;
}
Also used : IndexMappingFactory(org.graylog2.indexer.IndexMappingFactory) IgnoreIndexTemplate(org.graylog2.indexer.IgnoreIndexTemplate)

Example 2 with IgnoreIndexTemplate

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");
}
Also used : IndexTemplateNotFoundException(org.graylog2.indexer.IndexTemplateNotFoundException) IgnoreIndexTemplate(org.graylog2.indexer.IgnoreIndexTemplate) Test(org.junit.jupiter.api.Test)

Example 3 with IgnoreIndexTemplate

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();
}
Also used : IgnoreIndexTemplate(org.graylog2.indexer.IgnoreIndexTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with IgnoreIndexTemplate

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();
}
Also used : IgnoreIndexTemplate(org.graylog2.indexer.IgnoreIndexTemplate) Test(org.junit.jupiter.api.Test)

Example 5 with IgnoreIndexTemplate

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)));
        }
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexTemplateNotFoundException(org.graylog2.indexer.IndexTemplateNotFoundException) IgnoreIndexTemplate(org.graylog2.indexer.IgnoreIndexTemplate)

Aggregations

IgnoreIndexTemplate (org.graylog2.indexer.IgnoreIndexTemplate)5 Test (org.junit.jupiter.api.Test)3 IndexTemplateNotFoundException (org.graylog2.indexer.IndexTemplateNotFoundException)2 Nonnull (javax.annotation.Nonnull)1 IndexMappingFactory (org.graylog2.indexer.IndexMappingFactory)1 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)1 SearchVersion (org.graylog2.storage.SearchVersion)1