Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.9] Fixed exception when datasource is updated with existing configuration. #2009

Merged
merged 1 commit into from
Aug 22, 2023
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 @@ -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