Search in sources :

Example 1 with ZEN2_DISCOVERY_TYPE

use of org.opensearch.discovery.DiscoveryModule.ZEN2_DISCOVERY_TYPE in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testDiscoveryConfiguredCheck.

public void testDiscoveryConfiguredCheck() throws NodeValidationException {
    final List<BootstrapCheck> checks = Collections.singletonList(new BootstrapChecks.DiscoveryConfiguredCheck());
    final BootstrapContext zen2Context = createTestContext(Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), ZEN2_DISCOVERY_TYPE).build(), Metadata.EMPTY_METADATA);
    // not always enforced
    BootstrapChecks.check(zen2Context, false, checks);
    // not enforced for non-zen2 discovery
    BootstrapChecks.check(createTestContext(Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), randomFrom("single-node", randomAlphaOfLength(5))).build(), Metadata.EMPTY_METADATA), true, checks);
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(zen2Context, true, checks));
    assertThat(e, hasToString(containsString("the default discovery settings are unsuitable for production use; at least one " + "of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured")));
    CheckedConsumer<Settings.Builder, NodeValidationException> ensureChecksPass = b -> {
        final BootstrapContext context = createTestContext(b.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), ZEN2_DISCOVERY_TYPE).build(), Metadata.EMPTY_METADATA);
        BootstrapChecks.check(context, true, checks);
    };
    ensureChecksPass.accept(Settings.builder().putList(ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING.getKey()));
    ensureChecksPass.accept(Settings.builder().putList(DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING.getKey()));
    ensureChecksPass.accept(Settings.builder().putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()));
}
Also used : Matchers.hasToString(org.hamcrest.Matchers.hasToString) Arrays(java.util.Arrays) ClusterBootstrapService(org.opensearch.cluster.coordination.ClusterBootstrapService) Metadata(org.opensearch.cluster.metadata.Metadata) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CheckedConsumer(org.opensearch.common.CheckedConsumer) Matchers.not(org.hamcrest.Matchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) ZEN2_DISCOVERY_TYPE(org.opensearch.discovery.DiscoveryModule.ZEN2_DISCOVERY_TYPE) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Locale(java.util.Locale) JvmInfo(org.opensearch.monitor.jvm.JvmInfo) AbstractBootstrapCheckTestCase(org.opensearch.test.AbstractBootstrapCheckTestCase) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Settings(org.opensearch.common.settings.Settings) SettingsBasedSeedHostsProvider(org.opensearch.discovery.SettingsBasedSeedHostsProvider) Mockito.when(org.mockito.Mockito.when) NodeValidationException(org.opensearch.node.NodeValidationException) Mockito.verify(org.mockito.Mockito.verify) TransportAddress(org.opensearch.common.transport.TransportAddress) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Constants(org.apache.lucene.util.Constants) Matcher(org.hamcrest.Matcher) Collections(java.util.Collections) DiscoveryModule(org.opensearch.discovery.DiscoveryModule) Mockito.mock(org.mockito.Mockito.mock) NodeValidationException(org.opensearch.node.NodeValidationException)

Aggregations

InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Logger (org.apache.logging.log4j.Logger)1 Constants (org.apache.lucene.util.Constants)1 CoreMatchers.allOf (org.hamcrest.CoreMatchers.allOf)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)1 Matcher (org.hamcrest.Matcher)1 Matchers.hasToString (org.hamcrest.Matchers.hasToString)1 Matchers.not (org.hamcrest.Matchers.not)1 Mockito.mock (org.mockito.Mockito.mock)1