Search in sources :

Example 1 with MigrationCompleted

use of org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted in project graylog2-server by Graylog2.

the class V20191129134600_CreateInitialUrlWhitelist method upgrade.

@Override
public void upgrade() {
    final MigrationCompleted migrationCompleted = configService.get(MigrationCompleted.class);
    if (migrationCompleted != null) {
        log.debug("Migration already completed.");
        return;
    }
    UrlWhitelist whitelist = createWhitelist();
    whitelistService.saveWhitelist(whitelist);
    configService.write(MigrationCompleted.create(whitelist.toString()));
}
Also used : UrlWhitelist(org.graylog2.system.urlwhitelist.UrlWhitelist)

Example 2 with MigrationCompleted

use of org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted in project graylog2-server by Graylog2.

the class V20191121145100_FixDefaultGrokPatternsTest method alreadyMigrated.

@Test
public void alreadyMigrated() {
    final MigrationCompleted migrationCompleted = MigrationCompleted.create(Collections.singleton(PATTERN_NAME));
    when(configService.get(MigrationCompleted.class)).thenReturn(migrationCompleted);
    migration.upgrade();
    verifyZeroInteractions(grokPatternService);
}
Also used : MigrationCompleted(org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted) Test(org.junit.Test)

Example 3 with MigrationCompleted

use of org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted 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 4 with MigrationCompleted

use of org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted in project graylog2-server by Graylog2.

the class V20170110150100_FixAlertConditionsMigrationTest method upgrade.

@Test
@MongoDBFixtures("V20170110150100_FixAlertConditionsMigration.json")
public void upgrade() throws Exception {
    // First check all types of the existing documents
    AlertConditionAssertions.assertThat(getAlertCondition("2fa6a415-ce0c-4a36-accc-dd9519eb06d9")).hasParameter("backlog", 2).hasParameter("grace", 1).hasParameter("threshold_type", "MORE").hasParameter("threshold", "5").hasParameter("time", "1");
    AlertConditionAssertions.assertThat(getAlertCondition("393fd8b2-9b17-42d3-86b0-6e55d0f5343a")).hasParameter("backlog", 0).hasParameter("field", "bar").hasParameter("grace", "0").hasParameter("value", "baz");
    AlertConditionAssertions.assertThat(getAlertCondition("0e75404f-c0ee-40b0-8872-b1aec441ba1c")).hasParameter("backlog", "0").hasParameter("field", "foo").hasParameter("grace", "0").hasParameter("threshold_type", "HIGHER").hasParameter("threshold", "0").hasParameter("time", "5").hasParameter("type", "MAX");
    // Run the migration that should convert all affected fields to integers
    migration.upgrade();
    // Check all types again
    AlertConditionAssertions.assertThat(getAlertCondition("2fa6a415-ce0c-4a36-accc-dd9519eb06d9")).hasParameter("backlog", 2).hasParameter("grace", 1).hasParameter("threshold_type", "MORE").hasParameter("threshold", 5).hasParameter("time", 1);
    AlertConditionAssertions.assertThat(getAlertCondition("393fd8b2-9b17-42d3-86b0-6e55d0f5343a")).hasParameter("backlog", 0).hasParameter("field", "bar").hasParameter("grace", 0).hasParameter("value", "baz");
    AlertConditionAssertions.assertThat(getAlertCondition("0e75404f-c0ee-40b0-8872-b1aec441ba1c")).hasParameter("backlog", 0).hasParameter("field", "foo").hasParameter("grace", 0).hasParameter("threshold_type", "HIGHER").hasParameter("threshold", 0).hasParameter("time", 5).hasParameter("type", "MAX");
    final MigrationCompleted migrationCompleted = clusterConfigService.get(MigrationCompleted.class);
    assertThat(migrationCompleted).isNotNull();
    assertThat(migrationCompleted.streamIds()).containsOnly("58458e442f857c314491344e", "58458e442f857c314491345e");
    assertThat(migrationCompleted.alertConditionIds()).containsOnly("2fa6a415-ce0c-4a36-accc-dd9519eb06d9", "393fd8b2-9b17-42d3-86b0-6e55d0f5343a", "0e75404f-c0ee-40b0-8872-b1aec441ba1c");
}
Also used : MigrationCompleted(org.graylog2.migrations.V20170110150100_FixAlertConditionsMigration.MigrationCompleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 5 with MigrationCompleted

use of org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted in project graylog2-server by Graylog2.

the class V20201103145400_LegacyAuthServiceMigration method upgrade.

@Override
public void upgrade() {
    final MigrationCompleted migrationState = clusterConfigService.getOrDefault(MigrationCompleted.class, MigrationCompleted.createEmpty());
    final ImmutableSet.Builder<String> migratedConfigsBuilder = ImmutableSet.builder();
    // While the LDAP settings collection could contain more than one document, in practice we only expect a
    // single one. That's why we are using the ID of the last created auth service for the notification.
    String lastCreatedAuthServiceId = null;
    // Add all configs that have already been migrated
    migratedConfigsBuilder.addAll(migrationState.migratedConfigs());
    for (final Document document : ldapSettings.find().sort(Sorts.ascending("_id"))) {
        final String idString = document.getObjectId("_id").toHexString();
        if (!document.getBoolean("enabled")) {
            LOG.debug("Skipping disabled configuration <{}>", idString);
            continue;
        }
        if (migrationState.isDone(idString)) {
            LOG.debug("Configuration <{}> already migrated", idString);
            continue;
        }
        final AuthServiceBackendDTO newConfig;
        if (document.getBoolean("active_directory")) {
            newConfig = buildActiveDirectoryConfig(document);
        } else {
            newConfig = buildLDAPConfig(document);
        }
        final AuthServiceBackendDTO savedConfig = authServiceBackendService.save(newConfig);
        for (final MigrationModule migrationModule : migrationModules) {
            migrationModule.upgrade(document, savedConfig);
        }
        lastCreatedAuthServiceId = savedConfig.id();
        migratedConfigsBuilder.add(idString);
    }
    final ImmutableSet<String> migratedConfigs = migratedConfigsBuilder.build();
    clusterConfigService.write(MigrationCompleted.create(migratedConfigs));
    if (lastCreatedAuthServiceId != null) {
        final Notification notification = notificationService.buildNow().addType(Notification.Type.LEGACY_LDAP_CONFIG_MIGRATION).addSeverity(Notification.Severity.URGENT).addDetail("auth_service_id", lastCreatedAuthServiceId);
        notificationService.publishIfFirst(notification);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) AuthServiceBackendDTO(org.graylog.security.authservice.AuthServiceBackendDTO) Document(org.bson.Document) Notification(org.graylog2.notifications.Notification)

Aggregations

Test (org.junit.Test)3 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Document (org.bson.Document)1 AuthServiceBackendDTO (org.graylog.security.authservice.AuthServiceBackendDTO)1 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)1 MigrationCompleted (org.graylog2.migrations.V20161215163900_MoveIndexSetDefaultConfig.MigrationCompleted)1 MigrationCompleted (org.graylog2.migrations.V20170110150100_FixAlertConditionsMigration.MigrationCompleted)1 MigrationCompleted (org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted)1 Notification (org.graylog2.notifications.Notification)1 UrlWhitelist (org.graylog2.system.urlwhitelist.UrlWhitelist)1