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


Java ClusterState.Builder方法代码示例

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


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

示例1: becomeMasterAndTrimConflictingNodes

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState.Builder becomeMasterAndTrimConflictingNodes(ClusterState currentState, List<DiscoveryNode> joiningNodes) {
    assert currentState.nodes().getMasterNodeId() == null : currentState;
    DiscoveryNodes currentNodes = currentState.nodes();
    DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(currentNodes);
    nodesBuilder.masterNodeId(currentState.nodes().getLocalNodeId());
    for (final DiscoveryNode joiningNode : joiningNodes) {
        final DiscoveryNode nodeWithSameId = nodesBuilder.get(joiningNode.getId());
        if (nodeWithSameId != null && nodeWithSameId.equals(joiningNode) == false) {
            logger.debug("removing existing node [{}], which conflicts with incoming join from [{}]", nodeWithSameId, joiningNode);
            nodesBuilder.remove(nodeWithSameId.getId());
        }
        final DiscoveryNode nodeWithSameAddress = currentNodes.findByAddress(joiningNode.getAddress());
        if (nodeWithSameAddress != null && nodeWithSameAddress.equals(joiningNode) == false) {
            logger.debug("removing existing node [{}], which conflicts with incoming join from [{}]", nodeWithSameAddress,
                joiningNode);
            nodesBuilder.remove(nodeWithSameAddress.getId());
        }
    }


    // now trim any left over dead nodes - either left there when the previous master stepped down
    // or removed by us above
    ClusterState tmpState = ClusterState.builder(currentState).nodes(nodesBuilder).build();
    return ClusterState.builder(allocationService.deassociateDeadNodes(tmpState, false,
        "removed dead nodes on election"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:NodeJoinController.java

示例2: innerPut

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
ClusterState innerPut(PutPipelineRequest request, ClusterState currentState) {
    IngestMetadata currentIngestMetadata = currentState.metaData().custom(IngestMetadata.TYPE);
    Map<String, PipelineConfiguration> pipelines;
    if (currentIngestMetadata != null) {
        pipelines = new HashMap<>(currentIngestMetadata.getPipelines());
    } else {
        pipelines = new HashMap<>();
    }

    pipelines.put(request.getId(), new PipelineConfiguration(request.getId(), request.getSource(), request.getXContentType()));
    ClusterState.Builder newState = ClusterState.builder(currentState);
    newState.metaData(MetaData.builder(currentState.getMetaData())
        .putCustom(IngestMetadata.TYPE, new IngestMetadata(pipelines))
        .build());
    return newState.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PipelineStore.java

示例3: applyRerouteResult

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private void applyRerouteResult(ClusterState newClusterState) {
    ClusterState previousClusterState = this.clusterState;
    ClusterState.Builder builder = ClusterState.builder(newClusterState).incrementVersion();
    if (previousClusterState.routingTable() != newClusterState.routingTable()) {
        builder.routingTable(RoutingTable.builder(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1)
                .build());
    }
    if (previousClusterState.metaData() != newClusterState.metaData()) {
        builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
    }
    this.clusterState = builder.build();
    final ClusterStateHealth clusterHealth = new ClusterStateHealth(clusterState);
    logger.info("applied reroute. active shards: p [{}], t [{}], init shards: [{}], relocating: [{}]",
            clusterHealth.getActivePrimaryShards(), clusterHealth.getActiveShards(),
            clusterHealth.getInitializingShards(), clusterHealth.getRelocatingShards());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PrimaryTermsTests.java

示例4: execute

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
@Override
public ClusterState execute(ClusterState currentState) {
    DiscoveryNodes.Builder nodesBuilder;
    nodesBuilder = DiscoveryNodes.builder(currentState.nodes());
    if (currentState.nodes().nodeExists(node.id())) {
        logger.debug("received a join request for an existing node [{}]", node);
        return currentState;
    } 
    // If this node is not in dead node list, then ignore this request
    ImmutableOpenMap<String, DiscoveryNode> deadNodes = clusterService.state().nodes().deadNodes();
    if (deadNodes.get(node.getIpPortAddress()) == null) {
        logger.warn("failed to find node [{}] in node list, ignore the join request", node);
        throw new IllegalStateException("could not find this node " + node + " from active node list and dead node list");
    }
    nodesBuilder.put(node);
    nodesBuilder.removeDeadNodeByIpPort(node);
    final ClusterState.Builder newStateBuilder = ClusterState.builder(currentState);
    newStateBuilder.nodes(nodesBuilder);
    ClusterState newState = newStateBuilder.build();
    return newState;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:JoinClusterAction.java

示例5: innerDelete

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
ClusterState innerDelete(DeletePipelineRequest request, ClusterState currentState) {
    IngestMetadata currentIngestMetadata = currentState.metaData().custom(IngestMetadata.TYPE);
    if (currentIngestMetadata == null) {
        return currentState;
    }
    Map<String, PipelineConfiguration> pipelines = currentIngestMetadata.getPipelines();
    Set<String> toRemove = new HashSet<>();
    for (String pipelineKey : pipelines.keySet()) {
        if (Regex.simpleMatch(request.getId(), pipelineKey)) {
            toRemove.add(pipelineKey);
        }
    }
    if (toRemove.isEmpty() && Regex.isMatchAllPattern(request.getId()) == false) {
        throw new ResourceNotFoundException("pipeline [{}] is missing", request.getId());
    } else if (toRemove.isEmpty()) {
        return currentState;
    }
    final Map<String, PipelineConfiguration> pipelinesCopy = new HashMap<>(pipelines);
    for (String key : toRemove) {
        pipelinesCopy.remove(key);
    }
    ClusterState.Builder newState = ClusterState.builder(currentState);
    newState.metaData(MetaData.builder(currentState.getMetaData())
            .putCustom(IngestMetadata.TYPE, new IngestMetadata(pipelinesCopy))
            .build());
    return newState.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:PipelineStore.java

示例6: execute

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
@Override
public ClusterTasksResult<ClusterChangedEvent> execute(ClusterState currentState, List<ClusterChangedEvent> tasks) throws Exception {
    ClusterTasksResult.Builder<ClusterChangedEvent> builder = ClusterTasksResult.builder();
    ClusterState.Builder newState = ClusterState.builder(currentState).incrementVersion();
    boolean clusterStateChanged = updateNodes(currentState, tasks, newState);
    clusterStateChanged |= updateIndicesAndMetaData(currentState, tasks, newState);
    builder.successes(tasks);
    return builder.build(clusterStateChanged ? newState.build() : currentState);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:TribeService.java

示例7: interceptSender

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
@Override
public AsyncSender interceptSender(AsyncSender sender) {
    return new AsyncSender() {
        @Override
        public <T extends TransportResponse> void sendRequest(Transport.Connection connection, String action,
                                                              TransportRequest request,
                                                              TransportRequestOptions options,
                                                              TransportResponseHandler<T> handler) {
            final ClusterName clusterName = new ClusterName("cluster1");
            if (TransportLivenessAction.NAME.equals(action)) {
                assertHeaders(threadPool);
                ((TransportResponseHandler<LivenessResponse>) handler).handleResponse(
                    new LivenessResponse(clusterName, connection.getNode()));
            } else if (ClusterStateAction.NAME.equals(action)) {
                assertHeaders(threadPool);
                ClusterName cluster1 = clusterName;
                ClusterState.Builder builder = ClusterState.builder(cluster1);
                //the sniffer detects only data nodes
                builder.nodes(DiscoveryNodes.builder().add(new DiscoveryNode("node_id", "someId", "some_ephemeralId_id",
                    address.address().getHostString(), address.getAddress(), address, Collections.emptyMap(),
                        Collections.singleton(DiscoveryNode.Role.DATA), Version.CURRENT)));
                ((TransportResponseHandler<ClusterStateResponse>) handler)
                        .handleResponse(new ClusterStateResponse(cluster1, builder.build(), 0L));
                clusterStateLatch.countDown();
            } else if (TransportService.HANDSHAKE_ACTION_NAME .equals(action)) {
                ((TransportResponseHandler<TransportService.HandshakeResponse>) handler).handleResponse(
                    new TransportService.HandshakeResponse(connection.getNode(), clusterName, connection.getNode().getVersion()));
            } else {
                handler.handleException(new TransportException("", new InternalException(action)));
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:TransportClientHeadersTests.java

示例8: testStartedShardsMatching

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testStartedShardsMatching() {
    AllocationService allocation = createAllocationService();

    logger.info("--> building initial cluster state");
    AllocationId allocationId = AllocationId.newRelocation(AllocationId.newInitializing());
    final IndexMetaData indexMetaData = IndexMetaData.builder("test")
            .settings(settings(Version.CURRENT))
            .numberOfShards(2).numberOfReplicas(0)
            .putInSyncAllocationIds(1, Collections.singleton(allocationId.getId()))
            .build();
    final Index index = indexMetaData.getIndex();
    ClusterState.Builder stateBuilder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
            .nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")))
            .metaData(MetaData.builder().put(indexMetaData, false));

    final ShardRouting initShard = TestShardRouting.newShardRouting(new ShardId(index, 0), "node1", true, ShardRoutingState.INITIALIZING);
    final ShardRouting relocatingShard = TestShardRouting.newShardRouting(new ShardId(index, 1), "node1", "node2", true, ShardRoutingState.RELOCATING, allocationId);
    stateBuilder.routingTable(RoutingTable.builder().add(IndexRoutingTable.builder(index)
            .addIndexShard(new IndexShardRoutingTable.Builder(initShard.shardId()).addShard(initShard).build())
            .addIndexShard(new IndexShardRoutingTable.Builder(relocatingShard.shardId()).addShard(relocatingShard).build())).build());

    ClusterState state = stateBuilder.build();

    logger.info("--> test starting of shard");

    ClusterState newState = allocation.applyStartedShards(state, Arrays.asList(initShard));
    assertThat("failed to start " + initShard + "\ncurrent routing table:" + newState.routingTable(), newState, not(equalTo(state)));
    assertTrue(initShard + "isn't started \ncurrent routing table:" + newState.routingTable(),
            newState.routingTable().index("test").shard(initShard.id()).allShardsStarted());
    state = newState;

    logger.info("--> testing starting of relocating shards");
    newState = allocation.applyStartedShards(state, Arrays.asList(relocatingShard.getTargetRelocatingShard()));
    assertThat("failed to start " + relocatingShard + "\ncurrent routing table:" + newState.routingTable(),
        newState, not(equalTo(state)));
    ShardRouting shardRouting = newState.routingTable().index("test").shard(relocatingShard.id()).getShards().get(0);
    assertThat(shardRouting.state(), equalTo(ShardRoutingState.STARTED));
    assertThat(shardRouting.currentNodeId(), equalTo("node2"));
    assertThat(shardRouting.relocatingNodeId(), nullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:StartedShardsRoutingTests.java

示例9: setClusterState

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
void setClusterState(ClusterService clusterService, String index) {
    int numberOfNodes = randomIntBetween(3, 5);
    DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
    IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(new Index(index, "_na_"));

    int shardIndex = -1;
    int totalIndexShards = 0;
    for (int i = 0; i < numberOfNodes; i++) {
        final DiscoveryNode node = newNode(i);
        discoBuilder = discoBuilder.add(node);
        int numberOfShards = randomIntBetween(1, 10);
        totalIndexShards += numberOfShards;
        for (int j = 0; j < numberOfShards; j++) {
            final ShardId shardId = new ShardId(index, "_na_", ++shardIndex);
            ShardRouting shard = TestShardRouting.newShardRouting(index, shardId.getId(), node.getId(), true, ShardRoutingState.STARTED);
            IndexShardRoutingTable.Builder indexShard = new IndexShardRoutingTable.Builder(shardId);
            indexShard.addShard(shard);
            indexRoutingTable.addIndexShard(indexShard.build());
        }
    }
    discoBuilder.localNodeId(newNode(0).getId());
    discoBuilder.masterNodeId(newNode(numberOfNodes - 1).getId());
    ClusterState.Builder stateBuilder = ClusterState.builder(new ClusterName(TEST_CLUSTER));
    stateBuilder.nodes(discoBuilder);
    final IndexMetaData.Builder indexMetaData = IndexMetaData.builder(index)
            .settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT))
            .numberOfReplicas(0)
            .numberOfShards(totalIndexShards);

    stateBuilder.metaData(MetaData.builder().put(indexMetaData));
    stateBuilder.routingTable(RoutingTable.builder().add(indexRoutingTable.build()).build());
    ClusterState clusterState = stateBuilder.build();
    setState(clusterService, clusterState);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:TransportBroadcastByNodeActionTests.java

示例10: stateWithAssignedPrimariesAndOneReplica

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的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

示例11: stateWithNoShard

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的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

示例12: setUp

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的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

示例13: setState

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public static void setState(ClusterService clusterService, ClusterState.Builder clusterStateBuilder) {
    setState(clusterService, clusterStateBuilder.build());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ClusterServiceUtils.java

示例14: testShouldIgnoreNewClusterState

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的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.ClusterState.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。