当前位置: 首页>>代码示例>>Java>>正文


Java DiscoveryNodes.Builder方法代码示例

本文整理汇总了Java中org.elasticsearch.cluster.node.DiscoveryNodes.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryNodes.Builder方法的具体用法?Java DiscoveryNodes.Builder怎么用?Java DiscoveryNodes.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.cluster.node.DiscoveryNodes的用法示例。


在下文中一共展示了DiscoveryNodes.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createClusterService

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
public static ClusterService createClusterService(Settings settings, ThreadPool threadPool, DiscoveryNode localNode) {
    ClusterService clusterService = new ClusterService(
        Settings.builder().put("cluster.name", "ClusterServiceTests").put(settings).build(),
            new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS),
            threadPool, () -> localNode);
    clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) {
        @Override
        public void connectToNodes(DiscoveryNodes discoveryNodes) {
            // skip
        }

        @Override
        public void disconnectFromNodesExcept(DiscoveryNodes nodesToKeep) {
            // skip
        }
    });
    clusterService.setClusterStatePublisher((event, ackListener) -> {
    });
    clusterService.setDiscoverySettings(new DiscoverySettings(Settings.EMPTY,
        new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)));
    clusterService.start();
    final DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterService.state().nodes());
    nodes.masterNodeId(clusterService.localNode().getId());
    setState(clusterService, ClusterState.builder(clusterService.state()).nodes(nodes));
    return clusterService;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ClusterServiceUtils.java

示例2: testFailToPublishWithLessThanMinMasterNodes

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
public void testFailToPublishWithLessThanMinMasterNodes() throws Exception {
    final int masterNodes = randomIntBetween(1, 10);

    MockNode master = createMockNode("master");
    DiscoveryNodes.Builder discoveryNodesBuilder = DiscoveryNodes.builder().add(master.discoveryNode);
    for (int i = 1; i < masterNodes; i++) {
        discoveryNodesBuilder.add(createMockNode("node" + i).discoveryNode);
    }
    final int dataNodes = randomIntBetween(0, 5);
    final Settings dataSettings = Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build();
    for (int i = 0; i < dataNodes; i++) {
        discoveryNodesBuilder.add(createMockNode("data_" + i, dataSettings, null).discoveryNode);
    }
    discoveryNodesBuilder.localNodeId(master.discoveryNode.getId()).masterNodeId(master.discoveryNode.getId());
    DiscoveryNodes discoveryNodes = discoveryNodesBuilder.build();
    MetaData metaData = MetaData.EMPTY_META_DATA;
    ClusterState clusterState = ClusterState.builder(CLUSTER_NAME).metaData(metaData).nodes(discoveryNodes).build();
    ClusterState previousState = master.clusterState;
    try {
        publishState(master.action, clusterState, previousState, masterNodes + randomIntBetween(1, 5));
        fail("cluster state publishing didn't fail despite of not having enough nodes");
    } catch (Discovery.FailedToCommitClusterStateException expected) {
        logger.debug("failed to publish as expected", expected);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:PublishClusterStateActionTests.java

示例3: testRemovingNonExistentNodes

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
public void testRemovingNonExistentNodes() throws Exception {
    final ZenDiscovery.NodeRemovalClusterStateTaskExecutor executor =
            new ZenDiscovery.NodeRemovalClusterStateTaskExecutor(null, null, null, logger);
    final DiscoveryNodes.Builder builder = DiscoveryNodes.builder();
    final int nodes = randomIntBetween(2, 16);
    for (int i = 0; i < nodes; i++) {
        builder.add(node(i));
    }
    final ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(builder).build();

    final DiscoveryNodes.Builder removeBuilder = DiscoveryNodes.builder();
    for (int i = nodes; i < nodes + randomIntBetween(1, 16); i++) {
        removeBuilder.add(node(i));
    }
    final List<ZenDiscovery.NodeRemovalClusterStateTaskExecutor.Task> tasks =
            StreamSupport
                    .stream(removeBuilder.build().spliterator(), false)
                    .map(node -> new ZenDiscovery.NodeRemovalClusterStateTaskExecutor.Task(node, randomBoolean() ? "left" : "failed"))
                    .collect(Collectors.toList());

    final ClusterStateTaskExecutor.ClusterTasksResult<ZenDiscovery.NodeRemovalClusterStateTaskExecutor.Task> result
            = executor.execute(clusterState, tasks);
    assertThat(result.resultingState, equalTo(clusterState));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:NodeRemovalClusterStateTaskExecutorTests.java

示例4: testDefaultMaxConcurrentSearches

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
public void testDefaultMaxConcurrentSearches() {
    int numDataNodes = randomIntBetween(1, 10);
    DiscoveryNodes.Builder builder = DiscoveryNodes.builder();
    for (int i = 0; i < numDataNodes; i++) {
        builder.add(new DiscoveryNode("_id" + i, buildNewFakeTransportAddress(), Collections.emptyMap(),
                Collections.singleton(DiscoveryNode.Role.DATA), Version.CURRENT));
    }
    builder.add(new DiscoveryNode("master", buildNewFakeTransportAddress(), Collections.emptyMap(),
            Collections.singleton(DiscoveryNode.Role.MASTER), Version.CURRENT));
    builder.add(new DiscoveryNode("ingest", buildNewFakeTransportAddress(), Collections.emptyMap(),
            Collections.singleton(DiscoveryNode.Role.INGEST), Version.CURRENT));

    ClusterState state = ClusterState.builder(new ClusterName("_name")).nodes(builder).build();
    int result = TransportMultiSearchAction.defaultMaxConcurrentSearches(10, state);
    assertThat(result, equalTo(10 * numDataNodes));

    state = ClusterState.builder(new ClusterName("_name")).build();
    result = TransportMultiSearchAction.defaultMaxConcurrentSearches(10, state);
    assertThat(result, equalTo(1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:TransportMultiSearchActionTests.java

示例5: setUp

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
@Setup
public void setUp() throws Exception {
    final String[] params = indicesShardsReplicasNodes.split("\\|");

    int numIndices = toInt(params[0]);
    int numShards = toInt(params[1]);
    int numReplicas = toInt(params[2]);
    int numNodes = toInt(params[3]);

    strategy = Allocators.createAllocationService(Settings.builder()
            .put("cluster.routing.allocation.awareness.attributes", "tag")
            .build());

    MetaData.Builder mb = MetaData.builder();
    for (int i = 1; i <= numIndices; i++) {
        mb.put(IndexMetaData.builder("test_" + i)
                .settings(Settings.builder().put("index.version.created", Version.CURRENT))
                .numberOfShards(numShards)
                .numberOfReplicas(numReplicas)
        );
    }
    MetaData metaData = mb.build();
    RoutingTable.Builder rb = RoutingTable.builder();
    for (int i = 1; i <= numIndices; i++) {
        rb.addAsNew(metaData.index("test_" + i));
    }
    RoutingTable routingTable = rb.build();
    DiscoveryNodes.Builder nb = DiscoveryNodes.builder();
    for (int i = 1; i <= numNodes; i++) {
        nb.add(Allocators.newNode("node" + i, Collections.singletonMap("tag", "tag_" + (i % numTags))));
    }
    initialClusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData).routingTable(routingTable).nodes
            (nb).build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:AllocationBenchmark.java

示例6: stateWithNoShard

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
/**
 * Creates a cluster state with no index
 */
public static ClusterState stateWithNoShard() {
    DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
    discoBuilder.localNodeId(newNode(0).getId());
    discoBuilder.masterNodeId(newNode(1).getId());
    ClusterState.Builder state = ClusterState.builder(new ClusterName("test"));
    state.nodes(discoBuilder);
    state.metaData(MetaData.builder().generateClusterUuidIfNeeded());
    state.routingTable(RoutingTable.builder().build());
    return state.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:ClusterStateCreationUtils.java

示例7: addNodes

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
private void addNodes(int count) {
    ClusterState state = clusterService.state();
    final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(state.nodes());
    for (int i = 0;i< count;i++) {
        final DiscoveryNode node = new DiscoveryNode("node_" + state.nodes().getSize() + i, buildNewFakeTransportAddress(),
            emptyMap(), new HashSet<>(randomSubsetOf(Arrays.asList(DiscoveryNode.Role.values()))), Version.CURRENT);
        nodesBuilder.add(node);
    }
    setState(clusterService, ClusterState.builder(state).nodes(nodesBuilder));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:NodeJoinControllerTests.java

示例8: setUp

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    super.setUp();
    transport = new CapturingTransport();
    clusterService = createClusterService(THREAD_POOL);
    transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL,
        TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    int numNodes = randomIntBetween(3, 10);
    DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
    List<DiscoveryNode> discoveryNodes = new ArrayList<>();
    for (int i = 0; i < numNodes; i++) {
        Map<String, String> attributes = new HashMap<>();
        Set<DiscoveryNode.Role> roles = new HashSet<>(randomSubsetOf(Arrays.asList(DiscoveryNode.Role.values())));
        if (frequently()) {
            attributes.put("custom", randomBoolean() ? "match" : randomAsciiOfLengthBetween(3, 5));
        }
        final DiscoveryNode node = newNode(i, attributes, roles);
        discoBuilder = discoBuilder.add(node);
        discoveryNodes.add(node);
    }
    discoBuilder.localNodeId(randomFrom(discoveryNodes).getId());
    discoBuilder.masterNodeId(randomFrom(discoveryNodes).getId());
    ClusterState.Builder stateBuilder = ClusterState.builder(clusterService.getClusterName());
    stateBuilder.nodes(discoBuilder);
    ClusterState clusterState = stateBuilder.build();
    setState(clusterService, clusterState);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:TransportNodesActionTests.java

示例9: stateWithAssignedPrimariesAndOneReplica

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
/**
 * Creates cluster state with several shards and one replica and all shards STARTED.
 */
public static ClusterState stateWithAssignedPrimariesAndOneReplica(String index, int numberOfShards) {

    int numberOfNodes = 2; // we need a non-local master to test shard failures
    DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
    for (int i = 0; i < numberOfNodes + 1; i++) {
        final DiscoveryNode node = newNode(i);
        discoBuilder = discoBuilder.add(node);
    }
    discoBuilder.localNodeId(newNode(0).getId());
    discoBuilder.masterNodeId(newNode(1).getId()); // we need a non-local master to test shard failures
    IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(Settings.builder()
            .put(SETTING_VERSION_CREATED, Version.CURRENT)
            .put(SETTING_NUMBER_OF_SHARDS, numberOfShards).put(SETTING_NUMBER_OF_REPLICAS, 1)
            .put(SETTING_CREATION_DATE, System.currentTimeMillis())).build();
    ClusterState.Builder state = ClusterState.builder(new ClusterName("test"));
    state.nodes(discoBuilder);
    state.metaData(MetaData.builder().put(indexMetaData, false).generateClusterUuidIfNeeded());
    IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(indexMetaData.getIndex());
    for (int i = 0; i < numberOfShards; i++) {
        RoutingTable.Builder routing = new RoutingTable.Builder();
        routing.addAsNew(indexMetaData);
        final ShardId shardId = new ShardId(index, "_na_", i);
        IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(shardId);
        indexShardRoutingBuilder.addShard(TestShardRouting.newShardRouting(index, i, newNode(0).getId(), null, true,
                ShardRoutingState.STARTED));
        indexShardRoutingBuilder.addShard(TestShardRouting.newShardRouting(index, i, newNode(1).getId(), null, false,
                ShardRoutingState.STARTED));
        indexRoutingTableBuilder.addIndexShard(indexShardRoutingBuilder.build());
    }
    state.routingTable(RoutingTable.builder().add(indexRoutingTableBuilder.build()).build());
    return state.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:ClusterStateCreationUtils.java

示例10: createTimedClusterService

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
TimedClusterService createTimedClusterService(boolean makeMaster) throws InterruptedException {
    TimedClusterService timedClusterService = new TimedClusterService(Settings.builder().put("cluster.name",
        "ClusterServiceTests").build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS),
        threadPool, () -> new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(),
        emptySet(), Version.CURRENT));
    timedClusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) {
        @Override
        public void connectToNodes(DiscoveryNodes discoveryNodes) {
            // skip
        }

        @Override
        public void disconnectFromNodesExcept(DiscoveryNodes nodesToKeep) {
            // skip
        }
    });
    timedClusterService.setClusterStatePublisher((event, ackListener) -> {
    });
    timedClusterService.setDiscoverySettings(new DiscoverySettings(Settings.EMPTY,
        new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)));
    timedClusterService.start();
    ClusterState state = timedClusterService.state();
    final DiscoveryNodes nodes = state.nodes();
    final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(nodes)
        .masterNodeId(makeMaster ? nodes.getLocalNodeId() : null);
    state = ClusterState.builder(state).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK)
        .nodes(nodesBuilder).build();
    setState(timedClusterService, state);
    return timedClusterService;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:ClusterServiceTests.java

示例11: testRequestsAreNotSentToFailedMaster

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
public void testRequestsAreNotSentToFailedMaster() {
    Request request = new Request(new String[]{TEST_INDEX});
    PlainActionFuture<Response> listener = new PlainActionFuture<>();

    DiscoveryNode masterNode = clusterService.state().nodes().getMasterNode();
    DiscoveryNodes.Builder builder = DiscoveryNodes.builder(clusterService.state().getNodes());
    builder.remove(masterNode.getId());

    setState(clusterService, ClusterState.builder(clusterService.state()).nodes(builder));

    action.new AsyncAction(null, request, listener).start();

    Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();

    // the master should not be in the list of nodes that requests were sent to
    ShardsIterator shardIt = clusterService.state().routingTable().allShards(new String[]{TEST_INDEX});
    Set<String> set = new HashSet<>();
    for (ShardRouting shard : shardIt.asUnordered()) {
        if (!shard.currentNodeId().equals(masterNode.getId())) {
            set.add(shard.currentNodeId());
        }
    }

    // check a request was sent to the right number of nodes
    assertEquals(set.size(), capturedRequests.size());

    // check requests were sent to the right nodes
    assertEquals(set, capturedRequests.keySet());
    for (Map.Entry<String, List<CapturingTransport.CapturedRequest>> entry : capturedRequests.entrySet()) {
        // check one request was sent to each non-master node
        assertEquals(1, entry.getValue().size());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:TransportBroadcastByNodeActionTests.java

示例12: removeNodes

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
private ClusterState removeNodes(ClusterState clusterState, AllocationService strategy) {
    logger.info("Removing half the nodes (" + (numberOfNodes + 1) / 2 + ")");
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());

    boolean removed = false;
    for (int i = (numberOfNodes + 1) / 2; i <= numberOfNodes; i++) {
        nodes.remove("node" + i);
        removed = true;
    }

    clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
    if (removed) {
        clusterState = strategy.deassociateDeadNodes(clusterState, randomBoolean(), "removed nodes");
    }

    logger.info("start all the primary shards, replicas will start initializing");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("start the replica shards");
    routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("rebalancing");
    clusterState = strategy.reroute(clusterState, "reroute");

    logger.info("complete rebalancing");
    return applyStartedShardsUntilNoChange(clusterState, strategy);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:BalanceConfigurationTests.java

示例13: nodes

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
public Builder nodes(DiscoveryNodes.Builder nodesBuilder) {
    return nodes(nodesBuilder.build());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:4,代码来源:ClusterState.java

示例14: remainingNodesClusterState

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
ClusterState remainingNodesClusterState(final ClusterState currentState, DiscoveryNodes.Builder remainingNodesBuilder) {
    return ClusterState.builder(currentState).nodes(remainingNodesBuilder).build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ZenDiscovery.java

示例15: testShouldIgnoreNewClusterState

import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
public void testShouldIgnoreNewClusterState() {
    ClusterName clusterName = new ClusterName("abc");

    DiscoveryNodes.Builder currentNodes = DiscoveryNodes.builder();
    currentNodes.masterNodeId("a").add(new DiscoveryNode("a", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));
    DiscoveryNodes.Builder newNodes = DiscoveryNodes.builder();
    newNodes.masterNodeId("a").add(new DiscoveryNode("a", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));

    ClusterState.Builder currentState = ClusterState.builder(clusterName);
    currentState.nodes(currentNodes);
    ClusterState.Builder newState = ClusterState.builder(clusterName);
    newState.nodes(newNodes);

    currentState.version(2);
    newState.version(1);
    assertTrue("should ignore, because new state's version is lower to current state's version", shouldIgnoreOrRejectNewClusterState(logger, currentState.build(), newState.build()));
    currentState.version(1);
    newState.version(1);
    assertTrue("should ignore, because new state's version is equal to current state's version", shouldIgnoreOrRejectNewClusterState(logger, currentState.build(), newState.build()));
    currentState.version(1);
    newState.version(2);
    assertFalse("should not ignore, because new state's version is higher to current state's version", shouldIgnoreOrRejectNewClusterState(logger, currentState.build(), newState.build()));

    currentNodes = DiscoveryNodes.builder();
    currentNodes.masterNodeId("b").add(new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT));

    // version isn't taken into account, so randomize it to ensure this.
    if (randomBoolean()) {
        currentState.version(2);
        newState.version(1);
    } else {
        currentState.version(1);
        newState.version(2);
    }
    currentState.nodes(currentNodes);
    try {
        shouldIgnoreOrRejectNewClusterState(logger, currentState.build(), newState.build());
        fail("should ignore, because current state's master is not equal to new state's master");
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("cluster state from a different master than the current one, rejecting"));
    }

    currentNodes = DiscoveryNodes.builder();
    currentNodes.masterNodeId(null);
    currentState.nodes(currentNodes);
    // version isn't taken into account, so randomize it to ensure this.
    if (randomBoolean()) {
        currentState.version(2);
        newState.version(1);
    } else {
        currentState.version(1);
        newState.version(2);
    }
    assertFalse("should not ignore, because current state doesn't have a master", shouldIgnoreOrRejectNewClusterState(logger, currentState.build(), newState.build()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:56,代码来源:ZenDiscoveryUnitTests.java


注:本文中的org.elasticsearch.cluster.node.DiscoveryNodes.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。