use of org.graylog2.migrations.Migration in project graylog2-server by Graylog2.
the class RolesToGrantsMigrationTest method setUp.
@BeforeEach
void setUp(MongoDBTestService mongodb, MongoJackObjectMapperProvider mongoJackObjectMapperProvider, GRNRegistry grnRegistry, TestUserService userService) {
when(permissions.readerBasePermissions()).thenReturn(ImmutableSet.of());
when(validator.validate(any())).thenReturn(ImmutableSet.of());
this.grnRegistry = grnRegistry;
roleService = new RoleServiceImpl(mongodb.mongoConnection(), mongoJackObjectMapperProvider, permissions, validator);
dbGrantService = new DBGrantService(mongodb.mongoConnection(), mongoJackObjectMapperProvider, grnRegistry);
this.userService = userService;
DBGrantService dbGrantService = new DBGrantService(mongodb.mongoConnection(), mongoJackObjectMapperProvider, grnRegistry);
migration = new RolesToGrantsMigration(roleService, userService, dbGrantService, grnRegistry, "admin");
}
use of org.graylog2.migrations.Migration in project graylog2-server by Graylog2.
the class V20191121145100_FixDefaultGrokPatterns method migratePattern.
private void migratePattern(PatternToMigrate patternToMigrate) throws ValidationException {
final Optional<GrokPattern> currentPattern = grokPatternService.loadByName(patternToMigrate.name());
if (!currentPattern.isPresent()) {
log.debug("Couldn't find default pattern '{}'. Skipping migration.", patternToMigrate.name());
return;
}
final GrokPattern pattern = currentPattern.get();
if (!patternToMigrate.migrateFrom().equals(pattern.pattern())) {
log.info("Skipping migration of modified default Grok Pattern '{}'.", pattern.name());
} else {
log.info("Migrating default Grok Pattern '{}'.", pattern.name());
final GrokPattern migratedPattern = pattern.toBuilder().pattern(patternToMigrate.migrateTo()).build();
grokPatternService.update(migratedPattern);
}
}
use of org.graylog2.migrations.Migration in project graylog2-server by Graylog2.
the class V20191219090834_AddSourcesPage method upgrade.
@Override
public void upgrade() {
if (configService.get(V20191219090834_AddSourcesPage.MigrationCompleted.class) != null) {
LOG.debug("Migration already completed.");
return;
}
try {
final URL contentPackURL = V20191219090834_AddSourcesPage.class.getResource("V20191219090834_AddSourcesPage_Content_Pack.json");
final ContentPack contentPack = this.objectMapper.readValue(contentPackURL, ContentPack.class);
final ContentPack pack = this.contentPackPersistenceService.insert(contentPack).orElseThrow(() -> {
configService.write(V20191219090834_AddSourcesPage.MigrationCompleted.create(contentPack.id().toString()));
return new ContentPackException("Content pack " + contentPack.id() + " with this revision " + contentPack.revision() + " already found!");
});
contentPackService.installContentPack(pack, Collections.emptyMap(), "Add Sources Page", "admin");
configService.write(V20191219090834_AddSourcesPage.MigrationCompleted.create(pack.id().toString()));
} catch (Exception e) {
throw new RuntimeException("Could not install Source Page Content Pack.", e);
}
}
use of org.graylog2.migrations.Migration in project graylog2-server by Graylog2.
the class V20161215163900_MoveIndexSetDefaultConfig method upgrade.
@Override
public void upgrade() {
if (clusterConfigService.get(MigrationCompleted.class) != null) {
LOG.debug("Migration already done.");
return;
}
// Do not overwrite an existing default index config
boolean defaultDone = clusterConfigService.get(DefaultIndexSetConfig.class) != null;
final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
final FindIterable<Document> documents = collection.find(exists(FIELD_DEFAULT)).sort(ascending(FIELD_CREATION_DATE));
for (final Document document : documents) {
final ObjectId id = document.getObjectId(FIELD_ID);
final String idString = id.toHexString();
final boolean isDefault = firstNonNull(document.getBoolean(FIELD_DEFAULT), false);
if (!defaultDone && isDefault) {
defaultDone = true;
clusterConfigService.write(DefaultIndexSetConfig.create(idString));
}
final long modifiedCount = collection.updateOne(eq(FIELD_ID, id), unset(FIELD_DEFAULT)).getMatchedCount();
if (modifiedCount > 0) {
LOG.info("Removed <default> field from index set <{}> ({})", document.getString(FIELD_TITLE), idString);
builder.add(idString);
} else {
LOG.error("Couldn't remove <default> field from index set <{}> ({})", document.getString(FIELD_TITLE), idString);
}
}
clusterConfigService.write(MigrationCompleted.create(builder.build()));
}
Aggregations