Search in sources :

Example 11 with ClusterBlock

use of org.elasticsearch.cluster.block.ClusterBlock in project elasticsearch by elastic.

the class TransportBroadcastByNodeActionTests method testGlobalBlock.

public void testGlobalBlock() {
    Request request = new Request(new String[] { TEST_INDEX });
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    ClusterBlocks.Builder block = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(1, "test-block", false, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL));
    setState(clusterService, ClusterState.builder(clusterService.state()).blocks(block));
    try {
        action.new AsyncAction(null, request, listener).start();
        fail("expected ClusterBlockException");
    } catch (ClusterBlockException expected) {
        assertEquals("blocked by: [SERVICE_UNAVAILABLE/1/test-block];", expected.getMessage());
    }
}
Also used : BroadcastResponse(org.elasticsearch.action.support.broadcast.BroadcastResponse) TransportResponse(org.elasticsearch.transport.TransportResponse) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) IndicesRequest(org.elasticsearch.action.IndicesRequest) BroadcastRequest(org.elasticsearch.action.support.broadcast.BroadcastRequest) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException)

Example 12 with ClusterBlock

use of org.elasticsearch.cluster.block.ClusterBlock in project elasticsearch by elastic.

the class TransportBroadcastByNodeActionTests method testRequestBlock.

public void testRequestBlock() {
    Request request = new Request(new String[] { TEST_INDEX });
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    ClusterBlocks.Builder block = ClusterBlocks.builder().addIndexBlock(TEST_INDEX, new ClusterBlock(1, "test-block", false, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL));
    setState(clusterService, ClusterState.builder(clusterService.state()).blocks(block));
    try {
        action.new AsyncAction(null, request, listener).start();
        fail("expected ClusterBlockException");
    } catch (ClusterBlockException expected) {
        assertEquals("blocked by: [SERVICE_UNAVAILABLE/1/test-block];", expected.getMessage());
    }
}
Also used : BroadcastResponse(org.elasticsearch.action.support.broadcast.BroadcastResponse) TransportResponse(org.elasticsearch.transport.TransportResponse) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) IndicesRequest(org.elasticsearch.action.IndicesRequest) BroadcastRequest(org.elasticsearch.action.support.broadcast.BroadcastRequest) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException)

Example 13 with ClusterBlock

use of org.elasticsearch.cluster.block.ClusterBlock in project crate by crate.

the class TransportReplicationAllPermitsAcquisitionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    globalBlock = randomBoolean();
    RestStatus restStatus = randomFrom(RestStatus.values());
    block = new ClusterBlock(randomIntBetween(1, 10), randomAlphaOfLength(5), false, true, false, restStatus, ClusterBlockLevel.ALL);
    clusterService = createClusterService(threadPool);
    final ClusterState.Builder state = ClusterState.builder(clusterService.state());
    Set<DiscoveryNodeRole> roles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES);
    DiscoveryNode node1 = new DiscoveryNode("_name1", "_node1", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("_name2", "_node2", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
    state.nodes(DiscoveryNodes.builder().add(node1).add(node2).localNodeId(node1.getId()).masterNodeId(node1.getId()));
    shardId = new ShardId("index", UUID.randomUUID().toString(), 0);
    ShardRouting shardRouting = newShardRouting(shardId, node1.getId(), true, ShardRoutingState.INITIALIZING, RecoverySource.EmptyStoreRecoverySource.INSTANCE);
    Settings indexSettings = Settings.builder().put(SETTING_VERSION_CREATED, Version.CURRENT).put(SETTING_INDEX_UUID, shardId.getIndex().getUUID()).put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 1).put(SETTING_CREATION_DATE, System.currentTimeMillis()).build();
    primary = newStartedShard(p -> newShard(shardRouting, indexSettings, new InternalEngineFactory()), true);
    for (int i = 0; i < 10; i++) {
        final String id = Integer.toString(i);
        indexDoc(primary, id, "{\"value\":" + id + "}");
    }
    IndexMetadata indexMetadata = IndexMetadata.builder(shardId.getIndexName()).settings(indexSettings).primaryTerm(shardId.id(), primary.getOperationPrimaryTerm()).putMapping("default", "{ \"properties\": { \"value\":  { \"type\": \"short\"}}}").build();
    state.metadata(Metadata.builder().put(indexMetadata, false).generateClusterUuidIfNeeded());
    replica = newShard(primary.shardId(), false, node2.getId(), indexMetadata, null);
    recoverReplica(replica, primary, true);
    IndexRoutingTable.Builder routing = IndexRoutingTable.builder(indexMetadata.getIndex());
    routing.addIndexShard(new IndexShardRoutingTable.Builder(shardId).addShard(primary.routingEntry()).build());
    state.routingTable(RoutingTable.builder().add(routing.build()).build());
    setState(clusterService, state.build());
    final Settings transportSettings = Settings.builder().put("node.name", node1.getId()).build();
    MockTransport transport = new MockTransport() {

        @Override
        protected void onSendRequest(long requestId, String action, TransportRequest request, DiscoveryNode node) {
            assertThat(action, allOf(startsWith("cluster:admin/test/"), endsWith("[r]")));
            assertThat(node, equalTo(node2));
            // node2 doesn't really exist, but we are performing some trickery in mockIndicesService() to pretend that node1 holds both
            // the primary and the replica, so redirect the request back to node1.
            transportService.sendRequest(transportService.getLocalNode(), action, request, new TransportResponseHandler<TransportReplicationAction.ReplicaResponse>() {

                @Override
                public ReplicaResponse read(StreamInput in) throws IOException {
                    return new ReplicaResponse(in);
                }

                @SuppressWarnings("unchecked")
                private TransportResponseHandler<TransportReplicationAction.ReplicaResponse> getResponseHandler() {
                    return (TransportResponseHandler<TransportReplicationAction.ReplicaResponse>) getResponseHandlers().onResponseReceived(requestId, TransportMessageListener.NOOP_LISTENER);
                }

                @Override
                public void handleResponse(TransportReplicationAction.ReplicaResponse response) {
                    getResponseHandler().handleResponse(response);
                }

                @Override
                public void handleException(TransportException exp) {
                    getResponseHandler().handleException(exp);
                }

                @Override
                public String executor() {
                    return ThreadPool.Names.SAME;
                }
            });
        }
    };
    transportService = transport.createTransportService(transportSettings, threadPool, bta -> node1, null);
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) TransportRequest(org.elasticsearch.transport.TransportRequest) SETTING_VERSION_CREATED(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ClusterState(org.elasticsearch.cluster.ClusterState) TransportMessageListener(org.elasticsearch.transport.TransportMessageListener) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) After(org.junit.After) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ThreadPool(org.elasticsearch.threadpool.ThreadPool) InternalEngineFactory(org.elasticsearch.index.engine.InternalEngineFactory) Releasable(org.elasticsearch.common.lease.Releasable) CyclicBarrier(java.util.concurrent.CyclicBarrier) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) Set(java.util.Set) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) UUID(java.util.UUID) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Objects(java.util.Objects) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) RecoverySource(org.elasticsearch.cluster.routing.RecoverySource) List(java.util.List) Version(org.elasticsearch.Version) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) RestStatus(org.elasticsearch.rest.RestStatus) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) SETTING_INDEX_UUID(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_UUID) TransportException(org.elasticsearch.transport.TransportException) Matchers.endsWith(org.hamcrest.Matchers.endsWith) Mockito.mock(org.mockito.Mockito.mock) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) SETTING_NUMBER_OF_SHARDS(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS) TransportChannel(org.elasticsearch.transport.TransportChannel) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ArrayList(java.util.ArrayList) TestShardRouting.newShardRouting(org.elasticsearch.cluster.routing.TestShardRouting.newShardRouting) HashSet(java.util.HashSet) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) SETTING_NUMBER_OF_REPLICAS(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS) ReplicaResponse(org.elasticsearch.action.support.replication.TransportReplicationAction.ReplicaResponse) TransportResponse(org.elasticsearch.transport.TransportResponse) IndicesService(org.elasticsearch.indices.IndicesService) TransportService(org.elasticsearch.transport.TransportService) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) SetOnce(org.apache.lucene.util.SetOnce) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) MockTransport(org.elasticsearch.test.transport.MockTransport) Test(org.junit.Test) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) SETTING_CREATION_DATE(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_CREATION_DATE) Mockito.when(org.mockito.Mockito.when) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IndexShardTestCase(org.elasticsearch.index.shard.IndexShardTestCase) Matchers.hasItem(org.hamcrest.Matchers.hasItem) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ActionListener(org.elasticsearch.action.ActionListener) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ShardId(org.elasticsearch.index.shard.ShardId) InternalEngineFactory(org.elasticsearch.index.engine.InternalEngineFactory) MockTransport(org.elasticsearch.test.transport.MockTransport) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) TransportRequest(org.elasticsearch.transport.TransportRequest) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException) RestStatus(org.elasticsearch.rest.RestStatus) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ReplicaResponse(org.elasticsearch.action.support.replication.TransportReplicationAction.ReplicaResponse) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting.newShardRouting(org.elasticsearch.cluster.routing.TestShardRouting.newShardRouting) ReplicaResponse(org.elasticsearch.action.support.replication.TransportReplicationAction.ReplicaResponse) Before(org.junit.Before)

Example 14 with ClusterBlock

use of org.elasticsearch.cluster.block.ClusterBlock in project crate by crate.

the class TransportVerifyShardBeforeCloseActionTests method testUnavailableShardsMarkedAsStale.

@Test
public void testUnavailableShardsMarkedAsStale() throws Exception {
    String index = "test";
    ShardId shardId = new ShardId(index, "_na_", 0);
    int nbReplicas = randomIntBetween(1, 10);
    ShardRoutingState[] replicaStates = new ShardRoutingState[nbReplicas];
    Arrays.fill(replicaStates, ShardRoutingState.STARTED);
    final ClusterState clusterState = state(index, true, ShardRoutingState.STARTED, replicaStates);
    setState(clusterService, clusterState);
    IndexShardRoutingTable shardRoutingTable = clusterState.routingTable().index(index).shard(shardId.id());
    IndexMetadata indexMetaData = clusterState.getMetadata().index(index);
    ShardRouting primaryRouting = shardRoutingTable.primaryShard();
    long primaryTerm = indexMetaData.primaryTerm(0);
    Set<String> inSyncAllocationIds = indexMetaData.inSyncAllocationIds(0);
    Set<String> trackedShards = shardRoutingTable.getAllAllocationIds();
    List<ShardRouting> unavailableShards = randomSubsetOf(randomIntBetween(1, nbReplicas), shardRoutingTable.replicaShards());
    IndexShardRoutingTable.Builder shardRoutingTableBuilder = new IndexShardRoutingTable.Builder(shardRoutingTable);
    unavailableShards.forEach(shardRoutingTableBuilder::removeShard);
    shardRoutingTable = shardRoutingTableBuilder.build();
    ReplicationGroup replicationGroup = new ReplicationGroup(shardRoutingTable, inSyncAllocationIds, trackedShards);
    assertThat(replicationGroup.getUnavailableInSyncShards().size(), greaterThan(0));
    PlainActionFuture<PrimaryResult> listener = new PlainActionFuture<>();
    TransportVerifyShardBeforeCloseAction.ShardRequest request = new TransportVerifyShardBeforeCloseAction.ShardRequest(shardId, false, clusterBlock);
    ReplicationOperation.Replicas<TransportVerifyShardBeforeCloseAction.ShardRequest> proxy = action.newReplicasProxy();
    ReplicationOperation<TransportVerifyShardBeforeCloseAction.ShardRequest, TransportVerifyShardBeforeCloseAction.ShardRequest, PrimaryResult> operation = new ReplicationOperation<>(request, createPrimary(primaryRouting, replicationGroup), listener, proxy, logger, "test", primaryTerm);
    operation.execute();
    CapturingTransport.CapturedRequest[] capturedRequests = transport.getCapturedRequestsAndClear();
    assertThat(capturedRequests.length, equalTo(nbReplicas));
    for (CapturingTransport.CapturedRequest capturedRequest : capturedRequests) {
        String actionName = capturedRequest.action;
        if (actionName.startsWith(ShardStateAction.SHARD_FAILED_ACTION_NAME)) {
            assertThat(capturedRequest.request, instanceOf(ShardStateAction.FailedShardEntry.class));
            String allocationId = ((ShardStateAction.FailedShardEntry) capturedRequest.request).getAllocationId();
            assertTrue(unavailableShards.stream().anyMatch(shardRouting -> shardRouting.allocationId().getId().equals(allocationId)));
            transport.handleResponse(capturedRequest.requestId, TransportResponse.Empty.INSTANCE);
        } else if (actionName.startsWith(TransportVerifyShardBeforeCloseAction.NAME)) {
            assertThat(capturedRequest.request, instanceOf(ConcreteShardRequest.class));
            String allocationId = ((ConcreteShardRequest) capturedRequest.request).getTargetAllocationID();
            assertFalse(unavailableShards.stream().anyMatch(shardRouting -> shardRouting.allocationId().getId().equals(allocationId)));
            assertTrue(inSyncAllocationIds.stream().anyMatch(inSyncAllocationId -> inSyncAllocationId.equals(allocationId)));
            transport.handleResponse(capturedRequest.requestId, new TransportReplicationAction.ReplicaResponse(0L, 0L));
        } else {
            fail("Test does not support action " + capturedRequest.action);
        }
    }
    ReplicationResponse.ShardInfo shardInfo = listener.get().getShardInfo();
    assertThat(shardInfo.getFailed(), equalTo(0));
    assertThat(shardInfo.getFailures(), arrayWithSize(0));
    assertThat(shardInfo.getSuccessful(), equalTo(1 + nbReplicas - unavailableShards.size()));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Mockito.doThrow(org.mockito.Mockito.doThrow) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) After(org.junit.After) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) EnumSet(java.util.EnumSet) AfterClass(org.junit.AfterClass) ConcreteShardRequest(org.elasticsearch.action.support.replication.TransportReplicationAction.ConcreteShardRequest) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) UUIDs(org.elasticsearch.common.UUIDs) Set(java.util.Set) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) TransportReplicationAction(org.elasticsearch.action.support.replication.TransportReplicationAction) Engine(org.elasticsearch.index.engine.Engine) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) List(java.util.List) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) RestStatus(org.elasticsearch.rest.RestStatus) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ClusterStateCreationUtils.state(org.elasticsearch.action.support.replication.ClusterStateCreationUtils.state) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) BeforeClass(org.junit.BeforeClass) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ArgumentCaptor(org.mockito.ArgumentCaptor) TransportResponse(org.elasticsearch.transport.TransportResponse) IndicesService(org.elasticsearch.indices.IndicesService) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) INDEX_CLOSED_BLOCK_ID(io.crate.execution.ddl.tables.TransportCloseTable.INDEX_CLOSED_BLOCK_ID) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) Before(org.junit.Before) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) SetOnce(org.apache.lucene.util.SetOnce) IndexShard(org.elasticsearch.index.shard.IndexShard) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) ReplicationResponse(org.elasticsearch.action.support.replication.ReplicationResponse) ReplicationOperation(org.elasticsearch.action.support.replication.ReplicationOperation) ReplicationGroup(org.elasticsearch.index.shard.ReplicationGroup) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ActionListener(org.elasticsearch.action.ActionListener) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ReplicationGroup(org.elasticsearch.index.shard.ReplicationGroup) ReplicationResponse(org.elasticsearch.action.support.replication.ReplicationResponse) ShardId(org.elasticsearch.index.shard.ShardId) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) ReplicationOperation(org.elasticsearch.action.support.replication.ReplicationOperation) ClusterState(org.elasticsearch.cluster.ClusterState) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) ConcreteShardRequest(org.elasticsearch.action.support.replication.TransportReplicationAction.ConcreteShardRequest) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Test(org.junit.Test)

Example 15 with ClusterBlock

use of org.elasticsearch.cluster.block.ClusterBlock in project crate by crate.

the class TransportVerifyShardBeforeCloseActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    indexShard = mock(IndexShard.class);
    when(indexShard.getActiveOperationsCount()).thenReturn(IndexShard.OPERATIONS_BLOCKED);
    ShardId shardId = new ShardId("index", "_na_", randomIntBetween(0, 3));
    when(indexShard.shardId()).thenReturn(shardId);
    clusterService = createClusterService(threadPool);
    clusterBlock = new ClusterBlock(INDEX_CLOSED_BLOCK_ID, UUIDs.randomBase64UUID(), "index preparing to close. Reopen the index to allow " + "writes again or retry closing the index to fully close the index.", false, false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.WRITE));
    setState(clusterService, new ClusterState.Builder(clusterService.state()).blocks(ClusterBlocks.builder().blocks(clusterService.state().blocks()).addIndexBlock("index", clusterBlock).build()).build());
    transport = new CapturingTransport();
    TransportService transportService = transport.createTransportService(Settings.EMPTY, threadPool, x -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    ShardStateAction shardStateAction = new ShardStateAction(clusterService, transportService, null, null);
    action = new TransportVerifyShardBeforeCloseAction(Settings.EMPTY, transportService, clusterService, mock(IndicesService.class), mock(ThreadPool.class), shardStateAction);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ClusterState(org.elasticsearch.cluster.ClusterState) TransportService(org.elasticsearch.transport.TransportService) IndexShard(org.elasticsearch.index.shard.IndexShard) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) Before(org.junit.Before)

Aggregations

ClusterBlock (org.elasticsearch.cluster.block.ClusterBlock)15 ClusterBlocks (org.elasticsearch.cluster.block.ClusterBlocks)11 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)7 ClusterState (org.elasticsearch.cluster.ClusterState)7 Set (java.util.Set)6 Settings (org.elasticsearch.common.settings.Settings)6 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)5 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)5 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)5 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)5 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)5 ExecutionException (java.util.concurrent.ExecutionException)4 ClusterBlockLevel (org.elasticsearch.cluster.block.ClusterBlockLevel)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 TransportResponse (org.elasticsearch.transport.TransportResponse)4 IOException (java.io.IOException)3 EnumSet (java.util.EnumSet)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ActionListener (org.elasticsearch.action.ActionListener)3