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


Java ClusterState.nodes方法代码示例

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


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

示例1: updateNodesAndPing

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * make sure that nodes in clusterState are pinged. Any pinging to nodes which are not
 * part of the cluster will be stopped
 */
public void updateNodesAndPing(ClusterState clusterState) {
    // remove any nodes we don't need, this will cause their FD to stop
    for (DiscoveryNode monitoredNode : nodesFD.keySet()) {
        if (!clusterState.nodes().nodeExists(monitoredNode)) {
            nodesFD.remove(monitoredNode);
        }
    }
    // add any missing nodes

    for (DiscoveryNode node : clusterState.nodes()) {
        if (node.equals(localNode)) {
            // no need to monitor the local node
            continue;
        }
        if (!nodesFD.containsKey(node)) {
            NodeFD fd = new NodeFD(node);
            // it's OK to overwrite an existing nodeFD - it will just stop and the new one will pick things up.
            nodesFD.put(node, fd);
            // we use schedule with a 0 time value to run the pinger on the pool as it will run on later
            threadPool.schedule(TimeValue.timeValueMillis(0), ThreadPool.Names.SAME, fd);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:NodesFaultDetection.java

示例2: Async

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private Async(ClearScrollRequest request, ActionListener<ClearScrollResponse> listener, ClusterState clusterState) {
    int expectedOps = 0;
    this.nodes = clusterState.nodes();
    if (request.getScrollIds().size() == 1 && "_all".equals(request.getScrollIds().get(0))) {
        expectedOps = nodes.getSize();
    } else {
        for (String parsedScrollId : request.getScrollIds()) {
            ScrollIdForNode[] context = parseScrollId(parsedScrollId).getContext();
            expectedOps += context.length;
            this.contexts.add(context);
        }
    }
    this.listener = listener;
    this.expHolder = new AtomicReference<>();
    this.expectedOps = new CountDown(expectedOps);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:TransportClearScrollAction.java

示例3: updateNodesAndPing

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * make sure that nodes in clusterState are pinged. Any pinging to nodes which are not
 * part of the cluster will be stopped
 */
public void updateNodesAndPing(ClusterState clusterState) {
    // remove any nodes we don't need, this will cause their FD to stop
    for (DiscoveryNode monitoredNode : nodesFD.keySet()) {
        if (!clusterState.nodes().nodeExists(monitoredNode.id())) {
            nodesFD.remove(monitoredNode);
        }
    }
    // add any missing nodes

    for (DiscoveryNode node : clusterState.nodes()) {
        if (node.equals(localNode)) {
            // no need to monitor the local node
            continue;
        }
        if (!nodesFD.containsKey(node)) {
            NodeFD fd = new NodeFD(node);
            // it's OK to overwrite an existing nodeFD - it will just stop and the new one will pick things up.
            nodesFD.put(node, fd);
            // we use schedule with a 0 time value to run the pinger on the pool as it will run on later
            threadPool.schedule(TimeValue.timeValueMillis(0), ThreadPool.Names.SAME, fd);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:28,代码来源:NodesFaultDetection.java

示例4: reroute

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public RoutingAllocation.Result reroute(ClusterState clusterState, AllocationCommands commands, boolean explain) {
    RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
    // we don't shuffle the unassigned shards here, to try and get as close as possible to
    // a consistent result of the effect the commands have on the routing
    // this allows systems to dry run the commands, see the resulting cluster state, and act on it
    RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, clusterState.nodes(), clusterInfoService.getClusterInfo(), currentNanoTime());
    // don't short circuit deciders, we want a full explanation
    allocation.debugDecision(true);
    // we ignore disable allocation, because commands are explicit
    allocation.ignoreDisable(true);
    RoutingExplanations explanations = commands.execute(allocation, explain);
    // we revert the ignore disable flag, since when rerouting, we want the original setting to take place
    allocation.ignoreDisable(false);
    // the assumption is that commands will move / act on shards (or fail through exceptions)
    // so, there will always be shard "movements", so no need to check on reroute
    reroute(allocation);
    RoutingTable routingTable = new RoutingTable.Builder().updateNodes(routingNodes).build().validateRaiseException(clusterState.metaData());
    RoutingAllocation.Result result = new RoutingAllocation.Result(true, routingTable, explanations);
    logClusterHealthStateChange(
            new ClusterStateHealth(clusterState),
            new ClusterStateHealth(clusterState.getMetaData(), routingTable),
            "reroute commands"
    );
    return result;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:AllocationService.java

示例5: nodeIndexDeleted

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void nodeIndexDeleted(final ClusterState clusterState, final String index, final Settings indexSettings, final String nodeId) {
    final DiscoveryNodes nodes = clusterState.nodes();
    transportService.sendRequest(clusterState.nodes().masterNode(),
            INDEX_DELETED_ACTION_NAME, new NodeIndexDeletedMessage(index, nodeId), EmptyTransportResponseHandler.INSTANCE_SAME);
    if (nodes.localNode().isDataNode() == false) {
        logger.trace("[{}] not acking store deletion (not a data node)", index);
        return;
    }
    threadPool.generic().execute(new AbstractRunnable() {
        @Override
        public void onFailure(Throwable t) {
            logger.warn("[{}] failed to ack index store deleted for index", t, index);
        }

        @Override
        protected void doRun() throws Exception {
            lockIndexAndAck(index, nodes, nodeId, clusterState, indexSettings);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:NodeIndexDeletedAction.java

示例6: Async

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private Async(ClearScrollRequest request, ActionListener<ClearScrollResponse> listener, ClusterState clusterState) {
    int expectedOps = 0;
    this.nodes = clusterState.nodes();
    if (request.getScrollIds().size() == 1 && "_all".equals(request.getScrollIds().get(0))) {
        expectedOps = nodes.size();
    } else {
        for (String parsedScrollId : request.getScrollIds()) {
            ScrollIdForNode[] context = parseScrollId(parsedScrollId).getContext();
            expectedOps += context.length;
            this.contexts.add(context);
        }
    }

    this.request = request;
    this.listener = listener;
    this.expHolder = new AtomicReference<>();
    this.expectedOps = new CountDown(expectedOps);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:TransportClearScrollAction.java

示例7: RoutingAllocation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Creates a new {@link RoutingAllocation}
 *  @param deciders {@link AllocationDeciders} to used to make decisions for routing allocations
 * @param routingNodes Routing nodes in the current cluster
 * @param clusterState cluster state before rerouting
 * @param currentNanoTime the nano time to use for all delay allocation calculation (typically {@link System#nanoTime()})
 */
public RoutingAllocation(AllocationDeciders deciders, RoutingNodes routingNodes, ClusterState clusterState, ClusterInfo clusterInfo,
                         long currentNanoTime, boolean retryFailed) {
    this.deciders = deciders;
    this.routingNodes = routingNodes;
    this.metaData = clusterState.metaData();
    this.routingTable = clusterState.routingTable();
    this.nodes = clusterState.nodes();
    this.customs = clusterState.customs();
    this.clusterInfo = clusterInfo;
    this.currentNanoTime = currentNanoTime;
    this.retryFailed = retryFailed;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RoutingAllocation.java

示例8: AsyncSingleAction

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private AsyncSingleAction(Request request, ActionListener<Response> listener) {
    this.listener = listener;

    ClusterState clusterState = clusterService.state();
    if (logger.isTraceEnabled()) {
        logger.trace("executing [{}] based on cluster state version [{}]", request, clusterState.version());
    }
    nodes = clusterState.nodes();
    ClusterBlockException blockException = checkGlobalBlock(clusterState);
    if (blockException != null) {
        throw blockException;
    }

    String concreteSingleIndex;
    if (resolveIndex(request)) {
        concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, request).getName();
    } else {
        concreteSingleIndex = request.index();
    }
    this.internalRequest = new InternalRequest(request, concreteSingleIndex);
    resolveRequest(clusterState, internalRequest);

    blockException = checkRequestBlock(clusterState, internalRequest);
    if (blockException != null) {
        throw blockException;
    }

    this.shardIt = shards(clusterState, internalRequest);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:TransportSingleShardAction.java

示例9: assertNodesInCurrentState

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
protected void assertNodesInCurrentState(List<DiscoveryNode> expectedNodes) {
    final ClusterState state = clusterService.state();
    logger.info("assert for [{}] in:\n{}", expectedNodes, state);
    DiscoveryNodes discoveryNodes = state.nodes();
    for (DiscoveryNode node : expectedNodes) {
        assertThat("missing " + node + "\n" + discoveryNodes, discoveryNodes.get(node.getId()), equalTo(node));
    }
    assertThat(discoveryNodes.getSize(), equalTo(expectedNodes.size()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:NodeJoinControllerTests.java

示例10: createTimedClusterService

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

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void nodeMappingRefresh(final ClusterState state, final NodeMappingRefreshRequest request) {
    final DiscoveryNodes nodes = state.nodes();
    if (nodes.masterNode() == null) {
        logger.warn("can't send mapping refresh for [{}][{}], no master known.", request.index(), Strings.arrayToCommaDelimitedString(request.types()));
        return;
    }
    transportService.sendRequest(nodes.masterNode(), ACTION_NAME, request, EmptyTransportResponseHandler.INSTANCE_SAME);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:NodeMappingRefreshAction.java

示例12: AsyncSingleAction

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private AsyncSingleAction(Request request, ActionListener<Response> listener) {
    this.listener = listener;

    ClusterState clusterState = clusterService.state();
    if (logger.isTraceEnabled()) {
        logger.trace("executing [{}] based on cluster state version [{}]", request, clusterState.version());
    }
    nodes = clusterState.nodes();
    ClusterBlockException blockException = checkGlobalBlock(clusterState);
    if (blockException != null) {
        throw blockException;
    }

    String concreteSingleIndex;
    if (resolveIndex(request)) {
        concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, request);
    } else {
        concreteSingleIndex = request.index();
    }
    this.internalRequest = new InternalRequest(request, concreteSingleIndex);
    resolveRequest(clusterState, internalRequest);

    blockException = checkRequestBlock(clusterState, internalRequest);
    if (blockException != null) {
        throw blockException;
    }

    this.shardIt = shards(clusterState, internalRequest);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:TransportSingleShardAction.java

示例13: doStart

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
protected void doStart(ClusterState clusterState) {
    final Predicate<ClusterState> masterChangePredicate = MasterNodeChangePredicate.build(clusterState);
    final DiscoveryNodes nodes = clusterState.nodes();
    if (nodes.isLocalNodeElectedMaster() || localExecute(request)) {
        // check for block, if blocked, retry, else, execute locally
        final ClusterBlockException blockException = checkBlock(request, clusterState);
        if (blockException != null) {
            if (!blockException.retryable()) {
                listener.onFailure(blockException);
            } else {
                logger.trace("can't execute due to a cluster block, retrying", blockException);
                retry(blockException, newState -> {
                    ClusterBlockException newException = checkBlock(request, newState);
                    return (newException == null || !newException.retryable());
                });
            }
        } else {
            ActionListener<Response> delegate = new ActionListener<Response>() {
                @Override
                public void onResponse(Response response) {
                    listener.onResponse(response);
                }

                @Override
                public void onFailure(Exception t) {
                    if (t instanceof Discovery.FailedToCommitClusterStateException
                            || (t instanceof NotMasterException)) {
                        logger.debug((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("master could not publish cluster state or stepped down before publishing action [{}], scheduling a retry", actionName), t);
                        retry(t, masterChangePredicate);
                    } else {
                        listener.onFailure(t);
                    }
                }
            };
            threadPool.executor(executor).execute(new ActionRunnable(delegate) {
                @Override
                protected void doRun() throws Exception {
                    masterOperation(task, request, clusterState, delegate);
                }
            });
        }
    } else {
        if (nodes.getMasterNode() == null) {
            logger.debug("no known master node, scheduling a retry");
            retry(null, masterChangePredicate);
        } else {
            transportService.sendRequest(nodes.getMasterNode(), actionName, request, new ActionListenerResponseHandler<Response>(listener, TransportMasterNodeAction.this::newResponse) {
                @Override
                public void handleException(final TransportException exp) {
                    Throwable cause = exp.unwrapCause();
                    if (cause instanceof ConnectTransportException) {
                        // we want to retry here a bit to see if a new master is elected
                        logger.debug("connection exception while trying to forward request with action name [{}] to master node [{}], scheduling a retry. Error: [{}]",
                                actionName, nodes.getMasterNode(), exp.getDetailedMessage());
                        retry(cause, masterChangePredicate);
                    } else {
                        listener.onFailure(exp);
                    }
                }
            });
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:64,代码来源:TransportMasterNodeAction.java

示例14: testLocalNodeMasterListenerCallbacks

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testLocalNodeMasterListenerCallbacks() throws Exception {
    TimedClusterService timedClusterService = createTimedClusterService(false);

    AtomicBoolean isMaster = new AtomicBoolean();
    timedClusterService.addLocalNodeMasterListener(new LocalNodeMasterListener() {
        @Override
        public void onMaster() {
            isMaster.set(true);
        }

        @Override
        public void offMaster() {
            isMaster.set(false);
        }

        @Override
        public String executorName() {
            return ThreadPool.Names.SAME;
        }
    });

    ClusterState state = timedClusterService.state();
    DiscoveryNodes nodes = state.nodes();
    DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(nodes).masterNodeId(nodes.getLocalNodeId());
    state = ClusterState.builder(state).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).nodes(nodesBuilder).build();
    setState(timedClusterService, state);
    assertThat(isMaster.get(), is(true));

    nodes = state.nodes();
    nodesBuilder = DiscoveryNodes.builder(nodes).masterNodeId(null);
    state = ClusterState.builder(state).blocks(ClusterBlocks.builder().addGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_WRITES))
        .nodes(nodesBuilder).build();
    setState(timedClusterService, state);
    assertThat(isMaster.get(), is(false));
    nodesBuilder = DiscoveryNodes.builder(nodes).masterNodeId(nodes.getLocalNodeId());
    state = ClusterState.builder(state).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).nodes(nodesBuilder).build();
    setState(timedClusterService, state);
    assertThat(isMaster.get(), is(true));

    timedClusterService.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:42,代码来源:ClusterServiceTests.java

示例15: doStart

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
protected void doStart() {
    final ClusterState clusterState = observer.observedState();
    final DiscoveryNodes nodes = clusterState.nodes();
    if (nodes.localNodeMaster() || localExecute(request)) {
        // check for block, if blocked, retry, else, execute locally
        final ClusterBlockException blockException = checkBlock(request, clusterState);
        if (blockException != null) {
            if (!blockException.retryable()) {
                listener.onFailure(blockException);
            } else {
                logger.trace("can't execute due to a cluster block, retrying", blockException);
                retry(blockException, retryableOrNoBlockPredicate);
            }
        } else {
            final ActionListener<Response> delegate = new ActionListener<Response>() {
                @Override
                public void onResponse(Response response) {
                    listener.onResponse(response);
                }

                @Override
                public void onFailure(Throwable t) {
                    if (t instanceof NotMasterException) {
                        logger.debug("master could not publish cluster state or stepped down before publishing action [{}], scheduling a retry", t, actionName);
                        retry(t, masterNodeChangedPredicate);
                    } else {
                        listener.onFailure(t);
                    }
                }
            };
            taskManager.registerChildTask(task, nodes.getLocalNodeId());
            threadPool.executor(executor).execute(new ActionRunnable(delegate) {
                @Override
                protected void doRun() throws Exception {
                    masterOperation(task, request, clusterService.state(), delegate);
                }
            });
        }
    } else {
        if (nodes.masterNode() == null) {
            logger.debug("no known master node, scheduling a retry");
            retry(null, masterNodeChangedPredicate);
        } else {
            taskManager.registerChildTask(task, nodes.masterNode().getId());
            transportService.sendRequest(nodes.masterNode(), actionName, request, new ActionListenerResponseHandler<Response>(listener) {
                @Override
                public Response newInstance() {
                    return newResponse();
                }

                @Override
                public void handleException(final TransportException exp) {
                    Throwable cause = exp.unwrapCause();
                    if (cause instanceof ConnectTransportException) {
                        // we want to retry here a bit to see if a new master is elected
                        logger.debug("connection exception while trying to forward request with action name [{}] to master node [{}], scheduling a retry. Error: [{}]",
                                actionName, nodes.masterNode(), exp.getDetailedMessage());
                        retry(cause, masterNodeChangedPredicate);
                    } else {
                        listener.onFailure(exp);
                    }
                }
            });
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:67,代码来源:TransportMasterNodeAction.java


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