in reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/PluginBaseAction.kt [50:108]
override fun doExecute(
task: Task?,
request: Request,
listener: ActionListener<Response>
) {
val userStr: String? =
client.threadPool().threadContext.getTransient<String>(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT)
val user: User? = User.parse(userStr)
val storedThreadContext = client.threadPool().threadContext.newStoredContext(false)
scope.launch {
try {
client.threadPool().threadContext.stashContext().use {
storedThreadContext.restore()
listener.onResponse(executeRequest(request, user))
}
} catch (exception: OpenSearchStatusException) {
Metrics.REPORT_EXCEPTIONS_ES_STATUS_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:OpenSearchStatusException: message:${exception.message}")
listener.onFailure(exception)
} catch (exception: OpenSearchSecurityException) {
Metrics.REPORT_EXCEPTIONS_ES_SECURITY_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:OpenSearchSecurityException:", exception)
listener.onFailure(
OpenSearchStatusException(
"Permissions denied: ${exception.message} - Contact administrator",
RestStatus.FORBIDDEN
)
)
} catch (exception: VersionConflictEngineException) {
Metrics.REPORT_EXCEPTIONS_VERSION_CONFLICT_ENGINE_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:VersionConflictEngineException:", exception)
listener.onFailure(OpenSearchStatusException(exception.message, RestStatus.CONFLICT))
} catch (exception: IndexNotFoundException) {
Metrics.REPORT_EXCEPTIONS_INDEX_NOT_FOUND_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:IndexNotFoundException:", exception)
listener.onFailure(OpenSearchStatusException(exception.message, RestStatus.NOT_FOUND))
} catch (exception: InvalidIndexNameException) {
Metrics.REPORT_EXCEPTIONS_INVALID_INDEX_NAME_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:InvalidIndexNameException:", exception)
listener.onFailure(OpenSearchStatusException(exception.message, RestStatus.BAD_REQUEST))
} catch (exception: IllegalArgumentException) {
Metrics.REPORT_EXCEPTIONS_ILLEGAL_ARGUMENT_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:IllegalArgumentException:", exception)
listener.onFailure(OpenSearchStatusException(exception.message, RestStatus.BAD_REQUEST))
} catch (exception: IllegalStateException) {
Metrics.REPORT_EXCEPTIONS_ILLEGAL_STATE_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:IllegalStateException:", exception)
listener.onFailure(OpenSearchStatusException(exception.message, RestStatus.SERVICE_UNAVAILABLE))
} catch (exception: IOException) {
Metrics.REPORT_EXCEPTIONS_IO_EXCEPTION.counter.increment()
log.error("$LOG_PREFIX:Uncaught IOException:", exception)
listener.onFailure(OpenSearchStatusException(exception.message, RestStatus.FAILED_DEPENDENCY))
} catch (exception: Exception) {
Metrics.REPORT_EXCEPTIONS_INTERNAL_SERVER_ERROR.counter.increment()
log.error("$LOG_PREFIX:Uncaught Exception:", exception)
listener.onFailure(OpenSearchStatusException(exception.message, RestStatus.INTERNAL_SERVER_ERROR))
}
}
}