當前位置: 首頁>>代碼示例>>Java>>正文


Java ClusterState.getClusterName方法代碼示例

本文整理匯總了Java中org.elasticsearch.cluster.ClusterState.getClusterName方法的典型用法代碼示例。如果您正苦於以下問題:Java ClusterState.getClusterName方法的具體用法?Java ClusterState.getClusterName怎麽用?Java ClusterState.getClusterName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.cluster.ClusterState的用法示例。


在下文中一共展示了ClusterState.getClusterName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateIncomingState

import org.elasticsearch.cluster.ClusterState; //導入方法依賴的package包/類
/**
 * does simple sanity check of the incoming cluster state. Throws an exception on rejections.
 */
void validateIncomingState(ClusterState incomingState, ClusterState lastSeenClusterState) {
    final ClusterName incomingClusterName = incomingState.getClusterName();
    if (!incomingClusterName.equals(this.clusterName)) {
        logger.warn("received cluster state from [{}] which is also master but with a different cluster name [{}]",
            incomingState.nodes().getMasterNode(), incomingClusterName);
        throw new IllegalStateException("received state from a node that is not part of the cluster");
    }
    final ClusterState clusterState = clusterStateSupplier.get();

    if (clusterState.nodes().getLocalNode().equals(incomingState.nodes().getLocalNode()) == false) {
        logger.warn("received a cluster state from [{}] and not part of the cluster, should not happen",
            incomingState.nodes().getMasterNode());
        throw new IllegalStateException("received state with a local node that does not match the current local node");
    }

    if (ZenDiscovery.shouldIgnoreOrRejectNewClusterState(logger, clusterState, incomingState)) {
        String message = String.format(
                Locale.ROOT,
                "rejecting cluster state version [%d] uuid [%s] received from [%s]",
                incomingState.version(),
                incomingState.stateUUID(),
                incomingState.nodes().getMasterNodeId()
        );
        logger.warn(message);
        throw new IllegalStateException(message);
    }

}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:32,代碼來源:PublishClusterStateAction.java

示例2: PingResponse

import org.elasticsearch.cluster.ClusterState; //導入方法依賴的package包/類
public PingResponse(DiscoveryNode node, DiscoveryNode master, ClusterState state) {
    this(node, master, state.getClusterName(),
        state.blocks().hasGlobalBlock(STATE_NOT_RECOVERED_BLOCK) ?
            ElectMasterService.MasterCandidate.UNRECOVERED_CLUSTER_VERSION : state.version());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:6,代碼來源:ZenPing.java

示例3: testNodesFaultDetectionConnectOnDisconnect

import org.elasticsearch.cluster.ClusterState; //導入方法依賴的package包/類
public void testNodesFaultDetectionConnectOnDisconnect() throws InterruptedException {
    boolean shouldRetry = randomBoolean();
    // make sure we don't ping again after the initial ping
    final Settings pingSettings = Settings.builder()
        .put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry)
        .put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").build();
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(buildNodesForA(true)).build();
    NodesFaultDetection nodesFDA = new NodesFaultDetection(Settings.builder().put(settingsA).put(pingSettings).build(),
        threadPool, serviceA, clusterState.getClusterName());
    nodesFDA.setLocalNode(nodeA);
    NodesFaultDetection nodesFDB = new NodesFaultDetection(Settings.builder().put(settingsB).put(pingSettings).build(),
        threadPool, serviceB, clusterState.getClusterName());
    nodesFDB.setLocalNode(nodeB);
    final CountDownLatch pingSent = new CountDownLatch(1);
    nodesFDB.addListener(new NodesFaultDetection.Listener() {
        @Override
        public void onPingReceived(NodesFaultDetection.PingRequest pingRequest) {
            pingSent.countDown();
        }
    });
    nodesFDA.updateNodesAndPing(clusterState);

    // wait for the first ping to go out, so we will really respond to a disconnect event rather then
    // the ping failing
    pingSent.await(30, TimeUnit.SECONDS);

    final String[] failureReason = new String[1];
    final DiscoveryNode[] failureNode = new DiscoveryNode[1];
    final CountDownLatch notified = new CountDownLatch(1);
    nodesFDA.addListener(new NodesFaultDetection.Listener() {
        @Override
        public void onNodeFailure(DiscoveryNode node, String reason) {
            failureNode[0] = node;
            failureReason[0] = reason;
            notified.countDown();
        }
    });
    // will raise a disconnect on A
    serviceB.stop();
    notified.await(30, TimeUnit.SECONDS);

    CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
    assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));

    assertEquals(nodeB, failureNode[0]);
    Matcher<String> matcher = Matchers.containsString("verified");
    if (!shouldRetry) {
        matcher = Matchers.not(matcher);
    }

    assertThat(failureReason[0], matcher);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:53,代碼來源:ZenFaultDetectionTests.java


注:本文中的org.elasticsearch.cluster.ClusterState.getClusterName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。