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 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 ProxyConnectionStrategyTests method testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesOrServerNameChange.
public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesOrServerNameChange() {
try (MockTransportService remoteTransport = startTransport("node1", Version.CURRENT)) {
TransportAddress remoteAddress = remoteTransport.boundAddress().publishAddress();
try (MockTransportService localService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool)) {
localService.start();
localService.acceptIncomingRequests();
ClusterConnectionManager connectionManager = new ClusterConnectionManager(profile, localService.transport);
int numOfConnections = randomIntBetween(4, 8);
try (RemoteConnectionManager remoteConnectionManager = new RemoteConnectionManager(clusterAlias, connectionManager);
ProxyConnectionStrategy strategy = new ProxyConnectionStrategy(clusterAlias, localService, remoteConnectionManager, Settings.EMPTY, numOfConnections, remoteAddress.toString(), "server-name")) {
PlainActionFuture<Void> connectFuture = PlainActionFuture.newFuture();
strategy.connect(connectFuture);
connectFuture.actionGet();
assertTrue(connectionManager.getAllConnectedNodes().stream().anyMatch(n -> n.getAddress().equals(remoteAddress)));
assertEquals(numOfConnections, connectionManager.size());
assertTrue(strategy.assertNoRunningConnections());
Setting<?> modeSetting = RemoteConnectionStrategy.REMOTE_CONNECTION_MODE.getConcreteSettingForNamespace("cluster-alias");
Setting<?> addressesSetting = ProxyConnectionStrategy.PROXY_ADDRESS.getConcreteSettingForNamespace("cluster-alias");
Setting<?> socketConnections = ProxyConnectionStrategy.REMOTE_SOCKET_CONNECTIONS.getConcreteSettingForNamespace("cluster-alias");
Setting<?> serverName = ProxyConnectionStrategy.SERVER_NAME.getConcreteSettingForNamespace("cluster-alias");
Settings noChange = Settings.builder().put(modeSetting.getKey(), "proxy").put(addressesSetting.getKey(), remoteAddress.toString()).put(socketConnections.getKey(), numOfConnections).put(serverName.getKey(), "server-name").build();
assertFalse(strategy.shouldRebuildConnection(noChange));
Settings addressesChanged = Settings.builder().put(modeSetting.getKey(), "proxy").put(addressesSetting.getKey(), remoteAddress.toString()).build();
assertTrue(strategy.shouldRebuildConnection(addressesChanged));
Settings socketsChanged = Settings.builder().put(modeSetting.getKey(), "proxy").put(addressesSetting.getKey(), remoteAddress.toString()).put(socketConnections.getKey(), numOfConnections + 1).build();
assertTrue(strategy.shouldRebuildConnection(socketsChanged));
Settings serverNameChange = Settings.builder().put(modeSetting.getKey(), "proxy").put(addressesSetting.getKey(), remoteAddress.toString()).put(socketConnections.getKey(), numOfConnections).put(serverName.getKey(), "server-name2").build();
assertTrue(strategy.shouldRebuildConnection(serverNameChange));
}
}
}
}
use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.
the class DedicatedClusterSnapshotRestoreIT method testExceptionWhenRestoringPersistentSettings.
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37485")
public void testExceptionWhenRestoringPersistentSettings() {
logger.info("--> start 2 nodes");
internalCluster().startNodes(2);
Client client = client();
Consumer<String> setSettingValue = value -> {
client.admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().put(BrokenSettingPlugin.BROKEN_SETTING.getKey(), value)).execute().actionGet();
};
Consumer<String> assertSettingValue = value -> {
assertThat(client.admin().cluster().prepareState().setRoutingTable(false).setNodes(false).execute().actionGet().getState().getMetadata().persistentSettings().get(BrokenSettingPlugin.BROKEN_SETTING.getKey()), equalTo(value));
};
logger.info("--> set test persistent setting");
setSettingValue.accept("new value");
assertSettingValue.accept("new value");
createRepository("test-repo", "fs");
createFullSnapshot("test-repo", "test-snap");
assertThat(getSnapshot("test-repo", "test-snap").state(), equalTo(SnapshotState.SUCCESS));
logger.info("--> change the test persistent setting and break it");
setSettingValue.accept("new value 2");
assertSettingValue.accept("new value 2");
BrokenSettingPlugin.breakSetting(true);
logger.info("--> restore snapshot");
try {
client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setRestoreGlobalState(true).setWaitForCompletion(true).execute().actionGet();
} catch (IllegalArgumentException ex) {
assertEquals(BrokenSettingPlugin.EXCEPTION.getMessage(), ex.getMessage());
}
assertSettingValue.accept("new value 2");
}
use of org.opensearch.common.settings.Setting in project OpenSearch by opensearch-project.
the class AzureStorageSettings method getValue.
private static <T> T getValue(Settings settings, String groupName, Setting<T> setting) {
final Setting.AffixKey k = (Setting.AffixKey) setting.getRawKey();
final String fullKey = k.toConcreteKey(groupName).toString();
return setting.getConcreteSetting(fullKey).get(settings);
}
Aggregations