use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.
the class IndexSettingsTests method testMergedSettingsArePassed.
public void testMergedSettingsArePassed() {
Version version = VersionUtils.getPreviousVersion();
Settings theSettings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).put(IndexMetadata.SETTING_INDEX_UUID, "0xdeadbeef").build();
final AtomicInteger integer = new AtomicInteger(0);
final StringBuilder builder = new StringBuilder();
Setting<Integer> integerSetting = Setting.intSetting("index.test.setting.int", -1, Property.Dynamic, Property.IndexScope);
Setting<String> notUpdated = new Setting<>("index.not.updated", "", Function.identity(), Property.Dynamic, Property.IndexScope);
IndexSettings settings = newIndexSettings(newIndexMeta("index", theSettings), Settings.EMPTY, integerSetting, notUpdated);
settings.getScopedSettings().addSettingsUpdateConsumer(integerSetting, integer::set);
settings.getScopedSettings().addSettingsUpdateConsumer(notUpdated, builder::append);
assertEquals(0, integer.get());
assertEquals("", builder.toString());
IndexMetadata newMetadata = newIndexMeta("index", Settings.builder().put(settings.getIndexMetadata().getSettings()).put("index.test.setting.int", 42).build());
assertTrue(settings.updateIndexMetadata(newMetadata));
assertSame(settings.getIndexMetadata(), newMetadata);
assertEquals(42, integer.get());
assertEquals("", builder.toString());
integer.set(0);
assertTrue(settings.updateIndexMetadata(newIndexMeta("index", Settings.builder().put(settings.getIndexMetadata().getSettings()).put("index.not.updated", "boom").build())));
assertEquals("boom", builder.toString());
assertEquals("not updated - we preserve the old settings", 0, integer.get());
}
use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.
the class MetadataCreateIndexServiceTests method runPrepareResizeIndexSettingsTest.
private void runPrepareResizeIndexSettingsTest(final Settings sourceSettings, final Settings requestSettings, final Collection<Setting<?>> additionalIndexScopedSettings, final boolean copySettings, final Consumer<Settings> consumer) {
final String indexName = randomAlphaOfLength(10);
final Settings indexSettings = Settings.builder().put("index.blocks.write", true).put("index.routing.allocation.require._name", "node1").put(sourceSettings).build();
final ClusterState initialClusterState = ClusterState.builder(createClusterState(indexName, randomIntBetween(2, 10), 0, indexSettings)).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
final AllocationService service = new AllocationService(new AllocationDeciders(singleton(new MaxRetryAllocationDecider())), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE, EmptySnapshotsInfoService.INSTANCE);
final RoutingTable initialRoutingTable = service.reroute(initialClusterState, "reroute").routingTable();
final ClusterState routingTableClusterState = ClusterState.builder(initialClusterState).routingTable(initialRoutingTable).build();
// now we start the shard
final RoutingTable routingTable = OpenSearchAllocationTestCase.startInitializingShardsAndReroute(service, routingTableClusterState, indexName).routingTable();
final ClusterState clusterState = ClusterState.builder(routingTableClusterState).routingTable(routingTable).build();
final Settings.Builder indexSettingsBuilder = Settings.builder().put("index.number_of_shards", 1).put(requestSettings);
final Set<Setting<?>> settingsSet = Stream.concat(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS.stream(), additionalIndexScopedSettings.stream()).collect(Collectors.toSet());
MetadataCreateIndexService.prepareResizeIndexSettings(clusterState, indexSettingsBuilder, clusterState.metadata().index(indexName).getIndex(), "target", ResizeType.SHRINK, copySettings, new IndexScopedSettings(Settings.EMPTY, settingsSet));
consumer.accept(indexSettingsBuilder.build());
}
use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.
the class OpenSearchExecutorsTests method runProcessorsBoundTest.
private void runProcessorsBoundTest(final Setting<Integer> processorsSetting) {
final int available = Runtime.getRuntime().availableProcessors();
final int processors = randomIntBetween(available + 1, Integer.MAX_VALUE);
final Settings settings = Settings.builder().put(processorsSetting.getKey(), processors).build();
processorsSetting.get(settings);
final Setting<?>[] deprecatedSettings;
if (processorsSetting.getProperties().contains(Setting.Property.Deprecated)) {
deprecatedSettings = new Setting<?>[] { processorsSetting };
} else {
deprecatedSettings = new Setting<?>[0];
}
final String expectedWarning = String.format(Locale.ROOT, "setting [%s] to value [%d] which is more than available processors [%d] is deprecated", processorsSetting.getKey(), processors, available);
assertSettingDeprecationsAndWarnings(deprecatedSettings, expectedWarning);
}
use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.
the class SettingsUpdaterTests method testDeprecationLogging.
public void testDeprecationLogging() {
Setting<String> deprecatedSetting = Setting.simpleString("deprecated.setting", Property.Dynamic, Property.NodeScope, Property.Deprecated);
final Settings settings = Settings.builder().put("deprecated.setting", "foo").build();
final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(deprecatedSetting)).collect(Collectors.toSet());
final ClusterSettings clusterSettings = new ClusterSettings(settings, settingsSet);
clusterSettings.addSettingsUpdateConsumer(deprecatedSetting, s -> {
});
final SettingsUpdater settingsUpdater = new SettingsUpdater(clusterSettings);
final ClusterState clusterState = ClusterState.builder(new ClusterName("foo")).metadata(Metadata.builder().persistentSettings(settings).build()).build();
final Settings toApplyDebug = Settings.builder().put("logger.org.opensearch", "debug").build();
final ClusterState afterDebug = settingsUpdater.updateSettings(clusterState, toApplyDebug, Settings.EMPTY, logger);
assertSettingDeprecationsAndWarnings(new Setting<?>[] { deprecatedSetting });
final Settings toApplyUnset = Settings.builder().putNull("logger.org.opensearch").build();
final ClusterState afterUnset = settingsUpdater.updateSettings(afterDebug, toApplyUnset, Settings.EMPTY, logger);
assertNoDeprecationWarnings();
// we also check that if no settings are changed, deprecation logging still occurs
settingsUpdater.updateSettings(afterUnset, toApplyUnset, Settings.EMPTY, logger);
assertNoDeprecationWarnings();
}
use of org.opensearch.common.settings.Setting 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