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);
}
}
}
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);
}
}
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);
}
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);
}
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.");
}
}
Aggregations