use of org.graylog2.indexer.searches.SearchesClusterConfig in project graylog2-server by Graylog2.
the class V20151210140600_ElasticsearchConfigMigration method upgrade.
// Migrate old Elasticsearch config settings to new ClusterConfig based ones.
@Override
public void upgrade() {
// All default rotation strategy settings.
final MessageCountRotationStrategyConfig messageCountRotationStrategyConfig = clusterConfigService.get(MessageCountRotationStrategyConfig.class);
final SizeBasedRotationStrategyConfig sizeBasedRotationStrategyConfig = clusterConfigService.get(SizeBasedRotationStrategyConfig.class);
final TimeBasedRotationStrategyConfig timeBasedRotationStrategyConfig = clusterConfigService.get(TimeBasedRotationStrategyConfig.class);
if (messageCountRotationStrategyConfig == null) {
final MessageCountRotationStrategyConfig countConfig = MessageCountRotationStrategyConfig.create(elasticsearchConfiguration.getMaxDocsPerIndex());
clusterConfigService.write(countConfig);
LOG.info("Migrated \"{}\" setting: {}", "elasticsearch_max_docs_per_index", countConfig);
}
if (sizeBasedRotationStrategyConfig == null) {
final SizeBasedRotationStrategyConfig sizeConfig = SizeBasedRotationStrategyConfig.create(elasticsearchConfiguration.getMaxSizePerIndex());
clusterConfigService.write(sizeConfig);
LOG.info("Migrated \"{}\" setting: {}", "elasticsearch_max_size_per_index", sizeConfig);
}
if (timeBasedRotationStrategyConfig == null) {
final TimeBasedRotationStrategyConfig timeConfig = TimeBasedRotationStrategyConfig.create(elasticsearchConfiguration.getMaxTimePerIndex(), elasticsearchConfiguration.getMaxWriteIndexAge());
clusterConfigService.write(timeConfig);
LOG.info("Migrated \"{}\" setting: {}", "elasticsearch_max_time_per_index", timeConfig);
}
// All default retention strategy settings
final ClosingRetentionStrategyConfig closingRetentionStrategyConfig = clusterConfigService.get(ClosingRetentionStrategyConfig.class);
final DeletionRetentionStrategyConfig deletionRetentionStrategyConfig = clusterConfigService.get(DeletionRetentionStrategyConfig.class);
if (closingRetentionStrategyConfig == null) {
final ClosingRetentionStrategyConfig closingConfig = ClosingRetentionStrategyConfig.create(elasticsearchConfiguration.getMaxNumberOfIndices());
clusterConfigService.write(closingConfig);
LOG.info("Migrated \"{}\" setting: {}", "elasticsearch_max_number_of_indices", closingConfig);
}
if (deletionRetentionStrategyConfig == null) {
final DeletionRetentionStrategyConfig deletionConfig = DeletionRetentionStrategyConfig.create(elasticsearchConfiguration.getMaxNumberOfIndices());
clusterConfigService.write(deletionConfig);
LOG.info("Migrated \"{}\" setting: {}", "elasticsearch_max_number_of_indices", deletionConfig);
}
// Selected rotation and retention strategies.
final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
if (indexManagementConfig == null) {
final Class<? extends RotationStrategy> rotationStrategyClass;
switch(elasticsearchConfiguration.getRotationStrategy()) {
case "size":
rotationStrategyClass = SizeBasedRotationStrategy.class;
break;
case "time":
rotationStrategyClass = TimeBasedRotationStrategy.class;
break;
case "count":
rotationStrategyClass = MessageCountRotationStrategy.class;
break;
default:
LOG.warn("Unknown retention strategy \"{}\"", elasticsearchConfiguration.getRotationStrategy());
rotationStrategyClass = MessageCountRotationStrategy.class;
}
final Class<? extends RetentionStrategy> retentionStrategyClass;
switch(elasticsearchConfiguration.getRetentionStrategy()) {
case "close":
retentionStrategyClass = ClosingRetentionStrategy.class;
break;
case "delete":
retentionStrategyClass = DeletionRetentionStrategy.class;
break;
default:
LOG.warn("Unknown retention strategy \"{}\"", elasticsearchConfiguration.getRetentionStrategy());
retentionStrategyClass = DeletionRetentionStrategy.class;
}
final IndexManagementConfig config = IndexManagementConfig.create(rotationStrategyClass.getCanonicalName(), retentionStrategyClass.getCanonicalName());
clusterConfigService.write(config);
LOG.info("Migrated \"{}\" and \"{}\" setting: {}", "rotation_strategy", "retention_strategy", config);
}
final SearchesClusterConfig searchesClusterConfig = clusterConfigService.get(SearchesClusterConfig.class);
if (searchesClusterConfig == null) {
final SearchesClusterConfig config = SearchesClusterConfig.createDefault();
LOG.info("Creating searches cluster config: {}", config);
clusterConfigService.write(config);
}
}
use of org.graylog2.indexer.searches.SearchesClusterConfig in project graylog2-server by Graylog2.
the class SearchConfigProvider method get.
@Override
public SearchConfig get() {
final SearchesClusterConfig searchesClusterConfig = clusterConfigService.get(SearchesClusterConfig.class);
final Period queryTimeRangeLimit = Optional.ofNullable(searchesClusterConfig).map(SearchesClusterConfig::queryTimeRangeLimit).orElse(Period.ZERO);
return new SearchConfig(queryTimeRangeLimit);
}
use of org.graylog2.indexer.searches.SearchesClusterConfig in project graylog2-server by Graylog2.
the class SearchResource method restrictTimeRange.
protected org.graylog2.plugin.indexer.searches.timeranges.TimeRange restrictTimeRange(final org.graylog2.plugin.indexer.searches.timeranges.TimeRange timeRange) {
final DateTime originalFrom = timeRange.getFrom();
final DateTime to = timeRange.getTo();
final DateTime from;
final SearchesClusterConfig config = clusterConfigService.get(SearchesClusterConfig.class);
if (config == null || Period.ZERO.equals(config.queryTimeRangeLimit())) {
from = originalFrom;
} else {
final DateTime limitedFrom = to.minus(config.queryTimeRangeLimit());
from = limitedFrom.isAfter(originalFrom) ? limitedFrom : originalFrom;
}
return AbsoluteRange.create(from, to);
}
Aggregations