Search in sources :

Example 21 with Settings.builder

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

the class CoordinatorTests method testAppliesNoMasterBlock.

private void testAppliesNoMasterBlock(String noMasterBlockSetting, ClusterBlock expectedBlock) {
    try (Cluster cluster = new Cluster(3)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader = cluster.getAnyLeader();
        leader.submitUpdateTask("update NO_MASTER_BLOCK_SETTING", cs -> {
            final Builder settingsBuilder = Settings.builder().put(cs.metadata().persistentSettings());
            settingsBuilder.put(NO_MASTER_BLOCK_SETTING.getKey(), noMasterBlockSetting);
            return ClusterState.builder(cs).metadata(Metadata.builder(cs.metadata()).persistentSettings(settingsBuilder.build())).build();
        }, (source, e) -> {
        });
        cluster.runFor(DEFAULT_CLUSTER_STATE_UPDATE_DELAY, "committing setting update");
        final ClusterNode removedNode = cluster.getAnyNode();
        removedNode.disconnect();
        cluster.runFor(Math.max(defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING) + defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING), defaultMillis(LEADER_CHECK_TIMEOUT_SETTING) + defaultMillis(LEADER_CHECK_INTERVAL_SETTING)) + DEFAULT_CLUSTER_STATE_UPDATE_DELAY, "detecting disconnection");
        assertThat(removedNode.getLastAppliedClusterState().blocks().global(), hasItem(expectedBlock));
        removedNode.close();
        final ClusterNode restartedNode = removedNode.restartedNode();
        cluster.clusterNodes.replaceAll(cn -> cn == removedNode ? restartedNode : cn);
        restartedNode.disconnect();
        cluster.stabilise();
        assertThat(restartedNode.getLastAppliedClusterState().blocks().global(), hasItem(expectedBlock));
    }
}
Also used : ClusterNode(org.opensearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) Builder(org.opensearch.common.settings.Settings.Builder) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 22 with Settings.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)

Example 23 with Settings.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 defaultMinMasterNodes) {
    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 (autoManageMasterNodes) {
            assertThat("if master 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 24 with Settings.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 newMasterCount = Math.toIntExact(Stream.of(extraSettings).filter(DiscoveryNode::isMasterNode).count());
    final int defaultMinMasterNodes;
    if (autoManageMasterNodes) {
        defaultMinMasterNodes = getMinMasterNodes(getMasterNodesCount() + newMasterCount);
    } else {
        defaultMinMasterNodes = -1;
    }
    final List<NodeAndClient> nodes = new ArrayList<>();
    final int prevMasterCount = getMasterNodesCount();
    int autoBootstrapMasterNodeIndex = autoManageMasterNodes && prevMasterCount == 0 && newMasterCount > 0 && Arrays.stream(extraSettings).allMatch(s -> DiscoveryNode.isMasterNode(s) == false || ZEN2_DISCOVERY_TYPE.equals(DISCOVERY_TYPE_SETTING.get(s))) ? RandomNumbers.randomIntBetween(random, 0, newMasterCount - 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], defaultMinMasterNodes));
    }
    nextNodeId.set(firstNodeId + numOfNodes);
    final List<String> initialMasterNodes = settings.stream().filter(DiscoveryNode::isMasterNode).map(Node.NODE_NAME_SETTING::get).collect(Collectors.toList());
    final List<Settings> updatedSettings = bootstrapMasterNodeWithSpecifiedIndex(settings);
    for (int i = 0; i < numOfNodes; i++) {
        final Settings nodeSettings = updatedSettings.get(i);
        final Builder builder = Settings.builder();
        if (DiscoveryNode.isMasterNode(nodeSettings)) {
            if (autoBootstrapMasterNodeIndex == 0) {
                builder.putList(INITIAL_MASTER_NODES_SETTING.getKey(), initialMasterNodes);
            }
            autoBootstrapMasterNodeIndex -= 1;
        }
        final NodeAndClient nodeAndClient = buildNode(firstNodeId + i, builder.put(nodeSettings).build(), false, () -> rebuildUnicastHostFiles(nodes));
        nodes.add(nodeAndClient);
    }
    startAndPublishNodesAndClients(nodes);
    if (autoManageMasterNodes) {
        validateClusterFormed();
    }
    return nodes.stream().map(NodeAndClient::getName).collect(Collectors.toList());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) NodeRoles.masterOnlyNode(org.opensearch.test.NodeRoles.masterOnlyNode) 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 25 with Settings.builder

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

the class StopTokenFilterTests method testPositionIncrementSetting.

public void testPositionIncrementSetting() throws IOException {
    Builder builder = Settings.builder().put("index.analysis.filter.my_stop.type", "stop").put("index.analysis.filter.my_stop.enable_position_increments", false);
    if (random().nextBoolean()) {
        builder.put("index.analysis.filter.my_stop.version", "5.0");
    }
    builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString());
    Settings settings = builder.build();
    try {
        AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("enable_position_increments is not supported anymore"));
    }
}
Also used : Builder(org.opensearch.common.settings.Settings.Builder) Settings(org.opensearch.common.settings.Settings)

Aggregations

Builder (org.opensearch.common.settings.Settings.Builder)25 Settings (org.opensearch.common.settings.Settings)9 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)8 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 XContentFactory.jsonBuilder (org.opensearch.common.xcontent.XContentFactory.jsonBuilder)6 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)5 QueryRescorerBuilder (org.opensearch.search.rescore.QueryRescorerBuilder)5 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)5 DiskThresholdSettings (org.opensearch.cluster.routing.allocation.DiskThresholdSettings)4 MockSecureSettings (org.opensearch.common.settings.MockSecureSettings)4 SecureSettings (org.opensearch.common.settings.SecureSettings)4 RecoverySettings (org.opensearch.indices.recovery.RecoverySettings)4 DiscoverySettings (org.opensearch.node.Node.DiscoverySettings)4 ArrayList (java.util.ArrayList)3 OpenSearchException (org.opensearch.OpenSearchException)3 TransportSettings (org.opensearch.transport.TransportSettings)3 HashSet (java.util.HashSet)2