use of org.opensearch.common.settings.Setting in project job-scheduler by opensearch-project.
the class JobSweeperTests method setup.
@Before
public void setup() throws IOException {
this.client = Mockito.mock(Client.class);
this.threadPool = Mockito.mock(ThreadPool.class);
this.scheduler = Mockito.mock(JobScheduler.class);
this.jobRunner = Mockito.mock(ScheduledJobRunner.class);
this.jobParser = Mockito.mock(ScheduledJobParser.class);
// NamedXContentRegistry.Entry xContentRegistryEntry = new NamedXContentRegistry.Entry(ScheduledJobParameter.class,
// new ParseField("JOB_TYPE"), this.jobParser);
List<NamedXContentRegistry.Entry> namedXContentRegistryEntries = new ArrayList<>();
// namedXContentRegistryEntries.add(xContentRegistryEntry);
this.xContentRegistry = new NamedXContentRegistry(namedXContentRegistryEntries);
this.settings = Settings.builder().build();
this.discoveryNode = new DiscoveryNode("node", OpenSearchTestCase.buildNewFakeTransportAddress(), Version.CURRENT);
Set<Setting<?>> settingSet = new HashSet<>();
settingSet.addAll(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
settingSet.add(JobSchedulerSettings.REQUEST_TIMEOUT);
settingSet.add(JobSchedulerSettings.SWEEP_PERIOD);
settingSet.add(JobSchedulerSettings.SWEEP_BACKOFF_RETRY_COUNT);
settingSet.add(JobSchedulerSettings.SWEEP_BACKOFF_MILLIS);
settingSet.add(JobSchedulerSettings.SWEEP_PAGE_SIZE);
settingSet.add(JobSchedulerSettings.JITTER_LIMIT);
ClusterSettings clusterSettings = new ClusterSettings(this.settings, settingSet);
ClusterService originClusterService = ClusterServiceUtils.createClusterService(this.threadPool, discoveryNode, clusterSettings);
this.clusterService = Mockito.spy(originClusterService);
ScheduledJobProvider jobProvider = new ScheduledJobProvider("JOB_TYPE", "job-index-name", this.jobParser, this.jobRunner);
Map<String, ScheduledJobProvider> jobProviderMap = new HashMap<>();
jobProviderMap.put("index-name", jobProvider);
sweeper = new JobSweeper(settings, this.client, this.clusterService, this.threadPool, xContentRegistry, jobProviderMap, scheduler, new LockService(client, clusterService));
}
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 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)));
}
use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.
the class ScriptServiceTests method testContextCacheStats.
public void testContextCacheStats() throws IOException {
ScriptContext<?> contextA = randomFrom(contexts.values());
String aRate = "2/10m";
ScriptContext<?> contextB = randomValueOtherThan(contextA, () -> randomFrom(contexts.values()));
String bRate = "3/10m";
BiFunction<String, String, String> msg = (rate, ctx) -> ("[script] Too many dynamic script compilations within, max: [" + rate + "]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.context." + ctx + ".max_compilations_rate] setting");
buildScriptService(Settings.builder().put(SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace(contextA.name).getKey(), 1).put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(contextA.name).getKey(), aRate).put(SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace(contextB.name).getKey(), 2).put(SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace(contextB.name).getKey(), bRate).build());
// Context A
scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), contextA);
scriptService.compile(new Script(ScriptType.INLINE, "test", "2+2", Collections.emptyMap()), contextA);
GeneralScriptException gse = expectThrows(GeneralScriptException.class, () -> scriptService.compile(new Script(ScriptType.INLINE, "test", "3+3", Collections.emptyMap()), contextA));
assertEquals(msg.apply(aRate, contextA.name), gse.getRootCause().getMessage());
assertEquals(CircuitBreakingException.class, gse.getRootCause().getClass());
// Context B
scriptService.compile(new Script(ScriptType.INLINE, "test", "4+4", Collections.emptyMap()), contextB);
scriptService.compile(new Script(ScriptType.INLINE, "test", "5+5", Collections.emptyMap()), contextB);
scriptService.compile(new Script(ScriptType.INLINE, "test", "6+6", Collections.emptyMap()), contextB);
gse = expectThrows(GeneralScriptException.class, () -> scriptService.compile(new Script(ScriptType.INLINE, "test", "7+7", Collections.emptyMap()), contextB));
assertEquals(msg.apply(bRate, contextB.name), gse.getRootCause().getMessage());
gse = expectThrows(GeneralScriptException.class, () -> scriptService.compile(new Script(ScriptType.INLINE, "test", "8+8", Collections.emptyMap()), contextB));
assertEquals(msg.apply(bRate, contextB.name), gse.getRootCause().getMessage());
assertEquals(CircuitBreakingException.class, gse.getRootCause().getClass());
// Context specific
ScriptCacheStats stats = scriptService.cacheStats();
assertEquals(2L, stats.getContextStats().get(contextA.name).getCompilations());
assertEquals(1L, stats.getContextStats().get(contextA.name).getCacheEvictions());
assertEquals(1L, stats.getContextStats().get(contextA.name).getCompilationLimitTriggered());
assertEquals(3L, stats.getContextStats().get(contextB.name).getCompilations());
assertEquals(1L, stats.getContextStats().get(contextB.name).getCacheEvictions());
assertEquals(2L, stats.getContextStats().get(contextB.name).getCompilationLimitTriggered());
assertNull(scriptService.cacheStats().getGeneralStats());
// Summed up
assertEquals(5L, scriptService.stats().getCompilations());
assertEquals(2L, scriptService.stats().getCacheEvictions());
assertEquals(3L, scriptService.stats().getCompilationLimitTriggered());
}
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);
}
Aggregations