Search in sources :

Example 31 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class PublishClusterStateActionTests method testSimpleClusterStatePublishing.

public void testSimpleClusterStatePublishing() throws Exception {
    MockNode nodeA = createMockNode("nodeA").setAsMaster();
    MockNode nodeB = createMockNode("nodeB");
    // Initial cluster state
    ClusterState clusterState = nodeA.clusterState;
    // cluster state update - add nodeB
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(clusterState.nodes()).add(nodeB.discoveryNode).build();
    ClusterState previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromFull(nodeB.clusterState, clusterState);
    // cluster state update - add block
    previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).blocks(ClusterBlocks.builder().addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK)).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    assertThat(nodeB.clusterState.blocks().global().size(), equalTo(1));
    // cluster state update - remove block
    previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    assertTrue(nodeB.clusterState.wasReadFromDiff());
    // Adding new node - this node should get full cluster state while nodeB should still be getting diffs
    MockNode nodeC = createMockNode("nodeC");
    // cluster state update 3 - register node C
    previousClusterState = clusterState;
    discoveryNodes = DiscoveryNodes.builder(discoveryNodes).add(nodeC.discoveryNode).build();
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    // First state
    assertSameStateFromFull(nodeC.clusterState, clusterState);
    // cluster state update 4 - update settings
    previousClusterState = clusterState;
    MetaData metaData = MetaData.builder(clusterState.metaData()).transientSettings(Settings.builder().put("foo", "bar").build()).build();
    clusterState = ClusterState.builder(clusterState).metaData(metaData).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
    assertThat(nodeB.clusterState.blocks().global().size(), equalTo(0));
    assertSameStateFromDiff(nodeC.clusterState, clusterState);
    assertThat(nodeC.clusterState.blocks().global().size(), equalTo(0));
    // cluster state update - skipping one version change - should request full cluster state
    previousClusterState = ClusterState.builder(clusterState).incrementVersion().build();
    clusterState = ClusterState.builder(clusterState).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromFull(nodeB.clusterState, clusterState);
    assertSameStateFromFull(nodeC.clusterState, clusterState);
    assertFalse(nodeC.clusterState.wasReadFromDiff());
    // node A steps down from being master
    nodeA.resetMasterId();
    nodeB.resetMasterId();
    nodeC.resetMasterId();
    // node B becomes the master and sends a version of the cluster state that goes back
    discoveryNodes = DiscoveryNodes.builder(discoveryNodes).add(nodeA.discoveryNode).add(nodeB.discoveryNode).add(nodeC.discoveryNode).masterNodeId(nodeB.discoveryNode.getId()).localNodeId(nodeB.discoveryNode.getId()).build();
    previousClusterState = ClusterState.builder(new ClusterName("test")).nodes(discoveryNodes).build();
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).incrementVersion().build();
    publishStateAndWait(nodeB.action, clusterState, previousClusterState);
    assertSameStateFromFull(nodeA.clusterState, clusterState);
    assertSameStateFromFull(nodeC.clusterState, clusterState);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 32 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class ZenFaultDetectionTests method testMasterFaultDetectionConnectOnDisconnect.

public void testMasterFaultDetectionConnectOnDisconnect() throws InterruptedException {
    Settings.Builder settings = Settings.builder();
    boolean shouldRetry = randomBoolean();
    ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20));
    // make sure we don't ping
    settings.put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry).put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").put("cluster.name", clusterName.value());
    final ClusterState state = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build();
    setState(clusterServiceA, state);
    MasterFaultDetection masterFD = new MasterFaultDetection(settings.build(), threadPool, serviceA, clusterServiceA);
    masterFD.restart(nodeB, "test");
    final String[] failureReason = new String[1];
    final DiscoveryNode[] failureNode = new DiscoveryNode[1];
    final CountDownLatch notified = new CountDownLatch(1);
    masterFD.addListener((masterNode, cause, reason) -> {
        failureNode[0] = masterNode;
        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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CountDownLatch(java.util.concurrent.CountDownLatch) MasterFaultDetection(org.elasticsearch.discovery.zen.MasterFaultDetection) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 33 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class ZenFaultDetectionTests method testNodesFaultDetectionConnectOnDisconnect.

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CountDownLatch(java.util.concurrent.CountDownLatch) NodesFaultDetection(org.elasticsearch.discovery.zen.NodesFaultDetection) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 34 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class PipelineStoreTests method testDeleteUsingWildcard.

public void testDeleteUsingWildcard() {
    HashMap<String, PipelineConfiguration> pipelines = new HashMap<>();
    BytesArray definition = new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}");
    pipelines.put("p1", new PipelineConfiguration("p1", definition, XContentType.JSON));
    pipelines.put("p2", new PipelineConfiguration("p2", definition, XContentType.JSON));
    pipelines.put("q1", new PipelineConfiguration("q1", definition, XContentType.JSON));
    IngestMetadata ingestMetadata = new IngestMetadata(pipelines);
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    ClusterState previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder().putCustom(IngestMetadata.TYPE, ingestMetadata)).build();
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("p1"), notNullValue());
    assertThat(store.get("p2"), notNullValue());
    assertThat(store.get("q1"), notNullValue());
    // Delete pipeline matching wildcard
    DeletePipelineRequest deleteRequest = new DeletePipelineRequest("p*");
    previousClusterState = clusterState;
    clusterState = store.innerDelete(deleteRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("p1"), nullValue());
    assertThat(store.get("p2"), nullValue());
    assertThat(store.get("q1"), notNullValue());
    // Exception if we used name which does not exist
    try {
        store.innerDelete(new DeletePipelineRequest("unknown"), clusterState);
        fail("exception expected");
    } catch (ResourceNotFoundException e) {
        assertThat(e.getMessage(), equalTo("pipeline [unknown] is missing"));
    }
    // match all wildcard works on last remaining pipeline
    DeletePipelineRequest matchAllDeleteRequest = new DeletePipelineRequest("*");
    previousClusterState = clusterState;
    clusterState = store.innerDelete(matchAllDeleteRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("p1"), nullValue());
    assertThat(store.get("p2"), nullValue());
    assertThat(store.get("q1"), nullValue());
    // match all wildcard does not throw exception if none match
    store.innerDelete(matchAllDeleteRequest, clusterState);
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) HashMap(java.util.HashMap) ClusterName(org.elasticsearch.cluster.ClusterName) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Example 35 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class PipelineStoreTests method testDeleteWithExistingUnmatchedPipelines.

public void testDeleteWithExistingUnmatchedPipelines() {
    HashMap<String, PipelineConfiguration> pipelines = new HashMap<>();
    BytesArray definition = new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}");
    pipelines.put("p1", new PipelineConfiguration("p1", definition, XContentType.JSON));
    IngestMetadata ingestMetadata = new IngestMetadata(pipelines);
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    ClusterState previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder().putCustom(IngestMetadata.TYPE, ingestMetadata)).build();
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("p1"), notNullValue());
    DeletePipelineRequest deleteRequest = new DeletePipelineRequest("z*");
    try {
        store.innerDelete(deleteRequest, clusterState);
        fail("exception expected");
    } catch (ResourceNotFoundException e) {
        assertThat(e.getMessage(), equalTo("pipeline [z*] is missing"));
    }
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) HashMap(java.util.HashMap) ClusterName(org.elasticsearch.cluster.ClusterName) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Aggregations

ClusterName (org.elasticsearch.cluster.ClusterName)95 ClusterState (org.elasticsearch.cluster.ClusterState)76 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)22 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)20 Settings (org.elasticsearch.common.settings.Settings)20 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Version (org.elasticsearch.Version)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 MetaData (org.elasticsearch.cluster.metadata.MetaData)12 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)12 ArrayList (java.util.ArrayList)11 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)10 List (java.util.List)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 ESTestCase (org.elasticsearch.test.ESTestCase)8