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()));
}
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");
}
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);
}
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());
}
}
Aggregations