Skip to content

Commit fc37940

Browse files
authored
Create the report definitions and instances indices in the system context to avoid permissions issues (#1108)
Signed-off-by: Craig Perkins <cwperx@amazon.com>
1 parent 026545c commit fc37940

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/main/kotlin/org/opensearch/reportsscheduler/index/ReportDefinitionsIndex.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ internal object ReportDefinitionsIndex {
6868
.mapping(indexMappingSource, XContentType.YAML)
6969
.settings(indexSettingsSource, XContentType.YAML)
7070
try {
71-
val actionFuture = client.admin().indices().create(request)
72-
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
73-
if (response.isAcknowledged) {
74-
log.info("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation Acknowledged")
75-
} else {
76-
Metrics.REPORT_DEFINITION_CREATE_SYSTEM_ERROR.counter.increment()
77-
error("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation not Acknowledged")
71+
client.threadPool().threadContext.stashContext().use {
72+
val actionFuture = client.admin().indices().create(request)
73+
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
74+
if (response.isAcknowledged) {
75+
log.info("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation Acknowledged")
76+
} else {
77+
Metrics.REPORT_DEFINITION_CREATE_SYSTEM_ERROR.counter.increment()
78+
error("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation not Acknowledged")
79+
}
7880
}
7981
} catch (exception: ResourceAlreadyExistsException) {
8082
log.warn("message: ${exception.message}")

src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ internal object ReportInstancesIndex {
6868
.mapping(indexMappingSource, XContentType.YAML)
6969
.settings(indexSettingsSource, XContentType.YAML)
7070
try {
71-
val actionFuture = client.admin().indices().create(request)
72-
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
73-
if (response.isAcknowledged) {
74-
log.info("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation Acknowledged")
75-
} else {
76-
error("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation not Acknowledged")
71+
client.threadPool().threadContext.stashContext().use {
72+
val actionFuture = client.admin().indices().create(request)
73+
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
74+
if (response.isAcknowledged) {
75+
log.info("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation Acknowledged")
76+
} else {
77+
error("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation not Acknowledged")
78+
}
7779
}
7880
} catch (exception: ResourceAlreadyExistsException) {
7981
log.warn("message: ${exception.message}")

0 commit comments

Comments
 (0)