use of org.elasticsearch.common.lease.Releasable 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.common.lease.Releasable 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.common.lease.Releasable in project elasticsearch by elastic.
the class TribeIT method testMergingRemovedCustomMetaData.
public void testMergingRemovedCustomMetaData() throws Exception {
removeCustomMetaData(cluster1, MergableCustomMetaData1.TYPE);
removeCustomMetaData(cluster2, MergableCustomMetaData1.TYPE);
MergableCustomMetaData1 customMetaData1 = new MergableCustomMetaData1("a");
MergableCustomMetaData1 customMetaData2 = new MergableCustomMetaData1("b");
try (Releasable tribeNode = startTribeNode()) {
assertNodes(ALL);
putCustomMetaData(cluster1, customMetaData1);
putCustomMetaData(cluster2, customMetaData2);
assertCustomMetaDataUpdated(internalCluster(), customMetaData2);
removeCustomMetaData(cluster2, customMetaData2.getWriteableName());
assertCustomMetaDataUpdated(internalCluster(), customMetaData1);
}
}
use of org.elasticsearch.common.lease.Releasable in project elasticsearch by elastic.
the class TribeIT method testGlobalReadWriteBlocks.
public void testGlobalReadWriteBlocks() throws Exception {
Settings additionalSettings = Settings.builder().put("tribe.blocks.write", true).put("tribe.blocks.metadata", true).build();
try (Releasable tribeNode = startTribeNode(ALL, additionalSettings)) {
// Creates 2 indices, test1 on cluster1 and test2 on cluster2
assertAcked(cluster1.client().admin().indices().prepareCreate("test1"));
ensureGreen(cluster1.client());
assertAcked(cluster2.client().admin().indices().prepareCreate("test2"));
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");
// Writes not allowed through the tribe node
ClusterBlockException e = expectThrows(ClusterBlockException.class, () -> {
client().prepareIndex("test1", "type1").setSource("field", "value").get();
});
assertThat(e.getMessage(), containsString("blocked by: [BAD_REQUEST/11/tribe node, write not allowed]"));
e = expectThrows(ClusterBlockException.class, () -> client().prepareIndex("test2", "type2").setSource("field", "value").get());
assertThat(e.getMessage(), containsString("blocked by: [BAD_REQUEST/11/tribe node, write not allowed]"));
e = expectThrows(ClusterBlockException.class, () -> client().admin().indices().prepareForceMerge("test1").get());
assertThat(e.getMessage(), containsString("blocked by: [BAD_REQUEST/10/tribe node, metadata not allowed]"));
e = expectThrows(ClusterBlockException.class, () -> client().admin().indices().prepareForceMerge("test2").get());
assertThat(e.getMessage(), containsString("blocked by: [BAD_REQUEST/10/tribe node, metadata not allowed]"));
}
}
use of org.elasticsearch.common.lease.Releasable in project elasticsearch by elastic.
the class TribeIT method testIndexWriteBlocks.
public void testIndexWriteBlocks() throws Exception {
Settings additionalSettings = Settings.builder().put("tribe.blocks.write.indices", "block_*").build();
try (Releasable tribeNode = startTribeNode(ALL, additionalSettings)) {
// Creates 2 indices on each remote cluster, test1 and block_test1 on cluster1 and test2 and block_test2 on cluster2
assertAcked(cluster1.client().admin().indices().prepareCreate("test1"));
assertAcked(cluster1.client().admin().indices().prepareCreate("block_test1"));
ensureGreen(cluster1.client());
assertAcked(cluster2.client().admin().indices().prepareCreate("test2"));
assertAcked(cluster2.client().admin().indices().prepareCreate("block_test2"));
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", "block_test1", "block_test2");
// Writes allowed through the tribe node for test1/test2 indices
client().prepareIndex("test1", "type1").setSource("field", "value").get();
client().prepareIndex("test2", "type2").setSource("field", "value").get();
ClusterBlockException e;
e = expectThrows(ClusterBlockException.class, () -> client().prepareIndex("block_test1", "type1").setSource("foo", 0).get());
assertThat(e.getMessage(), containsString("blocked by: [FORBIDDEN/8/index write (api)]"));
e = expectThrows(ClusterBlockException.class, () -> client().prepareIndex("block_test2", "type2").setSource("foo", 0).get());
assertThat(e.getMessage(), containsString("blocked by: [FORBIDDEN/8/index write (api)]"));
}
}
Aggregations