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));
}
}
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));
}
});
}
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());
}
}
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()));
});
}
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();
}
}
Aggregations