use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest.
@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest() throws Exception {
SearchHit hit = new SearchHit(0, "id-0", new Text("ignored"), emptyMap(), emptyMap());
hit.sourceRef(new BytesArray(HIT_SOURCE));
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit }, new TotalHits(1, EQUAL_TO), Float.NaN));
SearchResponse response2 = mock(SearchResponse.class);
when(response2.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(1, EQUAL_TO), Float.NaN));
when(mockClient.scroll(any(), any())).thenReturn(response2);
// get different instance than default
TestSupport testSupport = runProcessor(request -> {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("TestHeader", "value");
return builder.build();
});
testSupport.expectOutput(newArrayList(HIT_SOURCE));
ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
verify(mockClient).scroll(any(), captor.capture());
RequestOptions capturedOptions = captor.getValue();
assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ClientES7 method templateExists.
@Override
public boolean templateExists(String templateName) {
final GetIndexTemplatesRequest request = new GetIndexTemplatesRequest("*");
final GetIndexTemplatesResponse result = client.execute((c, requestOptions) -> c.indices().getIndexTemplate(request, requestOptions));
return result.getIndexTemplates().stream().anyMatch(indexTemplate -> indexTemplate.name().equals(templateName));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ClientES7 method putTemplate.
@Override
public void putTemplate(String templateName, Map<String, Object> source) {
final PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).source(source);
client.execute((c, requestOptions) -> c.indices().putTemplate(request, requestOptions), "Unable to put template " + templateName);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ClientES7 method deleteIndices.
@Override
public void deleteIndices(String... indices) {
for (String index : indices) {
if (indicesExists(index)) {
final DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(index);
client.execute((c, requestOptions) -> c.indices().delete(deleteIndexRequest, requestOptions));
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ClientES7 method removeAliasMapping.
@Override
public void removeAliasMapping(String indexName, String alias) {
final IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
final AliasActions aliasAction = new AliasActions(AliasActions.Type.REMOVE).index(indexName).alias(alias);
indicesAliasesRequest.addAliasAction(aliasAction);
client.execute((c, requestOptions) -> c.indices().updateAliases(indicesAliasesRequest, requestOptions), "failed to remove alias " + alias + " for index " + indexName);
}
Aggregations