Search in sources :

Example 6 with Migration

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

the class ViewSharingToGrantsMigration method upgrade.

public void upgrade() {
    for (final Document document : collection.find()) {
        LOG.debug("Migrate view sharing: {}", document);
        final ObjectId sharingId = document.getObjectId("_id");
        final String sharingType = document.get("type", String.class);
        final String viewId = document.get("view_id", String.class);
        try {
            switch(sharingType) {
                case "users":
                    // noinspection unchecked
                    migrateUsers(viewId, (Collection<String>) document.get("users", Collection.class));
                    break;
                case "roles":
                    // noinspection unchecked
                    migrateRoles(viewId, (Collection<String>) document.get("roles", Collection.class));
                    break;
                case "all_of_instance":
                    migrateAllOfInstance(viewId);
                    break;
                default:
                    LOG.warn("Skipping unknown view sharing type: {}", sharingType);
                    // Continue here so we don't delete the sharing document
                    continue;
            }
            // The view sharing document should be removed after successful migration
            deleteViewSharing(sharingId);
        } catch (Exception e) {
            LOG.error("Couldn't migrate view sharing: {}", document, e);
        }
    }
}
Also used : ObjectId(org.bson.types.ObjectId) Document(org.bson.Document) NotFoundException(org.graylog2.database.NotFoundException)

Example 7 with Migration

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

the class V20180924111644_AddDefaultGrokPatterns method upgrade.

@Override
public void upgrade() {
    if (configService.get(MigrationCompleted.class) != null) {
        LOG.debug("Migration already completed.");
        return;
    }
    try {
        final URL contentPackURL = V20180924111644_AddDefaultGrokPatterns.class.getResource("V20180924111644_AddDefaultGrokPatterns_Default_Grok_Patterns.json");
        final ContentPack contentPack = this.objectMapper.readValue(contentPackURL, ContentPack.class);
        final ContentPack pack = this.contentPackPersistenceService.insert(contentPack).orElseThrow(() -> {
            configService.write(MigrationCompleted.create(contentPack.id().toString()));
            return new ContentPackException("Content pack " + contentPack.id() + " with this revision " + contentPack.revision() + " already found!");
        });
        try {
            contentPackService.installContentPack(pack, Collections.emptyMap(), "Add default Grok patterns", "admin");
        } catch (ContentPackException e) {
            LOG.warn("Could not install default grok patterns: the installation found some modified default grok" + "patterns in your setup and did not update them. If you wish to use the default grok" + "patterns we provide, please delete the modified grok pattern and install the 'Default grok" + "patterns' content pack manually.");
        }
        configService.write(MigrationCompleted.create(pack.id().toString()));
    } catch (IOException e) {
        LOG.error("Unable to import content pack for default grok patterns: {}", e);
    }
}
Also used : ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) ContentPack(org.graylog2.contentpacks.model.ContentPack) IOException(java.io.IOException) URL(java.net.URL)

Example 8 with Migration

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

the class V20190805115800_RemoveDashboardStateFromViewsTest method removesDashboardStateFromExistingViews.

@Test
@MongoDBFixtures("V20190805115800_RemoveDashboardStateFromViewsTest.json")
public void removesDashboardStateFromExistingViews() {
    final Migration migration = new V20190805115800_RemoveDashboardStateFromViews(clusterConfigService, mongodb.mongoConnection());
    migration.upgrade();
    final ArgumentCaptor<V20190805115800_RemoveDashboardStateFromViews.MigrationCompleted> argumentCaptor = ArgumentCaptor.forClass(V20190805115800_RemoveDashboardStateFromViews.MigrationCompleted.class);
    verify(clusterConfigService, times(1)).write(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().modifiedViewsCount()).isEqualTo(4);
    MongoCollection<Document> collection = mongodb.mongoConnection().getMongoDatabase().getCollection("views");
    assertThat(collection.count()).isEqualTo(4);
}
Also used : Migration(org.graylog2.migrations.Migration) Document(org.bson.Document) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 9 with Migration

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

the class V20191125144500_MigrateDashboardsToViewsTest method setUp.

@Before
public void setUp() throws Exception {
    final MongoJackObjectMapperProvider mapperProvider = new MongoJackObjectMapperProvider(new ObjectMapper());
    final DashboardsService dashboardsService = new DashboardsService(mongodb.mongoConnection(), mapperProvider);
    final RandomObjectIdProvider randomObjectIdProvider = new StaticRandomObjectIdProvider(new Date(1575020937839L));
    final RandomUUIDProvider randomUUIDProvider = new RandomUUIDProvider(new Date(1575020937839L), 1575020937839L);
    this.viewService = spy(new ViewService(mongodb.mongoConnection(), mapperProvider));
    this.searchService = spy(new SearchService(mongodb.mongoConnection(), mapperProvider));
    migration = new V20191125144500_MigrateDashboardsToViews(dashboardsService, searchService, viewService, clusterConfigService, randomObjectIdProvider, randomUUIDProvider);
}
Also used : MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) Before(org.junit.Before)

Example 10 with Migration

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

the class LegacyDefaultStreamMigration method doRun.

@Override
public void doRun() {
    try {
        final PipelineConnections defaultConnections = connectionsService.load(LEGACY_STREAM_ID);
        connectionsService.save(defaultConnections.toBuilder().streamId(Stream.DEFAULT_STREAM_ID).build());
        connectionsService.delete(LEGACY_STREAM_ID);
        clusterConfigService.write(LegacyDefaultStreamMigrated.create(true));
        LOG.info("Pipeline connections to legacy default streams migrated successfully.");
    } catch (NotFoundException e) {
        LOG.info("Legacy default stream has no connections, no migration needed.");
    }
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections) NotFoundException(org.graylog2.database.NotFoundException)

Aggregations

Set (java.util.Set)4 Document (org.bson.Document)4 NotFoundException (org.graylog2.database.NotFoundException)4 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)4 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)4 ValidationException (org.graylog2.plugin.database.ValidationException)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 ObjectId (org.bson.types.ObjectId)3 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)3 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)3 Before (org.junit.Before)3 Test (org.junit.Test)3 BasicDBObject (com.mongodb.BasicDBObject)2 Map (java.util.Map)2