Search in sources :

Example 16 with Builder

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

the class CoordinatorTests method testSingleNodeDiscoveryWithoutQuorum.

public void testSingleNodeDiscoveryWithoutQuorum() {
    try (Cluster cluster = new Cluster(3)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode clusterNode = cluster.getAnyNode();
        logger.debug("rebooting [{}]", clusterNode.getId());
        clusterNode.close();
        cluster.clusterNodes.forEach(cn -> cluster.deterministicTaskQueue.scheduleNow(cn.onNode(new Runnable() {

            @Override
            public void run() {
                cn.transportService.disconnectFromNode(clusterNode.getLocalNode());
            }

            @Override
            public String toString() {
                return "disconnect from " + clusterNode.getLocalNode() + " after shutdown";
            }
        })));
        IllegalStateException ise = expectThrows(IllegalStateException.class, () -> cluster.clusterNodes.replaceAll(cn -> cn == clusterNode ? cn.restartedNode(Function.identity(), Function.identity(), Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE).build()) : cn));
        assertThat(ise.getMessage(), allOf(containsString("cannot start with [discovery.type] set to [single-node] when local node"), containsString("does not have quorum in voting configuration")));
        // to avoid closing it twice
        cluster.clusterNodes.remove(clusterNode);
    }
}
Also used : ClusterNode(org.opensearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) Arrays(java.util.Arrays) FOLLOWER_CHECK_INTERVAL_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING) Metadata(org.opensearch.cluster.metadata.Metadata) FOLLOWER_CHECK_TIMEOUT_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING) NodeRoles.nonMasterNode(org.opensearch.test.NodeRoles.nonMasterNode) Matchers.not(org.hamcrest.Matchers.not) Level(org.apache.logging.log4j.Level) Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) LogEvent(org.apache.logging.log4j.core.LogEvent) Regex(org.opensearch.common.regex.Regex) LEADER_CHECK_TIMEOUT_SETTING(org.opensearch.cluster.coordination.LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterBlock(org.opensearch.cluster.block.ClusterBlock) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) GatewayService(org.opensearch.gateway.GatewayService) UNHEALTHY(org.opensearch.monitor.StatusInfo.Status.UNHEALTHY) TimeValue(org.opensearch.common.unit.TimeValue) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) HEALTHY(org.opensearch.monitor.StatusInfo.Status.HEALTHY) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) Collectors(java.util.stream.Collectors) NO_MASTER_BLOCK_METADATA_WRITES(org.opensearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_METADATA_WRITES) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) NO_MASTER_BLOCK_WRITES(org.opensearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_WRITES) DISCOVERY_FIND_PEERS_INTERVAL_SETTING(org.opensearch.discovery.PeerFinder.DISCOVERY_FIND_PEERS_INTERVAL_SETTING) Matchers.equalTo(org.hamcrest.Matchers.equalTo) StatusInfo(org.opensearch.monitor.StatusInfo) FOLLOWER_CHECK_RETRY_COUNT_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING) Matchers.is(org.hamcrest.Matchers.is) CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION(org.opensearch.cluster.coordination.Reconfigurator.CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION) Builder(org.opensearch.common.settings.Settings.Builder) Matchers.anyOf(org.hamcrest.Matchers.anyOf) Matchers.containsString(org.hamcrest.Matchers.containsString) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) MockLogAppender(org.opensearch.test.MockLogAppender) AbstractDiffable(org.opensearch.cluster.AbstractDiffable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StreamOutput(org.opensearch.common.io.stream.StreamOutput) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) NO_MASTER_BLOCK_ALL(org.opensearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ALL) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) LEADER_CHECK_RETRY_COUNT_SETTING(org.opensearch.cluster.coordination.LeaderChecker.LEADER_CHECK_RETRY_COUNT_SETTING) LEADER_CHECK_INTERVAL_SETTING(org.opensearch.cluster.coordination.LeaderChecker.LEADER_CHECK_INTERVAL_SETTING) Matchers.hasSize(org.hamcrest.Matchers.hasSize) EXTREME_DELAY_VARIABILITY(org.opensearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.EXTREME_DELAY_VARIABILITY) PUBLISH_TIMEOUT_SETTING(org.opensearch.cluster.coordination.Coordinator.PUBLISH_TIMEOUT_SETTING) ELECTION_INITIAL_TIMEOUT_SETTING(org.opensearch.cluster.coordination.ElectionSchedulerFactory.ELECTION_INITIAL_TIMEOUT_SETTING) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ClusterNode(org.opensearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) IOException(java.io.IOException) DEFAULT_DELAY_VARIABILITY(org.opensearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.DEFAULT_DELAY_VARIABILITY) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) Sets(org.opensearch.common.util.set.Sets) NO_CLUSTER_MANAGER_BLOCK_SETTING(org.opensearch.cluster.coordination.NoMasterBlockService.NO_CLUSTER_MANAGER_BLOCK_SETTING) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Mode(org.opensearch.cluster.coordination.Coordinator.Mode) CANDIDATE(org.opensearch.cluster.coordination.Coordinator.Mode.CANDIDATE) LogManager(org.apache.logging.log4j.LogManager) DiscoveryModule(org.opensearch.discovery.DiscoveryModule) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 17 with Builder

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

the class ReconfiguratorTests method testAutoShrinking.

public void testAutoShrinking() {
    final String[] allNodes = new String[] { "a", "b", "c", "d", "e", "f", "g" };
    final String[] liveNodes = new String[randomIntBetween(1, allNodes.length)];
    randomSubsetOf(liveNodes.length, allNodes).toArray(liveNodes);
    final String[] initialVotingNodes = new String[randomIntBetween(1, allNodes.length)];
    randomSubsetOf(initialVotingNodes.length, allNodes).toArray(initialVotingNodes);
    final Builder settingsBuilder = Settings.builder();
    if (randomBoolean()) {
        settingsBuilder.put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), true);
    }
    final Reconfigurator reconfigurator = makeReconfigurator(settingsBuilder.build());
    final Set<DiscoveryNode> liveNodesSet = nodes(liveNodes);
    final VotingConfiguration initialConfig = conf(initialVotingNodes);
    final int quorumSize = Math.max(liveNodes.length / 2 + 1, initialVotingNodes.length < 3 ? 1 : 2);
    final VotingConfiguration finalConfig = reconfigurator.reconfigure(liveNodesSet, emptySet(), randomFrom(liveNodesSet), initialConfig);
    final String description = "reconfigure " + liveNodesSet + " from " + initialConfig + " yielded " + finalConfig;
    if (quorumSize > liveNodes.length) {
        assertFalse(description + " without a live quorum", finalConfig.hasQuorum(Arrays.asList(liveNodes)));
    } else {
        final List<String> expectedQuorum = randomSubsetOf(quorumSize, liveNodes);
        assertTrue(description + " with quorum[" + quorumSize + "] of " + expectedQuorum, finalConfig.hasQuorum(expectedQuorum));
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Builder(org.opensearch.common.settings.Settings.Builder) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 18 with Builder

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

the class InternalTestCluster method getNodeSettings.

private Settings getNodeSettings(final int nodeId, final long seed, final Settings extraSettings, final int defaultMinClusterManagerNodes) {
    final Settings settings = getSettings(nodeId, seed, extraSettings);
    final String name = buildNodeName(nodeId, settings);
    final Settings.Builder updatedSettings = Settings.builder();
    updatedSettings.put(Environment.PATH_HOME_SETTING.getKey(), baseDir);
    if (numDataPaths > 1) {
        updatedSettings.putList(Environment.PATH_DATA_SETTING.getKey(), IntStream.range(0, numDataPaths).mapToObj(i -> baseDir.resolve(name).resolve("d" + i).toString()).collect(Collectors.toList()));
    } else {
        updatedSettings.put(Environment.PATH_DATA_SETTING.getKey(), baseDir.resolve(name));
    }
    updatedSettings.put(Environment.PATH_SHARED_DATA_SETTING.getKey(), baseDir.resolve(name + "-shared"));
    // allow overriding the above
    updatedSettings.put(settings);
    // force certain settings
    updatedSettings.put("node.name", name);
    updatedSettings.put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), seed);
    final String discoveryType = DISCOVERY_TYPE_SETTING.get(updatedSettings.build());
    final boolean usingSingleNodeDiscovery = discoveryType.equals("single-node");
    if (usingSingleNodeDiscovery == false) {
        if (autoManageClusterManagerNodes) {
            assertThat("if cluster-manager nodes are automatically managed then nodes must complete a join cycle when starting", updatedSettings.get(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey()), nullValue());
        }
    }
    return updatedSettings.build();
}
Also used : Builder(org.opensearch.common.settings.Settings.Builder) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings) SecureSettings(org.opensearch.common.settings.SecureSettings) TransportSettings(org.opensearch.transport.TransportSettings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 19 with Builder

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

the class InternalTestCluster method startNodes.

/**
 * Starts multiple nodes with the given settings and returns their names
 */
public synchronized List<String> startNodes(Settings... extraSettings) {
    final int newClusterManagerCount = Math.toIntExact(Stream.of(extraSettings).filter(DiscoveryNode::isMasterNode).count());
    final int defaultMinClusterManagerNodes;
    if (autoManageClusterManagerNodes) {
        defaultMinClusterManagerNodes = getMinClusterManagerNodes(getClusterManagerNodesCount() + newClusterManagerCount);
    } else {
        defaultMinClusterManagerNodes = -1;
    }
    final List<NodeAndClient> nodes = new ArrayList<>();
    final int prevClusterManagerCount = getClusterManagerNodesCount();
    int autoBootstrapClusterManagerNodeIndex = autoManageClusterManagerNodes && prevClusterManagerCount == 0 && newClusterManagerCount > 0 && Arrays.stream(extraSettings).allMatch(s -> DiscoveryNode.isMasterNode(s) == false || ZEN2_DISCOVERY_TYPE.equals(DISCOVERY_TYPE_SETTING.get(s))) ? RandomNumbers.randomIntBetween(random, 0, newClusterManagerCount - 1) : -1;
    final int numOfNodes = extraSettings.length;
    final int firstNodeId = nextNodeId.getAndIncrement();
    final List<Settings> settings = new ArrayList<>();
    for (int i = 0; i < numOfNodes; i++) {
        settings.add(getNodeSettings(firstNodeId + i, random.nextLong(), extraSettings[i], defaultMinClusterManagerNodes));
    }
    nextNodeId.set(firstNodeId + numOfNodes);
    final List<String> initialClusterManagerNodes = settings.stream().filter(DiscoveryNode::isMasterNode).map(Node.NODE_NAME_SETTING::get).collect(Collectors.toList());
    final List<Settings> updatedSettings = bootstrapClusterManagerNodeWithSpecifiedIndex(settings);
    for (int i = 0; i < numOfNodes; i++) {
        final Settings nodeSettings = updatedSettings.get(i);
        final Builder builder = Settings.builder();
        if (DiscoveryNode.isMasterNode(nodeSettings)) {
            if (autoBootstrapClusterManagerNodeIndex == 0) {
                builder.putList(INITIAL_CLUSTER_MANAGER_NODES_SETTING.getKey(), initialClusterManagerNodes);
            }
            autoBootstrapClusterManagerNodeIndex -= 1;
        }
        final NodeAndClient nodeAndClient = buildNode(firstNodeId + i, builder.put(nodeSettings).build(), false, () -> rebuildUnicastHostFiles(nodes));
        nodes.add(nodeAndClient);
    }
    startAndPublishNodesAndClients(nodes);
    if (autoManageClusterManagerNodes) {
        validateClusterFormed();
    }
    return nodes.stream().map(NodeAndClient::getName).collect(Collectors.toList());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) NodeRoles.dataOnlyNode(org.opensearch.test.NodeRoles.dataOnlyNode) Node(org.opensearch.node.Node) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockNode(org.opensearch.node.MockNode) Builder(org.opensearch.common.settings.Settings.Builder) ArrayList(java.util.ArrayList) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings) SecureSettings(org.opensearch.common.settings.SecureSettings) TransportSettings(org.opensearch.transport.TransportSettings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 20 with Builder

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

the class InternalTestCluster method getSettings.

private Settings getSettings(int nodeOrdinal, long nodeSeed, Settings others) {
    Builder builder = Settings.builder().put(defaultSettings).put(getRandomNodeSettings(nodeSeed));
    Settings settings = nodeConfigurationSource.nodeSettings(nodeOrdinal);
    if (settings != null) {
        if (settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) != null) {
            throw new IllegalStateException("Tests must not set a '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "' as a node setting set '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "': [" + settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) + "]");
        }
        builder.put(settings);
    }
    if (others != null) {
        builder.put(others);
    }
    builder.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName);
    return builder.build();
}
Also used : Builder(org.opensearch.common.settings.Settings.Builder) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings) SecureSettings(org.opensearch.common.settings.SecureSettings) TransportSettings(org.opensearch.transport.TransportSettings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Aggregations

Builder (org.opensearch.common.settings.Settings.Builder)35 Settings (org.opensearch.common.settings.Settings)11 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)9 SearchRequestBuilder (org.opensearch.action.search.SearchRequestBuilder)7 QueryBuilder (org.opensearch.index.query.QueryBuilder)7 IndexRequestBuilder (org.opensearch.action.index.IndexRequestBuilder)6 SearchResponse (org.opensearch.action.search.SearchResponse)6 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)6 XContentFactory.jsonBuilder (org.opensearch.common.xcontent.XContentFactory.jsonBuilder)6 QueryRescorerBuilder (org.opensearch.search.rescore.QueryRescorerBuilder)5 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 OpenSearchException (org.opensearch.OpenSearchException)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3