diff --git a/reports-scheduler/build.gradle b/reports-scheduler/build.gradle index f2af2968..c63c0258 100644 --- a/reports-scheduler/build.gradle +++ b/reports-scheduler/build.gradle @@ -179,7 +179,7 @@ dependencies { testCompile "org.mockito:mockito-core:3.12.4" testCompile 'com.google.code.gson:gson:2.8.9' - ktlint "com.pinterest:ktlint:0.33.0" + ktlint "com.pinterest:ktlint:0.45.1" } javadoc.enabled = false // turn off javadoc as it barfs on Kotlin code diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/ReportsSchedulerPlugin.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/ReportsSchedulerPlugin.kt index c0fd258f..e1d68fba 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/ReportsSchedulerPlugin.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/ReportsSchedulerPlugin.kt @@ -5,9 +5,26 @@ package org.opensearch.reportsscheduler +import org.opensearch.action.ActionRequest +import org.opensearch.action.ActionResponse +import org.opensearch.client.Client +import org.opensearch.cluster.metadata.IndexNameExpressionResolver +import org.opensearch.cluster.node.DiscoveryNodes +import org.opensearch.cluster.service.ClusterService +import org.opensearch.common.io.stream.NamedWriteableRegistry +import org.opensearch.common.settings.ClusterSettings +import org.opensearch.common.settings.IndexScopedSettings +import org.opensearch.common.settings.Setting +import org.opensearch.common.settings.Settings +import org.opensearch.common.settings.SettingsFilter +import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.env.Environment +import org.opensearch.env.NodeEnvironment 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.Plugin import org.opensearch.reportsscheduler.action.CreateReportDefinitionAction import org.opensearch.reportsscheduler.action.DeleteReportDefinitionAction import org.opensearch.reportsscheduler.action.GetAllReportDefinitionsAction @@ -30,24 +47,6 @@ import org.opensearch.reportsscheduler.resthandler.ReportStatsRestHandler import org.opensearch.reportsscheduler.scheduler.ReportDefinitionJobParser import org.opensearch.reportsscheduler.scheduler.ReportDefinitionJobRunner import org.opensearch.reportsscheduler.settings.PluginSettings - -import org.opensearch.action.ActionRequest -import org.opensearch.action.ActionResponse -import org.opensearch.client.Client -import org.opensearch.cluster.metadata.IndexNameExpressionResolver -import org.opensearch.cluster.node.DiscoveryNodes -import org.opensearch.cluster.service.ClusterService -import org.opensearch.common.io.stream.NamedWriteableRegistry -import org.opensearch.common.settings.ClusterSettings -import org.opensearch.common.settings.IndexScopedSettings -import org.opensearch.common.settings.Setting -import org.opensearch.common.settings.Settings -import org.opensearch.common.settings.SettingsFilter -import org.opensearch.common.xcontent.NamedXContentRegistry -import org.opensearch.env.Environment -import org.opensearch.env.NodeEnvironment -import org.opensearch.plugins.ActionPlugin -import org.opensearch.plugins.Plugin import org.opensearch.repositories.RepositoriesService import org.opensearch.rest.RestController import org.opensearch.rest.RestHandler diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/CreateReportDefinitionAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/CreateReportDefinitionAction.kt index 77306b9c..3c953c16 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/CreateReportDefinitionAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/CreateReportDefinitionAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.CreateReportDefinitionRequest -import org.opensearch.reportsscheduler.model.CreateReportDefinitionResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.CreateReportDefinitionRequest +import org.opensearch.reportsscheduler.model.CreateReportDefinitionResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class CreateReportDefinitionAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::CreateReportDefinitionRequest) { + ::CreateReportDefinitionRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/definition/create" internal val ACTION_TYPE = ActionType(NAME, ::CreateReportDefinitionResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/DeleteReportDefinitionAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/DeleteReportDefinitionAction.kt index 938ebc22..d80ab47c 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/DeleteReportDefinitionAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/DeleteReportDefinitionAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.DeleteReportDefinitionRequest -import org.opensearch.reportsscheduler.model.DeleteReportDefinitionResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.DeleteReportDefinitionRequest +import org.opensearch.reportsscheduler.model.DeleteReportDefinitionResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class DeleteReportDefinitionAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::DeleteReportDefinitionRequest) { + ::DeleteReportDefinitionRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/definition/delete" internal val ACTION_TYPE = ActionType(NAME, ::DeleteReportDefinitionResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportDefinitionsAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportDefinitionsAction.kt index d8abe4c5..40bd71f5 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportDefinitionsAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportDefinitionsAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.GetAllReportDefinitionsRequest -import org.opensearch.reportsscheduler.model.GetAllReportDefinitionsResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.GetAllReportDefinitionsRequest +import org.opensearch.reportsscheduler.model.GetAllReportDefinitionsResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class GetAllReportDefinitionsAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::GetAllReportDefinitionsRequest) { + ::GetAllReportDefinitionsRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/definition/list" internal val ACTION_TYPE = ActionType(NAME, ::GetAllReportDefinitionsResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportInstancesAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportInstancesAction.kt index b85e7a01..5234d920 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportInstancesAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetAllReportInstancesAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.GetAllReportInstancesRequest -import org.opensearch.reportsscheduler.model.GetAllReportInstancesResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.GetAllReportInstancesRequest +import org.opensearch.reportsscheduler.model.GetAllReportInstancesResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class GetAllReportInstancesAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::GetAllReportInstancesRequest) { + ::GetAllReportInstancesRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/instance/list" internal val ACTION_TYPE = ActionType(NAME, ::GetAllReportInstancesResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportDefinitionAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportDefinitionAction.kt index c37d2f5d..f52c6b18 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportDefinitionAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportDefinitionAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.GetReportDefinitionRequest -import org.opensearch.reportsscheduler.model.GetReportDefinitionResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.GetReportDefinitionRequest +import org.opensearch.reportsscheduler.model.GetReportDefinitionResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class GetReportDefinitionAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::GetReportDefinitionRequest) { + ::GetReportDefinitionRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/definition/get" internal val ACTION_TYPE = ActionType(NAME, ::GetReportDefinitionResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportInstanceAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportInstanceAction.kt index 3e3729a8..49782f5a 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportInstanceAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/GetReportInstanceAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.GetReportInstanceRequest -import org.opensearch.reportsscheduler.model.GetReportInstanceResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.GetReportInstanceRequest +import org.opensearch.reportsscheduler.model.GetReportInstanceResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class GetReportInstanceAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::GetReportInstanceRequest) { + ::GetReportInstanceRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/instance/get" internal val ACTION_TYPE = ActionType(NAME, ::GetReportInstanceResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/InContextReportCreateAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/InContextReportCreateAction.kt index 208b21ff..69f06ad0 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/InContextReportCreateAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/InContextReportCreateAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.InContextReportCreateRequest -import org.opensearch.reportsscheduler.model.InContextReportCreateResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.InContextReportCreateRequest +import org.opensearch.reportsscheduler.model.InContextReportCreateResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class InContextReportCreateAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::InContextReportCreateRequest) { + ::InContextReportCreateRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/menu/download" internal val ACTION_TYPE = ActionType(NAME, ::InContextReportCreateResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/OnDemandReportCreateAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/OnDemandReportCreateAction.kt index d654cba2..a6d75f68 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/OnDemandReportCreateAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/OnDemandReportCreateAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.OnDemandReportCreateRequest -import org.opensearch.reportsscheduler.model.OnDemandReportCreateResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.OnDemandReportCreateRequest +import org.opensearch.reportsscheduler.model.OnDemandReportCreateResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class OnDemandReportCreateAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::OnDemandReportCreateRequest) { + ::OnDemandReportCreateRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/definition/on_demand" internal val ACTION_TYPE = ActionType(NAME, ::OnDemandReportCreateResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/PluginBaseAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/PluginBaseAction.kt index 46aabdb2..1b56c97a 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/PluginBaseAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/PluginBaseAction.kt @@ -5,11 +5,6 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.util.logger import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -23,9 +18,14 @@ import org.opensearch.action.support.HandledTransportAction import org.opensearch.client.Client import org.opensearch.common.io.stream.Writeable 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.index.IndexNotFoundException 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.util.logger import org.opensearch.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportDefinitionActions.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportDefinitionActions.kt index 34e26ec1..a3c30a1d 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportDefinitionActions.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportDefinitionActions.kt @@ -5,6 +5,7 @@ package org.opensearch.reportsscheduler.action +import org.opensearch.OpenSearchStatusException import org.opensearch.commons.authuser.User import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX import org.opensearch.reportsscheduler.index.ReportDefinitionsIndex @@ -22,7 +23,6 @@ import org.opensearch.reportsscheduler.model.UpdateReportDefinitionRequest import org.opensearch.reportsscheduler.model.UpdateReportDefinitionResponse import org.opensearch.reportsscheduler.security.UserAccessManager import org.opensearch.reportsscheduler.util.logger -import org.opensearch.OpenSearchStatusException import org.opensearch.rest.RestStatus import java.time.Instant @@ -41,7 +41,8 @@ internal object ReportDefinitionActions { log.info("$LOG_PREFIX:ReportDefinition-create") UserAccessManager.validateUser(user) val currentTime = Instant.now() - val reportDefinitionDetails = ReportDefinitionDetails("ignore", + val reportDefinitionDetails = ReportDefinitionDetails( + "ignore", currentTime, currentTime, UserAccessManager.getUserTenant(user), @@ -49,8 +50,10 @@ internal object ReportDefinitionActions { request.reportDefinition ) val docId = ReportDefinitionsIndex.createReportDefinition(reportDefinitionDetails) - docId ?: throw OpenSearchStatusException("Report Definition Creation failed", - RestStatus.INTERNAL_SERVER_ERROR) + docId ?: throw OpenSearchStatusException( + "Report Definition Creation failed", + RestStatus.INTERNAL_SERVER_ERROR + ) return CreateReportDefinitionResponse(docId) } @@ -74,7 +77,8 @@ internal object ReportDefinitionActions { throw OpenSearchStatusException("Permission denied for Report Definition ${request.reportDefinitionId}", RestStatus.FORBIDDEN) } val currentTime = Instant.now() - val reportDefinitionDetails = ReportDefinitionDetails(request.reportDefinitionId, + val reportDefinitionDetails = ReportDefinitionDetails( + request.reportDefinitionId, currentTime, currentReportDefinitionDetails.createdTime, UserAccessManager.getUserTenant(user), @@ -144,10 +148,12 @@ internal object ReportDefinitionActions { fun getAll(request: GetAllReportDefinitionsRequest, user: User?): GetAllReportDefinitionsResponse { log.info("$LOG_PREFIX:ReportDefinition-getAll fromIndex:${request.fromIndex} maxItems:${request.maxItems}") UserAccessManager.validateUser(user) - val reportDefinitionsList = ReportDefinitionsIndex.getAllReportDefinitions(UserAccessManager.getUserTenant(user), + val reportDefinitionsList = ReportDefinitionsIndex.getAllReportDefinitions( + UserAccessManager.getUserTenant(user), UserAccessManager.getSearchAccessInfo(user), request.fromIndex, - request.maxItems) + request.maxItems + ) return GetAllReportDefinitionsResponse(reportDefinitionsList, true) } } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportInstanceActions.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportInstanceActions.kt index d1233741..37f32280 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportInstanceActions.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/ReportInstanceActions.kt @@ -43,7 +43,8 @@ internal object ReportInstanceActions { log.info("$LOG_PREFIX:ReportInstance-createOnDemand") UserAccessManager.validateUser(user) val currentTime = Instant.now() - val reportInstance = ReportInstance("ignore", + val reportInstance = ReportInstance( + "ignore", currentTime, currentTime, request.beginTime, @@ -53,7 +54,8 @@ internal object ReportInstanceActions { request.reportDefinitionDetails, Status.Success, // TODO: Revert to request.status when background job execution supported request.statusText, - request.inContextDownloadUrlPath) + request.inContextDownloadUrlPath + ) val docId = ReportInstancesIndex.createReportInstance(reportInstance) docId ?: run { Metrics.REPORT_FROM_DEFINITION_SYSTEM_ERROR.counter.increment() @@ -86,7 +88,8 @@ internal object ReportInstanceActions { val beginTime: Instant = currentTime.minus(reportDefinitionDetails.reportDefinition.format.duration) val endTime: Instant = currentTime val currentStatus: Status = Status.Success // TODO: Revert to Executing when background job execution supported - val reportInstance = ReportInstance("ignore", + val reportInstance = ReportInstance( + "ignore", currentTime, currentTime, beginTime, @@ -94,7 +97,8 @@ internal object ReportInstanceActions { UserAccessManager.getUserTenant(user), reportDefinitionDetails.access, reportDefinitionDetails, - currentStatus) + currentStatus + ) val docId = ReportInstancesIndex.createReportInstance(reportInstance) docId ?: run { Metrics.REPORT_FROM_DEFINITION_ID_SYSTEM_ERROR.counter.increment() @@ -127,9 +131,11 @@ internal object ReportInstanceActions { throw OpenSearchStatusException("Status cannot be updated to ${Status.Scheduled}", RestStatus.BAD_REQUEST) } val currentTime = Instant.now() - val updatedReportInstance = currentReportInstance.copy(updatedTime = currentTime, + val updatedReportInstance = currentReportInstance.copy( + updatedTime = currentTime, status = request.status, - statusText = request.statusText) + statusText = request.statusText + ) if (!ReportInstancesIndex.updateReportInstance(updatedReportInstance)) { Metrics.REPORT_INSTANCE_UPDATE_SYSTEM_ERROR.counter.increment() throw OpenSearchStatusException("Report Instance state update failed", RestStatus.INTERNAL_SERVER_ERROR) @@ -167,10 +173,12 @@ internal object ReportInstanceActions { fun getAll(request: GetAllReportInstancesRequest, user: User?): GetAllReportInstancesResponse { log.info("$LOG_PREFIX:ReportInstance-getAll fromIndex:${request.fromIndex} maxItems:${request.maxItems}") UserAccessManager.validateUser(user) - val reportInstanceList = ReportInstancesIndex.getAllReportInstances(UserAccessManager.getUserTenant(user), + val reportInstanceList = ReportInstancesIndex.getAllReportInstances( + UserAccessManager.getUserTenant(user), UserAccessManager.getSearchAccessInfo(user), request.fromIndex, - request.maxItems) + request.maxItems + ) return GetAllReportInstancesResponse(reportInstanceList, true) } } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportDefinitionAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportDefinitionAction.kt index 395c3a06..43d77d0b 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportDefinitionAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportDefinitionAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.UpdateReportDefinitionRequest -import org.opensearch.reportsscheduler.model.UpdateReportDefinitionResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.UpdateReportDefinitionRequest +import org.opensearch.reportsscheduler.model.UpdateReportDefinitionResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class UpdateReportDefinitionAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::UpdateReportDefinitionRequest) { + ::UpdateReportDefinitionRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/definition/update" internal val ACTION_TYPE = ActionType(NAME, ::UpdateReportDefinitionResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportInstanceStatusAction.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportInstanceStatusAction.kt index ae6f5a20..8ef85700 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportInstanceStatusAction.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/action/UpdateReportInstanceStatusAction.kt @@ -5,14 +5,14 @@ package org.opensearch.reportsscheduler.action -import org.opensearch.commons.authuser.User -import org.opensearch.reportsscheduler.model.UpdateReportInstanceStatusRequest -import org.opensearch.reportsscheduler.model.UpdateReportInstanceStatusResponse import org.opensearch.action.ActionType import org.opensearch.action.support.ActionFilters import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.NamedXContentRegistry +import org.opensearch.commons.authuser.User +import org.opensearch.reportsscheduler.model.UpdateReportInstanceStatusRequest +import org.opensearch.reportsscheduler.model.UpdateReportInstanceStatusResponse import org.opensearch.transport.TransportService /** @@ -23,11 +23,13 @@ internal class UpdateReportInstanceStatusAction @Inject constructor( client: Client, actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry -) : PluginBaseAction(NAME, +) : PluginBaseAction( + NAME, transportService, client, actionFilters, - ::UpdateReportInstanceStatusRequest) { + ::UpdateReportInstanceStatusRequest +) { companion object { private const val NAME = "cluster:admin/opendistro/reports/instance/update_status" internal val ACTION_TYPE = ActionType(NAME, ::UpdateReportInstanceStatusResponse) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt index be7277a5..1291e758 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt @@ -128,9 +128,11 @@ internal object ReportInstancesIndex { log.warn("$LOG_PREFIX:getReportInstance - $id not found; response:$response") null } else { - val parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, + val parser = XContentType.JSON.xContent().createParser( + NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - response.sourceAsString) + response.sourceAsString + ) parser.nextToken() ReportInstance.parse(parser, id) } @@ -167,8 +169,10 @@ internal object ReportInstancesIndex { val actionFuture = client.search(searchRequest) val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs) val result = ReportInstanceSearchResults(from.toLong(), response) - log.info("$LOG_PREFIX:getAllReportInstances from:$from, maxItems:$maxItems," + - " retCount:${result.objectList.size}, totalCount:${result.totalHits}") + log.info( + "$LOG_PREFIX:getAllReportInstances from:$from, maxItems:$maxItems," + + " retCount:${result.objectList.size}, totalCount:${result.totalHits}" + ) return result } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionRequest.kt index cb84d2a5..ad7c0f1b 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionRequest.kt @@ -5,11 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_FIELD -import org.opensearch.reportsscheduler.util.createJsonParser -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -21,6 +16,11 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_FIELD +import org.opensearch.reportsscheduler.util.createJsonParser +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionResponse.kt index e2d6efc8..03e483cb 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/CreateReportDefinitionResponse.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -16,6 +12,10 @@ import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequest.kt index 8222ba0b..13578a79 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequest.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -20,6 +16,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponse.kt index d1838320..898759c3 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponse.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -16,6 +12,10 @@ import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsRequest.kt index 809ff8df..7cef7c35 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsRequest.kt @@ -5,12 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.FROM_INDEX_FIELD -import org.opensearch.reportsscheduler.model.RestTag.MAX_ITEMS_FIELD -import org.opensearch.reportsscheduler.settings.PluginSettings -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -22,6 +16,12 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.FROM_INDEX_FIELD +import org.opensearch.reportsscheduler.model.RestTag.MAX_ITEMS_FIELD +import org.opensearch.reportsscheduler.settings.PluginSettings +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsResponse.kt index 69a4513b..b8b3cd46 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportDefinitionsResponse.kt @@ -5,13 +5,13 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.util.createJsonParser import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser +import org.opensearch.reportsscheduler.util.createJsonParser import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesRequest.kt index ced680ee..6a3f1dce 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesRequest.kt @@ -5,12 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.FROM_INDEX_FIELD -import org.opensearch.reportsscheduler.model.RestTag.MAX_ITEMS_FIELD -import org.opensearch.reportsscheduler.settings.PluginSettings -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -22,6 +16,12 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.FROM_INDEX_FIELD +import org.opensearch.reportsscheduler.model.RestTag.MAX_ITEMS_FIELD +import org.opensearch.reportsscheduler.settings.PluginSettings +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesResponse.kt index 5afbe0f3..de7c5266 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetAllReportInstancesResponse.kt @@ -5,13 +5,13 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.util.createJsonParser import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser +import org.opensearch.reportsscheduler.util.createJsonParser import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionRequest.kt index f254b18e..725029a3 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionRequest.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -20,6 +16,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionResponse.kt index 518fe565..63ad0baa 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportDefinitionResponse.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.util.createJsonParser -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -17,6 +13,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.util.createJsonParser +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceRequest.kt index abf112ef..edbd2c46 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceRequest.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -20,6 +16,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceResponse.kt index dae9b403..03931aa9 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/GetReportInstanceResponse.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_FIELD -import org.opensearch.reportsscheduler.util.createJsonParser -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -17,6 +13,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_FIELD +import org.opensearch.reportsscheduler.util.createJsonParser +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateRequest.kt index 959c6261..76684362 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateRequest.kt @@ -5,6 +5,17 @@ package org.opensearch.reportsscheduler.model +import org.opensearch.action.ActionRequest +import org.opensearch.action.ActionRequestValidationException +import org.opensearch.common.io.stream.StreamInput +import org.opensearch.common.io.stream.StreamOutput +import org.opensearch.common.xcontent.ToXContent +import org.opensearch.common.xcontent.ToXContentObject +import org.opensearch.common.xcontent.XContentBuilder +import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.common.xcontent.XContentParser +import org.opensearch.common.xcontent.XContentParser.Token +import org.opensearch.common.xcontent.XContentParserUtils import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX import org.opensearch.reportsscheduler.metrics.Metrics import org.opensearch.reportsscheduler.model.ReportInstance.Status @@ -18,17 +29,6 @@ import org.opensearch.reportsscheduler.model.RestTag.STATUS_TEXT_FIELD import org.opensearch.reportsscheduler.util.createJsonParser import org.opensearch.reportsscheduler.util.fieldIfNotNull import org.opensearch.reportsscheduler.util.logger -import org.opensearch.action.ActionRequest -import org.opensearch.action.ActionRequestValidationException -import org.opensearch.common.io.stream.StreamInput -import org.opensearch.common.io.stream.StreamOutput -import org.opensearch.common.xcontent.ToXContent -import org.opensearch.common.xcontent.ToXContentObject -import org.opensearch.common.xcontent.XContentBuilder -import org.opensearch.common.xcontent.XContentFactory -import org.opensearch.common.xcontent.XContentParser -import org.opensearch.common.xcontent.XContentParser.Token -import org.opensearch.common.xcontent.XContentParserUtils import java.io.IOException import java.time.Instant diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateResponse.kt index e895266b..73780e7e 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/InContextReportCreateResponse.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_FIELD -import org.opensearch.reportsscheduler.util.createJsonParser -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -17,6 +13,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_FIELD +import org.opensearch.reportsscheduler.util.createJsonParser +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateRequest.kt index c26e2b47..02d8e9f9 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateRequest.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -20,6 +16,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateResponse.kt index 17493d14..4d1331b8 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/OnDemandReportCreateResponse.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_FIELD -import org.opensearch.reportsscheduler.util.createJsonParser -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -17,6 +13,10 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_FIELD +import org.opensearch.reportsscheduler.util.createJsonParser +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt index ec14ff16..6544a284 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt @@ -5,17 +5,17 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.jobscheduler.spi.schedule.Schedule -import org.opensearch.jobscheduler.spi.schedule.ScheduleParser -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.util.logger -import org.opensearch.reportsscheduler.util.stringList import org.opensearch.common.xcontent.ToXContent import org.opensearch.common.xcontent.ToXContentObject import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.jobscheduler.spi.schedule.Schedule +import org.opensearch.jobscheduler.spi.schedule.ScheduleParser +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.util.logger +import org.opensearch.reportsscheduler.util.stringList import java.time.Duration /** @@ -120,12 +120,14 @@ internal data class ReportDefinition( source ?: throw IllegalArgumentException("$SOURCE_TAG field absent") format ?: throw IllegalArgumentException("$FORMAT_TAG field absent") trigger ?: throw IllegalArgumentException("$TRIGGER_TAG field absent") - return ReportDefinition(name, + return ReportDefinition( + name, isEnabled, source, format, trigger, - delivery) + delivery + ) } } @@ -204,7 +206,8 @@ internal data class ReportDefinition( type ?: throw IllegalArgumentException("$TYPE_TAG field absent") origin ?: throw IllegalArgumentException("$ORIGIN_TAG field absent") id ?: throw IllegalArgumentException("$ID_TAG field absent") - return Source(description, + return Source( + description, type, origin, id @@ -274,11 +277,13 @@ internal data class ReportDefinition( durationSeconds ?: throw IllegalArgumentException("$DURATION_TAG field absent") fileFormat ?: throw IllegalArgumentException("$FILE_FORMAT_TAG field absent") - return Format(durationSeconds, + return Format( + durationSeconds, fileFormat, limit, header, - footer) + footer + ) } } @@ -400,7 +405,8 @@ internal data class ReportDefinition( title, textDescription, htmlDescription, - configIds) + configIds + ) } } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetails.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetails.kt index 1e5067db..82bd1ae3 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetails.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetails.kt @@ -5,6 +5,12 @@ package org.opensearch.reportsscheduler.model +import org.opensearch.common.xcontent.ToXContent +import org.opensearch.common.xcontent.ToXContent.EMPTY_PARAMS +import org.opensearch.common.xcontent.XContentBuilder +import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.common.xcontent.XContentParser +import org.opensearch.common.xcontent.XContentParserUtils import org.opensearch.jobscheduler.spi.ScheduledJobParameter import org.opensearch.jobscheduler.spi.schedule.Schedule import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX @@ -18,12 +24,6 @@ import org.opensearch.reportsscheduler.model.RestTag.UPDATED_TIME_FIELD import org.opensearch.reportsscheduler.security.UserAccessManager.DEFAULT_TENANT import org.opensearch.reportsscheduler.util.logger import org.opensearch.reportsscheduler.util.stringList -import org.opensearch.common.xcontent.ToXContent -import org.opensearch.common.xcontent.ToXContent.EMPTY_PARAMS -import org.opensearch.common.xcontent.XContentBuilder -import org.opensearch.common.xcontent.XContentFactory -import org.opensearch.common.xcontent.XContentParser -import org.opensearch.common.xcontent.XContentParserUtils import java.time.Instant /** @@ -88,12 +88,14 @@ internal data class ReportDefinitionDetails( createdTime ?: throw IllegalArgumentException("$CREATED_TIME_FIELD field absent") tenant = tenant ?: DEFAULT_TENANT reportDefinition ?: throw IllegalArgumentException("$REPORT_DEFINITION_FIELD field absent") - return ReportDefinitionDetails(id, + return ReportDefinitionDetails( + id, updatedTime, createdTime, tenant, access, - reportDefinition) + reportDefinition + ) } } @@ -154,8 +156,10 @@ internal data class ReportDefinitionDetails( override fun isEnabled(): Boolean { val trigger = reportDefinition.trigger - return (reportDefinition.isEnabled && - (reportDefinition.trigger.schedule != null) && - (trigger.triggerType == TriggerType.IntervalSchedule || trigger.triggerType == TriggerType.CronSchedule)) + return ( + reportDefinition.isEnabled && + (reportDefinition.trigger.schedule != null) && + (trigger.triggerType == TriggerType.IntervalSchedule || trigger.triggerType == TriggerType.CronSchedule) + ) } } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetailsSearchResults.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetailsSearchResults.kt index 129a658e..86e51116 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetailsSearchResults.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinitionDetailsSearchResults.kt @@ -6,9 +6,9 @@ package org.opensearch.reportsscheduler.model import org.apache.lucene.search.TotalHits -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_LIST_FIELD import org.opensearch.action.search.SearchResponse import org.opensearch.common.xcontent.XContentParser +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_LIST_FIELD /** * ReportDefinitions search results diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstance.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstance.kt index fbcb99ac..c08bd78d 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstance.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstance.kt @@ -5,6 +5,12 @@ package org.opensearch.reportsscheduler.model +import org.opensearch.common.xcontent.ToXContent +import org.opensearch.common.xcontent.ToXContentObject +import org.opensearch.common.xcontent.XContentBuilder +import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.common.xcontent.XContentParser +import org.opensearch.common.xcontent.XContentParserUtils import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX import org.opensearch.reportsscheduler.model.RestTag.ACCESS_LIST_FIELD import org.opensearch.reportsscheduler.model.RestTag.BEGIN_TIME_FIELD @@ -21,12 +27,6 @@ import org.opensearch.reportsscheduler.model.RestTag.UPDATED_TIME_FIELD import org.opensearch.reportsscheduler.security.UserAccessManager.DEFAULT_TENANT import org.opensearch.reportsscheduler.util.logger import org.opensearch.reportsscheduler.util.stringList -import org.opensearch.common.xcontent.ToXContent -import org.opensearch.common.xcontent.ToXContentObject -import org.opensearch.common.xcontent.XContentBuilder -import org.opensearch.common.xcontent.XContentFactory -import org.opensearch.common.xcontent.XContentParser -import org.opensearch.common.xcontent.XContentParserUtils import java.time.Instant /** @@ -114,7 +114,8 @@ internal data class ReportInstance( endTime ?: throw IllegalArgumentException("$END_TIME_FIELD field absent") tenant = tenant ?: DEFAULT_TENANT status ?: throw IllegalArgumentException("$STATUS_FIELD field absent") - return ReportInstance(id, + return ReportInstance( + id, updatedTime, createdTime, beginTime, @@ -124,7 +125,8 @@ internal data class ReportInstance( reportDefinitionDetails, status, statusText, - inContextDownloadUrlPath) + inContextDownloadUrlPath + ) } } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstanceSearchResults.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstanceSearchResults.kt index 298973c3..84274652 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstanceSearchResults.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportInstanceSearchResults.kt @@ -5,10 +5,10 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_LIST_FIELD import org.apache.lucene.search.TotalHits import org.opensearch.action.search.SearchResponse import org.opensearch.common.xcontent.XContentParser +import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_LIST_FIELD /** * ReportInstances search results diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/SearchResults.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/SearchResults.kt index 95a885b9..6e68a398 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/SearchResults.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/SearchResults.kt @@ -5,9 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.model.RestTag.REST_OUTPUT_PARAMS -import org.opensearch.reportsscheduler.util.logger import org.apache.lucene.search.TotalHits import org.apache.lucene.search.TotalHits.Relation import org.apache.lucene.search.TotalHits.Relation.EQUAL_TO @@ -21,6 +18,9 @@ import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParserUtils import org.opensearch.common.xcontent.XContentType +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.model.RestTag.REST_OUTPUT_PARAMS +import org.opensearch.reportsscheduler.util.logger internal abstract class SearchResults : ToXContentObject { val startIndex: Long @@ -68,9 +68,11 @@ internal abstract class SearchResults : ToXContent constructor(from: Long, response: SearchResponse, objectListFieldName: String) { val mutableList: MutableList = mutableListOf() response.hits.forEach { - val parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, + val parser = XContentType.JSON.xContent().createParser( + NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - it.sourceAsString) + it.sourceAsString + ) parser.nextToken() mutableList.add(parseItem(parser, it.id)) } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionRequest.kt index 450a2443..221f710f 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionRequest.kt @@ -5,12 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_FIELD -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD -import org.opensearch.reportsscheduler.util.createJsonParser -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -22,6 +16,12 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_FIELD +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD +import org.opensearch.reportsscheduler.util.createJsonParser +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionResponse.kt index 3a706f0e..529beeb4 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportDefinitionResponse.kt @@ -5,10 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -16,6 +12,10 @@ import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusRequest.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusRequest.kt index 29378c51..83053ff7 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusRequest.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusRequest.kt @@ -5,14 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.reportsscheduler.model.ReportInstance.Status -import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_ID_FIELD -import org.opensearch.reportsscheduler.model.RestTag.STATUS_FIELD -import org.opensearch.reportsscheduler.model.RestTag.STATUS_TEXT_FIELD -import org.opensearch.reportsscheduler.util.fieldIfNotNull -import org.opensearch.reportsscheduler.util.logger import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.common.io.stream.StreamInput @@ -24,6 +16,14 @@ import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.metrics.Metrics +import org.opensearch.reportsscheduler.model.ReportInstance.Status +import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_ID_FIELD +import org.opensearch.reportsscheduler.model.RestTag.STATUS_FIELD +import org.opensearch.reportsscheduler.model.RestTag.STATUS_TEXT_FIELD +import org.opensearch.reportsscheduler.util.fieldIfNotNull +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusResponse.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusResponse.kt index 266d6e69..229bad2c 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusResponse.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/UpdateReportInstanceStatusResponse.kt @@ -5,9 +5,6 @@ package org.opensearch.reportsscheduler.model -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX -import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_ID_FIELD -import org.opensearch.reportsscheduler.util.logger import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.xcontent.ToXContent @@ -15,6 +12,9 @@ import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX +import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_ID_FIELD +import org.opensearch.reportsscheduler.util.logger import java.io.IOException /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/OnDemandReportRestHandler.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/OnDemandReportRestHandler.kt index b9770fca..492aa346 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/OnDemandReportRestHandler.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/OnDemandReportRestHandler.kt @@ -4,6 +4,7 @@ */ package org.opensearch.reportsscheduler.resthandler +import org.opensearch.client.node.NodeClient import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.reportsscheduler.action.InContextReportCreateAction @@ -14,11 +15,10 @@ import org.opensearch.reportsscheduler.model.InContextReportCreateRequest import org.opensearch.reportsscheduler.model.OnDemandReportCreateRequest import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD import org.opensearch.reportsscheduler.util.contentParserNextToken -import org.opensearch.client.node.NodeClient import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse -import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestHandler.ReplacedRoute +import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.RestRequest.Method.PUT @@ -97,16 +97,22 @@ internal class OnDemandReportRestHandler : PluginBaseHandler() { PUT -> RestChannelConsumer { Metrics.REPORT_FROM_DEFINITION_TOTAL.counter.increment() Metrics.REPORT_FROM_DEFINITION_INTERVAL_COUNT.counter.increment() - client.execute(InContextReportCreateAction.ACTION_TYPE, + client.execute( + InContextReportCreateAction.ACTION_TYPE, InContextReportCreateRequest(request.contentParserNextToken()), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } POST -> RestChannelConsumer { Metrics.REPORT_FROM_DEFINITION_ID_TOTAL.counter.increment() Metrics.REPORT_FROM_DEFINITION_ID_INTERVAL_COUNT.counter.increment() - client.execute(OnDemandReportCreateAction.ACTION_TYPE, - OnDemandReportCreateRequest.parse(request.contentParserNextToken(), request.param(REPORT_DEFINITION_ID_FIELD)), - RestResponseToXContentListener(it)) + client.execute( + OnDemandReportCreateAction.ACTION_TYPE, + OnDemandReportCreateRequest.parse( + request.contentParserNextToken(), request.param(REPORT_DEFINITION_ID_FIELD) + ), + RestResponseToXContentListener(it) + ) } else -> RestChannelConsumer { it.sendResponse(BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "${request.method()} is not allowed")) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/PluginBaseHandler.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/PluginBaseHandler.kt index 9fbe64b6..a308c480 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/PluginBaseHandler.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/PluginBaseHandler.kt @@ -5,8 +5,8 @@ package org.opensearch.reportsscheduler.resthandler -import org.opensearch.reportsscheduler.metrics.Metrics import org.opensearch.client.node.NodeClient +import org.opensearch.reportsscheduler.metrics.Metrics import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestRequest diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionListRestHandler.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionListRestHandler.kt index 0b159911..3ea8fcd4 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionListRestHandler.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionListRestHandler.kt @@ -4,6 +4,7 @@ */ package org.opensearch.reportsscheduler.resthandler +import org.opensearch.client.node.NodeClient import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.reportsscheduler.action.GetAllReportDefinitionsAction @@ -13,12 +14,10 @@ import org.opensearch.reportsscheduler.model.GetAllReportDefinitionsRequest import org.opensearch.reportsscheduler.model.RestTag.FROM_INDEX_FIELD import org.opensearch.reportsscheduler.model.RestTag.MAX_ITEMS_FIELD import org.opensearch.reportsscheduler.settings.PluginSettings - -import org.opensearch.client.node.NodeClient import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse -import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestHandler.ReplacedRoute +import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.RestStatus @@ -78,9 +77,11 @@ internal class ReportDefinitionListRestHandler : PluginBaseHandler() { GET -> RestChannelConsumer { Metrics.REPORT_DEFINITION_LIST_TOTAL.counter.increment() Metrics.REPORT_DEFINITION_LIST_INTERVAL_COUNT.counter.increment() - client.execute(GetAllReportDefinitionsAction.ACTION_TYPE, + client.execute( + GetAllReportDefinitionsAction.ACTION_TYPE, GetAllReportDefinitionsRequest(from, maxItems), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } else -> RestChannelConsumer { it.sendResponse(BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "${request.method()} is not allowed")) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionRestHandler.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionRestHandler.kt index 9a89dd54..0a8c9221 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionRestHandler.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportDefinitionRestHandler.kt @@ -4,6 +4,7 @@ */ package org.opensearch.reportsscheduler.resthandler +import org.opensearch.client.node.NodeClient import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.reportsscheduler.action.CreateReportDefinitionAction @@ -18,11 +19,10 @@ import org.opensearch.reportsscheduler.model.GetReportDefinitionRequest import org.opensearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_ID_FIELD import org.opensearch.reportsscheduler.model.UpdateReportDefinitionRequest import org.opensearch.reportsscheduler.util.contentParserNextToken -import org.opensearch.client.node.NodeClient import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse -import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestHandler.ReplacedRoute +import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.DELETE import org.opensearch.rest.RestRequest.Method.GET @@ -126,9 +126,11 @@ internal class ReportDefinitionRestHandler : PluginBaseHandler() { POST -> RestChannelConsumer { Metrics.REPORT_DEFINITION_CREATE_TOTAL.counter.increment() Metrics.REPORT_DEFINITION_CREATE_INTERVAL_COUNT.counter.increment() - client.execute(CreateReportDefinitionAction.ACTION_TYPE, + client.execute( + CreateReportDefinitionAction.ACTION_TYPE, CreateReportDefinitionRequest(request.contentParserNextToken()), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } PUT -> RestChannelConsumer { Metrics.REPORT_DEFINITION_UPDATE_TOTAL.counter.increment() @@ -136,21 +138,26 @@ internal class ReportDefinitionRestHandler : PluginBaseHandler() { client.execute( UpdateReportDefinitionAction.ACTION_TYPE, UpdateReportDefinitionRequest(request.contentParserNextToken(), request.param(REPORT_DEFINITION_ID_FIELD)), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } GET -> RestChannelConsumer { Metrics.REPORT_DEFINITION_INFO_TOTAL.counter.increment() Metrics.REPORT_DEFINITION_INFO_INTERVAL_COUNT.counter.increment() - client.execute(GetReportDefinitionAction.ACTION_TYPE, + client.execute( + GetReportDefinitionAction.ACTION_TYPE, GetReportDefinitionRequest(request.param(REPORT_DEFINITION_ID_FIELD)), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } DELETE -> RestChannelConsumer { Metrics.REPORT_DEFINITION_DELETE_TOTAL.counter.increment() Metrics.REPORT_DEFINITION_DELETE_INTERVAL_COUNT.counter.increment() - client.execute(DeleteReportDefinitionAction.ACTION_TYPE, + client.execute( + DeleteReportDefinitionAction.ACTION_TYPE, DeleteReportDefinitionRequest(request.param(REPORT_DEFINITION_ID_FIELD)), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } else -> RestChannelConsumer { it.sendResponse(BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "${request.method()} is not allowed")) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceListRestHandler.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceListRestHandler.kt index 56cb779e..a3eaef1a 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceListRestHandler.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceListRestHandler.kt @@ -4,6 +4,7 @@ */ package org.opensearch.reportsscheduler.resthandler +import org.opensearch.client.node.NodeClient import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.reportsscheduler.action.GetAllReportInstancesAction @@ -13,11 +14,10 @@ import org.opensearch.reportsscheduler.model.GetAllReportInstancesRequest import org.opensearch.reportsscheduler.model.RestTag.FROM_INDEX_FIELD import org.opensearch.reportsscheduler.model.RestTag.MAX_ITEMS_FIELD import org.opensearch.reportsscheduler.settings.PluginSettings -import org.opensearch.client.node.NodeClient import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse -import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestHandler.ReplacedRoute +import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.RestStatus @@ -84,9 +84,11 @@ internal class ReportInstanceListRestHandler : PluginBaseHandler() { GET -> RestChannelConsumer { Metrics.REPORT_INSTANCE_LIST_TOTAL.counter.increment() Metrics.REPORT_INSTANCE_LIST_INTERVAL_COUNT.counter.increment() - client.execute(GetAllReportInstancesAction.ACTION_TYPE, + client.execute( + GetAllReportInstancesAction.ACTION_TYPE, GetAllReportInstancesRequest(from, maxItems), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } else -> RestChannelConsumer { it.sendResponse(BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "${request.method()} is not allowed")) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceRestHandler.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceRestHandler.kt index f09da177..5f3a6d99 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceRestHandler.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportInstanceRestHandler.kt @@ -4,6 +4,7 @@ */ package org.opensearch.reportsscheduler.resthandler +import org.opensearch.client.node.NodeClient import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.reportsscheduler.action.GetReportInstanceAction @@ -14,11 +15,10 @@ import org.opensearch.reportsscheduler.model.GetReportInstanceRequest import org.opensearch.reportsscheduler.model.RestTag.REPORT_INSTANCE_ID_FIELD import org.opensearch.reportsscheduler.model.UpdateReportInstanceStatusRequest import org.opensearch.reportsscheduler.util.contentParserNextToken -import org.opensearch.client.node.NodeClient import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse -import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestHandler.ReplacedRoute +import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.RestRequest.Method.POST @@ -97,16 +97,20 @@ internal class ReportInstanceRestHandler : PluginBaseHandler() { POST -> RestChannelConsumer { Metrics.REPORT_INSTANCE_UPDATE_TOTAL.counter.increment() Metrics.REPORT_INSTANCE_UPDATE_INTERVAL_COUNT.counter.increment() - client.execute(UpdateReportInstanceStatusAction.ACTION_TYPE, + client.execute( + UpdateReportInstanceStatusAction.ACTION_TYPE, UpdateReportInstanceStatusRequest.parse(request.contentParserNextToken(), reportInstanceId), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } GET -> RestChannelConsumer { Metrics.REPORT_INSTANCE_INFO_TOTAL.counter.increment() Metrics.REPORT_INSTANCE_INFO_INTERVAL_COUNT.counter.increment() - client.execute(GetReportInstanceAction.ACTION_TYPE, + client.execute( + GetReportInstanceAction.ACTION_TYPE, GetReportInstanceRequest(reportInstanceId), - RestResponseToXContentListener(it)) + RestResponseToXContentListener(it) + ) } else -> RestChannelConsumer { it.sendResponse(BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "${request.method()} is not allowed")) diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportStatsRestHandler.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportStatsRestHandler.kt index ee7ea93b..1900c7b6 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportStatsRestHandler.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/ReportStatsRestHandler.kt @@ -4,15 +4,15 @@ */ package org.opensearch.reportsscheduler.resthandler +import org.opensearch.client.node.NodeClient import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.reportsscheduler.metrics.Metrics -import org.opensearch.client.node.NodeClient import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse -import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestHandler.ReplacedRoute +import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.RestStatus diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/RestResponseToXContentListener.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/RestResponseToXContentListener.kt index ec36afb7..cb770da3 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/RestResponseToXContentListener.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/resthandler/RestResponseToXContentListener.kt @@ -5,9 +5,9 @@ package org.opensearch.reportsscheduler.resthandler +import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.reportsscheduler.metrics.Metrics import org.opensearch.reportsscheduler.model.BaseResponse -import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.rest.BytesRestResponse import org.opensearch.rest.RestChannel import org.opensearch.rest.RestResponse diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobParser.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobParser.kt index 4393b467..cb4b57db 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobParser.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobParser.kt @@ -5,11 +5,11 @@ package org.opensearch.reportsscheduler.scheduler +import org.opensearch.common.xcontent.XContentParser import org.opensearch.jobscheduler.spi.JobDocVersion import org.opensearch.jobscheduler.spi.ScheduledJobParameter import org.opensearch.jobscheduler.spi.ScheduledJobParser import org.opensearch.reportsscheduler.model.ReportDefinitionDetails -import org.opensearch.common.xcontent.XContentParser internal object ReportDefinitionJobParser : ScheduledJobParser { /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobRunner.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobRunner.kt index 96e12908..35af1b78 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobRunner.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/scheduler/ReportDefinitionJobRunner.kt @@ -32,7 +32,8 @@ internal object ReportDefinitionJobRunner : ScheduledJobRunner { val currentTime = Instant.now() val endTime = context.expectedExecutionTime val beginTime = endTime.minus(reportDefinitionDetails.reportDefinition.format.duration) - val reportInstance = ReportInstance(context.jobId, + val reportInstance = ReportInstance( + context.jobId, currentTime, currentTime, beginTime, @@ -40,7 +41,8 @@ internal object ReportDefinitionJobRunner : ScheduledJobRunner { job.tenant, job.access, reportDefinitionDetails, - ReportInstance.Status.Success) // TODO: Revert to Scheduled when background job execution supported + ReportInstance.Status.Success + ) // TODO: Revert to Scheduled when background job execution supported val id = ReportInstancesIndex.createReportInstance(reportInstance) if (id == null) { log.warn("$LOG_PREFIX:runJob-job creation failed for $reportInstance") diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/UserAccessManager.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/UserAccessManager.kt index 6168cd0b..a7ee17c9 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/UserAccessManager.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/UserAccessManager.kt @@ -5,10 +5,10 @@ package org.opensearch.reportsscheduler.security +import org.opensearch.OpenSearchStatusException import org.opensearch.commons.authuser.User import org.opensearch.reportsscheduler.metrics.Metrics import org.opensearch.reportsscheduler.settings.PluginSettings -import org.opensearch.OpenSearchStatusException import org.opensearch.rest.RestStatus /** diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt index 45e061cb..1521c0a9 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt @@ -156,7 +156,8 @@ internal object PluginSettings { * @return list of settings defined in this plugin */ fun getAllSettings(): List> { - return listOf(OPERATION_TIMEOUT_MS, + return listOf( + OPERATION_TIMEOUT_MS, DEFAULT_ITEMS_QUERY_COUNT ) } diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/IntegTestHelpers.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/IntegTestHelpers.kt index 49a98429..423db1c0 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/IntegTestHelpers.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/IntegTestHelpers.kt @@ -18,7 +18,8 @@ fun constructReportDefinitionRequest( "trigger":{ "triggerType":"OnDemand" }, - """.trimIndent(), + """ + .trimIndent(), name: String = "report_definition", delivery: String = "" ): String { @@ -44,7 +45,8 @@ fun constructReportDefinitionRequest( } } } - """.trimIndent() + """ + .trimIndent() } fun jsonify(text: String): JsonObject { diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/ReportsSchedulerPluginIT.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/ReportsSchedulerPluginIT.kt index d35b167a..e8931189 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/ReportsSchedulerPluginIT.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/ReportsSchedulerPluginIT.kt @@ -25,9 +25,11 @@ class ReportsSchedulerPluginIT : OpenSearchIntegTestCase() { val pluginInfos = nodesInfoResponse.nodes[0].getInfo(PluginsAndModules::class.java).pluginInfos assertTrue( pluginInfos.stream() - .anyMatch { pluginInfo: PluginInfo -> pluginInfo.name == "opensearch-job-scheduler" }) + .anyMatch { pluginInfo: PluginInfo -> pluginInfo.name == "opensearch-job-scheduler" } + ) assertTrue( pluginInfos.stream() - .anyMatch { pluginInfo: PluginInfo -> pluginInfo.name == "opensearch-reports-scheduler" }) + .anyMatch { pluginInfo: PluginInfo -> pluginInfo.name == "opensearch-reports-scheduler" } + ) } } diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/bwc/ReportsSchedulerBackwardsCompatibilityIT.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/bwc/ReportsSchedulerBackwardsCompatibilityIT.kt index c37a396f..e1eb7550 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/bwc/ReportsSchedulerBackwardsCompatibilityIT.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/bwc/ReportsSchedulerBackwardsCompatibilityIT.kt @@ -8,9 +8,9 @@ package org.opensearch.integTest.bwc import org.junit.Assert import org.opensearch.common.settings.Settings import org.opensearch.integTest.PluginRestTestCase +import org.opensearch.integTest.constructReportDefinitionRequest import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI -import org.opensearch.integTest.constructReportDefinitionRequest import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus import java.time.Instant diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/InContextMenuReportGenerationIT.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/InContextMenuReportGenerationIT.kt index 4b445510..07e8c243 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/InContextMenuReportGenerationIT.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/InContextMenuReportGenerationIT.kt @@ -5,15 +5,15 @@ package org.opensearch.integTest.rest +import org.junit.Assert import org.opensearch.integTest.PluginRestTestCase -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.integTest.jsonify import org.opensearch.integTest.validateErrorResponse import org.opensearch.integTest.validateTimeRecency +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus -import org.junit.Assert import java.time.Instant class InContextMenuReportGenerationIT : PluginRestTestCase() { diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/OnDemandReportGenerationIT.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/OnDemandReportGenerationIT.kt index 62709cd9..399d144e 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/OnDemandReportGenerationIT.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/OnDemandReportGenerationIT.kt @@ -5,16 +5,16 @@ package org.opensearch.integTest.rest +import org.junit.Assert import org.opensearch.integTest.PluginRestTestCase -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.integTest.jsonify import org.opensearch.integTest.validateErrorResponse import org.opensearch.integTest.validateTimeNearRefTime import org.opensearch.integTest.validateTimeRecency +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus -import org.junit.Assert import java.time.Duration import java.time.Instant diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportDefinitionIT.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportDefinitionIT.kt index 398c66b6..15385396 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportDefinitionIT.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportDefinitionIT.kt @@ -5,14 +5,14 @@ package org.opensearch.integTest.rest +import org.junit.Assert import org.opensearch.integTest.PluginRestTestCase -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.integTest.constructReportDefinitionRequest import org.opensearch.integTest.validateErrorResponse +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus -import org.junit.Assert class ReportDefinitionIT : PluginRestTestCase() { fun `test create, get, update, delete report definition`() { diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportInstanceIT.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportInstanceIT.kt index cb2160b7..926cd8ff 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportInstanceIT.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/rest/ReportInstanceIT.kt @@ -5,14 +5,14 @@ package org.opensearch.integTest.rest +import org.junit.Assert import org.opensearch.integTest.PluginRestTestCase -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI -import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.integTest.constructReportDefinitionRequest import org.opensearch.integTest.validateErrorResponse +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.BASE_REPORTS_URI +import org.opensearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LEGACY_BASE_REPORTS_URI import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus -import org.junit.Assert class ReportInstanceIT : PluginRestTestCase() { fun `test update on-demand report definition status to success after creation`() { diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequestTests.kt b/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequestTests.kt index 83120dab..2239c294 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequestTests.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionRequestTests.kt @@ -6,7 +6,7 @@ package org.opensearch.reportsscheduler.model import com.fasterxml.jackson.core.JsonParseException -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.opensearch.reportsscheduler.createObjectFromJsonString diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponseTests.kt b/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponseTests.kt index 7ea878b8..96f5a7f0 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponseTests.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/model/DeleteReportDefinitionResponseTests.kt @@ -6,7 +6,7 @@ package org.opensearch.reportsscheduler.model import com.fasterxml.jackson.core.JsonParseException -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.opensearch.commons.utils.recreateObject diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/util/HelpersTests.kt b/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/util/HelpersTests.kt index e34a3fac..dc78bfa8 100644 --- a/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/util/HelpersTests.kt +++ b/reports-scheduler/src/test/kotlin/org/opensearch/reportsscheduler/util/HelpersTests.kt @@ -5,8 +5,8 @@ package org.opensearch.reportsscheduler.util -import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test internal class HelpersTests { private val sampleOrigin = "https://localhost:5601/base/path"