Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,6 @@ private void doInitializeInternal() throws IOException {
openSearchClientRefresher = new OpenSearchClientRefresher(
pluginMetrics, connectionConfiguration, clientFunction);

if (queryExecutorService != null) {
existingDocumentQueryManager = new ExistingDocumentQueryManager(openSearchSinkConfig.getIndexConfiguration(), pluginMetrics, openSearchClient);
queryExecutorService.submit(existingDocumentQueryManager);
}

pluginConfigObservable.addPluginConfigObserver(
newOpenSearchSinkConfig -> openSearchClientRefresher.update((OpenSearchSinkConfig) newOpenSearchSinkConfig));
configuredIndexAlias = openSearchSinkConfig.getIndexConfiguration().getIndexAlias();
Expand Down Expand Up @@ -304,6 +299,11 @@ private void doInitializeInternal() throws IOException {
PLUGIN_NAME,
openSearchSinkConfig.getIndexConfiguration().getQueryOnBulkFailures() ? existingDocumentQueryManager : null);

if (queryExecutorService != null) {
existingDocumentQueryManager = new ExistingDocumentQueryManager(openSearchSinkConfig.getIndexConfiguration(), pluginMetrics, openSearchClient);
queryExecutorService.submit(existingDocumentQueryManager);
}

this.initialized = true;
LOG.info("Initialized OpenSearch sink");
}
Expand Down Expand Up @@ -649,7 +649,7 @@ public void shutdown() {
super.shutdown();
closeFiles();
openSearchClient.shutdown();
if (queryExecutorService != null) {
if (queryExecutorService != null && existingDocumentQueryManager != null) {
existingDocumentQueryManager.stop();
queryExecutorService.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opensearch.dataprepper.model.sink.SinkLatencyMetrics.EXTERNAL_LATENCY;
Expand Down Expand Up @@ -203,6 +204,19 @@ void test_initialization() throws IOException {
verify(pluginConfigObservable).addPluginConfigObserver(any());
}

@Test
void test_initialization_with_failure_and_retry_with_query_manager() throws IOException {
when(openSearchSinkConfiguration.getIndexConfiguration().getQueryTerm()).thenReturn(UUID.randomUUID().toString());

final OpenSearchSink objectUnderTest = createObjectUnderTest();
when(indexManagerFactory.getIndexManager(any(IndexType.class), eq(openSearchClient), any(RestHighLevelClient.class), eq(openSearchSinkConfiguration), any(TemplateStrategy.class), any()))
.thenThrow(RuntimeException.class).thenReturn(indexManager);
doNothing().when(indexManager).setupIndex();
objectUnderTest.initialize();
objectUnderTest.initialize();
verify(pluginConfigObservable, times(2)).addPluginConfigObserver(any());
}

@Test
void doOutput_with_invalid_version_expression_catches_NumberFormatException_and_creates_DLQObject() throws IOException {
when(pluginSetting.getName()).thenReturn("opensearch");
Expand Down
Loading