use of io.kestra.repository.elasticsearch.configs.IndicesConfig in project kestra by kestra-io.
the class ElasticSearchIndicesService method updateMapping.
public void updateMapping(@Nullable Map<String, IndicesConfig> indicesConfigs) {
for (Map.Entry<String, IndicesConfig> index : (indicesConfigs == null ? this.indicesConfigs : indicesConfigs).entrySet()) {
if (index.getValue().getMappingContent() != null) {
try {
PutMappingRequest request = new PutMappingRequest(index.getValue().getIndex());
request.source(index.getValue().getMappingContent(), XContentType.JSON);
client.indices().putMapping(request, RequestOptions.DEFAULT);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
use of io.kestra.repository.elasticsearch.configs.IndicesConfig in project kestra by kestra-io.
the class KafkaElasticIndexerTest method run.
@Test
void run() throws IOException, InterruptedException {
String topic = this.topicsConfig.stream().filter(indicesConfig -> indicesConfig.getCls() == Execution.class).findFirst().orElseThrow().getName();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestHighLevelClient elasticClientSpy = spy(elasticClient);
doAnswer(invocation -> {
countDownLatch.countDown();
return invocation.callRealMethod();
}).when(elasticClientSpy).bulk(any(), any());
KafkaConsumerService kafkaConsumerServiceSpy = mock(KafkaConsumerService.class);
MockConsumer<String, String> mockConsumer = mockConsumer(topic);
doReturn(mockConsumer).when(kafkaConsumerServiceSpy).of(any(), any(), any());
ConsumerRecord<String, String> first = buildExecutionRecord(topic, 0);
mockConsumer.addRecord(first);
mockConsumer.addRecord(buildExecutionRecord(topic, 1));
mockConsumer.addRecord(buildExecutionRecord(topic, 2));
mockConsumer.addRecord(buildExecutionRecord(topic, 3));
mockConsumer.addRecord(buildExecutionRecord(topic, 4));
mockConsumer.addRecord(buildRecord(topic, first.key(), null, 5));
KafkaElasticIndexer indexer = new KafkaElasticIndexer(metricRegistry, elasticClientSpy, indexerConfig, topicsConfig, indicesConfigs, elasticSearchIndicesService, kafkaConsumerServiceSpy, executorsUtils);
Thread thread = new Thread(indexer);
thread.start();
countDownLatch.await();
assertThat(countDownLatch.getCount(), is(0L));
}
use of io.kestra.repository.elasticsearch.configs.IndicesConfig in project kestra by kestra-io.
the class ElasticSearchIndicesService method createIndice.
public void createIndice(@Nullable Map<String, IndicesConfig> indicesConfigs) {
try {
for (Map.Entry<String, IndicesConfig> index : (indicesConfigs == null ? this.indicesConfigs : indicesConfigs).entrySet()) {
GetIndexRequest exists = new GetIndexRequest(index.getValue().getIndex());
if (!client.indices().exists(exists, RequestOptions.DEFAULT)) {
CreateIndexRequest request = new CreateIndexRequest(index.getValue().getIndex());
request.settings(index.getValue().getSettingsContent(), XContentType.JSON);
client.indices().create(request, RequestOptions.DEFAULT);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations