Search in sources :

Example 11 with Setting

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));
}
Also used : JobScheduler(org.opensearch.jobscheduler.scheduler.JobScheduler) ScheduledJobParser(org.opensearch.jobscheduler.spi.ScheduledJobParser) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterSettings(org.opensearch.common.settings.ClusterSettings) LockService(org.opensearch.jobscheduler.spi.utils.LockService) HashMap(java.util.HashMap) Setting(org.opensearch.common.settings.Setting) ThreadPool(org.opensearch.threadpool.ThreadPool) ArrayList(java.util.ArrayList) ScheduledJobRunner(org.opensearch.jobscheduler.spi.ScheduledJobRunner) ClusterService(org.opensearch.cluster.service.ClusterService) ScheduledJobProvider(org.opensearch.jobscheduler.ScheduledJobProvider) Client(org.opensearch.client.Client) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 12 with Setting

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());
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) ClusterState(org.opensearch.cluster.ClusterState) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) Setting(org.opensearch.common.settings.Setting) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) RoutingTable(org.opensearch.cluster.routing.RoutingTable) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Settings(org.opensearch.common.settings.Settings) MetadataCreateIndexService.aggregateIndexSettings(org.opensearch.cluster.metadata.MetadataCreateIndexService.aggregateIndexSettings) IndexSettings(org.opensearch.index.IndexSettings) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService)

Example 13 with Setting

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)));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ClusterService(org.opensearch.cluster.service.ClusterService) Setting(org.opensearch.common.settings.Setting) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) SettingUpgrader(org.opensearch.common.settings.SettingUpgrader) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) ClusterStateUpdaters.upgradeAndArchiveUnknownOrInvalidSettings(org.opensearch.gateway.ClusterStateUpdaters.upgradeAndArchiveUnknownOrInvalidSettings)

Example 14 with Setting

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());
}
Also used : Metadata(org.opensearch.cluster.metadata.Metadata) BytesReference(org.opensearch.common.bytes.BytesReference) SCRIPT_GENERAL_CACHE_EXPIRE_SETTING(org.opensearch.script.ScriptService.SCRIPT_GENERAL_CACHE_EXPIRE_SETTING) BiFunction(java.util.function.BiFunction) HashMap(java.util.HashMap) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) Function(java.util.function.Function) SCRIPT_MAX_COMPILATIONS_RATE_SETTING(org.opensearch.script.ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING) ClusterState(org.opensearch.cluster.ClusterState) Map(java.util.Map) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) XContentFactory(org.opensearch.common.xcontent.XContentFactory) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) Environment(org.opensearch.env.Environment) Setting(org.opensearch.common.settings.Setting) TimeValue(org.opensearch.common.unit.TimeValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) SCRIPT_CACHE_SIZE_SETTING(org.opensearch.script.ScriptService.SCRIPT_CACHE_SIZE_SETTING) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) SCRIPT_CACHE_EXPIRE_SETTING(org.opensearch.script.ScriptService.SCRIPT_CACHE_EXPIRE_SETTING) SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING(org.opensearch.script.ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING) SCRIPT_GENERAL_CACHE_SIZE_SETTING(org.opensearch.script.ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) BytesArray(org.opensearch.common.bytes.BytesArray) ClusterName(org.opensearch.cluster.ClusterName) XContentType(org.opensearch.common.xcontent.XContentType) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 15 with Setting

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);
}
Also used : Setting(org.opensearch.common.settings.Setting) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings)

Aggregations

Setting (org.opensearch.common.settings.Setting)32 ClusterSettings (org.opensearch.common.settings.ClusterSettings)22 Settings (org.opensearch.common.settings.Settings)21 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 Before (org.junit.Before)10 ClusterState (org.opensearch.cluster.ClusterState)9 ClusterService (org.opensearch.cluster.service.ClusterService)7 Client (org.opensearch.client.Client)6 Metadata (org.opensearch.cluster.metadata.Metadata)6 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)6 Version (org.opensearch.Version)5 ClusterName (org.opensearch.cluster.ClusterName)5 AbstractScopedSettings (org.opensearch.common.settings.AbstractScopedSettings)5 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)5 ExecutorBuilder (org.opensearch.threadpool.ExecutorBuilder)5 ScalingExecutorBuilder (org.opensearch.threadpool.ScalingExecutorBuilder)5 ThreadPool (org.opensearch.threadpool.ThreadPool)5 Arrays (java.util.Arrays)4 Set (java.util.Set)4