Search in sources :

Example 1 with IndexManagementConfig

use of org.graylog2.indexer.management.IndexManagementConfig 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());
        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);
    }
}
Also used : TimeBasedRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategyConfig) MessageCountRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig) SearchesClusterConfig(org.graylog2.indexer.searches.SearchesClusterConfig) ClosingRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.ClosingRetentionStrategyConfig) SizeBasedRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.SizeBasedRotationStrategyConfig) DeletionRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig)

Example 2 with IndexManagementConfig

use of org.graylog2.indexer.management.IndexManagementConfig in project graylog2-server by Graylog2.

the class V20161116172100_DefaultIndexSetMigration method getRotationStrategyConfig.

private RotationStrategyConfig getRotationStrategyConfig(IndexManagementConfig indexManagementConfig) {
    final String strategyName = indexManagementConfig.rotationStrategy();
    final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
    checkState(provider != null, "Couldn't retrieve rotation strategy provider for <" + strategyName + ">");
    final RotationStrategy rotationStrategy = provider.get();
    @SuppressWarnings("unchecked") final Class<RotationStrategyConfig> configClass = (Class<RotationStrategyConfig>) rotationStrategy.configurationClass();
    final RotationStrategyConfig rotationStrategyConfig = clusterConfigService.get(configClass);
    checkState(rotationStrategyConfig != null, "Couldn't retrieve rotation strategy config for <" + strategyName + ">");
    return rotationStrategyConfig;
}
Also used : RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)

Example 3 with IndexManagementConfig

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

use of org.graylog2.indexer.management.IndexManagementConfig 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 5 with IndexManagementConfig

use of org.graylog2.indexer.management.IndexManagementConfig in project graylog2-server by Graylog2.

the class RotationStrategyResource method config.

@PUT
@Path("config")
@Consumes(MediaType.APPLICATION_JSON)
@Timed
@ApiOperation(value = "Configuration of the current rotation strategy", notes = "This resource stores the configuration of the currently used rotation strategy.")
@AuditEvent(type = AuditEventTypes.ES_INDEX_ROTATION_STRATEGY_UPDATE)
public RotationStrategySummary config(@ApiParam(value = "The description of the rotation strategy and its configuration", required = true) @Valid @NotNull RotationStrategySummary rotationStrategySummary) {
    if (!rotationStrategies.containsKey(rotationStrategySummary.strategy())) {
        throw new NotFoundException("Couldn't find rotation strategy for given type " + rotationStrategySummary.strategy());
    }
    final IndexManagementConfig oldConfig = clusterConfigService.get(IndexManagementConfig.class);
    if (oldConfig == null) {
        throw new InternalServerErrorException("Couldn't retrieve index management configuration");
    }
    final IndexManagementConfig indexManagementConfig = IndexManagementConfig.create(rotationStrategySummary.strategy(), oldConfig.retentionStrategy());
    clusterConfigService.write(rotationStrategySummary.config());
    clusterConfigService.write(indexManagementConfig);
    return rotationStrategySummary;
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Aggregations

IndexManagementConfig (org.graylog2.indexer.management.IndexManagementConfig)7 Timed (com.codahale.metrics.annotation.Timed)4 ApiOperation (io.swagger.annotations.ApiOperation)4 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)4 Path (javax.ws.rs.Path)4 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 NotFoundException (javax.ws.rs.NotFoundException)2 PUT (javax.ws.rs.PUT)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)2 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)2 RetentionStrategy (org.graylog2.plugin.indexer.retention.RetentionStrategy)2 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)2 RotationStrategy (org.graylog2.plugin.indexer.rotation.RotationStrategy)2 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 DefaultIndexSetCreated (org.graylog2.indexer.indexset.DefaultIndexSetCreated)1 ClosingRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.ClosingRetentionStrategyConfig)1 DeletionRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig)1