Skip to content

Commit

Permalink
Fixed exception when datasource is updated with existing configuration (
Browse files Browse the repository at this point in the history
#2006) (#2009)

(cherry picked from commit b3fd4c4)

Signed-off-by: Vamsi Manohar <reddyvam@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 9eb2c4f commit 8313c34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,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("Saving dataSource metadata information failed with result : "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,24 @@ public void testUpdateDataSourceMetadata() {

}

@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");
Expand Down

0 comments on commit 8313c34

Please sign in to comment.