Search in sources :

Example 1 with Releasable

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));
    }
}
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 2 with Releasable

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());
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Releasable(org.elasticsearch.common.lease.Releasable)

Example 3 with Releasable

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);
    }
}
Also used : MergableCustomMetaData1(org.elasticsearch.tribe.TribeServiceTests.MergableCustomMetaData1) Releasable(org.elasticsearch.common.lease.Releasable)

Example 4 with Releasable

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]"));
    }
}
Also used : Releasable(org.elasticsearch.common.lease.Releasable) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) Settings(org.elasticsearch.common.settings.Settings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings)

Example 5 with Releasable

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)]"));
    }
}
Also used : Releasable(org.elasticsearch.common.lease.Releasable) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) Settings(org.elasticsearch.common.settings.Settings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings)

Aggregations

Releasable (org.elasticsearch.common.lease.Releasable)38 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)7 IndexShard (org.elasticsearch.index.shard.IndexShard)7 ClusterState (org.elasticsearch.cluster.ClusterState)6 IOException (java.io.IOException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)5 TestShardRouting (org.elasticsearch.cluster.routing.TestShardRouting)5 Settings (org.elasticsearch.common.settings.Settings)5 ExecutionException (java.util.concurrent.ExecutionException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)4 ArrayList (java.util.ArrayList)3 ActionListener (org.elasticsearch.action.ActionListener)3 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)3 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)3 DiscoverySettings (org.elasticsearch.discovery.DiscoverySettings)3 ShardId (org.elasticsearch.index.shard.ShardId)3 List (java.util.List)2