Search in sources :

Example 1 with IndexSetConfig

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

the class V20161116172100_DefaultIndexSetMigration method upgrade.

@Override
public void upgrade() {
    // Do not run again if the migration marker can be found in the database.
    if (clusterConfigService.get(DefaultIndexSetCreated.class) != null) {
        return;
    }
    final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
    checkState(indexManagementConfig != null, "Couldn't find index management configuration");
    final IndexSetConfig config = IndexSetConfig.builder().title("Default index set").description("The Graylog default index set").indexPrefix(elasticsearchConfiguration.getIndexPrefix()).shards(elasticsearchConfiguration.getShards()).replicas(elasticsearchConfiguration.getReplicas()).rotationStrategy(getRotationStrategyConfig(indexManagementConfig)).retentionStrategy(getRetentionStrategyConfig(indexManagementConfig)).creationDate(ZonedDateTime.now(ZoneOffset.UTC)).indexAnalyzer(elasticsearchConfiguration.getAnalyzer()).indexTemplateName(elasticsearchConfiguration.getTemplateName()).indexOptimizationMaxNumSegments(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments()).indexOptimizationDisabled(elasticsearchConfiguration.isDisableIndexOptimization()).build();
    final IndexSetConfig savedConfig = indexSetService.save(config);
    clusterConfigService.write(DefaultIndexSetConfig.create(savedConfig.id()));
    clusterConfigService.write(DefaultIndexSetCreated.create());
    // Publish event to cluster event bus so the stream router will reload.
    clusterEventBus.post(IndexSetCreatedEvent.create(savedConfig));
    LOG.debug("Successfully created default index set: {}", savedConfig);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) DefaultIndexSetCreated(org.graylog2.indexer.indexset.DefaultIndexSetCreated) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig)

Example 2 with IndexSetConfig

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

the class V20161122174500_AssignIndexSetsToStreamsMigration method upgrade.

@Override
public void upgrade() {
    // Only run this migration once.
    if (clusterConfigService.get(MigrationCompleted.class) != null) {
        LOG.debug("Migration already completed.");
        return;
    }
    final IndexSetConfig indexSetConfig = findDefaultIndexSet();
    final ImmutableSet.Builder<String> completedStreamIds = ImmutableSet.builder();
    final ImmutableSet.Builder<String> failedStreamIds = ImmutableSet.builder();
    // index sets, so the only one that exists is the "default" one created by an earlier migration.
    for (Stream stream : streamService.loadAll()) {
        if (isNullOrEmpty(stream.getIndexSetId())) {
            LOG.info("Assigning index set <{}> ({}) to stream <{}> ({})", indexSetConfig.id(), indexSetConfig.title(), stream.getId(), stream.getTitle());
            stream.setIndexSetId(indexSetConfig.id());
            try {
                streamService.save(stream);
                completedStreamIds.add(stream.getId());
            } catch (ValidationException e) {
                LOG.error("Unable to save stream <{}>", stream.getId(), e);
                failedStreamIds.add(stream.getId());
            }
        }
    }
    // Mark this migration as done.
    clusterConfigService.write(MigrationCompleted.create(indexSetConfig.id(), completedStreamIds.build(), failedStreamIds.build()));
    // Make sure the stream router will reload the changed streams.
    clusterEventBus.post(StreamsChangedEvent.create(completedStreamIds.build()));
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) ImmutableSet(com.google.common.collect.ImmutableSet) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Stream(org.graylog2.plugin.streams.Stream)

Example 3 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig 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 4 with IndexSetConfig

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

the class V20161216123500_DefaultIndexSetMigration method migrateIndexSet.

private void migrateIndexSet(IndexSetConfig indexSetConfig, String templateName) {
    final String analyzer = elasticsearchConfiguration.getAnalyzer();
    final IndexSetConfig updatedConfig = indexSetConfig.toBuilder().indexAnalyzer(analyzer).indexTemplateName(templateName).indexOptimizationMaxNumSegments(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments()).indexOptimizationDisabled(elasticsearchConfiguration.isDisableIndexOptimization()).build();
    final IndexSetConfig savedConfig = indexSetService.save(updatedConfig);
    // Publish event to cluster event bus so the stream router will reload.
    clusterEventBus.post(IndexSetCreatedEvent.create(savedConfig));
    LOG.debug("Successfully updated index set: {}", savedConfig);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig)

Example 5 with IndexSetConfig

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

the class V20161216123500_DefaultIndexSetMigration method upgrade.

@Override
public void upgrade() {
    if (clusterConfigService.get(V20161216123500_Succeeded.class) != null) {
        return;
    }
    // The default index set must have been created first.
    checkState(clusterConfigService.get(DefaultIndexSetCreated.class) != null, "The default index set hasn't been created yet. This is a bug!");
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    migrateIndexSet(defaultIndexSet, elasticsearchConfiguration.getTemplateName());
    final List<IndexSetConfig> allWithoutDefault = indexSetService.findAll().stream().filter(indexSetConfig -> !indexSetConfig.equals(defaultIndexSet)).collect(Collectors.toList());
    for (IndexSetConfig indexSetConfig : allWithoutDefault) {
        migrateIndexSet(indexSetConfig, indexSetConfig.indexPrefix() + "-template");
    }
    clusterConfigService.write(V20161216123500_Succeeded.create());
}
Also used : Logger(org.slf4j.Logger) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ElasticsearchConfiguration(org.graylog2.configuration.ElasticsearchConfiguration) Inject(javax.inject.Inject) DefaultIndexSetCreated(org.graylog2.indexer.indexset.DefaultIndexSetCreated) List(java.util.List) ClusterEventBus(org.graylog2.events.ClusterEventBus) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) V20161216123500_Succeeded(org.graylog2.indexer.indexset.V20161216123500_Succeeded) IndexSetCreatedEvent(org.graylog2.indexer.indexset.events.IndexSetCreatedEvent) ZoneOffset(java.time.ZoneOffset) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) V20161216123500_Succeeded(org.graylog2.indexer.indexset.V20161216123500_Succeeded)

Aggregations

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)53 Test (org.junit.Test)39 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)21 IndexSet (org.graylog2.indexer.IndexSet)11 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)10 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)10 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)8 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)5 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 NotFoundException (javax.ws.rs.NotFoundException)4 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 IndexSetService (org.graylog2.indexer.indexset.IndexSetService)4 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)4