Search in sources :

Example 1 with DefaultIndexSetConfig

use of org.graylog2.indexer.indexset.DefaultIndexSetConfig in project graylog2-server by Graylog2.

the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration method upgrade.

@Override
public void upgrade() {
    if (clusterConfigService.get(MigrationCompleted.class) != null) {
        LOG.debug("Migration already completed!");
        return;
    }
    final ImmutableSet.Builder<String> updatedIds = ImmutableSet.builder();
    final ImmutableSet.Builder<String> skippedIds = ImmutableSet.builder();
    final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
    checkState(indexManagementConfig != null, "Couldn't find index management configuration");
    for (final IndexSetConfig indexSetConfig : indexSetService.findAll()) {
        final IndexSetConfig.Builder updated = indexSetConfig.toBuilder();
        if (isNullOrEmpty(indexSetConfig.rotationStrategyClass())) {
            // Paranoia
            checkState(indexSetConfig.rotationStrategy().type().startsWith(indexManagementConfig.rotationStrategy()), "rotation strategy config type <%s> does not match rotation strategy <%s>", indexSetConfig.rotationStrategy().type(), indexManagementConfig.rotationStrategy());
            LOG.info("Adding rotation_strategy_class <{}> to index set <{}>", indexManagementConfig.rotationStrategy(), indexSetConfig.id());
            updated.rotationStrategyClass(indexManagementConfig.rotationStrategy());
        }
        if (isNullOrEmpty(indexSetConfig.retentionStrategyClass())) {
            // Paranoia
            checkState(indexSetConfig.retentionStrategy().type().startsWith(indexManagementConfig.retentionStrategy()), "retention strategy config type <%s> does not match retention strategy <%s>", indexSetConfig.retentionStrategy().type(), indexManagementConfig.retentionStrategy());
            LOG.info("Adding retention_strategy_class <{}> to index set <{}>", indexManagementConfig.retentionStrategy(), indexSetConfig.id());
            updated.retentionStrategyClass(indexManagementConfig.retentionStrategy());
        }
        if (!indexSetConfig.equals(updated.build())) {
            indexSetService.save(updated.build());
            updatedIds.add(Optional.ofNullable(indexSetConfig.id()).orElseThrow(() -> new IllegalStateException("no id??")));
        } else {
            skippedIds.add(Optional.ofNullable(indexSetConfig.id()).orElseThrow(() -> new IllegalStateException("no id??")));
        }
    }
    // Mark the oldest index set (there should be only one at this point, though) as default.
    final IndexSetConfig defaultIndexSetConfig = indexSetService.findAll().stream().sorted(Comparator.comparing(IndexSetConfig::creationDate)).findFirst().orElseThrow(() -> new IllegalStateException("Unable to find any index set - this should not happen!"));
    LOG.info("Setting index set <{}> as default", defaultIndexSetConfig.id());
    clusterConfigService.write(DefaultIndexSetConfig.create(defaultIndexSetConfig.id()));
    clusterConfigService.write(MigrationCompleted.create(updatedIds.build(), skippedIds.build(), defaultIndexSetConfig.id()));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig)

Example 2 with DefaultIndexSetConfig

use of org.graylog2.indexer.indexset.DefaultIndexSetConfig in project graylog2-server by Graylog2.

the class V20161215163900_MoveIndexSetDefaultConfigTest method upgrade.

@Test
@MongoDBFixtures("V20161215163900_MoveIndexSetDefaultConfigTest.json")
public void upgrade() throws Exception {
    final long count = collection.count();
    migration.upgrade();
    final MigrationCompleted migrationCompleted = clusterConfigService.get(MigrationCompleted.class);
    assertThat(collection.count()).withFailMessage("No document should be deleted by the migration!").isEqualTo(count);
    assertThat(collection.count(Filters.exists("default"))).withFailMessage("The migration should have deleted the \"default\" field from the documents!").isEqualTo(0L);
    assertThat(clusterConfigService.get(DefaultIndexSetConfig.class)).withFailMessage("The DefaultIndexSetConfig should have been written to cluster config!").isNotNull();
    assertThat(clusterConfigService.get(DefaultIndexSetConfig.class).defaultIndexSetId()).isEqualTo("57f3d721a43c2d59cb750001");
    assertThat(migrationCompleted).isNotNull();
    assertThat(migrationCompleted.indexSetIds()).containsExactlyInAnyOrder("57f3d721a43c2d59cb750001", "57f3d721a43c2d59cb750003");
}
Also used : DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) MigrationCompleted(org.graylog2.migrations.V20161215163900_MoveIndexSetDefaultConfig.MigrationCompleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with DefaultIndexSetConfig

use of org.graylog2.indexer.indexset.DefaultIndexSetConfig in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method setDefaultMakesIndexDefaultIfWritable.

@Test
public void setDefaultMakesIndexDefaultIfWritable() throws Exception {
    final String indexSetId = "newDefaultIndexSetId";
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = IndexSetConfig.create(indexSetId, "title", "description", true, true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", null, 1, false);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetService.get(indexSetId)).thenReturn(Optional.of(indexSetConfig));
    indexSetsResource.setDefault(indexSetId);
    final ArgumentCaptor<DefaultIndexSetConfig> defaultIndexSetIdCaptor = ArgumentCaptor.forClass(DefaultIndexSetConfig.class);
    verify(clusterConfigService, times(1)).write(defaultIndexSetIdCaptor.capture());
    final DefaultIndexSetConfig defaultIndexSetConfig = defaultIndexSetIdCaptor.getValue();
    assertThat(defaultIndexSetConfig).isNotNull();
    assertThat(defaultIndexSetConfig.defaultIndexSetId()).isEqualTo(indexSetId);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 4 with DefaultIndexSetConfig

use of org.graylog2.indexer.indexset.DefaultIndexSetConfig in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method updateFailsWhenDefaultSetIsSetReadOnly.

@Test
public void updateFailsWhenDefaultSetIsSetReadOnly() throws Exception {
    final String defaultIndexSetId = "defaultIndexSet";
    final IndexSetConfig defaultIndexSetConfig = IndexSetConfig.create(defaultIndexSetId, "title", "description", true, true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", null, 1, false);
    when(indexSetService.getDefault()).thenReturn(defaultIndexSetConfig);
    when(indexSetService.get(defaultIndexSetId)).thenReturn(Optional.of(defaultIndexSetConfig));
    final IndexSetConfig defaultIndexSetConfigSetReadOnly = defaultIndexSetConfig.toBuilder().isWritable(false).build();
    expectedException.expect(ClientErrorException.class);
    expectedException.expectMessage("Default index set must be writable.");
    try {
        indexSetsResource.update("defaultIndexSet", IndexSetUpdateRequest.fromIndexSetConfig(defaultIndexSetConfigSetReadOnly));
    } finally {
        verify(indexSetService, never()).save(any());
    }
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)4 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)3 Test (org.junit.Test)3 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)2 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)1 IndexSet (org.graylog2.indexer.IndexSet)1 IndexManagementConfig (org.graylog2.indexer.management.IndexManagementConfig)1 MigrationCompleted (org.graylog2.migrations.V20161215163900_MoveIndexSetDefaultConfig.MigrationCompleted)1