use of org.opensearch.common.settings.SettingUpgrader in project OpenSearch by opensearch-project.
the class ClusterStateUpdatersTests method runUpgradeSettings.
private void runUpgradeSettings(final BiConsumer<Metadata.Builder, Settings> applySettingsToBuilder, final Function<Metadata, Settings> metadataSettings) {
final Setting<String> oldSetting = Setting.simpleString("foo.old", Setting.Property.Dynamic, Setting.Property.NodeScope);
final Setting<String> newSetting = Setting.simpleString("foo.new", Setting.Property.Dynamic, Setting.Property.NodeScope);
final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(oldSetting, newSetting)).collect(Collectors.toSet());
final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet, Collections.singleton(new SettingUpgrader<String>() {
@Override
public Setting<String> getSetting() {
return oldSetting;
}
@Override
public String getKey(final String key) {
return "foo.new";
}
@Override
public String getValue(final String value) {
return "new." + value;
}
}));
final ClusterService clusterService = new ClusterService(Settings.EMPTY, clusterSettings, null);
final Metadata.Builder builder = Metadata.builder();
final Settings settings = Settings.builder().put("foo.old", randomAlphaOfLength(8)).build();
applySettingsToBuilder.accept(builder, settings);
final ClusterState initialState = ClusterState.builder(clusterService.getClusterName()).metadata(builder.build()).build();
final ClusterState state = upgradeAndArchiveUnknownOrInvalidSettings(initialState, clusterService.getClusterSettings());
assertFalse(oldSetting.exists(metadataSettings.apply(state.metadata())));
assertTrue(newSetting.exists(metadataSettings.apply(state.metadata())));
assertThat(newSetting.get(metadataSettings.apply(state.metadata())), equalTo("new." + oldSetting.get(settings)));
}
Aggregations