-
Notifications
You must be signed in to change notification settings - Fork 90
Route getNotificationConfigs through SdkClient #1225
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,6 @@ import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest | |
| import org.opensearch.action.bulk.BulkResponse | ||
| import org.opensearch.action.delete.DeleteResponse | ||
| import org.opensearch.action.get.GetResponse | ||
| import org.opensearch.action.get.MultiGetRequest | ||
| import org.opensearch.action.get.MultiGetResponse | ||
| import org.opensearch.action.index.IndexResponse | ||
| import org.opensearch.action.search.SearchResponse | ||
| import org.opensearch.action.support.clustermanager.AcknowledgedResponse | ||
|
|
@@ -212,12 +210,39 @@ internal object NotificationConfigIndex : ConfigOperations { | |
| */ | ||
| override suspend fun getNotificationConfigs(ids: Set<String>): List<NotificationConfigDocInfo> { | ||
| createIndex() | ||
| val getRequest = MultiGetRequest() | ||
| ids.forEach { getRequest.add(INDEX_NAME, it) } | ||
| val response: MultiGetResponse = client.suspendUntilTimeout(PluginSettings.operationTimeoutMs) { | ||
| multiGet(getRequest, it) | ||
| val sourceBuilder = SearchSourceBuilder() | ||
| .timeout(TimeValue(PluginSettings.operationTimeoutMs, TimeUnit.MILLISECONDS)) | ||
| .query(QueryBuilders.idsQuery().addIds(*ids.toTypedArray())) | ||
| .size(ids.size) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably an unlikely edge case, but do we need to worry about |
||
| val searchRequest = SearchDataObjectRequest.builder() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that |
||
| .indices(INDEX_NAME) | ||
| .tenantId(currentTenantId()) | ||
| .searchSourceBuilder(sourceBuilder) | ||
| .build() | ||
| val response: SearchResponse = sdkClient.suspendUntilTimeout(PluginSettings.operationTimeoutMs) { | ||
| sdkClient.searchDataObjectAsync(searchRequest).whenComplete(it) | ||
| } | ||
| return response.hits.hits.mapNotNull { hit -> | ||
| try { | ||
| val parser = XContentType.JSON.xContent().createParser( | ||
| NamedXContentRegistry.EMPTY, | ||
| LoggingDeprecationHandler.INSTANCE, | ||
| hit.sourceAsString | ||
| ) | ||
| parser.nextToken() | ||
| val doc = NotificationConfigDoc.parse(parser) | ||
| val info = DocInfo( | ||
| id = hit.id, | ||
| version = hit.version, | ||
| seqNo = hit.seqNo, | ||
| primaryTerm = hit.primaryTerm | ||
| ) | ||
| NotificationConfigDocInfo(info, doc) | ||
| } catch (e: Exception) { | ||
| log.warn("$LOG_PREFIX:getNotificationConfigs - failed to parse ${hit.id}: ${e.message}") | ||
| null | ||
| } | ||
| } | ||
| return response.responses.mapNotNull { parseNotificationConfigDoc(it.id, it.response) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the existing parse method not able to handle the search response?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currently parseNotificationConfigDoc takes a GetResponse, but the search returns SearchHit objects. The SearchHit has sourceAsString but not a GetResponse, so we can't pass it directly |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldnt there be a new gradle wrapper jar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MohammedAghil could you take a look at this gradle bump PR for the alerting plugin? you may be able to just copy those changes.
https://github.com/opensearch-project/alerting/pull/2122/changes