Search in sources :

Example 16 with ClusterState

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

the class TribeIT method testOnConflictDrop.

public void testOnConflictDrop() throws Exception {
    Settings additionalSettings = Settings.builder().put("tribe.on_conflict", "drop").build();
    try (Releasable tribeNode = startTribeNode(ALL, additionalSettings)) {
        // Creates 2 indices on each remote cluster, test1 and conflict on cluster1 and test2 and also conflict on cluster2
        assertAcked(cluster1.client().admin().indices().prepareCreate("test1"));
        assertAcked(cluster1.client().admin().indices().prepareCreate("conflict"));
        ensureGreen(cluster1.client());
        assertAcked(cluster2.client().admin().indices().prepareCreate("test2"));
        assertAcked(cluster2.client().admin().indices().prepareCreate("conflict"));
        ensureGreen(cluster2.client());
        // Wait for the tribe node to connect to the two remote clusters
        assertNodes(ALL);
        // Wait for the tribe node to retrieve the indices into its cluster state
        assertIndicesExist(client(), "test1", "test2");
        ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
        assertThat(clusterState.getMetaData().hasIndex("test1"), is(true));
        assertThat(clusterState.getMetaData().index("test1").getSettings().get("tribe.name"), equalTo(cluster1.getClusterName()));
        assertThat(clusterState.getMetaData().hasIndex("test2"), is(true));
        assertThat(clusterState.getMetaData().index("test2").getSettings().get("tribe.name"), equalTo(cluster2.getClusterName()));
        assertThat(clusterState.getMetaData().hasIndex("conflict"), is(false));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Releasable(org.elasticsearch.common.lease.Releasable) Settings(org.elasticsearch.common.settings.Settings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings)

Example 17 with ClusterState

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

the class TribeIT method assertIndicesExist.

private void assertIndicesExist(Client client, String... indices) throws Exception {
    assertBusy(() -> {
        ClusterState state = client.admin().cluster().prepareState().setRoutingTable(true).setMetaData(true).get().getState();
        assertThat(state.getMetaData().getIndices().size(), equalTo(indices.length));
        for (String index : indices) {
            assertTrue(state.getMetaData().hasIndex(index));
            assertTrue(state.getRoutingTable().hasIndex(index));
        }
    });
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 18 with ClusterState

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

the class TribeIT method testCloseAndOpenIndex.

public void testCloseAndOpenIndex() throws Exception {
    // Creates an index on remote cluster 1
    assertTrue(cluster1.client().admin().indices().prepareCreate("first").get().isAcknowledged());
    ensureGreen(cluster1.client());
    // Closes the index
    assertTrue(cluster1.client().admin().indices().prepareClose("first").get().isAcknowledged());
    try (Releasable tribeNode = startTribeNode()) {
        // Wait for the tribe node to connect to the two remote clusters
        assertNodes(ALL);
        // The closed index is not part of the tribe node cluster state
        ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
        assertFalse(clusterState.getMetaData().hasIndex("first"));
        // Open the index, it becomes part of the tribe node cluster state
        assertTrue(cluster1.client().admin().indices().prepareOpen("first").get().isAcknowledged());
        assertIndicesExist(client(), "first");
        // Create a second index, wait till it is seen from within the tribe node
        assertTrue(cluster2.client().admin().indices().prepareCreate("second").get().isAcknowledged());
        assertIndicesExist(client(), "first", "second");
        ensureGreen(cluster2.client());
        // Close the second index, wait till it gets removed from the tribe node cluster state
        assertTrue(cluster2.client().admin().indices().prepareClose("second").get().isAcknowledged());
        assertIndicesExist(client(), "first");
        // Open the second index, wait till it gets added back to the tribe node cluster state
        assertTrue(cluster2.client().admin().indices().prepareOpen("second").get().isAcknowledged());
        assertIndicesExist(client(), "first", "second");
        ensureGreen(cluster2.client());
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Releasable(org.elasticsearch.common.lease.Releasable)

Example 19 with ClusterState

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

the class TribeIT method assertNodes.

private static void assertNodes(Predicate<InternalTestCluster> filter) throws Exception {
    final Set<String> expectedNodes = Sets.newHashSet(internalCluster().getNodeNames());
    doWithAllClusters(filter, c -> {
        for (String tribeNode : internalCluster().getNodeNames()) {
            expectedNodes.add(tribeNode + "/" + c.getClusterName());
        }
        Collections.addAll(expectedNodes, c.getNodeNames());
    });
    assertBusy(() -> {
        ClusterState state = client().admin().cluster().prepareState().setNodes(true).get().getState();
        Set<String> nodes = StreamSupport.stream(state.getNodes().spliterator(), false).map(DiscoveryNode::getName).collect(toSet());
        assertThat(nodes, containsInAnyOrder(expectedNodes.toArray()));
    });
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 20 with ClusterState

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

the class TransportDeleteByQueryAction method doExecute.

@Override
public void doExecute(Task task, DeleteByQueryRequest request, ActionListener<BulkByScrollResponse> listener) {
    if (request.getSlices() > 1) {
        BulkByScrollParallelizationHelper.startSlices(client, taskManager, DeleteByQueryAction.INSTANCE, clusterService.localNode().getId(), (ParentBulkByScrollTask) task, request, listener);
    } else {
        ClusterState state = clusterService.state();
        ParentTaskAssigningClient client = new ParentTaskAssigningClient(this.client, clusterService.localNode(), task);
        new AsyncDeleteByQueryAction((WorkingBulkByScrollTask) task, logger, client, threadPool, request, scriptService, state, listener).start();
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ParentTaskAssigningClient(org.elasticsearch.client.ParentTaskAssigningClient) WorkingBulkByScrollTask(org.elasticsearch.action.bulk.byscroll.WorkingBulkByScrollTask) AsyncDeleteByQueryAction(org.elasticsearch.action.bulk.byscroll.AsyncDeleteByQueryAction)

Aggregations

ClusterState (org.elasticsearch.cluster.ClusterState)564 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)211 MetaData (org.elasticsearch.cluster.metadata.MetaData)179 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)150 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)123 Settings (org.elasticsearch.common.settings.Settings)100 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)85 ClusterName (org.elasticsearch.cluster.ClusterName)82 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)75 Matchers.containsString (org.hamcrest.Matchers.containsString)72 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)62 ShardId (org.elasticsearch.index.shard.ShardId)61 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)59 ArrayList (java.util.ArrayList)57 IOException (java.io.IOException)55 Index (org.elasticsearch.index.Index)53 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)49 CountDownLatch (java.util.concurrent.CountDownLatch)47 HashSet (java.util.HashSet)45 List (java.util.List)45