use of org.elasticsearch.client.GetAliasesResponse in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method resolveAlias.
@Override
public Set<String> resolveAlias(String alias) {
final GetAliasesRequest request = new GetAliasesRequest().aliases(alias);
final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions));
return result.getAliases().keySet();
}
use of org.elasticsearch.client.GetAliasesResponse in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method aliases.
@Override
public Map<String, Set<String>> aliases(String indexPattern) {
final GetAliasesRequest request = new GetAliasesRequest().indices(indexPattern).indicesOptions(IndicesOptions.fromOptions(false, false, true, false));
final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions), "Couldn't collect aliases for index pattern " + indexPattern);
return result.getAliases().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(AliasMetadata::alias).collect(Collectors.toSet())));
}
use of org.elasticsearch.client.GetAliasesResponse in project jackrabbit-oak by apache.
the class TestHelper method cleanupRemoteElastic.
/*
Deletes the remote elastic index from the elastic server.
*/
public static void cleanupRemoteElastic(ElasticConnection connection, String indexName) throws IOException {
String alias = ElasticIndexNameHelper.getElasticSafeIndexName(connection.getIndexPrefix(), "/oak:index/" + indexName);
// get and delete the indexes which this alias is pointing to
GetAliasesRequest getAliasesRequest = new GetAliasesRequest(alias);
GetAliasesResponse aliasesResponse = connection.getClient().indices().getAlias(getAliasesRequest, RequestOptions.DEFAULT);
Map<String, Set<AliasMetadata>> aliases = aliasesResponse.getAliases();
for (String remoteIndexName : aliases.keySet()) {
AcknowledgedResponse deleteIndexResponse = connection.getClient().indices().delete(new DeleteIndexRequest(remoteIndexName), RequestOptions.DEFAULT);
if (!deleteIndexResponse.isAcknowledged()) {
LOG.warn("Delete index call not acknowledged for index " + remoteIndexName + " .Please check if remote index deleted or not.");
}
}
}
use of org.elasticsearch.client.GetAliasesResponse in project herd by FINRAOS.
the class IndexFunctionsDaoTest method testUpdateIndexDocumentsFunctionWithFailures.
@Test
public void testUpdateIndexDocumentsFunctionWithFailures() throws Exception {
// Build mocks
GetAliasesResponse getAliasesResponse = mock(GetAliasesResponse.class);
IndicesClient indicesClient = mock(IndicesClient.class);
RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class);
AliasMetadata AliasMetadata = mock(AliasMetadata.class);
BulkResponse bulkResponse = mock(BulkResponse.class);
// Create objects needed for the test.
Map<String, String> documentMap = new HashMap<>();
documentMap.put(SEARCH_INDEX_DOCUMENT, SEARCH_INDEX_DOCUMENT_JSON);
Set<AliasMetadata> AliasMetadataSet = new HashSet<>();
AliasMetadataSet.add(AliasMetadata);
Map<String, Set<AliasMetadata>> aliases = new HashMap<>();
aliases.put(SEARCH_INDEX_ALIAS_BDEF, AliasMetadataSet);
// Mock the calls to external methods
when(elasticsearchRestHighLevelClientFactory.getRestHighLevelClient()).thenReturn(restHighLevelClient);
when(restHighLevelClient.indices()).thenReturn(indicesClient);
when(indicesClient.getAlias(any(GetAliasesRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(getAliasesResponse);
when(getAliasesResponse.getAliases()).thenReturn(aliases);
when(restHighLevelClient.bulk(any(BulkRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(bulkResponse);
when(bulkResponse.hasFailures()).thenReturn(true);
when(bulkResponse.buildFailureMessage()).thenReturn(ERROR_MESSAGE);
// Call the method under test
indexFunctionsDao.updateIndexDocuments(SEARCH_INDEX_NAME, documentMap);
// Verify the calls to external methods
verify(elasticsearchRestHighLevelClientFactory, times(2)).getRestHighLevelClient();
verify(restHighLevelClient).indices();
verify(restHighLevelClient).bulk(any(BulkRequest.class), eq(RequestOptions.DEFAULT));
verify(indicesClient).getAlias(any(GetAliasesRequest.class), eq(RequestOptions.DEFAULT));
verify(getAliasesResponse).getAliases();
verify(bulkResponse).hasFailures();
verify(bulkResponse).buildFailureMessage();
verify(restHighLevelClient, times(2)).close();
verifyNoMoreInteractions(bulkResponse, elasticsearchRestHighLevelClientFactory, getAliasesResponse, indicesClient, restHighLevelClient);
}
use of org.elasticsearch.client.GetAliasesResponse in project herd by FINRAOS.
the class IndexFunctionsDaoTest method testCreateIndexDocumentsFunctionThrowsElasticsearchRestClientExceptionWhenBulkRequest.
@Test(expected = ElasticsearchRestClientException.class)
public void testCreateIndexDocumentsFunctionThrowsElasticsearchRestClientExceptionWhenBulkRequest() throws Exception {
// Build mocks
GetAliasesResponse getAliasesResponse = mock(GetAliasesResponse.class);
IndicesClient indicesClient = mock(IndicesClient.class);
RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class);
AliasMetadata AliasMetadata = mock(AliasMetadata.class);
// Create objects needed for the test.
Map<String, String> documentMap = new HashMap<>();
documentMap.put(SEARCH_INDEX_DOCUMENT, SEARCH_INDEX_DOCUMENT_JSON);
Set<AliasMetadata> AliasMetadataSet = new HashSet<>();
AliasMetadataSet.add(AliasMetadata);
Map<String, Set<AliasMetadata>> aliases = new HashMap<>();
aliases.put(SEARCH_INDEX_ALIAS_BDEF, AliasMetadataSet);
// Mock the calls to external methods
when(elasticsearchRestHighLevelClientFactory.getRestHighLevelClient()).thenReturn(restHighLevelClient);
when(restHighLevelClient.indices()).thenReturn(indicesClient);
when(indicesClient.getAlias(any(GetAliasesRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(getAliasesResponse);
when(getAliasesResponse.getAliases()).thenReturn(aliases);
when(restHighLevelClient.bulk(any(BulkRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new IOException());
// Call the method under test
indexFunctionsDao.createIndexDocuments(SEARCH_INDEX_NAME, documentMap);
}
Aggregations