From b3fd4c4154080ab271c33ef4d5d12b67aa2d713b Mon Sep 17 00:00:00 2001 From: Vamsi Manohar Date: Tue, 22 Aug 2023 01:20:50 -0700 Subject: [PATCH] Fixed exception when datasource is updated with existing configuration (#2006) Signed-off-by: Vamsi Manohar --- .../OpenSearchDataSourceMetadataStorage.java | 3 ++- ...penSearchDataSourceMetadataStorageTest.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java index 73eb297fea..4eb16924c4 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java @@ -150,7 +150,8 @@ public void updateDataSourceMetadata(DataSourceMetadata dataSourceMetadata) { throw new RuntimeException(e); } - if (updateResponse.getResult().equals(DocWriteResponse.Result.UPDATED)) { + if (updateResponse.getResult().equals(DocWriteResponse.Result.UPDATED) + || updateResponse.getResult().equals(DocWriteResponse.Result.NOOP)) { LOG.debug("DatasourceMetadata : {} successfully updated", dataSourceMetadata.getName()); } else { throw new RuntimeException( diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java index cc663d56e6..7d41737b2d 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java @@ -451,6 +451,24 @@ public void testUpdateDataSourceMetadata() { Mockito.verify(client.threadPool().getThreadContext(), Mockito.times(1)).stashContext(); } + @Test + public void testUpdateDataSourceMetadataWithNOOP() { + Mockito.when(encryptor.encrypt("secret_key")).thenReturn("secret_key"); + Mockito.when(encryptor.encrypt("access_key")).thenReturn("access_key"); + Mockito.when(client.update(ArgumentMatchers.any())).thenReturn(updateResponseActionFuture); + Mockito.when(updateResponseActionFuture.actionGet()).thenReturn(updateResponse); + Mockito.when(updateResponse.getResult()).thenReturn(DocWriteResponse.Result.NOOP); + DataSourceMetadata dataSourceMetadata = getDataSourceMetadata(); + + this.openSearchDataSourceMetadataStorage.updateDataSourceMetadata(dataSourceMetadata); + + Mockito.verify(encryptor, Mockito.times(1)).encrypt("secret_key"); + Mockito.verify(encryptor, Mockito.times(1)).encrypt("access_key"); + Mockito.verify(client.admin().indices(), Mockito.times(0)).create(ArgumentMatchers.any()); + Mockito.verify(client, Mockito.times(1)).update(ArgumentMatchers.any()); + Mockito.verify(client.threadPool().getThreadContext(), Mockito.times(1)).stashContext(); + } + @Test public void testUpdateDataSourceMetadataWithNotFoundResult() { Mockito.when(encryptor.encrypt("secret_key")).thenReturn("secret_key");