Search in sources :

Example 51 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class AbstractSimpleTransportTestCase method testProfileSettings.

public void testProfileSettings() {
    boolean enable = randomBoolean();
    Settings globalSettings = Settings.builder().put("network.tcp.no_delay", enable).put("network.tcp.keep_alive", enable).put("network.tcp.keep_idle", "42").put("network.tcp.keep_interval", "7").put("network.tcp.keep_count", "13").put("network.tcp.reuse_address", enable).put("network.tcp.send_buffer_size", "43000b").put("network.tcp.receive_buffer_size", "42000b").put("network.publish_host", "the_publish_host").put("network.bind_host", "the_bind_host").build();
    Settings globalSettings2 = Settings.builder().put("network.tcp.no_delay", !enable).put("network.tcp.keep_alive", !enable).put("network.tcp.keep_idle", "43").put("network.tcp.keep_interval", "8").put("network.tcp.keep_count", "14").put("network.tcp.reuse_address", !enable).put("network.tcp.send_buffer_size", "4b").put("network.tcp.receive_buffer_size", "3b").put("network.publish_host", "another_publish_host").put("network.bind_host", "another_bind_host").build();
    Settings transportSettings = Settings.builder().put("transport.tcp.no_delay", enable).put("transport.tcp.keep_alive", enable).put("transport.tcp.keep_idle", "42").put("transport.tcp.keep_interval", "7").put("transport.tcp.keep_count", "13").put("transport.tcp.reuse_address", enable).put("transport.tcp.send_buffer_size", "43000b").put("transport.tcp.receive_buffer_size", "42000b").put("transport.publish_host", "the_publish_host").put("transport.port", "9700-9800").put("transport.bind_host", "the_bind_host").put(globalSettings2).build();
    Settings transportSettings2 = Settings.builder().put("transport.tcp.no_delay", !enable).put("transport.tcp.keep_alive", !enable).put("transport.tcp.keep_idle", "43").put("transport.tcp.keep_interval", "8").put("transport.tcp.keep_count", "14").put("transport.tcp.reuse_address", !enable).put("transport.tcp.send_buffer_size", "5b").put("transport.tcp.receive_buffer_size", "6b").put("transport.publish_host", "another_publish_host").put("transport.port", "9702-9802").put("transport.bind_host", "another_bind_host").put(globalSettings2).build();
    Settings defaultProfileSettings = Settings.builder().put("transport.profiles.default.tcp.no_delay", enable).put("transport.profiles.default.tcp.keep_alive", enable).put("transport.profiles.default.tcp.keep_idle", "42").put("transport.profiles.default.tcp.keep_interval", "7").put("transport.profiles.default.tcp.keep_count", "13").put("transport.profiles.default.tcp.reuse_address", enable).put("transport.profiles.default.tcp.send_buffer_size", "43000b").put("transport.profiles.default.tcp.receive_buffer_size", "42000b").put("transport.profiles.default.port", "9700-9800").put("transport.profiles.default.publish_host", "the_publish_host").put("transport.profiles.default.bind_host", "the_bind_host").put("transport.profiles.default.publish_port", 42).put(// ensure that we have profile precedence
    randomBoolean() ? transportSettings2 : globalSettings2).build();
    Settings profileSettings = Settings.builder().put("transport.profiles.some_profile.tcp.no_delay", enable).put("transport.profiles.some_profile.tcp.keep_alive", enable).put("transport.profiles.some_profile.tcp.keep_idle", "42").put("transport.profiles.some_profile.tcp.keep_interval", "7").put("transport.profiles.some_profile.tcp.keep_count", "13").put("transport.profiles.some_profile.tcp.reuse_address", enable).put("transport.profiles.some_profile.tcp.send_buffer_size", "43000b").put("transport.profiles.some_profile.tcp.receive_buffer_size", "42000b").put("transport.profiles.some_profile.port", "9700-9800").put("transport.profiles.some_profile.publish_host", "the_publish_host").put("transport.profiles.some_profile.bind_host", "the_bind_host").put("transport.profiles.some_profile.publish_port", 42).put(// ensure that we have profile precedence
    randomBoolean() ? transportSettings2 : globalSettings2).put(randomBoolean() ? defaultProfileSettings : Settings.EMPTY).build();
    Settings randomSettings = randomFrom(random(), globalSettings, transportSettings, profileSettings);
    ClusterSettings clusterSettings = new ClusterSettings(randomSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    clusterSettings.validate(randomSettings, false);
    TcpTransport.ProfileSettings settings = new TcpTransport.ProfileSettings(// port is required
    Settings.builder().put(randomSettings).put("transport.profiles.some_profile.port", "9700-9800").build(), "some_profile");
    assertEquals(enable, settings.tcpNoDelay);
    assertEquals(enable, settings.tcpKeepAlive);
    assertEquals(42, settings.tcpKeepIdle);
    assertEquals(7, settings.tcpKeepInterval);
    assertEquals(13, settings.tcpKeepCount);
    assertEquals(enable, settings.reuseAddress);
    assertEquals(43000, settings.sendBufferSize.getBytes());
    assertEquals(42000, settings.receiveBufferSize.getBytes());
    if (randomSettings == profileSettings) {
        assertEquals(42, settings.publishPort);
    } else {
        assertEquals(-1, settings.publishPort);
    }
    if (randomSettings == globalSettings) {
        // publish host has no global fallback for the profile since we later resolve it based on
        // the bound address
        assertEquals(Collections.emptyList(), settings.publishHosts);
    } else {
        assertEquals(Collections.singletonList("the_publish_host"), settings.publishHosts);
    }
    assertEquals("9700-9800", settings.portOrRange);
    assertEquals(Collections.singletonList("the_bind_host"), settings.bindHosts);
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings)

Example 52 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class AbstractSimpleTransportTestCase method buildService.

private MockTransportService buildService(final String name, final Version version, @Nullable ClusterSettings clusterSettings, Settings settings, boolean acceptRequests, boolean doHandshake, TransportInterceptor interceptor) {
    Settings updatedSettings = Settings.builder().put(TransportSettings.PORT.getKey(), getPortRange()).put(settings).put(Node.NODE_NAME_SETTING.getKey(), name).build();
    if (clusterSettings == null) {
        clusterSettings = new ClusterSettings(updatedSettings, getSupportedSettings());
    }
    Transport transport = build(updatedSettings, version, clusterSettings, doHandshake);
    MockTransportService service = MockTransportService.createNewService(updatedSettings, transport, version, threadPool, clusterSettings, Collections.emptySet(), interceptor);
    service.start();
    if (acceptRequests) {
        service.acceptIncomingRequests();
    }
    return service;
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) MockTransportService(org.opensearch.test.transport.MockTransportService) StubbableTransport(org.opensearch.test.transport.StubbableTransport) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings)

Example 53 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class PersistentTasksDecidersTestCase method updateSettings.

protected void updateSettings(final Settings settings) {
    ClusterSettings clusterSettings = clusterService.getClusterSettings();
    Settings.Builder updated = Settings.builder();
    clusterSettings.updateDynamicSettings(settings, updated, Settings.builder(), getTestClass().getName());
    clusterSettings.applySettings(updated.build());
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings)

Example 54 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class ResponseCollectorServiceTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    threadpool = new TestThreadPool("response_collector_tests");
    clusterService = new ClusterService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadpool);
    collector = new ResponseCollectorService(clusterService);
}
Also used : ClusterService(org.opensearch.cluster.service.ClusterService) ClusterSettings(org.opensearch.common.settings.ClusterSettings) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 55 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class FsHealthServiceTests method testLoggingOnHungIO.

@TestLogging(value = "org.opensearch.monitor.fs:WARN", reason = "to ensure that we log on hung IO at WARN level")
public void testLoggingOnHungIO() throws Exception {
    long slowLogThreshold = randomLongBetween(100, 200);
    final Settings settings = Settings.builder().put(FsHealthService.SLOW_PATH_LOGGING_THRESHOLD_SETTING.getKey(), slowLogThreshold + "ms").build();
    FileSystem fileSystem = PathUtils.getDefaultFileSystem();
    TestThreadPool testThreadPool = new TestThreadPool(getClass().getName(), settings);
    FileSystemFsyncHungProvider disruptFileSystemProvider = new FileSystemFsyncHungProvider(fileSystem, randomLongBetween(slowLogThreshold + 1, 400), testThreadPool);
    fileSystem = disruptFileSystemProvider.getFileSystem(null);
    PathUtilsForTesting.installMock(fileSystem);
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    try (MockLogAppender mockAppender = MockLogAppender.createForLoggers(LogManager.getLogger(FsHealthService.class));
        NodeEnvironment env = newNodeEnvironment()) {
        FsHealthService fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
        int counter = 0;
        for (Path path : env.nodeDataPaths()) {
            mockAppender.addExpectation(new MockLogAppender.SeenEventExpectation("test" + ++counter, FsHealthService.class.getCanonicalName(), Level.WARN, "health check of [" + path + "] took [*ms] which is above the warn threshold*"));
        }
        // disrupt file system
        disruptFileSystemProvider.injectIODelay.set(true);
        fsHealthService.new FsHealthMonitor().run();
        assertEquals(env.nodeDataPaths().length, disruptFileSystemProvider.getInjectedPathCount());
        assertBusy(mockAppender::assertAllExpectationsMatched);
    } finally {
        PathUtilsForTesting.teardown();
        ThreadPool.terminate(testThreadPool, 500, TimeUnit.MILLISECONDS);
    }
}
Also used : Path(java.nio.file.Path) ClusterSettings(org.opensearch.common.settings.ClusterSettings) MockLogAppender(org.opensearch.test.MockLogAppender) NodeEnvironment(org.opensearch.env.NodeEnvironment) TestThreadPool(org.opensearch.threadpool.TestThreadPool) FileSystem(java.nio.file.FileSystem) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) TestLogging(org.opensearch.test.junit.annotations.TestLogging)

Aggregations

ClusterSettings (org.opensearch.common.settings.ClusterSettings)218 Settings (org.opensearch.common.settings.Settings)136 ClusterState (org.opensearch.cluster.ClusterState)70 ClusterService (org.opensearch.cluster.service.ClusterService)67 HashSet (java.util.HashSet)46 Metadata (org.opensearch.cluster.metadata.Metadata)37 Matchers.containsString (org.hamcrest.Matchers.containsString)36 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)36 Before (org.junit.Before)33 ArrayList (java.util.ArrayList)31 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)31 ClusterName (org.opensearch.cluster.ClusterName)30 ThreadPool (org.opensearch.threadpool.ThreadPool)29 RoutingTable (org.opensearch.cluster.routing.RoutingTable)26 TestThreadPool (org.opensearch.threadpool.TestThreadPool)25 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 Setting (org.opensearch.common.settings.Setting)23 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)23 IOException (java.io.IOException)19 BalancedShardsAllocator (org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)19