org.elasticsearch.cluster.block.ClusterBlockException Java Examples
The following examples show how to use
org.elasticsearch.cluster.block.ClusterBlockException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportUpdateSettingsAction.java From crate with Apache License 2.0 | 6 votes |
@Override protected ClusterBlockException checkBlock(UpdateSettingsRequest request, ClusterState state) { // allow for dedicated changes to the metadata blocks, so we don't block those to allow to "re-enable" it ClusterBlockException globalBlock = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); if (globalBlock != null) { return globalBlock; } // always allow removing of archived settings, so filter them out before doing further block checks Settings settings = request.settings().filter(k -> k.startsWith(ARCHIVED_SETTINGS_PREFIX + "*") == false); if (settings.size() == 1 && // we have to allow resetting these settings otherwise users can't unblock an index IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.exists(settings) || IndexMetaData.INDEX_READ_ONLY_SETTING.exists(settings) || IndexMetaData.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.exists(settings)) { return null; } return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request)); }
Example #2
Source File: AbstractRetryableEsRequestTest.java From io with Apache License 2.0 | 6 votes |
/** * リトライ対象例外が続き_リトライ5回目でリトライ対象外の例外が発生した場合、EsClientExceptionが投げられること. */ @Test(expected = EsClientException.class) public void リトライ対象例外が続き_リトライ5回目でリトライ対象外の例外が発生した場合_EsClientExceptionが投げられること() { TestRequest requestMock = Mockito.spy(new TestRequest()); ClusterBlockException toBeThrown = Mockito.mock(ClusterBlockException.class); IndexMissingException toBeThrown2 = Mockito.mock(IndexMissingException.class); Mockito.doThrow(toBeThrown) // 初回 .doThrow(toBeThrown) // リトライ1回目 .doThrow(toBeThrown) // リトライ2回目 .doThrow(toBeThrown) // リトライ3回目 .doThrow(toBeThrown) // リトライ4回目 .doThrow(toBeThrown2) // リトライ5回目 .when(requestMock) .doProcess(); try { requestMock.doRequest(); fail("Should not return"); } finally { // doProcessが6回呼び出されるはず Mockito.verify(requestMock, Mockito.times(6)).doProcess(); Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class)); } }
Example #3
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 6 votes |
/** * Executes the request and fails if the request has not been blocked by a specific {@link ClusterBlock}. * * @param builder the request builder * @param expectedBlock the expected block */ public static void assertBlocked(ActionRequestBuilder builder, ClusterBlock expectedBlock) { try { builder.get(); fail("Request executed with success but a ClusterBlockException was expected"); } catch (ClusterBlockException e) { assertThat(e.blocks().size(), greaterThan(0)); assertThat(e.status(), equalTo(RestStatus.FORBIDDEN)); if (expectedBlock != null) { boolean found = false; for (ClusterBlock clusterBlock : e.blocks()) { if (clusterBlock.id() == expectedBlock.id()) { found = true; break; } } assertThat("Request should have been blocked by [" + expectedBlock + "] instead of " + e.blocks(), found, equalTo(true)); } } }
Example #4
Source File: AbstractRetryableEsRequestTest.java From io with Apache License 2.0 | 6 votes |
/** * リトライ対象例外が続き_リトライ5回目でもNGな場合_EsNoResponseExceptionが投げられること. */ @Test(expected = EsClientException.EsNoResponseException.class) public void リトライ対象例外が続き_リトライ5回目でもNGな場合_EsNoResponseExceptionが投げられること() { TestRequest requestMock = Mockito.spy(new TestRequest()); ClusterBlockException toBeThrown = Mockito.mock(ClusterBlockException.class); Mockito.doThrow(toBeThrown) // 初回 .doThrow(toBeThrown) // リトライ1回目 .doThrow(toBeThrown) // リトライ2回目 .doThrow(toBeThrown) // リトライ3回目 .doThrow(toBeThrown) // リトライ4回目 .doThrow(toBeThrown) // リトライ5回目 .when(requestMock) .doProcess(); try { requestMock.doRequest(); fail("Should not return"); } finally { // doProcessが6回呼び出されるはず Mockito.verify(requestMock, Mockito.times(6)).doProcess(); Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class)); } }
Example #5
Source File: AbstractRetryableEsRequestTest.java From io with Apache License 2.0 | 6 votes |
/** * リトライ対象例外が続き_リトライ5回目でリトライ対象外の例外が発生した場合、EsClientExceptionが投げられること. */ @Test(expected = EsClientException.class) public void リトライ対象例外が続き_リトライ5回目でリトライ対象外の例外が発生した場合_EsClientExceptionが投げられること() { TestRequest requestMock = Mockito.spy(new TestRequest()); ClusterBlockException toBeThrown = Mockito.mock(ClusterBlockException.class); IndexNotFoundException toBeThrown2 = new IndexNotFoundException("abc"); Mockito.doThrow(toBeThrown) // 初回 .doThrow(toBeThrown) // リトライ1回目 .doThrow(toBeThrown) // リトライ2回目 .doThrow(toBeThrown) // リトライ3回目 .doThrow(toBeThrown) // リトライ4回目 .doThrow(toBeThrown2) // リトライ5回目 .when(requestMock) .doProcess(); try { requestMock.doRequest(); fail("Should not return"); } finally { // doProcessが6回呼び出されるはず Mockito.verify(requestMock, Mockito.times(6)).doProcess(); Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class)); } }
Example #6
Source File: ElasticsearchClient.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 5 votes |
/** * Get the number of documents in the search index for a given search query * * @param q * the query * @return the count of all documents in the index which matches with the query */ public long count(final QueryBuilder q, final String indexName) { while (true) try { return countInternal(q, indexName); } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) { Data.logger.info("ElasticsearchClient count failed with " + e.getMessage() + ", retrying to connect node..."); try {Thread.sleep(1000);} catch (InterruptedException ee) {} connect(); } }
Example #7
Source File: TransportCreateTableAction.java From crate with Apache License 2.0 | 5 votes |
@Override protected ClusterBlockException checkBlock(CreateTableRequest request, ClusterState state) { if (request.getCreateIndexRequest() != null) { CreateIndexRequest createIndexRequest = request.getCreateIndexRequest(); return transportCreateIndexAction.checkBlock(createIndexRequest, state); } else if (request.getPutIndexTemplateRequest() != null) { PutIndexTemplateRequest putIndexTemplateRequest = request.getPutIndexTemplateRequest(); return transportPutIndexTemplateAction.checkBlock(putIndexTemplateRequest, state); } else { throw new IllegalStateException("Unknown table request"); } }
Example #8
Source File: TransportAnalyzeAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected ClusterBlockException checkRequestBlock(ClusterState state, InternalRequest request) { if (request.concreteIndex() != null) { return super.checkRequestBlock(state, request); } return null; }
Example #9
Source File: TransportSwapRelationsAction.java From crate with Apache License 2.0 | 5 votes |
@Override protected ClusterBlockException checkBlock(SwapRelationsRequest request, ClusterState state) { Set<String> affectedIndices = new HashSet<>(); for (RelationNameSwap swapAction : request.swapActions()) { affectedIndices.addAll(Arrays.asList(indexNameExpressionResolver.concreteIndexNames( state, IndicesOptions.LENIENT_EXPAND_OPEN, swapAction.source().indexNameOrAlias()))); affectedIndices.addAll(Arrays.asList(indexNameExpressionResolver.concreteIndexNames( state, IndicesOptions.LENIENT_EXPAND_OPEN, swapAction.target().indexNameOrAlias()))); } for (RelationName dropRelation : request.dropRelations()) { affectedIndices.addAll(Arrays.asList(indexNameExpressionResolver.concreteIndexNames( state, IndicesOptions.LENIENT_EXPAND_OPEN, dropRelation.indexNameOrAlias()))); } return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, affectedIndices.toArray(new String[0])); }
Example #10
Source File: TransportSingleShardAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
private AsyncSingleAction(Request request, ActionListener<Response> listener) { this.listener = listener; ClusterState clusterState = clusterService.state(); if (logger.isTraceEnabled()) { logger.trace("executing [{}] based on cluster state version [{}]", request, clusterState.version()); } nodes = clusterState.nodes(); ClusterBlockException blockException = checkGlobalBlock(clusterState); if (blockException != null) { throw blockException; } String concreteSingleIndex; if (resolveIndex(request)) { concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, request); } else { concreteSingleIndex = request.index(); } this.internalRequest = new InternalRequest(request, concreteSingleIndex); resolveRequest(clusterState, internalRequest); blockException = checkRequestBlock(clusterState, internalRequest); if (blockException != null) { throw blockException; } this.shardIt = shards(clusterState, internalRequest); }
Example #11
Source File: TransportClusterUpdateSettingsAction.java From crate with Apache License 2.0 | 5 votes |
@Override protected ClusterBlockException checkBlock(ClusterUpdateSettingsRequest request, ClusterState state) { // allow for dedicated changes to the metadata blocks, so we don't block those to allow to "re-enable" it if (request.transientSettings().size() + request.persistentSettings().size() == 1) { // only one setting if (MetaData.SETTING_READ_ONLY_SETTING.exists(request.persistentSettings()) || MetaData.SETTING_READ_ONLY_SETTING.exists(request.transientSettings()) || MetaData.SETTING_READ_ONLY_ALLOW_DELETE_SETTING.exists(request.transientSettings()) || MetaData.SETTING_READ_ONLY_ALLOW_DELETE_SETTING.exists(request.persistentSettings())) { // one of the settings above as the only setting in the request means - resetting the block! return null; } } return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); }
Example #12
Source File: BulkNodeClusterBlockTest.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Test(expected = ClusterBlockException.class) public void testClusterBlock() throws Exception { BulkRequestBuilder brb = client("1").prepareBulk(); XContentBuilder builder = jsonBuilder().startObject().field("field1", "value1").endObject(); String jsonString = builder.string(); IndexRequestBuilder irb = client("1").prepareIndex("test", "test", "1").setSource(jsonString); brb.add(irb); brb.execute().actionGet(); }
Example #13
Source File: ElasticsearchClient.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 5 votes |
public Map<String, Map<String, Object>> readMapBulk(final String indexName, final Collection<String> ids) { while (true) try { return readMapBulkInternal(indexName, ids); } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) { Data.logger.info("ElasticsearchClient readMapBulk failed with " + e.getMessage() + ", retrying to connect node..."); try {Thread.sleep(1000);} catch (InterruptedException ee) {} connect(); continue; } }
Example #14
Source File: ElasticsearchClient.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 5 votes |
/** * Read a json document from the search index for a given id. * Elasticsearch reads the '_source' field and parses the content as json. * * @param id * the unique identifier of a document * @return the document as json, matched on a Map<String, Object> object instance */ public Map<String, Object> readMap(final String indexName, final String id) { while (true) try { return readMapInternal(indexName, id); } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) { Data.logger.info("ElasticsearchClient readMap failed with " + e.getMessage() + ", retrying to connect node..."); try {Thread.sleep(1000);} catch (InterruptedException ee) {} connect(); continue; } }
Example #15
Source File: TransportReplicationAction.java From crate with Apache License 2.0 | 5 votes |
private void handleBlockException(ClusterBlockException blockException) { if (blockException.retryable()) { logger.trace("cluster is blocked, scheduling a retry", blockException); retry(blockException); } else { finishAsFailed(blockException); } }
Example #16
Source File: TransportRestoreSnapshotAction.java From crate with Apache License 2.0 | 5 votes |
@Override protected ClusterBlockException checkBlock(RestoreSnapshotRequest request, ClusterState state) { // Restoring a snapshot might change the global state and create/change an index, // so we need to check for METADATA_WRITE and WRITE blocks ClusterBlockException blockException = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); if (blockException != null) { return blockException; } return state.blocks().globalBlockedException(ClusterBlockLevel.WRITE); }
Example #17
Source File: TransportPutRepositoryAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(PutRepositoryRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); }
Example #18
Source File: TransportFieldStatsTransportAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkRequestBlock(ClusterState state, FieldStatsRequest request, String[] concreteIndices) { return state.blocks().indicesBlockedException(ClusterBlockLevel.READ, concreteIndices); }
Example #19
Source File: TransportAlterUserAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(AlterUserRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); }
Example #20
Source File: TransportGetIndexTemplatesAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(GetIndexTemplatesRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); }
Example #21
Source File: TransportVerifyRepositoryAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(VerifyRepositoryRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); }
Example #22
Source File: TransportSingleShardAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
protected ClusterBlockException checkGlobalBlock(ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.READ); }
Example #23
Source File: TransportValidateQueryAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkRequestBlock(ClusterState state, ValidateQueryRequest countRequest, String[] concreteIndices) { return state.blocks().indicesBlockedException(ClusterBlockLevel.READ, concreteIndices); }
Example #24
Source File: TransportValidateQueryAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkGlobalBlock(ClusterState state, ValidateQueryRequest request) { return state.blocks().globalBlockedException(ClusterBlockLevel.READ); }
Example #25
Source File: TransportDeleteRepositoryAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(DeleteRepositoryRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); }
Example #26
Source File: TransportFieldStatsTransportAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkGlobalBlock(ClusterState state, FieldStatsRequest request) { return state.blocks().globalBlockedException(ClusterBlockLevel.READ); }
Example #27
Source File: TransportGetWarmersAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(GetWarmersRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); }
Example #28
Source File: TransportDeleteIndexAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(DeleteIndexRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndices(state, request)); }
Example #29
Source File: TransportPendingClusterTasksAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(PendingClusterTasksRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); }
Example #30
Source File: TransportResizeAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected ClusterBlockException checkBlock(ResizeRequest request, ClusterState state) { return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, request.getTargetIndexRequest().index()); }