Skip to content
Draft
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 @@ -65,6 +65,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: reports-scheduler-linux
overwrite: true
path: reports-scheduler-builds

build-windows-macos:
Expand Down Expand Up @@ -97,5 +98,6 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: eports-scheduler-${{ matrix.os }}
path: eports-scheduler-builds
name: reports-scheduler-${{ matrix.os }}
overwrite: true
path: reports-scheduler-builds
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import org.opensearch.core.common.io.stream.NamedWriteableRegistry
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.env.Environment
import org.opensearch.env.NodeEnvironment
import org.opensearch.identity.PluginSubject
import org.opensearch.indices.SystemIndexDescriptor
import org.opensearch.jobscheduler.spi.JobSchedulerExtension
import org.opensearch.jobscheduler.spi.ScheduledJobParser
import org.opensearch.jobscheduler.spi.ScheduledJobRunner
import org.opensearch.plugins.ActionPlugin
import org.opensearch.plugins.IdentityAwarePlugin
import org.opensearch.plugins.Plugin
import org.opensearch.plugins.SystemIndexPlugin
import org.opensearch.reportsscheduler.action.CreateReportDefinitionAction
Expand All @@ -48,6 +50,7 @@ import org.opensearch.reportsscheduler.resthandler.ReportInstanceRestHandler
import org.opensearch.reportsscheduler.resthandler.ReportStatsRestHandler
import org.opensearch.reportsscheduler.scheduler.ReportDefinitionJobParser
import org.opensearch.reportsscheduler.scheduler.ReportDefinitionJobRunner
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.reportsscheduler.settings.PluginSettings
import org.opensearch.repositories.RepositoriesService
import org.opensearch.rest.RestController
Expand All @@ -62,13 +65,14 @@ import java.util.function.Supplier
* Entry point of the OpenSearch Reports scheduler plugin.
* This class initializes the rest handlers.
*/
class ReportsSchedulerPlugin : Plugin(), ActionPlugin, SystemIndexPlugin, JobSchedulerExtension {
class ReportsSchedulerPlugin : Plugin(), ActionPlugin, SystemIndexPlugin, IdentityAwarePlugin, JobSchedulerExtension {

companion object {
const val PLUGIN_NAME = "opensearch-reports-scheduler"
const val LOG_PREFIX = "reports"
const val BASE_REPORTS_URI = "/_plugins/_reports"
const val LEGACY_BASE_REPORTS_URI = "/_opendistro/_reports"
private lateinit var pluginClient: PluginClient
}

/**
Expand Down Expand Up @@ -104,9 +108,16 @@ class ReportsSchedulerPlugin : Plugin(), ActionPlugin, SystemIndexPlugin, JobSch
repositoriesServiceSupplier: Supplier<RepositoriesService>
): Collection<Any> {
PluginSettings.addSettingsUpdateConsumer(clusterService)
ReportDefinitionsIndex.initialize(client, clusterService)
ReportInstancesIndex.initialize(client, clusterService)
return emptyList()
pluginClient = PluginClient(client)
ReportDefinitionsIndex.initialize(pluginClient, clusterService)
ReportInstancesIndex.initialize(pluginClient, clusterService)
return listOf(pluginClient)
}

override fun assignSubject(pluginSubject: PluginSubject) {
// When security is not installed, the pluginSubject will still be assigned.
requireNotNull(pluginSubject)
pluginClient.setSubject(pluginSubject)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.CreateReportDefinitionRequest
import org.opensearch.reportsscheduler.model.CreateReportDefinitionResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* Create reportDefinition transport action
*/
internal class CreateReportDefinitionAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<CreateReportDefinitionRequest, CreateReportDefinitionResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::CreateReportDefinitionRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.DeleteReportDefinitionRequest
import org.opensearch.reportsscheduler.model.DeleteReportDefinitionResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* Delete reportDefinition transport action
*/
internal class DeleteReportDefinitionAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<DeleteReportDefinitionRequest, DeleteReportDefinitionResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::DeleteReportDefinitionRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.GetAllReportDefinitionsRequest
import org.opensearch.reportsscheduler.model.GetAllReportDefinitionsResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* Get all reportDefinitions transport action
*/
internal class GetAllReportDefinitionsAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<GetAllReportDefinitionsRequest, GetAllReportDefinitionsResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::GetAllReportDefinitionsRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.GetAllReportInstancesRequest
import org.opensearch.reportsscheduler.model.GetAllReportInstancesResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* Get all report instances transport action
*/
internal class GetAllReportInstancesAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<GetAllReportInstancesRequest, GetAllReportInstancesResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::GetAllReportInstancesRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.GetReportDefinitionRequest
import org.opensearch.reportsscheduler.model.GetReportDefinitionResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* Get reportDefinition transport action
*/
internal class GetReportDefinitionAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<GetReportDefinitionRequest, GetReportDefinitionResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::GetReportDefinitionRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.GetReportInstanceRequest
import org.opensearch.reportsscheduler.model.GetReportInstanceResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* Get report instance transport action
*/
internal class GetReportInstanceAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<GetReportInstanceRequest, GetReportInstanceResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::GetReportInstanceRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.InContextReportCreateRequest
import org.opensearch.reportsscheduler.model.InContextReportCreateResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* In-Context ReportCreate transport action
*/
internal class InContextReportCreateAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<InContextReportCreateRequest, InContextReportCreateResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::InContextReportCreateRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.OnDemandReportCreateRequest
import org.opensearch.reportsscheduler.model.OnDemandReportCreateResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* On-Demand ReportCreate transport action
*/
internal class OnDemandReportCreateAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<OnDemandReportCreateRequest, OnDemandReportCreateResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::OnDemandReportCreateRequest
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.opensearch.OpenSearchStatusException
import org.opensearch.action.ActionRequest
import org.opensearch.action.support.ActionFilters
import org.opensearch.action.support.HandledTransportAction
import org.opensearch.common.util.concurrent.ThreadContext
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT
import org.opensearch.commons.authuser.User
import org.opensearch.core.action.ActionListener
Expand All @@ -25,16 +24,16 @@ import org.opensearch.index.engine.VersionConflictEngineException
import org.opensearch.indices.InvalidIndexNameException
import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX
import org.opensearch.reportsscheduler.metrics.Metrics
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.reportsscheduler.util.logger
import org.opensearch.tasks.Task
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client
import java.io.IOException

abstract class PluginBaseAction<Request : ActionRequest, Response : ActionResponse>(
name: String,
transportService: TransportService,
val client: Client,
val pluginClient: PluginClient,
actionFilters: ActionFilters,
requestReader: Writeable.Reader<Request>
) : HandledTransportAction<Request, Response>(name, transportService, actionFilters, requestReader) {
Expand All @@ -53,15 +52,11 @@ abstract class PluginBaseAction<Request : ActionRequest, Response : ActionRespon
listener: ActionListener<Response>
) {
val userStr: String? =
client.threadPool().threadContext.getTransient<String>(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT)
pluginClient.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))
}
listener.onResponse(executeRequest(request, user))
} catch (exception: OpenSearchStatusException) {
Metrics.REPORT_EXCEPTIONS_ES_STATUS_EXCEPTION.counter.increment()
log.warn("$LOG_PREFIX:OpenSearchStatusException: message:${exception.message}")
Expand Down Expand Up @@ -113,43 +108,4 @@ abstract class PluginBaseAction<Request : ActionRequest, Response : ActionRespon
* @return the response to return.
*/
abstract fun executeRequest(request: Request, user: User?): Response

/**
* Executes the given [block] function on this resource and then closes it down correctly whether an exception
* is thrown or not.
*
* In case if the resource is being closed due to an exception occurred in [block], and the closing also fails with an exception,
* the latter is added to the [suppressed][java.lang.Throwable.addSuppressed] exceptions of the former.
*
* @param block a function to process this [AutoCloseable] resource.
* @return the result of [block] function invoked on this resource.
*/
@Suppress("TooGenericExceptionCaught")
private inline fun <T : ThreadContext.StoredContext, R> T.use(block: (T) -> R): R {
var exception: Throwable? = null
try {
return block(this)
} catch (e: Throwable) {
exception = e
throw e
} finally {
closeFinally(exception)
}
}

/**
* Closes this [AutoCloseable], suppressing possible exception or error thrown by [AutoCloseable.close] function when
* it's being closed due to some other [cause] exception occurred.
*
* The suppressed exception is added to the list of suppressed exceptions of [cause] exception.
*/
@Suppress("TooGenericExceptionCaught")
private fun ThreadContext.StoredContext.closeFinally(cause: Throwable?) = when (cause) {
null -> close()
else -> try {
close()
} catch (closeException: Throwable) {
cause.addSuppressed(closeException)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.opensearch.commons.authuser.User
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.reportsscheduler.model.UpdateReportDefinitionRequest
import org.opensearch.reportsscheduler.model.UpdateReportDefinitionResponse
import org.opensearch.reportsscheduler.security.PluginClient
import org.opensearch.transport.TransportService
import org.opensearch.transport.client.Client

/**
* Update reportDefinitions transport action
*/
internal class UpdateReportDefinitionAction @Inject constructor(
transportService: TransportService,
client: Client,
pluginClient: PluginClient,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<UpdateReportDefinitionRequest, UpdateReportDefinitionResponse>(
NAME,
transportService,
client,
pluginClient,
actionFilters,
::UpdateReportDefinitionRequest
) {
Expand Down
Loading
Loading