From b967abc382b0f7efab0fb42920d9b2e402c567b9 Mon Sep 17 00:00:00 2001 From: Rohit Ashiwal Date: Fri, 9 Feb 2024 01:34:49 +0530 Subject: [PATCH] lint: add rules and apply formatting Signed-off-by: Rohit Ashiwal --- .editorconfig | 13 +- detekt.yml | 3 +- .../indexstatemanagement/Action.kt | 2 +- .../indexstatemanagement/StatusChecker.kt | 3 +- .../indexstatemanagement/Step.kt | 3 +- .../indexstatemanagement/Validate.kt | 7 +- .../model/ActionMetaData.kt | 10 +- .../model/ActionProperties.kt | 4 +- .../indexstatemanagement/model/ActionRetry.kt | 21 +- .../model/ActionTimeout.kt | 4 +- .../model/ManagedIndexMetaData.kt | 16 +- .../model/PolicyRetryInfoMetaData.kt | 10 +- .../model/ShrinkActionProperties.kt | 8 +- .../model/StateMetaData.kt | 10 +- .../indexstatemanagement/model/StepContext.kt | 2 +- .../model/StepMetaData.kt | 10 +- .../model/TransformActionProperties.kt | 6 +- .../model/ValidationResult.kt | 10 +- .../indexmanagement/IndexManagementIndices.kt | 16 +- .../indexmanagement/IndexManagementPlugin.kt | 42 +-- .../common/model/dimension/DateHistogram.kt | 8 +- .../common/model/dimension/Dimension.kt | 5 +- .../common/model/dimension/Histogram.kt | 9 +- .../common/model/dimension/Terms.kt | 10 +- .../common/model/notification/Channel.kt | 18 +- .../model/notification/NotificationUtils.kt | 3 +- .../common/model/rest/SearchParams.kt | 4 +- .../notification/ControlCenterIndices.kt | 14 +- .../notification/LRONConfigResponse.kt | 4 +- .../action/delete/DeleteLRONConfigRequest.kt | 6 +- .../delete/TransportDeleteLRONConfigAction.kt | 16 +- .../action/get/GetLRONConfigRequest.kt | 10 +- .../get/TransportGetLRONConfigAction.kt | 20 +- .../action/index/IndexLRONConfigRequest.kt | 4 +- .../index/TransportIndexLRONConfigAction.kt | 22 +- .../filter/IndexOperationActionFilter.kt | 10 +- .../filter/NotificationActionListener.kt | 50 ++-- .../notification/filter/OperationResult.kt | 5 +- .../parser/ForceMergeIndexRespParser.kt | 24 +- .../filter/parser/OpenIndexRespParser.kt | 39 +-- .../filter/parser/ReindexRespParser.kt | 30 +-- .../filter/parser/ResizeIndexRespParser.kt | 34 +-- .../filter/parser/ResponseParser.kt | 18 +- .../notification/model/LRONCondition.kt | 8 +- .../notification/model/LRONConfig.kt | 30 ++- .../resthandler/RestDeleteLRONConfigAction.kt | 2 +- .../resthandler/RestGetLRONConfigAction.kt | 6 +- .../resthandler/RestIndexLRONConfigAction.kt | 4 +- .../notification/util/LRONUtils.kt | 21 +- .../ISMTemplateService.kt | 6 +- .../IndexMetadataProvider.kt | 2 +- .../IndexStateManagementHistory.kt | 29 ++- .../ManagedIndexCoordinator.kt | 61 +++-- .../ManagedIndexRunner.kt | 94 +++---- .../indexstatemanagement/MetadataService.kt | 34 ++- .../indexstatemanagement/SkipExecution.kt | 14 +- .../action/AliasAction.kt | 6 +- .../action/AllocationAction.kt | 2 +- .../action/CloseAction.kt | 2 +- .../action/DeleteAction.kt | 2 +- .../action/ForceMergeAction.kt | 4 +- .../action/ForceMergeActionParser.kt | 2 +- .../action/IndexPriorityAction.kt | 2 +- .../action/IndexPriorityActionParser.kt | 2 +- .../action/NotificationAction.kt | 2 +- .../action/NotificationActionParser.kt | 4 +- .../indexstatemanagement/action/OpenAction.kt | 2 +- .../action/ReadOnlyAction.kt | 2 +- .../action/ReadWriteAction.kt | 2 +- .../action/ReplicaCountAction.kt | 2 +- .../action/ReplicaCountActionParser.kt | 2 +- .../action/RolloverAction.kt | 10 +- .../action/RolloverActionParser.kt | 4 +- .../action/RollupAction.kt | 2 +- .../action/ShrinkAction.kt | 8 +- .../action/SnapshotAction.kt | 2 +- .../action/SnapshotActionParser.kt | 2 +- .../action/TransformAction.kt | 2 +- .../action/TransitionsAction.kt | 2 +- .../migration/MigrationServices.kt | 21 +- .../model/ChangePolicy.kt | 10 +- .../model/ErrorNotification.kt | 6 +- .../model/ExplainFilter.kt | 4 +- .../indexstatemanagement/model/ISMTemplate.kt | 6 +- .../model/ManagedIndexConfig.kt | 8 +- .../indexstatemanagement/model/Policy.kt | 16 +- .../indexstatemanagement/model/State.kt | 8 +- .../indexstatemanagement/model/StateFilter.kt | 2 +- .../indexstatemanagement/model/Transition.kt | 12 +- .../ClusterStateManagedIndexConfig.kt | 2 +- .../coordinator/SweptManagedIndexConfig.kt | 4 +- .../model/destination/Chime.kt | 2 +- .../model/destination/CustomWebhook.kt | 4 +- .../model/destination/Destination.kt | 14 +- .../model/destination/Slack.kt | 2 +- .../opensearchapi/OpenSearchExtensions.kt | 10 +- .../resthandler/RestAddPolicyAction.kt | 8 +- .../resthandler/RestChangePolicyAction.kt | 6 +- .../resthandler/RestDeletePolicyAction.kt | 4 +- .../resthandler/RestExplainAction.kt | 20 +- .../resthandler/RestGetPolicyAction.kt | 8 +- .../resthandler/RestIndexPolicyAction.kt | 16 +- .../resthandler/RestRemovePolicyAction.kt | 6 +- .../RestRetryFailedManagedIndexAction.kt | 12 +- .../LegacyOpenDistroManagedIndexSettings.kt | 44 ++-- .../settings/ManagedIndexSettings.kt | 50 ++-- .../step/alias/AttemptAliasActionsStep.kt | 6 +- .../step/allocation/AttemptAllocationStep.kt | 2 +- .../step/close/AttemptCloseStep.kt | 2 +- .../step/delete/AttemptDeleteStep.kt | 2 +- .../forcemerge/AttemptCallForceMergeStep.kt | 7 +- .../step/forcemerge/AttemptSetReadOnlyStep.kt | 2 +- .../step/forcemerge/WaitForForceMergeStep.kt | 19 +- .../AttemptSetIndexPriorityStep.kt | 2 +- .../notification/AttemptNotificationStep.kt | 2 +- .../step/open/AttemptOpenStep.kt | 2 +- .../step/readonly/SetReadOnlyStep.kt | 2 +- .../step/readwrite/SetReadWriteStep.kt | 4 +- .../replicacount/AttemptReplicaCountStep.kt | 2 +- .../step/rollover/AttemptRolloverStep.kt | 36 +-- .../step/rollup/AttemptCreateRollupJobStep.kt | 2 +- .../rollup/WaitForRollupCompletionStep.kt | 6 +- .../step/shrink/AttemptMoveShardsStep.kt | 40 +-- .../step/shrink/AttemptShrinkStep.kt | 8 +- .../step/shrink/ShrinkStep.kt | 8 +- .../step/shrink/WaitForMoveShardsStep.kt | 10 +- .../step/shrink/WaitForShrinkStep.kt | 9 +- .../step/snapshot/AttemptSnapshotStep.kt | 8 +- .../step/snapshot/WaitForSnapshotStep.kt | 2 +- .../AttemptCreateTransformJobStep.kt | 4 +- .../WaitForTransformCompletionStep.kt | 2 +- .../step/transition/AttemptTransitionStep.kt | 10 +- .../transport/action/ISMStatusResponse.kt | 4 +- .../action/addpolicy/AddPolicyRequest.kt | 6 +- .../addpolicy/TransportAddPolicyAction.kt | 38 +-- .../changepolicy/ChangePolicyRequest.kt | 6 +- .../TransportChangePolicyAction.kt | 58 ++--- .../deletepolicy/DeletePolicyRequest.kt | 4 +- .../TransportDeletePolicyAction.kt | 18 +- .../action/explain/ExplainRequest.kt | 8 +- .../action/explain/ExplainResponse.kt | 8 +- .../action/explain/TransportExplainAction.kt | 45 ++-- .../action/getpolicy/GetPoliciesRequest.kt | 4 +- .../action/getpolicy/GetPoliciesResponse.kt | 4 +- .../action/getpolicy/GetPolicyRequest.kt | 6 +- .../action/getpolicy/GetPolicyResponse.kt | 4 +- .../getpolicy/TransportGetPoliciesAction.kt | 18 +- .../getpolicy/TransportGetPolicyAction.kt | 18 +- .../action/indexpolicy/IndexPolicyRequest.kt | 4 +- .../action/indexpolicy/IndexPolicyResponse.kt | 6 +- .../indexpolicy/TransportIndexPolicyAction.kt | 46 ++-- .../TransportManagedIndexAction.kt | 4 +- .../removepolicy/RemovePolicyRequest.kt | 6 +- .../TransportRemovePolicyAction.kt | 74 +++--- .../RetryFailedManagedIndexRequest.kt | 8 +- .../TransportRetryFailedManagedIndexAction.kt | 40 +-- ...ansportUpdateManagedIndexMetaDataAction.kt | 14 +- .../UpdateManagedIndexMetaDataRequest.kt | 4 +- .../util/DestinationType.kt | 2 +- .../util/ManagedIndexUtils.kt | 45 ++-- .../util/NotificationUtils.kt | 7 +- .../util/RestHandlerUtils.kt | 13 +- .../indexstatemanagement/util/StepUtils.kt | 30 ++- .../validation/ActionValidation.kt | 4 +- .../validation/ValidateClose.kt | 2 +- .../validation/ValidateDelete.kt | 2 +- .../validation/ValidateForceMerge.kt | 4 +- .../validation/ValidateIndexPriority.kt | 4 +- .../validation/ValidateNothing.kt | 4 +- .../validation/ValidateOpen.kt | 2 +- .../validation/ValidateReadOnly.kt | 2 +- .../validation/ValidateReadWrite.kt | 2 +- .../validation/ValidateReplicaCount.kt | 2 +- .../validation/ValidateRollover.kt | 4 +- .../validation/ValidateSnapshot.kt | 2 +- .../validation/ValidateTransition.kt | 2 +- .../opensearchapi/OpenSearchExtensions.kt | 48 ++-- .../RefreshSearchAnalyzerResponse.kt | 10 +- .../RestRefreshSearchAnalyzerAction.kt | 6 +- .../TransportRefreshSearchAnalyzerAction.kt | 16 +- .../indexmanagement/rollup/RollupIndexer.kt | 6 +- .../rollup/RollupMapperService.kt | 12 +- .../rollup/RollupMetadataService.kt | 44 ++-- .../indexmanagement/rollup/RollupRunner.kt | 32 +-- .../rollup/RollupSearchService.kt | 18 +- .../delete/TransportDeleteRollupAction.kt | 18 +- .../action/explain/ExplainRollupResponse.kt | 2 +- .../explain/TransportExplainRollupAction.kt | 17 +- .../rollup/action/get/GetRollupRequest.kt | 4 +- .../rollup/action/get/GetRollupResponse.kt | 6 +- .../rollup/action/get/GetRollupsRequest.kt | 4 +- .../rollup/action/get/GetRollupsResponse.kt | 6 +- .../action/get/TransportGetRollupAction.kt | 16 +- .../action/get/TransportGetRollupsAction.kt | 20 +- .../rollup/action/index/IndexRollupRequest.kt | 2 +- .../action/index/IndexRollupResponse.kt | 6 +- .../index/TransportIndexRollupAction.kt | 32 +-- .../TransportUpdateRollupMappingAction.kt | 22 +- .../start/TransportStartRollupAction.kt | 36 +-- .../action/stop/TransportStopRollupAction.kt | 45 ++-- .../rollup/actionfilter/FieldCapsFilter.kt | 22 +- .../rollup/actionfilter/SerDeHelper.kt | 22 +- .../rollup/interceptor/RollupInterceptor.kt | 42 +-- .../rollup/model/ExplainRollup.kt | 4 +- .../indexmanagement/rollup/model/ISMRollup.kt | 18 +- .../indexmanagement/rollup/model/Rollup.kt | 26 +- .../rollup/model/RollupFieldMapping.kt | 14 +- .../rollup/model/RollupMetadata.kt | 31 +-- .../rollup/model/RollupMetrics.kt | 8 +- .../rollup/model/metric/Metric.kt | 3 +- .../rollup/query/QueryStringQueryParserExt.kt | 7 +- .../rollup/query/QueryStringQueryUtil.kt | 20 +- .../resthandler/RestDeleteRollupAction.kt | 4 +- .../resthandler/RestExplainRollupAction.kt | 4 +- .../rollup/resthandler/RestGetRollupAction.kt | 10 +- .../resthandler/RestIndexRollupAction.kt | 11 +- .../resthandler/RestStartRollupAction.kt | 4 +- .../resthandler/RestStopRollupAction.kt | 4 +- .../LegacyOpenDistroRollupSettings.kt | 16 +- .../rollup/settings/RollupSettings.kt | 18 +- .../rollup/util/QueryShardContextFactory.kt | 12 +- .../rollup/util/RollupUtils.kt | 50 ++-- .../settings/IndexManagementSettings.kt | 2 +- .../snapshotmanagement/SMRunner.kt | 28 +- .../snapshotmanagement/SMUtils.kt | 19 +- .../RestBaseIndexSMPolicyHandler.kt | 4 +- .../resthandler/RestCreateSMPolicyHandler.kt | 2 +- .../resthandler/RestDeleteSMPolicyHandler.kt | 4 +- .../resthandler/RestExplainSMPolicyHandler.kt | 4 +- .../api/resthandler/RestGetSMPolicyHandler.kt | 4 +- .../resthandler/RestStartSMPolicyHandler.kt | 4 +- .../resthandler/RestStopSMPolicyHandler.kt | 4 +- .../resthandler/RestUpdateSMPolicyHandler.kt | 2 +- .../api/transport/BaseTransportAction.kt | 14 +- .../api/transport/SMActions.kt | 4 +- .../delete/TransportDeleteSMPolicyAction.kt | 6 +- .../explain/ExplainSMPolicyRequest.kt | 2 +- .../explain/ExplainSMPolicyResponse.kt | 2 +- .../explain/TransportExplainSMAction.kt | 10 +- .../api/transport/get/GetSMPoliciesRequest.kt | 2 +- .../transport/get/GetSMPoliciesResponse.kt | 4 +- .../api/transport/get/GetSMPolicyRequest.kt | 2 +- .../api/transport/get/GetSMPolicyResponse.kt | 4 +- .../get/TransportGetSMPoliciesAction.kt | 10 +- .../get/TransportGetSMPolicyAction.kt | 6 +- .../transport/index/IndexSMPolicyRequest.kt | 2 +- .../transport/index/IndexSMPolicyResponse.kt | 6 +- .../index/TransportIndexSMPolicyAction.kt | 6 +- .../transport/start/TransportStartSMAction.kt | 12 +- .../transport/stop/TransportStopSMAction.kt | 12 +- .../engine/SMStateMachine.kt | 34 +-- .../engine/states/SMState.kt | 4 +- .../engine/states/creation/CreatingState.kt | 6 +- .../creation/CreationConditionMetState.kt | 2 +- .../states/creation/CreationFinishedState.kt | 4 +- .../engine/states/deletion/DeletingState.kt | 9 +- .../deletion/DeletionConditionMetState.kt | 4 +- .../states/deletion/DeletionFinishedState.kt | 5 +- .../model/ExplainSMPolicy.kt | 4 +- .../model/NotificationConfig.kt | 14 +- .../snapshotmanagement/model/SMMetadata.kt | 68 ++--- .../snapshotmanagement/model/SMPolicy.kt | 18 +- .../settings/SnapshotManagementSettings.kt | 2 +- .../util/RestHandlerUtils.kt | 1 + .../transform/TargetIndexMappingService.kt | 5 +- .../transform/TransformIndexer.kt | 8 +- .../transform/TransformMetadataService.kt | 6 +- .../transform/TransformProcessedBucketLog.kt | 7 +- .../transform/TransformRunner.kt | 51 ++-- .../transform/TransformSearchService.kt | 37 +-- .../transform/TransformValidator.kt | 4 +- .../action/delete/DeleteTransformsRequest.kt | 4 +- .../delete/TransportDeleteTransformsAction.kt | 37 +-- .../explain/ExplainTransformResponse.kt | 6 +- .../TransportExplainTransformAction.kt | 26 +- .../action/get/GetTransformRequest.kt | 4 +- .../action/get/GetTransformResponse.kt | 6 +- .../action/get/GetTransformsRequest.kt | 4 +- .../action/get/GetTransformsResponse.kt | 6 +- .../action/get/TransportGetTransformAction.kt | 20 +- .../get/TransportGetTransformsAction.kt | 22 +- .../action/index/IndexTransformRequest.kt | 2 +- .../action/index/IndexTransformResponse.kt | 6 +- .../index/TransportIndexTransformAction.kt | 30 +-- .../action/preview/PreviewTransformRequest.kt | 4 +- .../preview/PreviewTransformResponse.kt | 6 +- .../TransportPreviewTransformAction.kt | 22 +- .../start/TransportStartTransformAction.kt | 42 +-- .../stop/TransportStopTransformAction.kt | 40 +-- .../model/ContinuousTransformStats.kt | 4 +- .../transform/model/ExplainTransform.kt | 4 +- .../transform/model/ISMTransform.kt | 12 +- .../transform/model/Transform.kt | 44 ++-- .../transform/model/TransformMetadata.kt | 15 +- .../transform/model/TransformSearchResult.kt | 6 +- .../transform/model/TransformStats.kt | 6 +- .../opensearchapi/OpenSearchExtensions.kt | 6 +- .../resthandler/RestDeleteTransformAction.kt | 2 +- .../resthandler/RestGetTransformAction.kt | 4 +- .../resthandler/RestIndexTransformAction.kt | 7 +- .../resthandler/RestPreviewTransformAction.kt | 2 +- .../resthandler/RestStartTransformAction.kt | 2 +- .../resthandler/RestStopTransformAction.kt | 2 +- .../transform/settings/TransformSettings.kt | 12 +- .../transform/util/TransformLockManager.kt | 5 +- .../util/IndexManagementException.kt | 5 +- .../indexmanagement/util/IndexUtils.kt | 16 +- .../indexmanagement/util/RestHandlerUtils.kt | 1 + .../indexmanagement/util/ScheduledJobUtils.kt | 24 +- .../indexmanagement/util/SecurityUtils.kt | 38 +-- .../opensearch/indexmanagement/AccessRoles.kt | 5 + .../IndexManagementIndicesIT.kt | 44 ++-- .../IndexManagementRestTestCase.kt | 43 ++-- .../IndexManagementSettingsTests.kt | 20 +- .../IndexStateManagementSecurityBehaviorIT.kt | 26 +- .../indexmanagement/MocksTestCase.kt | 37 ++- .../PolicySecurityBehaviorIT.kt | 10 +- .../RollupSecurityBehaviorIT.kt | 12 +- .../indexmanagement/SecurityBehaviorIT.kt | 12 +- .../indexmanagement/SecurityRestTestCase.kt | 33 ++- .../opensearch/indexmanagement/TestHelpers.kt | 6 +- .../TransformSecurityBehaviorIT.kt | 10 +- .../bwc/ISMBackwardsCompatibilityIT.kt | 9 +- ...IndexManagementBackwardsCompatibilityIT.kt | 13 +- .../LRONConfigSecurityBehaviorIT.kt | 8 +- .../notification/SerializationTests.kt | 14 +- .../controlcenter/notification/TestHelpers.kt | 25 +- .../notification/XContentTests.kt | 30 +-- .../filter/IndexOperationActionFilterTests.kt | 14 +- .../filter/NotificationActionListenerIT.kt | 68 ++--- .../filter/NotificationActionListenerTests.kt | 12 +- .../parser/ForceMergeIndexRespParserTests.kt | 20 +- .../filter/parser/ReindexRespParserTests.kt | 24 +- .../parser/ResizeIndexRespParserTests.kt | 10 +- .../resthandler/LRONConfigRestTestCase.kt | 4 +- .../RestDeleteLRONConfigActionIT.kt | 2 +- .../resthandler/RestGetLRONConfigActionIT.kt | 8 +- .../RestIndexLRONConfigActionIT.kt | 26 +- .../notification/util/LRONUtilsTests.kt | 2 +- .../IndexMetadataProviderTests.kt | 4 +- .../IndexStateManagementIntegTestCase.kt | 63 ++--- .../IndexStateManagementRestTestCase.kt | 124 ++++----- .../ManagedIndexConfigTests.kt | 3 +- .../MetadataRegressionIT.kt | 44 ++-- .../MetadataServiceTests.kt | 25 +- .../indexstatemanagement/TestHelpers.kt | 60 ++--- .../action/ActionRetryIT.kt | 22 +- .../action/ActionTimeoutIT.kt | 16 +- .../action/AliasActionIT.kt | 6 +- .../action/AllocationActionIT.kt | 20 +- .../action/CloseActionIT.kt | 10 +- .../action/DeleteActionIT.kt | 4 +- .../action/ForceMergeActionIT.kt | 6 +- .../action/IndexPolicyActionIT.kt | 12 +- .../action/IndexPriorityActionIT.kt | 2 +- .../action/IndexStateManagementHistoryIT.kt | 16 +- .../action/NotificationActionIT.kt | 10 +- .../action/OpenActionIT.kt | 8 +- .../action/ReadOnlyActionIT.kt | 4 +- .../action/ReadWriteActionIT.kt | 6 +- .../action/ReplicaCountActionIT.kt | 2 +- .../action/RolloverActionIT.kt | 84 +++--- .../action/RollupActionIT.kt | 100 ++++---- .../action/ShrinkActionIT.kt | 56 ++-- .../action/SnapshotActionIT.kt | 32 +-- .../action/TransformActionIT.kt | 52 ++-- .../action/TransitionActionIT.kt | 12 +- .../coordinator/ManagedIndexCoordinatorIT.kt | 42 +-- .../ManagedIndexCoordinatorTests.kt | 4 +- .../extension/ISMActionsParserTests.kt | 2 +- .../extension/SampleCustomActionParser.kt | 2 +- .../migration/MigrationServicesIT.kt | 24 +- .../model/ActionPropertiesTests.kt | 2 +- .../indexstatemanagement/model/ActionTests.kt | 12 +- .../model/ConditionsTests.kt | 6 +- .../model/ManagedIndexMetaDataTests.kt | 8 +- .../model/XContentTests.kt | 18 +- .../resthandler/ISMTemplateRestAPIIT.kt | 18 +- .../IndexStateManagementRestApiIT.kt | 36 +-- .../resthandler/RestAddPolicyActionIT.kt | 58 ++--- .../resthandler/RestChangePolicyActionIT.kt | 108 ++++---- .../resthandler/RestExplainActionIT.kt | 134 +++++----- .../resthandler/RestRemovePolicyActionIT.kt | 48 ++-- .../RestRetryFailedManagedIndexActionIT.kt | 104 ++++---- .../runner/ManagedIndexRunnerIT.kt | 20 +- .../step/AttemptCloseStepTests.kt | 9 +- .../step/AttemptCreateRollupJobStepTests.kt | 4 +- .../AttemptCreateTransformJobStepTests.kt | 10 +- .../step/AttemptDeleteStepTests.kt | 9 +- .../step/AttemptOpenStepTests.kt | 9 +- .../step/AttemptRolloverStepTests.kt | 34 ++- .../step/AttemptSetIndexPriorityStepTests.kt | 9 +- .../step/AttemptSetReplicaCountStepTests.kt | 9 +- .../step/AttemptSnapshotStepTests.kt | 11 +- .../step/AttemptTransitionStepTests.kt | 12 +- .../step/SetReadOnlyStepTests.kt | 9 +- .../step/SetReadWriteStepTests.kt | 9 +- .../step/WaitForRollupCompletionStepTests.kt | 20 +- .../step/WaitForShrinkStepTests.kt | 7 +- .../step/WaitForSnapshotStepTests.kt | 9 +- .../WaitForTransformCompletionStepTests.kt | 26 +- .../action/explain/ExplainRequestTests.kt | 2 +- .../action/explain/ExplainResponseTests.kt | 2 +- .../getpolicy/GetPoliciesResponseTests.kt | 6 +- .../getpolicy/GetPolicyResponseTests.kt | 8 +- .../indexpolicy/IndexPolicyRequestTests.kt | 8 +- .../indexpolicy/IndexPolicyResponseTests.kt | 10 +- .../RetryFailedManagedIndexRequestTests.kt | 2 +- .../util/ManagedIndexUtilsTests.kt | 76 +++--- .../util/StepUtilsTests.kt | 8 +- .../RefreshSearchAnalyzerActionIT.kt | 2 +- .../RestRefreshSearchAnalyzerActionIT.kt | 8 +- .../rollup/RollupMapperServiceTests.kt | 107 ++++---- .../rollup/RollupMetadataServiceTests.kt | 144 ++++++----- .../rollup/RollupRestTestCase.kt | 18 +- .../indexmanagement/rollup/TestHelpers.kt | 26 +- .../rollup/action/RequestTests.kt | 4 +- .../rollup/action/ResponseTests.kt | 2 +- .../rollup/actionfilter/FieldCapsFilterIT.kt | 2 +- .../rollup/interceptor/RollupInterceptorIT.kt | 242 +++++++++--------- .../rollup/model/ISMRollupTests.kt | 18 +- .../rollup/model/RollupTests.kt | 4 +- .../rollup/model/WriteableTests.kt | 2 +- .../rollup/model/XContentTests.kt | 2 +- .../resthandler/RestDeleteRollupActionIT.kt | 4 +- .../resthandler/RestExplainRollupActionIT.kt | 4 +- .../resthandler/RestGetRollupActionIT.kt | 4 +- .../resthandler/RestIndexRollupActionIT.kt | 50 ++-- .../resthandler/RestStartRollupActionIT.kt | 8 +- .../resthandler/RestStopRollupActionIT.kt | 20 +- .../rollup/runner/RollupRunnerIT.kt | 136 +++++----- ...RollupFieldValueExpressionResolverTests.kt | 2 +- .../snapshotmanagement/SMRunnerIT.kt | 2 +- .../SnapshotManagementRestTestCase.kt | 18 +- .../snapshotmanagement/TestUtils.kt | 24 +- .../snapshotmanagement/action/ActionTests.kt | 4 +- .../action/ResponseTests.kt | 2 +- .../engine/SMStateMachineTests.kt | 12 +- .../states/creation/CreatingStateTests.kt | 4 +- .../creation/CreationFinishedStateTests.kt | 2 +- .../creation/CreationStartStateTests.kt | 2 +- .../states/deletion/DeletingStateTests.kt | 4 +- .../DeletionConditionMetStateTests.kt | 2 +- .../deletion/DeletionStartStateTests.kt | 2 +- .../RestDeleteSnapshotManagementIT.kt | 2 +- .../RestExplainSnapshotManagementIT.kt | 8 +- .../RestGetSnapshotManagementIT.kt | 8 +- .../RestIndexSnapshotManagementIT.kt | 14 +- .../RestStartSnapshotManagementIT.kt | 2 +- .../RestStopSnapshotManagementIT.kt | 2 +- .../indexmanagement/transform/TestHelpers.kt | 26 +- .../transform/TransformRestTestCase.kt | 18 +- .../transform/TransformRunnerIT.kt | 122 +++++---- .../transform/action/RequestTests.kt | 4 +- .../transform/action/ResponseTests.kt | 4 +- .../transform/model/ISMTransformTests.kt | 6 +- .../transform/model/XContentTests.kt | 6 +- .../opensearchapi/ExtensionsTests.kt | 10 +- .../RestDeleteTransformActionIT.kt | 6 +- .../RestExplainTransformActionIT.kt | 8 +- .../resthandler/RestGetTransformActionIT.kt | 4 +- .../resthandler/RestIndexTransformActionIT.kt | 18 +- .../RestPreviewTransformActionIT.kt | 20 +- .../resthandler/RestStartTransformActionIT.kt | 10 +- .../resthandler/RestStopTransformActionIT.kt | 12 +- 465 files changed, 3778 insertions(+), 3525 deletions(-) diff --git a/.editorconfig b/.editorconfig index a9c874b1c..7ba6925bf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,9 +3,16 @@ root = true [*.{kt,kts}] +ktlint_code_style = intellij_idea # we have detekt also checking for max line length. Disable the linter and use only one tool to check for max line length. - # See https://github.com/arturbosch/detekt -max_line_length=off +ktlint_standard_max-line-length = disabled +ktlint_ignore_back_ticked_identifier = true + +ktlint_standard_function-naming = disabled +ktlint_standard_property-naming = disabled +ktlint_standard_function-signature = disabled +ktlint_standard_value-argument-comment = disabled +ktlint_standard_argument-list-wrapping = disabled +ktlint_standard_value-parameter-comment = disabled -disabled_rules=import-ordering \ No newline at end of file diff --git a/detekt.yml b/detekt.yml index 8ed992998..57ab2f3c5 100644 --- a/detekt.yml +++ b/detekt.yml @@ -11,7 +11,7 @@ style: ForbiddenComment: active: false MaxLineLength: - maxLineLength: 150 + maxLineLength: 160 excludes: ['**/test/**'] FunctionOnlyReturningConstant: active: false @@ -20,6 +20,7 @@ complexity: LargeClass: excludes: ['**/test/**'] LongMethod: + threshold: 80 excludes: ['**/test/**'] LongParameterList: excludes: ['**/test/**'] diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Action.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Action.kt index 4d251b9d2..6c010c2f3 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Action.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Action.kt @@ -19,7 +19,7 @@ import java.time.Instant abstract class Action( val type: String, - val actionIndex: Int + val actionIndex: Int, ) : ToXContentObject, Writeable { var configTimeout: ActionTimeout? = null diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/StatusChecker.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/StatusChecker.kt index d2adf9ad3..2eeffec5b 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/StatusChecker.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/StatusChecker.kt @@ -19,7 +19,8 @@ interface StatusChecker { enum class Status(private val value: String) { ENABLED("enabled"), - DISABLED("disabled"); + DISABLED("disabled"), + ; override fun toString(): String { return value diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt index abb476aed..a259a4b1b 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt @@ -56,7 +56,8 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { STARTING("starting"), CONDITION_NOT_MET("condition_not_met"), FAILED("failed"), - COMPLETED("completed"); + COMPLETED("completed"), + ; override fun toString(): String { return status diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Validate.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Validate.kt index e64d3637f..718731acd 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Validate.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Validate.kt @@ -6,17 +6,17 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement import org.opensearch.cluster.service.ClusterService +import org.opensearch.common.settings.Settings import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.settings.Settings import org.opensearch.monitor.jvm.JvmService import java.util.Locale abstract class Validate( val settings: Settings, val clusterService: ClusterService, - val jvmService: JvmService + val jvmService: JvmService, ) { var validationStatus = ValidationStatus.PASSED @@ -27,7 +27,8 @@ abstract class Validate( enum class ValidationStatus(val status: String) : Writeable { PASSED("passed"), RE_VALIDATING("re_validating"), - FAILED("failed"); + FAILED("failed"), + ; override fun toString(): String { return status diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionMetaData.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionMetaData.kt index 1d7e94a74..b02e9ea5c 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionMetaData.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionMetaData.kt @@ -5,17 +5,17 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model +import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType import org.opensearch.core.common.Strings import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser -import org.opensearch.common.xcontent.XContentType import org.opensearch.core.xcontent.XContentParserUtils import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.NAME import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.START_TIME @@ -29,7 +29,7 @@ data class ActionMetaData( val failed: Boolean, val consumedRetries: Int, val lastRetryTime: Long?, - val actionProperties: ActionProperties? + val actionProperties: ActionProperties?, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -89,7 +89,7 @@ data class ActionMetaData( requireNotNull(failed) { "$FAILED is null" }, requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" }, lastRetryTime, - actionProperties + actionProperties, ) } @@ -139,7 +139,7 @@ data class ActionMetaData( requireNotNull(failed) { "$FAILED is null" }, requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" }, lastRetryTime, - actionProperties + actionProperties, ) } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionProperties.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionProperties.kt index 1b75aec11..a8493f709 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionProperties.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionProperties.kt @@ -24,7 +24,7 @@ data class ActionProperties( val rollupId: String? = null, val hasRollupFailed: Boolean? = null, val shrinkActionProperties: ShrinkActionProperties? = null, - val transformActionProperties: TransformActionProperties? = null + val transformActionProperties: TransformActionProperties? = null, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -94,6 +94,6 @@ data class ActionProperties( MAX_NUM_SEGMENTS("max_num_segments"), SNAPSHOT_NAME("snapshot_name"), ROLLUP_ID("rollup_id"), - HAS_ROLLUP_FAILED("has_rollup_failed") + HAS_ROLLUP_FAILED("has_rollup_failed"), } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionRetry.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionRetry.kt index 338d4a016..d2d16a560 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionRetry.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionRetry.kt @@ -6,10 +6,10 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model import org.apache.logging.log4j.LogManager +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.unit.TimeValue import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder @@ -23,10 +23,12 @@ import kotlin.math.pow data class ActionRetry( val count: Long, val backoff: Backoff = Backoff.EXPONENTIAL, - val delay: TimeValue = TimeValue.timeValueMinutes(1) + val delay: TimeValue = TimeValue.timeValueMinutes(1), ) : ToXContentFragment, Writeable { - init { require(count >= 0) { "Count for ActionRetry must be a non-negative number" } } + init { + require(count >= 0) { "Count for ActionRetry must be a non-negative number" } + } override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { builder @@ -42,7 +44,7 @@ data class ActionRetry( constructor(sin: StreamInput) : this( count = sin.readLong(), backoff = sin.readEnum(Backoff::class.java), - delay = sin.readTimeValue() + delay = sin.readTimeValue(), ) @Throws(IOException::class) @@ -80,7 +82,7 @@ data class ActionRetry( return ActionRetry( count = requireNotNull(count) { "ActionRetry count is null" }, backoff = backoff, - delay = delay + delay = delay, ) } } @@ -90,20 +92,21 @@ data class ActionRetry( "exponential", { consumedRetries, timeValue -> (2.0.pow(consumedRetries - 1)).toLong() * timeValue.millis - } + }, ), CONSTANT( "constant", { _, timeValue -> timeValue.millis - } + }, ), LINEAR( "linear", { consumedRetries, timeValue -> consumedRetries * timeValue.millis - } - ); + }, + ), + ; private val logger = LogManager.getLogger(javaClass) diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionTimeout.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionTimeout.kt index bf56d7322..c724b88fe 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionTimeout.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ActionTimeout.kt @@ -5,10 +5,10 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.unit.TimeValue import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder @@ -23,7 +23,7 @@ data class ActionTimeout(val timeout: TimeValue) : ToXContentFragment, Writeable @Throws(IOException::class) constructor(sin: StreamInput) : this( - timeout = sin.readTimeValue() + timeout = sin.readTimeValue(), ) @Throws(IOException::class) diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ManagedIndexMetaData.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ManagedIndexMetaData.kt index f099bb788..5e23639e8 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ManagedIndexMetaData.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ManagedIndexMetaData.kt @@ -5,17 +5,17 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model +import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.common.xcontent.XContentHelper +import org.opensearch.common.xcontent.json.JsonXContent import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder -import org.opensearch.common.xcontent.XContentFactory -import org.opensearch.common.xcontent.XContentHelper import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils -import org.opensearch.common.xcontent.json.JsonXContent import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.spi.indexstatemanagement.addObject import java.io.IOException @@ -43,7 +43,7 @@ data class ManagedIndexMetaData( @Suppress("ComplexMethod") fun toMap(): Map { - val resultMap = mutableMapOf () + val resultMap = mutableMapOf() resultMap[INDEX] = index resultMap[INDEX_UUID] = indexUuid resultMap[POLICY_ID] = policyID @@ -220,7 +220,7 @@ data class ManagedIndexMetaData( actionMetaData = action, stepMetaData = step, policyRetryInfo = retryInfo, - info = info + info = info, ) } @@ -232,7 +232,7 @@ data class ManagedIndexMetaData( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): ManagedIndexMetaData { var index: String? = null var indexUuid: String? = null @@ -314,7 +314,7 @@ data class ManagedIndexMetaData( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): ManagedIndexMetaData { XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp) @@ -340,7 +340,7 @@ data class ManagedIndexMetaData( actionMetaData = ActionMetaData.fromManagedIndexMetaDataMap(map), stepMetaData = StepMetaData.fromManagedIndexMetaDataMap(map), policyRetryInfo = PolicyRetryInfoMetaData.fromManagedIndexMetaDataMap(map), - info = map[INFO]?.let { XContentHelper.convertToMap(JsonXContent.jsonXContent, it, false) } + info = map[INFO]?.let { XContentHelper.convertToMap(JsonXContent.jsonXContent, it, false) }, ) } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/PolicyRetryInfoMetaData.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/PolicyRetryInfoMetaData.kt index a8fe8bf29..64a0dcea5 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/PolicyRetryInfoMetaData.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/PolicyRetryInfoMetaData.kt @@ -5,24 +5,24 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model +import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType import org.opensearch.core.common.Strings import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils -import org.opensearch.common.xcontent.XContentType import java.io.ByteArrayInputStream import java.nio.charset.StandardCharsets data class PolicyRetryInfoMetaData( val failed: Boolean, - val consumedRetries: Int + val consumedRetries: Int, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -49,7 +49,7 @@ data class PolicyRetryInfoMetaData( return PolicyRetryInfoMetaData( requireNotNull(failed) { "$FAILED is null" }, - requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" } + requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" }, ) } @@ -82,7 +82,7 @@ data class PolicyRetryInfoMetaData( return PolicyRetryInfoMetaData( requireNotNull(failed) { "$FAILED is null" }, - requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" } + requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" }, ) } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ShrinkActionProperties.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ShrinkActionProperties.kt index 9de9209b6..7d4426b06 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ShrinkActionProperties.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ShrinkActionProperties.kt @@ -23,7 +23,7 @@ data class ShrinkActionProperties( val lockEpochSecond: Long, val lockDurationSecond: Long, // Used to store the original index allocation and write block setting to reapply after shrink - val originalIndexSettings: Map + val originalIndexSettings: Map, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -63,7 +63,7 @@ data class ShrinkActionProperties( val originalIndexSettings: Map = si.readMap({ it.readString() }, { it.readString() }) return ShrinkActionProperties( - nodeName, targetIndexName, targetNumShards, lockPrimaryTerm, lockSeqNo, lockEpochSecond, lockDurationSecond, originalIndexSettings + nodeName, targetIndexName, targetNumShards, lockPrimaryTerm, lockSeqNo, lockEpochSecond, lockDurationSecond, originalIndexSettings, ) } @@ -102,7 +102,7 @@ data class ShrinkActionProperties( requireNotNull(lockSeqNo), requireNotNull(lockEpochSecond), requireNotNull(lockDurationSecond), - requireNotNull(originalIndexSettings) + requireNotNull(originalIndexSettings), ) } } @@ -115,6 +115,6 @@ data class ShrinkActionProperties( LOCK_PRIMARY_TERM("lock_primary_term"), LOCK_EPOCH_SECOND("lock_epoch_second"), LOCK_DURATION_SECOND("lock_duration_second"), - ORIGINAL_INDEX_SETTINGS("original_index_settings") + ORIGINAL_INDEX_SETTINGS("original_index_settings"), } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StateMetaData.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StateMetaData.kt index 7c6174106..e4fdfdfac 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StateMetaData.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StateMetaData.kt @@ -5,18 +5,18 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model +import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType import org.opensearch.core.common.Strings import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils -import org.opensearch.common.xcontent.XContentType import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.NAME import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.START_TIME import java.io.ByteArrayInputStream @@ -24,7 +24,7 @@ import java.nio.charset.StandardCharsets data class StateMetaData( val name: String, - val startTime: Long + val startTime: Long, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -49,7 +49,7 @@ data class StateMetaData( return StateMetaData( requireNotNull(name) { "$NAME is null" }, - requireNotNull(startTime) { "$START_TIME is null" } + requireNotNull(startTime) { "$START_TIME is null" }, ) } @@ -82,7 +82,7 @@ data class StateMetaData( return StateMetaData( requireNotNull(name) { "$NAME is null" }, - requireNotNull(startTime) { "$START_TIME is null" } + requireNotNull(startTime) { "$START_TIME is null" }, ) } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepContext.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepContext.kt index 6ee4ff4f9..e0cc84c64 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepContext.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepContext.kt @@ -21,7 +21,7 @@ class StepContext( val user: User?, val scriptService: ScriptService, val settings: Settings, - val lockService: LockService + val lockService: LockService, ) { fun getUpdatedContext(metadata: ManagedIndexMetaData): StepContext { return StepContext(metadata, this.clusterService, this.client, this.threadContext, this.user, this.scriptService, this.settings, this.lockService) diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepMetaData.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepMetaData.kt index defe49287..85681accc 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepMetaData.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/StepMetaData.kt @@ -5,18 +5,18 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model +import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType import org.opensearch.core.common.Strings import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils -import org.opensearch.common.xcontent.XContentType import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.NAME import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.START_TIME @@ -27,7 +27,7 @@ import java.util.Locale data class StepMetaData( val name: String, val startTime: Long, - val stepStatus: Step.StepStatus + val stepStatus: Step.StepStatus, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -61,7 +61,7 @@ data class StepMetaData( return StepMetaData( requireNotNull(name) { "$NAME is null" }, requireNotNull(startTime) { "$START_TIME is null" }, - requireNotNull(stepStatus) { "$STEP_STATUS is null" } + requireNotNull(stepStatus) { "$STEP_STATUS is null" }, ) } @@ -97,7 +97,7 @@ data class StepMetaData( return StepMetaData( requireNotNull(name) { "$NAME is null" }, requireNotNull(startTime) { "$START_TIME is null" }, - requireNotNull(stepStatus) { "$STEP_STATUS is null" } + requireNotNull(stepStatus) { "$STEP_STATUS is null" }, ) } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/TransformActionProperties.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/TransformActionProperties.kt index 70b593750..300e379d3 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/TransformActionProperties.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/TransformActionProperties.kt @@ -8,14 +8,14 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser +import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken data class TransformActionProperties( - val transformId: String? + val transformId: String?, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -53,6 +53,6 @@ data class TransformActionProperties( } enum class Properties(val key: String) { - TRANSFORM_ID("transform_id") + TRANSFORM_ID("transform_id"), } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ValidationResult.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ValidationResult.kt index c2d24a86a..4bdd20ced 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ValidationResult.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ValidationResult.kt @@ -5,18 +5,18 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.model +import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType import org.opensearch.core.common.Strings import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils -import org.opensearch.common.xcontent.XContentType import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate import java.io.ByteArrayInputStream import java.nio.charset.StandardCharsets @@ -24,7 +24,7 @@ import java.util.Locale data class ValidationResult( val validationMessage: String, - val validationStatus: Validate.ValidationStatus + val validationStatus: Validate.ValidationStatus, ) : Writeable, ToXContentFragment { override fun writeTo(out: StreamOutput) { @@ -54,7 +54,7 @@ data class ValidationResult( return ValidationResult( requireNotNull(validationMessage) { "$VALIDATION_MESSAGE is null" }, - requireNotNull(validationStatus) { "$VALIDATION_STATUS is null" } + requireNotNull(validationStatus) { "$VALIDATION_STATUS is null" }, ) } @@ -87,7 +87,7 @@ data class ValidationResult( return ValidationResult( requireNotNull(validationMessage) { "$VALIDATION_MESSAGE is null" }, - requireNotNull(validationStatus) { "$VALIDATION_STATUS is null" } + requireNotNull(validationStatus) { "$VALIDATION_STATUS is null" }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementIndices.kt b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementIndices.kt index 8eb6a5156..780cb4319 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementIndices.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementIndices.kt @@ -4,13 +4,13 @@ */ @file:Suppress("ReturnCount") + package org.opensearch.indexmanagement import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.opensearch.OpenSearchStatusException import org.opensearch.ResourceAlreadyExistsException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.alias.Alias import org.opensearch.action.admin.indices.create.CreateIndexRequest import org.opensearch.action.admin.indices.create.CreateIndexResponse @@ -21,6 +21,8 @@ import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN @@ -29,7 +31,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_NUMBER_OF_ import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.util.IndexUtils import org.opensearch.indexmanagement.util.OpenForTesting -import org.opensearch.core.rest.RestStatus import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @@ -38,12 +39,13 @@ import kotlin.coroutines.suspendCoroutine class IndexManagementIndices( settings: Settings, private val client: IndicesAdminClient, - private val clusterService: ClusterService + private val clusterService: ClusterService, ) { private val logger = LogManager.getLogger(javaClass) @Volatile private var historyNumberOfShards = ManagedIndexSettings.HISTORY_NUMBER_OF_SHARDS.get(settings) + @Volatile private var historyNumberOfReplicas = ManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS.get(settings) init { @@ -70,7 +72,7 @@ class IndexManagementIndices( override fun onResponse(response: CreateIndexResponse) { actionListener.onResponse(response) } - } + }, ) } else { IndexUtils.checkAndUpdateConfigIndexMapping(clusterService.state(), client, actionListener) @@ -83,7 +85,7 @@ class IndexManagementIndices( object : ActionListener { override fun onResponse(response: AcknowledgedResponse) = cont.resume(response) override fun onFailure(e: Exception) = cont.resumeWithException(e) - } + }, ) } if (response.isAcknowledged) { @@ -92,7 +94,7 @@ class IndexManagementIndices( logger.error("Unable to create or update $INDEX_MANAGEMENT_INDEX with newest mapping.") throw OpenSearchStatusException( "Unable to create or update $INDEX_MANAGEMENT_INDEX with newest mapping.", - RestStatus.INTERNAL_SERVER_ERROR + RestStatus.INTERNAL_SERVER_ERROR, ) } } @@ -170,7 +172,7 @@ class IndexManagementIndices( Settings.builder() .put(INDEX_HIDDEN, true) .put(INDEX_NUMBER_OF_SHARDS, historyNumberOfShards) - .put(INDEX_NUMBER_OF_REPLICAS, historyNumberOfReplicas).build() + .put(INDEX_NUMBER_OF_REPLICAS, historyNumberOfReplicas).build(), ) if (alias != null) request.alias(Alias(alias)) return try { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt index 7cc528f9e..b6b631573 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt @@ -7,24 +7,24 @@ package org.opensearch.indexmanagement import org.apache.logging.log4j.LogManager import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.support.ActionFilter import org.opensearch.action.support.ActiveShardsObserver 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.inject.Inject import org.opensearch.common.lifecycle.Lifecycle import org.opensearch.common.lifecycle.LifecycleComponent import org.opensearch.common.lifecycle.LifecycleListener -import org.opensearch.common.inject.Inject -import org.opensearch.core.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.util.concurrent.ThreadContext +import org.opensearch.core.action.ActionResponse +import org.opensearch.core.common.io.stream.NamedWriteableRegistry import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken @@ -51,6 +51,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.MetadataService import org.opensearch.indexmanagement.indexstatemanagement.PluginVersionSweepCoordinator import org.opensearch.indexmanagement.indexstatemanagement.SkipExecution +import org.opensearch.indexmanagement.indexstatemanagement.migration.ISMTemplateService import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestAddPolicyAction @@ -87,7 +88,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.transport.action.upda import org.opensearch.indexmanagement.indexstatemanagement.transport.action.updateindexmetadata.UpdateManagedIndexMetaDataAction import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE import org.opensearch.indexmanagement.indexstatemanagement.validation.ActionValidation -import org.opensearch.indexmanagement.indexstatemanagement.migration.ISMTemplateService import org.opensearch.indexmanagement.refreshanalyzer.RefreshSearchAnalyzerAction import org.opensearch.indexmanagement.refreshanalyzer.RestRefreshSearchAnalyzerAction import org.opensearch.indexmanagement.refreshanalyzer.TransportRefreshSearchAnalyzerAction @@ -127,6 +127,7 @@ import org.opensearch.indexmanagement.rollup.settings.RollupSettings import org.opensearch.indexmanagement.rollup.util.QueryShardContextFactory import org.opensearch.indexmanagement.rollup.util.RollupFieldValueExpressionResolver import org.opensearch.indexmanagement.settings.IndexManagementSettings +import org.opensearch.indexmanagement.snapshotmanagement.SMRunner import org.opensearch.indexmanagement.snapshotmanagement.api.resthandler.RestCreateSMPolicyHandler import org.opensearch.indexmanagement.snapshotmanagement.api.resthandler.RestDeleteSMPolicyHandler import org.opensearch.indexmanagement.snapshotmanagement.api.resthandler.RestExplainSMPolicyHandler @@ -142,7 +143,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.Trans import org.opensearch.indexmanagement.snapshotmanagement.api.transport.index.TransportIndexSMPolicyAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.start.TransportStartSMAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.stop.TransportStopSMAction -import org.opensearch.indexmanagement.snapshotmanagement.SMRunner import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManagementSettings @@ -312,7 +312,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin extension.overrideClusterStateIndexUuidSetting()?.let { if (customIndexUUIDSetting != null) { error( - "Multiple extensions of IndexManagement plugin overriding ClusterStateIndexUUIDSetting - not supported" + "Multiple extensions of IndexManagement plugin overriding ClusterStateIndexUUIDSetting - not supported", ) } customIndexUUIDSetting = extension.overrideClusterStateIndexUuidSetting() @@ -328,7 +328,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin indexScopedSettings: IndexScopedSettings, settingsFilter: SettingsFilter, indexNameExpressionResolver: IndexNameExpressionResolver, - nodesInCluster: Supplier + nodesInCluster: Supplier, ): List { return listOf( RestRefreshSearchAnalyzerAction(), @@ -362,7 +362,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin RestUpdateSMPolicyHandler(), RestIndexLRONConfigAction(), RestGetLRONConfigAction(), - RestDeleteLRONConfigAction() + RestDeleteLRONConfigAction(), ) } @@ -378,7 +378,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin nodeEnvironment: NodeEnvironment, namedWriteableRegistry: NamedWriteableRegistry, indexNameExpressionResolver: IndexNameExpressionResolver, - repositoriesServiceSupplier: Supplier + repositoriesServiceSupplier: Supplier, ): Collection { val settings = environment.settings() this.clusterService = clusterService @@ -388,7 +388,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin scriptService, xContentRegistry, namedWriteableRegistry, - environment + environment, ) rollupInterceptor = RollupInterceptor(clusterService, settings, indexNameExpressionResolver) val jvmService = JvmService(environment.settings()) @@ -399,7 +399,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin settings, indexNameExpressionResolver, jvmService, - threadPool + threadPool, ) fieldCapsFilter = FieldCapsFilter(clusterService, settings, indexNameExpressionResolver) this.indexNameExpressionResolver = indexNameExpressionResolver @@ -428,14 +428,14 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin client, threadPool, clusterService, - indexManagementIndices + indexManagementIndices, ) indexMetadataProvider = IndexMetadataProvider( settings, client, clusterService, hashMapOf( - DEFAULT_INDEX_TYPE to DefaultIndexMetadataService(customIndexUUIDSetting) - ) + DEFAULT_INDEX_TYPE to DefaultIndexMetadataService(customIndexUUIDSetting), + ), ) indexMetadataServices.forEach { indexMetadataProvider.addMetadataServices(it) } @@ -460,7 +460,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin val managedIndexCoordinator = ManagedIndexCoordinator( environment.settings(), - client, clusterService, threadPool, indexManagementIndices, metadataService, templateService, indexMetadataProvider, xContentRegistry + client, clusterService, threadPool, indexManagementIndices, metadataService, templateService, indexMetadataProvider, xContentRegistry, ) val smRunner = SMRunner.init(client, threadPool, settings, indexManagementIndices, clusterService) @@ -486,7 +486,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin indexStateManagementHistory, indexMetadataProvider, smRunner, - pluginVersionSweepCoordinator + pluginVersionSweepCoordinator, ) } @@ -564,7 +564,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin LegacyOpenDistroRollupSettings.ROLLUP_ENABLED, LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_ENABLED, LegacyOpenDistroRollupSettings.ROLLUP_DASHBOARDS, - SnapshotManagementSettings.FILTER_BY_BACKEND_ROLES + SnapshotManagementSettings.FILTER_BY_BACKEND_ROLES, ) } @@ -607,7 +607,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin ActionPlugin.ActionHandler(SMActions.GET_SM_POLICIES_ACTION_TYPE, TransportGetSMPoliciesAction::class.java), ActionPlugin.ActionHandler(IndexLRONConfigAction.INSTANCE, TransportIndexLRONConfigAction::class.java), ActionPlugin.ActionHandler(GetLRONConfigAction.INSTANCE, TransportGetLRONConfigAction::class.java), - ActionPlugin.ActionHandler(DeleteLRONConfigAction.INSTANCE, TransportDeleteLRONConfigAction::class.java) + ActionPlugin.ActionHandler(DeleteLRONConfigAction.INSTANCE, TransportDeleteLRONConfigAction::class.java), ) } @@ -623,11 +623,11 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin return listOf( SystemIndexDescriptor( INDEX_MANAGEMENT_INDEX, - "Index for storing index management configuration and metadata." + "Index for storing index management configuration and metadata.", ), SystemIndexDescriptor( CONTROL_CENTER_INDEX, - "Index for storing notification policy of long running index operations." + "Index for storing notification policy of long running index operations.", ), ) @@ -635,7 +635,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin } class GuiceHolder @Inject constructor( - remoteClusterService: TransportService + remoteClusterService: TransportService, ) : LifecycleComponent { override fun close() { /* do nothing */ } override fun lifecycleState(): Lifecycle.State? { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/DateHistogram.kt b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/DateHistogram.kt index 4f09758ce..f482573fc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/DateHistogram.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/DateHistogram.kt @@ -29,7 +29,7 @@ data class DateHistogram( val fixedInterval: String? = null, val calendarInterval: String? = null, val timezone: ZoneId = ZoneId.of(UTC), - val format: String? = null + val format: String? = null, ) : Dimension(Type.DATE_HISTOGRAM, sourceField, targetField) { init { @@ -44,7 +44,7 @@ data class DateHistogram( targetField = sin.readString(), fixedInterval = sin.readOptionalString(), calendarInterval = sin.readOptionalString(), - timezone = sin.readZoneId() + timezone = sin.readZoneId(), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -109,7 +109,7 @@ data class DateHistogram( fun getRewrittenAggregation( aggregationBuilder: DateHistogramAggregationBuilder, - subAggregations: AggregatorFactories.Builder + subAggregations: AggregatorFactories.Builder, ): DateHistogramAggregationBuilder = DateHistogramAggregationBuilder(aggregationBuilder.name) .also { aggregationBuilder.calendarInterval?.apply { it.calendarInterval(this) } } @@ -168,7 +168,7 @@ data class DateHistogram( fixedInterval = fixedInterval, calendarInterval = calendarInterval, timezone = timezone, - format = format + format = format, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Dimension.kt b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Dimension.kt index cea2d094c..3f4fe21a0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Dimension.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Dimension.kt @@ -17,12 +17,13 @@ import java.io.IOException abstract class Dimension( val type: Type, open val sourceField: String, - open val targetField: String + open val targetField: String, ) : ToXContentObject, Writeable { enum class Type(val type: String) { DATE_HISTOGRAM("date_histogram"), TERMS("terms"), - HISTOGRAM("histogram"); + HISTOGRAM("histogram"), + ; override fun toString(): String { return type diff --git a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Histogram.kt b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Histogram.kt index 558a42b5d..ebdc55add 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Histogram.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Histogram.kt @@ -26,7 +26,7 @@ import java.io.IOException data class Histogram( override val sourceField: String, override val targetField: String, - val interval: Double + val interval: Double, ) : Dimension(Type.HISTOGRAM, sourceField, targetField) { init { @@ -38,7 +38,7 @@ data class Histogram( constructor(sin: StreamInput) : this( sourceField = sin.readString(), targetField = sin.readString(), - interval = sin.readDouble() + interval = sin.readDouble(), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -87,7 +87,7 @@ data class Histogram( fun getRewrittenAggregation( aggregationBuilder: HistogramAggregationBuilder, - subAggregations: AggregatorFactories.Builder + subAggregations: AggregatorFactories.Builder, ): HistogramAggregationBuilder = HistogramAggregationBuilder(aggregationBuilder.name) .interval(aggregationBuilder.interval()) @@ -109,6 +109,7 @@ data class Histogram( companion object { const val HISTOGRAM_INTERVAL_FIELD = "interval" + // There can be rounding issues with small intervals where the range query will select documents differently than the Histogram // so add an error to the range query and then limit the buckets indexed later. private const val bucketError = 0.00005 @@ -137,7 +138,7 @@ data class Histogram( return Histogram( requireNotNull(sourceField) { "Source field must not be null" }, requireNotNull(targetField) { "Target field must not be null" }, - requireNotNull(interval) { "Interval field must not be null" } + requireNotNull(interval) { "Interval field must not be null" }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Terms.kt b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Terms.kt index 11eb6ef3b..da085b68d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Terms.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/common/model/dimension/Terms.kt @@ -23,7 +23,7 @@ import java.io.IOException data class Terms( override val sourceField: String, - override val targetField: String + override val targetField: String, ) : Dimension(Type.TERMS, sourceField, targetField) { init { @@ -33,7 +33,7 @@ data class Terms( @Throws(IOException::class) constructor(sin: StreamInput) : this( sourceField = sin.readString(), - targetField = sin.readString() + targetField = sin.readString(), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -72,7 +72,7 @@ data class Terms( // TODO missing terms field fun getRewrittenAggregation( aggregationBuilder: TermsAggregationBuilder, - subAggregations: AggregatorFactories.Builder + subAggregations: AggregatorFactories.Builder, ): TermsAggregationBuilder = TermsAggregationBuilder(aggregationBuilder.name) .also { aggregationBuilder.collectMode()?.apply { it.collectMode(this) } } @@ -114,7 +114,7 @@ data class Terms( ensureExpectedToken( Token.START_OBJECT, xcp.currentToken(), - xcp + xcp, ) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() @@ -129,7 +129,7 @@ data class Terms( if (targetField == null) targetField = sourceField return Terms( requireNotNull(sourceField) { "Source field cannot be null" }, - requireNotNull(targetField) { "Target field cannot be null" } + requireNotNull(targetField) { "Target field cannot be null" }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/Channel.kt b/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/Channel.kt index ebdff4e35..4d4a3b32e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/Channel.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/Channel.kt @@ -7,6 +7,12 @@ package org.opensearch.indexmanagement.common.model.notification import org.opensearch.client.Client import org.opensearch.client.node.NodeClient +import org.opensearch.commons.ConfigConstants +import org.opensearch.commons.authuser.User +import org.opensearch.commons.notifications.NotificationsPluginInterface +import org.opensearch.commons.notifications.action.SendNotificationResponse +import org.opensearch.commons.notifications.model.ChannelMessage +import org.opensearch.commons.notifications.model.EventSource import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable @@ -14,12 +20,6 @@ import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.ConfigConstants -import org.opensearch.commons.authuser.User -import org.opensearch.commons.notifications.NotificationsPluginInterface -import org.opensearch.commons.notifications.action.SendNotificationResponse -import org.opensearch.commons.notifications.model.ChannelMessage -import org.opensearch.commons.notifications.model.EventSource import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.util.SecurityUtils.Companion.generateUserString import java.io.IOException @@ -38,7 +38,7 @@ data class Channel(val id: String) : ToXContent, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( - sin.readString() + sin.readString(), ) @Throws(IOException::class) @@ -77,7 +77,7 @@ data class Channel(val id: String) : ToXContent, Writeable { client: Client, eventSource: EventSource, message: String, - user: User? + user: User?, ) { val channel = this client.threadPool().threadContext.stashContext().use { @@ -89,7 +89,7 @@ data class Channel(val id: String) : ToXContent, Writeable { eventSource, ChannelMessage(message, null, null), listOf(channel.id), - it + it, ) } validateResponseStatus(res.getStatus(), res.notificationEvent.eventSource.referenceId) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/NotificationUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/NotificationUtils.kt index e39ef0445..9e5c401c7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/NotificationUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/common/model/notification/NotificationUtils.kt @@ -4,6 +4,7 @@ */ @file:JvmName("NotificationUtils") + package org.opensearch.indexmanagement.common.model.notification import org.opensearch.OpenSearchStatusException @@ -16,7 +17,7 @@ private val VALID_RESPONSE_STATUS = setOf( RestStatus.OK.status, RestStatus.CREATED.status, RestStatus.ACCEPTED.status, RestStatus.NON_AUTHORITATIVE_INFORMATION.status, RestStatus.NO_CONTENT.status, RestStatus.RESET_CONTENT.status, RestStatus.PARTIAL_CONTENT.status, - RestStatus.MULTI_STATUS.status + RestStatus.MULTI_STATUS.status, ) @Throws(OpenSearchStatusException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/common/model/rest/SearchParams.kt b/src/main/kotlin/org/opensearch/indexmanagement/common/model/rest/SearchParams.kt index 53a6ac795..a42bc9dde 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/common/model/rest/SearchParams.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/common/model/rest/SearchParams.kt @@ -24,7 +24,7 @@ data class SearchParams( val from: Int, val sortField: String, val sortOrder: String, - val queryString: String + val queryString: String, ) : Writeable { @Throws(IOException::class) @@ -33,7 +33,7 @@ data class SearchParams( from = sin.readInt(), sortField = sin.readString(), sortOrder = sin.readString(), - queryString = sin.readString() + queryString = sin.readString(), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/ControlCenterIndices.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/ControlCenterIndices.kt index 1aa70dbf1..8e3ca7e7c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/ControlCenterIndices.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/ControlCenterIndices.kt @@ -7,13 +7,13 @@ package org.opensearch.indexmanagement.controlcenter.notification import org.opensearch.ExceptionsHelper import org.opensearch.ResourceAlreadyExistsException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.create.CreateIndexRequest import org.opensearch.action.admin.indices.create.CreateIndexResponse import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN import org.opensearch.indexmanagement.util.IndexUtils @@ -39,16 +39,18 @@ class ControlCenterIndices( CreateIndexResponse( true, true, - IndexManagementPlugin.CONTROL_CENTER_INDEX - ) + IndexManagementPlugin.CONTROL_CENTER_INDEX, + ), ) - } else actionListener.onFailure(e) + } else { + actionListener.onFailure(e) + } } override fun onResponse(response: CreateIndexResponse) { actionListener.onResponse(response) } - } + }, ) } else { IndexUtils.checkAndUpdateIndexMapping( @@ -57,7 +59,7 @@ class ControlCenterIndices( controlCenterMappings, clusterService.state(), client, - actionListener + actionListener, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigResponse.kt index 560384ed1..76cba4380 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigResponse.kt @@ -20,12 +20,12 @@ import java.io.IOException class LRONConfigResponse( val id: String, - val lronConfig: LRONConfig + val lronConfig: LRONConfig, ) : ActionResponse(), ToXContentObject { @Throws(IOException::class) constructor(sin: StreamInput) : this( id = sin.readString(), - lronConfig = LRONConfig(sin) + lronConfig = LRONConfig(sin), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/DeleteLRONConfigRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/DeleteLRONConfigRequest.kt index e6a73030a..aa1733a02 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/DeleteLRONConfigRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/DeleteLRONConfigRequest.kt @@ -14,11 +14,11 @@ import org.opensearch.indexmanagement.controlcenter.notification.util.LRON_DOC_I import java.io.IOException class DeleteLRONConfigRequest( - val docId: String + val docId: String, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( - docId = sin.readString() + docId = sin.readString(), ) override fun validate(): ActionRequestValidationException? { @@ -26,7 +26,7 @@ class DeleteLRONConfigRequest( if (!(docId.startsWith(LRON_DOC_ID_PREFIX))) { validationException = ValidateActions.addValidationError( "Invalid LRONConfig ID", - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/TransportDeleteLRONConfigAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/TransportDeleteLRONConfigAction.kt index ea9d40fba..49681b5a6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/TransportDeleteLRONConfigAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/delete/TransportDeleteLRONConfigAction.kt @@ -6,7 +6,6 @@ package org.opensearch.indexmanagement.controlcenter.notification.action.delete import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.delete.DeleteRequest import org.opensearch.action.delete.DeleteResponse import org.opensearch.action.support.ActionFilters @@ -15,6 +14,7 @@ import org.opensearch.action.support.WriteRequest import org.opensearch.client.node.NodeClient import org.opensearch.common.inject.Inject import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -22,9 +22,9 @@ import org.opensearch.transport.TransportService class TransportDeleteLRONConfigAction @Inject constructor( val client: NodeClient, transportService: TransportService, - actionFilters: ActionFilters + actionFilters: ActionFilters, ) : HandledTransportAction( - DeleteLRONConfigAction.NAME, transportService, actionFilters, ::DeleteLRONConfigRequest + DeleteLRONConfigAction.NAME, transportService, actionFilters, ::DeleteLRONConfigRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -36,15 +36,15 @@ class TransportDeleteLRONConfigAction @Inject constructor( private val client: NodeClient, private val actionListener: ActionListener, private val request: DeleteLRONConfigRequest, - private val docId: String = request.docId + private val docId: String = request.docId, ) { fun start() { log.debug( "User and roles string from thread context: ${ - client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - ) - }" + client.threadPool().threadContext.getTransient( + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + ) + }", ) client.threadPool().threadContext.stashContext().use { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/GetLRONConfigRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/GetLRONConfigRequest.kt index 6d41f7fdb..7b54786c6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/GetLRONConfigRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/GetLRONConfigRequest.kt @@ -16,12 +16,12 @@ import java.io.IOException class GetLRONConfigRequest( val docId: String? = null, - val searchParams: SearchParams? = null + val searchParams: SearchParams? = null, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( docId = sin.readOptionalString(), - searchParams = sin.readOptionalWriteable(::SearchParams) + searchParams = sin.readOptionalWriteable(::SearchParams), ) override fun validate(): ActionRequestValidationException? { @@ -29,19 +29,19 @@ class GetLRONConfigRequest( if (null == docId && null == searchParams) { validationException = ValidateActions.addValidationError( "GetLRONConfigRequest must contain docId or searchParams", - validationException + validationException, ) } if (null != docId && null != searchParams) { validationException = ValidateActions.addValidationError( "Get LRONConfig requires either docId or searchParams to be specified", - validationException + validationException, ) } if (null != docId && !docId.startsWith(LRON_DOC_ID_PREFIX)) { validationException = ValidateActions.addValidationError( "Invalid LRONConfig ID", - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/TransportGetLRONConfigAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/TransportGetLRONConfigAction.kt index 25c2a42a8..1cb1e658e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/TransportGetLRONConfigAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/get/TransportGetLRONConfigAction.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.controlcenter.notification.action.get import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper -import org.opensearch.core.action.ActionListener import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters @@ -18,8 +17,9 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.index.IndexNotFoundException import org.opensearch.index.query.QueryBuilders import org.opensearch.indexmanagement.IndexManagementPlugin @@ -37,7 +37,7 @@ class TransportGetLRONConfigAction @Inject constructor( actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - GetLRONConfigAction.NAME, transportService, actionFilters, ::GetLRONConfigRequest + GetLRONConfigAction.NAME, transportService, actionFilters, ::GetLRONConfigRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -48,13 +48,13 @@ class TransportGetLRONConfigAction @Inject constructor( inner class GetLRONConfigHandler( private val client: NodeClient, private val actionListener: ActionListener, - private val request: GetLRONConfigRequest + private val request: GetLRONConfigRequest, ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) client.threadPool().threadContext.stashContext().use { if (null != request.docId) { @@ -70,7 +70,7 @@ class TransportGetLRONConfigAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } else { doSearch() @@ -104,11 +104,11 @@ class TransportGetLRONConfigAction @Inject constructor( val lronConfigResponses = response.hits.hits.map { val xcp = XContentHelper.createParser( xContentRegistry, - LoggingDeprecationHandler.INSTANCE, it.sourceRef, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, it.sourceRef, XContentType.JSON, ) LRONConfigResponse( id = it.id, - lronConfig = xcp.parseWithType(id = it.id, parse = LRONConfig.Companion::parse) + lronConfig = xcp.parseWithType(id = it.id, parse = LRONConfig.Companion::parse), ) } actionListener.onResponse(GetLRONConfigResponse(lronConfigResponses, totalNumber.toInt())) @@ -122,7 +122,7 @@ class TransportGetLRONConfigAction @Inject constructor( } actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/IndexLRONConfigRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/IndexLRONConfigRequest.kt index f8041930c..32e71d37d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/IndexLRONConfigRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/IndexLRONConfigRequest.kt @@ -14,13 +14,13 @@ import java.io.IOException class IndexLRONConfigRequest( val lronConfig: LRONConfig, val isUpdate: Boolean = false, - val dryRun: Boolean = false + val dryRun: Boolean = false, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( lronConfig = LRONConfig(sin), isUpdate = sin.readBoolean(), - dryRun = sin.readBoolean() + dryRun = sin.readBoolean(), ) override fun validate() = null diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/TransportIndexLRONConfigAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/TransportIndexLRONConfigAction.kt index 811a69a8c..4b2f23a1a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/TransportIndexLRONConfigAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/action/index/TransportIndexLRONConfigAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.controlcenter.notification.action.index import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteRequest import org.opensearch.action.index.IndexRequest import org.opensearch.action.index.IndexResponse @@ -22,6 +21,8 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.XContentFactory import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.controlcenter.notification.ControlCenterIndices @@ -29,7 +30,6 @@ import org.opensearch.indexmanagement.controlcenter.notification.LRONConfigRespo import org.opensearch.indexmanagement.controlcenter.notification.util.getDocID import org.opensearch.indexmanagement.controlcenter.notification.util.getPriority import org.opensearch.indexmanagement.util.SecurityUtils -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -42,7 +42,7 @@ class TransportIndexLRONConfigAction @Inject constructor( val controlCenterIndices: ControlCenterIndices, val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - IndexLRONConfigAction.NAME, transportService, actionFilters, ::IndexLRONConfigRequest + IndexLRONConfigAction.NAME, transportService, actionFilters, ::IndexLRONConfigRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -55,13 +55,13 @@ class TransportIndexLRONConfigAction @Inject constructor( private val actionListener: ActionListener, private val request: IndexLRONConfigRequest, private val user: User? = SecurityUtils.buildUser(client.threadPool().threadContext), - private val docId: String = getDocID(request.lronConfig.taskId, request.lronConfig.actionName) + private val docId: String = getDocID(request.lronConfig.taskId, request.lronConfig.actionName), ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) client.threadPool().threadContext.stashContext().use { /* we use dryRun to help check permission and do request validation */ @@ -70,7 +70,7 @@ class TransportIndexLRONConfigAction @Inject constructor( return } controlCenterIndices.checkAndUpdateControlCenterIndex( - ActionListener.wrap(::onCreateMappingsResponse, actionListener::onFailure) + ActionListener.wrap(::onCreateMappingsResponse, actionListener::onFailure), ) } } @@ -98,7 +98,7 @@ class TransportIndexLRONConfigAction @Inject constructor( private fun putLRONConfig() { val lronConfig = request.lronConfig.copy( user = this.user, - priority = getPriority(request.lronConfig.taskId, request.lronConfig.actionName) + priority = getPriority(request.lronConfig.taskId, request.lronConfig.actionName), ) if (request.dryRun) { @@ -126,8 +126,8 @@ class TransportIndexLRONConfigAction @Inject constructor( actionListener.onResponse( LRONConfigResponse( response.id, - lronConfig - ) + lronConfig, + ), ) } } @@ -135,7 +135,7 @@ class TransportIndexLRONConfigAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilter.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilter.kt index 6b578b4bd..e371121dd 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilter.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilter.kt @@ -6,15 +6,15 @@ package org.opensearch.indexmanagement.controlcenter.notification.filter import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.support.ActionFilter import org.opensearch.action.support.ActionFilterChain import org.opensearch.action.support.ActiveShardsObserver import org.opensearch.client.Client import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.service.ClusterService +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse import org.opensearch.core.tasks.TaskId import org.opensearch.indexmanagement.controlcenter.notification.util.supportedActions import org.opensearch.tasks.Task @@ -23,7 +23,7 @@ class IndexOperationActionFilter( val client: Client, val clusterService: ClusterService, val activeShardsObserver: ActiveShardsObserver, - val indexNameExpressionResolver: IndexNameExpressionResolver + val indexNameExpressionResolver: IndexNameExpressionResolver, ) : ActionFilter { private val logger = LogManager.getLogger(IndexOperationActionFilter::class.java) @@ -34,7 +34,7 @@ class IndexOperationActionFilter( action: String, request: Request, listener: ActionListener, - chain: ActionFilterChain + chain: ActionFilterChain, ) { chain.proceed(task, action, request, wrapActionListener(task, action, request, listener)) } @@ -58,7 +58,7 @@ class IndexOperationActionFilter( task = task, request = request, activeShardsObserver = activeShardsObserver, - indexNameExpressionResolver = indexNameExpressionResolver + indexNameExpressionResolver = indexNameExpressionResolver, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListener.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListener.kt index c69409dca..3c2a621e0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListener.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListener.kt @@ -12,9 +12,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.DocWriteResponse import org.opensearch.action.admin.indices.forcemerge.ForceMergeAction import org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest @@ -34,13 +32,23 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.unit.TimeValue import org.opensearch.commons.notifications.model.EventSource import org.opensearch.commons.notifications.model.SeverityType +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse +import org.opensearch.core.tasks.TaskId import org.opensearch.index.IndexNotFoundException import org.opensearch.index.reindex.BulkByScrollResponse import org.opensearch.index.reindex.ReindexAction import org.opensearch.index.reindex.ReindexRequest +import org.opensearch.indexmanagement.common.model.rest.DEFAULT_PAGINATION_SIZE +import org.opensearch.indexmanagement.common.model.rest.SORT_ORDER_DESC +import org.opensearch.indexmanagement.common.model.rest.SearchParams import org.opensearch.indexmanagement.controlcenter.notification.LRONConfigResponse import org.opensearch.indexmanagement.controlcenter.notification.action.delete.DeleteLRONConfigAction import org.opensearch.indexmanagement.controlcenter.notification.action.delete.DeleteLRONConfigRequest +import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigAction +import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigRequest +import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse +import org.opensearch.indexmanagement.controlcenter.notification.filter.parser.ActionRespParseResult import org.opensearch.indexmanagement.controlcenter.notification.filter.parser.ForceMergeIndexRespParser import org.opensearch.indexmanagement.controlcenter.notification.filter.parser.OpenIndexRespParser import org.opensearch.indexmanagement.controlcenter.notification.filter.parser.ReindexRespParser @@ -48,17 +56,9 @@ import org.opensearch.indexmanagement.controlcenter.notification.filter.parser.R import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig import org.opensearch.indexmanagement.controlcenter.notification.util.DEFAULT_LRON_CONFIG_SORT_FIELD import org.opensearch.indexmanagement.controlcenter.notification.util.getDocID -import org.opensearch.indexmanagement.common.model.rest.DEFAULT_PAGINATION_SIZE -import org.opensearch.indexmanagement.common.model.rest.SORT_ORDER_DESC -import org.opensearch.indexmanagement.common.model.rest.SearchParams -import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigAction -import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigRequest -import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse -import org.opensearch.indexmanagement.controlcenter.notification.filter.parser.ActionRespParseResult import org.opensearch.indexmanagement.opensearchapi.retry import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.tasks.Task -import org.opensearch.core.tasks.TaskId import org.opensearch.threadpool.ThreadPool.Names.GENERIC import java.util.function.Consumer @@ -112,7 +112,7 @@ class NotificationActionListener { ResizeIndexRespParser( - activeShardsObserver, request as ResizeRequest, clusterService + activeShardsObserver, request as ResizeRequest, clusterService, ).parseAndSendNotification(if (response == null) null else response as ResizeResponse, ex, callback) } @@ -120,30 +120,30 @@ class NotificationActionListener { OpenIndexRespParser( - activeShardsObserver, request as OpenIndexRequest, indexNameExpressionResolver, clusterService + activeShardsObserver, request as OpenIndexRequest, indexNameExpressionResolver, clusterService, ).parseAndSendNotification( if (response == null) null else response as OpenIndexResponse, ex, - callback + callback, ) } ForceMergeAction.NAME -> { ForceMergeIndexRespParser( request as ForceMergeRequest, - clusterService + clusterService, ).parseAndSendNotification( - if (response == null) null else response as ForceMergeResponse, ex, callback + if (response == null) null else response as ForceMergeResponse, ex, callback, ) } @@ -164,7 +164,7 @@ class NotificationActionListener { override fun onResponse(response: DeleteResponse) { if (response.result == DocWriteResponse.Result.DELETED) { logger.info( - "One time notification policy for task: {} has been removed", taskId + "One time notification policy for task: {} has been removed", taskId, ) } } @@ -266,7 +266,7 @@ class NotificationActionListener @@ -78,18 +78,18 @@ class OpenIndexRespParser( ActionRespParseResult( OperationResult.FAILED, buildNotificationMessage(response, e), - buildNotificationTitle(OperationResult.FAILED) - ) + buildNotificationTitle(OperationResult.FAILED), + ), ) - } + }, ) } else { callback.accept( ActionRespParseResult( OperationResult.TIMEOUT, buildNotificationMessage(response, isTimeout = true), - buildNotificationTitle(OperationResult.TIMEOUT) - ) + buildNotificationTitle(OperationResult.TIMEOUT), + ), ) } } else { @@ -97,8 +97,8 @@ class OpenIndexRespParser( ActionRespParseResult( OperationResult.COMPLETE, buildNotificationMessage(response), - buildNotificationTitle(OperationResult.COMPLETE) - ) + buildNotificationTitle(OperationResult.COMPLETE), + ), ) } } @@ -110,16 +110,18 @@ class OpenIndexRespParser( ): String { val indexes = indexNameWithCluster + if (request.indices().size == 1) " has" else " have" - return if (isTimeout) + return if (isTimeout) { "Opening the index $indexes taken more than ${totalWaitTime.toHumanReadableString(1)} to complete. " + "To see the latest status, use `GET /${request.indices().joinToString(",")}/_recovery`" - else if (exception != null) - if (exception is OpenSearchException) + } else if (exception != null) { + if (exception is OpenSearchException) { "index [" + exception.index.name + "] ${exception.message}." - else + } else { exception.message ?: "" - else + } + } else { "$indexes been set to open." + } } override fun buildNotificationTitle(operationResult: OperationResult): String { @@ -130,9 +132,10 @@ class OpenIndexRespParser( else -> "timed out to open" } - return if (request.indices().size == 1) + return if (request.indices().size == 1) { "$indexNameWithCluster has $result" - else + } else { "${request.indices().size} indexes from [${clusterService.clusterName.value()}] have $result" + } } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParser.kt index 3e47bb55e..393a86eee 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParser.kt @@ -6,18 +6,18 @@ package org.opensearch.indexmanagement.controlcenter.notification.filter.parser import org.opensearch.cluster.service.ClusterService +import org.opensearch.core.tasks.TaskId import org.opensearch.index.reindex.BulkByScrollResponse import org.opensearch.index.reindex.ReindexRequest import org.opensearch.indexmanagement.controlcenter.notification.filter.NotificationActionListener import org.opensearch.indexmanagement.controlcenter.notification.filter.OperationResult import org.opensearch.tasks.Task -import org.opensearch.core.tasks.TaskId import java.util.function.Consumer class ReindexRespParser( val task: Task, val request: ReindexRequest, - val clusterService: ClusterService + val clusterService: ClusterService, ) : ResponseParser { private val sourceIndex = getIndexName(request, clusterService) @@ -25,15 +25,15 @@ class ReindexRespParser( override fun parseAndSendNotification( response: BulkByScrollResponse?, ex: Exception?, - callback: Consumer + callback: Consumer, ) { if (ex != null) { callback.accept( ActionRespParseResult( OperationResult.FAILED, buildNotificationMessage(null, ex), - buildNotificationTitle(OperationResult.FAILED) - ) + buildNotificationTitle(OperationResult.FAILED), + ), ) return } @@ -45,24 +45,24 @@ class ReindexRespParser( ActionRespParseResult( OperationResult.FAILED, buildNotificationMessage(response), - buildNotificationTitle(OperationResult.FAILED) - ) + buildNotificationTitle(OperationResult.FAILED), + ), ) } else if (!response.reasonCancelled.isNullOrEmpty()) { callback.accept( ActionRespParseResult( OperationResult.FAILED, buildNotificationMessage(response), - buildNotificationTitle(OperationResult.CANCELLED) - ) + buildNotificationTitle(OperationResult.CANCELLED), + ), ) } else { callback.accept( ActionRespParseResult( OperationResult.COMPLETE, buildNotificationMessage(response), - buildNotificationTitle(OperationResult.COMPLETE) - ) + buildNotificationTitle(OperationResult.COMPLETE), + ), ) } } @@ -70,10 +70,10 @@ class ReindexRespParser( override fun buildNotificationMessage( response: BulkByScrollResponse?, exception: Exception?, - isTimeout: Boolean + isTimeout: Boolean, ): String { val result = StringBuilder( - "The reindex operation from $sourceIndex to ${getIndexName(request.destination, clusterService)} " + "The reindex operation from $sourceIndex to ${getIndexName(request.destination, clusterService)} ", ) if (exception != null) { result.append("${NotificationActionListener.FAILED} ${exception.message}") @@ -104,14 +104,14 @@ class ReindexRespParser( "\nTo see full errors, use `GET /_tasks/$taskId`" } else { NotificationActionListener.COMPLETED - } + }, ) append("\n\n") append("*Summary (number of documents)* \n") append( "Total: ${response.total}, Created: ${response.created}, " + "Updated: ${response.updated}, Deleted: ${response.deleted}, " + - "Conflicts: ${response.versionConflicts}" + "Conflicts: ${response.versionConflicts}", ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParser.kt index 6531f33cb..c7ea9c6a9 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParser.kt @@ -9,16 +9,16 @@ import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.opensearch.ResourceAlreadyExistsException import org.opensearch.action.admin.indices.shrink.ResizeRequest +import org.opensearch.action.admin.indices.shrink.ResizeResponse import org.opensearch.action.support.ActiveShardCount import org.opensearch.action.support.ActiveShardsObserver import org.opensearch.cluster.service.ClusterService import org.opensearch.common.unit.TimeValue +import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.controlcenter.notification.filter.NotificationActionListener import org.opensearch.indexmanagement.controlcenter.notification.filter.OperationResult -import java.util.function.Consumer -import org.opensearch.action.admin.indices.shrink.ResizeResponse -import org.opensearch.index.IndexNotFoundException import java.lang.IllegalStateException +import java.util.function.Consumer class ResizeIndexRespParser( val activeShardsObserver: ActiveShardsObserver, @@ -42,8 +42,8 @@ class ResizeIndexRespParser( ActionRespParseResult( OperationResult.FAILED, buildNotificationMessage(null, ex), - buildNotificationTitle(OperationResult.FAILED) - ) + buildNotificationTitle(OperationResult.FAILED), + ), ) return } @@ -69,8 +69,8 @@ class ResizeIndexRespParser( ActionRespParseResult( result, buildNotificationMessage(response, isTimeout = !shardsAcknowledged), - buildNotificationTitle(result) - ) + buildNotificationTitle(result), + ), ) }, { e: Exception -> @@ -79,18 +79,18 @@ class ResizeIndexRespParser( ActionRespParseResult( OperationResult.FAILED, buildNotificationMessage(response, e), - buildNotificationTitle(OperationResult.FAILED) - ) + buildNotificationTitle(OperationResult.FAILED), + ), ) - } + }, ) } else { callback.accept( ActionRespParseResult( OperationResult.TIMEOUT, buildNotificationMessage(response, isTimeout = true), - buildNotificationTitle(OperationResult.TIMEOUT) - ) + buildNotificationTitle(OperationResult.TIMEOUT), + ), ) } } else { @@ -98,8 +98,8 @@ class ResizeIndexRespParser( ActionRespParseResult( OperationResult.COMPLETE, buildNotificationMessage(response), - buildNotificationTitle(OperationResult.COMPLETE) - ) + buildNotificationTitle(OperationResult.COMPLETE), + ), ) } } @@ -113,8 +113,8 @@ class ResizeIndexRespParser( val action = request.resizeType.name.lowercase() result.append( "The $action operation from $indexWithCluster to ${ - getIndexName(request.targetIndexRequest, clusterService) - } " + getIndexName(request.targetIndexRequest, clusterService) + } ", ).append( if (isTimeout) { "has taken more than ${totalWaitTime.toHumanReadableString(1)} to complete. " + @@ -148,7 +148,7 @@ class ResizeIndexRespParser( } } else { NotificationActionListener.COMPLETED - } + }, ) return result.toString() } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResponseParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResponseParser.kt index d865e8faa..6644e3eca 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResponseParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResponseParser.kt @@ -6,9 +6,9 @@ package org.opensearch.indexmanagement.controlcenter.notification.filter.parser import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.IndicesRequest import org.opensearch.cluster.service.ClusterService +import org.opensearch.core.action.ActionResponse import org.opensearch.index.reindex.ReindexRequest import org.opensearch.indexmanagement.controlcenter.notification.filter.OperationResult import java.util.function.Consumer @@ -17,36 +17,38 @@ interface ResponseParser { fun parseAndSendNotification( response: Response?, ex: Exception? = null, - callback: Consumer + callback: Consumer, ) fun buildNotificationMessage( response: Response?, exception: Exception? = null, - isTimeout: Boolean = false + isTimeout: Boolean = false, ): String fun buildNotificationTitle( - operationResult: OperationResult + operationResult: OperationResult, ): String fun getIndexName(req: ActionRequest, clusterService: ClusterService): String? { var clusterName = clusterService.clusterName.value() return when (req) { is IndicesRequest -> { - if (req.indices().size == 1) + if (req.indices().size == 1) { "[$clusterName/${req.indices().joinToString(",")}]" - else + } else { "[${req.indices().joinToString(",")}] from [$clusterName]" + } } is ReindexRequest -> { clusterName = if (req.remoteInfo != null) "remote cluster ${req.remoteInfo.host}" else clusterName - if (req.searchRequest.indices().size == 1) + if (req.searchRequest.indices().size == 1) { "[$clusterName/${req.searchRequest.indices().joinToString(",")}]" - else + } else { "[${req.searchRequest.indices().joinToString(",")}] from [$clusterName]" + } } else -> { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONCondition.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONCondition.kt index ebdf14039..68d6f265c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONCondition.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONCondition.kt @@ -19,7 +19,7 @@ import java.io.IOException data class LRONCondition( val success: Boolean = DEFAULT_ENABLED, - val failure: Boolean = DEFAULT_ENABLED + val failure: Boolean = DEFAULT_ENABLED, ) : ToXContentObject, Writeable { fun toXContent(builder: XContentBuilder): XContentBuilder { @@ -36,7 +36,7 @@ data class LRONCondition( @Throws(IOException::class) constructor(sin: StreamInput) : this( success = sin.readBoolean(), - failure = sin.readBoolean() + failure = sin.readBoolean(), ) @Throws(IOException::class) @@ -62,7 +62,7 @@ data class LRONCondition( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): LRONCondition { return parse(xcp) } @@ -88,7 +88,7 @@ data class LRONCondition( return LRONCondition( success = success, - failure = failure + failure = failure, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONConfig.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONConfig.kt index 8dab2978a..6338091ed 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONConfig.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/model/LRONConfig.kt @@ -5,24 +5,24 @@ package org.opensearch.indexmanagement.controlcenter.notification.model +import org.opensearch.commons.authuser.User import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable +import org.opensearch.core.tasks.TaskId import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.authuser.User import org.opensearch.index.seqno.SequenceNumbers -import org.opensearch.indexmanagement.controlcenter.notification.util.WITH_PRIORITY import org.opensearch.indexmanagement.common.model.notification.Channel +import org.opensearch.indexmanagement.controlcenter.notification.util.WITH_PRIORITY import org.opensearch.indexmanagement.controlcenter.notification.util.validateTaskIdAndActionName import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_TYPE import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_USER import org.opensearch.indexmanagement.opensearchapi.optionalUserField import org.opensearch.indexmanagement.util.NO_ID -import org.opensearch.core.tasks.TaskId import java.io.IOException data class LRONConfig( @@ -31,7 +31,7 @@ data class LRONConfig( val actionName: String?, val channels: List?, val user: User?, - val priority: Int? + val priority: Int?, ) : ToXContentObject, Writeable { init { validateTaskIdAndActionName(taskId, actionName) @@ -66,13 +66,17 @@ data class LRONConfig( lronCondition = LRONCondition(sin), taskId = if (sin.readBoolean()) { TaskId(sin.readString()) - } else null, + } else { + null + }, actionName = sin.readOptionalString(), channels = if (sin.readBoolean()) { sin.readList(::Channel) - } else null, + } else { + null + }, user = sin.readOptionalWriteable(::User), - priority = sin.readOptionalInt() + priority = sin.readOptionalInt(), ) @Throws(IOException::class) @@ -81,12 +85,16 @@ data class LRONConfig( if (null != taskId) { out.writeBoolean(true) out.writeString(taskId.toString()) - } else out.writeBoolean(false) + } else { + out.writeBoolean(false) + } out.writeOptionalString(actionName) if (null != channels) { out.writeBoolean(true) out.writeList(channels) - } else out.writeBoolean(false) + } else { + out.writeBoolean(false) + } out.writeOptionalWriteable(user) out.writeOptionalInt(priority) } @@ -109,7 +117,7 @@ data class LRONConfig( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): LRONConfig { return parse(xcp) } @@ -159,7 +167,7 @@ data class LRONConfig( actionName = actionName, channels = channels, user = user, - priority = priority + priority = priority, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigAction.kt index f24e243de..b8eef8e1c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigAction.kt @@ -18,7 +18,7 @@ import java.io.IOException class RestDeleteLRONConfigAction : BaseRestHandler() { override fun routes(): List { return listOf( - RestHandler.Route(RestRequest.Method.DELETE, "${IndexManagementPlugin.LRON_BASE_URI}/{id}") + RestHandler.Route(RestRequest.Method.DELETE, "${IndexManagementPlugin.LRON_BASE_URI}/{id}"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigAction.kt index e38825aae..514c96b7e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigAction.kt @@ -9,11 +9,11 @@ import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigAction import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigRequest import org.opensearch.indexmanagement.controlcenter.notification.util.DEFAULT_LRON_CONFIG_SORT_FIELD +import org.opensearch.indexmanagement.util.getSearchParams import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer -import org.opensearch.rest.RestRequest -import org.opensearch.indexmanagement.util.getSearchParams import org.opensearch.rest.RestHandler +import org.opensearch.rest.RestRequest import org.opensearch.rest.action.RestToXContentListener import java.io.IOException @@ -21,7 +21,7 @@ class RestGetLRONConfigAction : BaseRestHandler() { override fun routes(): List { return listOf( RestHandler.Route(RestRequest.Method.GET, IndexManagementPlugin.LRON_BASE_URI), - RestHandler.Route(RestRequest.Method.GET, "${IndexManagementPlugin.LRON_BASE_URI}/{id}") + RestHandler.Route(RestRequest.Method.GET, "${IndexManagementPlugin.LRON_BASE_URI}/{id}"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigAction.kt index b7e0588be..e92cab97b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigAction.kt @@ -6,10 +6,10 @@ package org.opensearch.indexmanagement.controlcenter.notification.resthandler import org.opensearch.client.node.NodeClient +import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.controlcenter.notification.action.index.IndexLRONConfigAction import org.opensearch.indexmanagement.controlcenter.notification.action.index.IndexLRONConfigRequest import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig -import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.controlcenter.notification.util.getDocID import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.util.DRY_RUN @@ -25,7 +25,7 @@ class RestIndexLRONConfigAction : BaseRestHandler() { override fun routes(): List { return listOf( RestHandler.Route(RestRequest.Method.POST, IndexManagementPlugin.LRON_BASE_URI), - RestHandler.Route(RestRequest.Method.PUT, "${IndexManagementPlugin.LRON_BASE_URI}/{id}") + RestHandler.Route(RestRequest.Method.PUT, "${IndexManagementPlugin.LRON_BASE_URI}/{id}"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtils.kt index dfcf81398..3f8dc1c58 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtils.kt @@ -4,24 +4,25 @@ */ @file:JvmName("LRONUtils") + package org.opensearch.indexmanagement.controlcenter.notification.util import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.forcemerge.ForceMergeAction import org.opensearch.action.admin.indices.open.OpenIndexAction import org.opensearch.action.admin.indices.shrink.ResizeAction import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse import org.opensearch.client.node.NodeClient +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.tasks.TaskId import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.index.reindex.ReindexAction import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.controlcenter.notification.LRONConfigResponse import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse -import org.opensearch.core.rest.RestStatus -import org.opensearch.core.tasks.TaskId const val LRON_DOC_ID_PREFIX = "LRON:" @@ -34,7 +35,7 @@ val supportedActions = setOf( ReindexAction.NAME, ResizeAction.NAME, ForceMergeAction.NAME, - OpenIndexAction.NAME + OpenIndexAction.NAME, ) fun validateTaskIdAndActionName(taskId: TaskId?, actionName: String?) { @@ -69,7 +70,7 @@ fun getLRONConfigAndParse( client: NodeClient, docId: String, xContentRegistry: NamedXContentRegistry, - actionListener: ActionListener + actionListener: ActionListener, ) { val getRequest = GetRequest(IndexManagementPlugin.CONTROL_CENTER_INDEX, docId) client.get( @@ -80,8 +81,8 @@ fun getLRONConfigAndParse( actionListener.onFailure( OpenSearchStatusException( "lronConfig $docId not found", - RestStatus.NOT_FOUND - ) + RestStatus.NOT_FOUND, + ), ) return } @@ -97,14 +98,14 @@ fun getLRONConfigAndParse( actionListener.onResponse( LRONConfigResponse( id = response.id, - lronConfig = lronConfig - ) + lronConfig = lronConfig, + ), ) } override fun onFailure(t: Exception) { actionListener.onFailure(t) } - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMTemplateService.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMTemplateService.kt index 0cb0a7b84..2f102a2ba 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMTemplateService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMTemplateService.kt @@ -7,9 +7,9 @@ package org.opensearch.indexmanagement.indexstatemanagement import org.apache.lucene.util.automaton.Operations import org.opensearch.OpenSearchException -import org.opensearch.core.common.Strings import org.opensearch.common.ValidationException import org.opensearch.common.regex.Regex +import org.opensearch.core.common.Strings import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate import org.opensearch.indexmanagement.util.IndexManagementException @@ -35,7 +35,7 @@ fun validateFormat(indexPatterns: List): OpenSearchException? { if (!Strings.validFileNameExcludingAstrix(indexPattern)) { indexPatternFormatErrors.add( "index_pattern [" + indexPattern + "] must not contain the following characters " + - Strings.INVALID_FILENAME_CHARS + Strings.INVALID_FILENAME_CHARS, ) } } @@ -90,7 +90,7 @@ fun overlapping(p1: List, p2: List): Boolean { fun Map>.findConflictingPolicyTemplates( candidate: String, indexPatterns: List, - priority: Int + priority: Int, ): Map> { val overlappingTemplates = mutableMapOf>() diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProvider.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProvider.kt index 471742c87..aa27ef19e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProvider.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProvider.kt @@ -57,7 +57,7 @@ class IndexMetadataProvider( */ suspend fun getMultiTypeISMIndexMetadata( types: List = services.keys.toList(), - indexNames: List + indexNames: List, ): Map> = coroutineScope { if (types.any { it != DEFAULT_INDEX_TYPE } && indexNames.size > 1) throw IllegalArgumentException(MULTIPLE_INDICES_CUSTOM_INDEX_TYPE_ERROR) val requests = ArrayList>>>() diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt index a3e0fd313..7a6aa3c6e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt @@ -6,7 +6,6 @@ package org.opensearch.indexmanagement.indexstatemanagement import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteRequest import org.opensearch.action.admin.cluster.state.ClusterStateRequest import org.opensearch.action.admin.cluster.state.ClusterStateResponse @@ -22,8 +21,9 @@ import org.opensearch.client.Client import org.opensearch.cluster.LocalNodeClusterManagerListener import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.core.action.ActionListener +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings @@ -46,18 +46,24 @@ class IndexStateManagementHistory( private val client: Client, private val threadPool: ThreadPool, private val clusterService: ClusterService, - private val indexManagementIndices: IndexManagementIndices + private val indexManagementIndices: IndexManagementIndices, ) : LocalNodeClusterManagerListener { private val logger = LogManager.getLogger(javaClass) private var scheduledRollover: Scheduler.Cancellable? = null @Volatile private var historyEnabled = ManagedIndexSettings.HISTORY_ENABLED.get(settings) + @Volatile private var historyMaxDocs = ManagedIndexSettings.HISTORY_MAX_DOCS.get(settings) + @Volatile private var historyMaxAge = ManagedIndexSettings.HISTORY_INDEX_MAX_AGE.get(settings) + @Volatile private var historyRolloverCheckPeriod = ManagedIndexSettings.HISTORY_ROLLOVER_CHECK_PERIOD.get(settings) + @Volatile private var historyRetentionPeriod = ManagedIndexSettings.HISTORY_RETENTION_PERIOD.get(settings) + @Volatile private var historyNumberOfShards = ManagedIndexSettings.HISTORY_NUMBER_OF_SHARDS.get(settings) + @Volatile private var historyNumberOfReplicas = ManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS.get(settings) init { @@ -89,7 +95,7 @@ class IndexStateManagementHistory( // schedule the next rollover for approx MAX_AGE later scheduledRollover = threadPool.scheduleWithFixedDelay( { rolloverAndDeleteHistoryIndex() }, - historyRolloverCheckPeriod, ThreadPool.Names.MANAGEMENT + historyRolloverCheckPeriod, ThreadPool.Names.MANAGEMENT, ) } catch (e: Exception) { // This should be run on cluster startup @@ -106,7 +112,7 @@ class IndexStateManagementHistory( scheduledRollover?.cancel() scheduledRollover = threadPool.scheduleWithFixedDelay( { rolloverAndDeleteHistoryIndex() }, - historyRolloverCheckPeriod, ThreadPool.Names.MANAGEMENT + historyRolloverCheckPeriod, ThreadPool.Names.MANAGEMENT, ) } } @@ -137,7 +143,7 @@ class IndexStateManagementHistory( Settings.builder() .put(INDEX_HIDDEN, true) .put(INDEX_NUMBER_OF_SHARDS, historyNumberOfShards) - .put(INDEX_NUMBER_OF_REPLICAS, historyNumberOfReplicas) + .put(INDEX_NUMBER_OF_REPLICAS, historyNumberOfReplicas), ) request.addMaxIndexDocsCondition(historyMaxDocs) request.addMaxIndexAgeCondition(historyMaxAge) @@ -150,7 +156,7 @@ class IndexStateManagementHistory( } else { logger.info( "${IndexManagementIndices.HISTORY_WRITE_INDEX_ALIAS} not rolled over. " + - "Conditions were: ${response.conditionStatus}" + "Conditions were: ${response.conditionStatus}", ) } } @@ -158,13 +164,12 @@ class IndexStateManagementHistory( override fun onFailure(e: Exception) { logger.error("${IndexManagementIndices.HISTORY_WRITE_INDEX_ALIAS} roll over failed.", e) } - } + }, ) } @Suppress("SpreadOperator", "NestedBlockDepth", "ComplexMethod") private fun deleteOldHistoryIndex() { - val clusterStateRequest = ClusterStateRequest() .clear() .indices(IndexManagementIndices.HISTORY_ALL) @@ -188,7 +193,7 @@ class IndexStateManagementHistory( override fun onFailure(exception: Exception) { logger.error("Error fetching cluster state ${exception.message}") } - } + }, ) } @@ -231,7 +236,7 @@ class IndexStateManagementHistory( logger.error("Error deleting old history indices ${exception.message}") deleteOldHistoryIndex(indicesToDelete) } - } + }, ) } } @@ -251,7 +256,7 @@ class IndexStateManagementHistory( override fun onFailure(exception: Exception) { logger.debug("Exception ${exception.message} while deleting the index $index") } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt index cc765acf2..852b76c0c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt @@ -42,12 +42,15 @@ import org.opensearch.common.regex.Regex import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue import org.opensearch.commons.authuser.User -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.index.Index +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.index.IndexNotFoundException import org.opensearch.index.query.QueryBuilders import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX +import org.opensearch.indexmanagement.indexstatemanagement.migration.ISMTemplateService import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.model.coordinator.ClusterStateManagedIndexConfig @@ -75,7 +78,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.isFailed import org.opensearch.indexmanagement.indexstatemanagement.util.isPolicyCompleted import org.opensearch.indexmanagement.indexstatemanagement.util.managedIndexConfigIndexRequest import org.opensearch.indexmanagement.indexstatemanagement.util.updateEnableManagedIndexRequest -import org.opensearch.indexmanagement.indexstatemanagement.migration.ISMTemplateService import org.opensearch.indexmanagement.opensearchapi.IndexManagementSecurityContext import org.opensearch.indexmanagement.opensearchapi.contentParser import org.opensearch.indexmanagement.opensearchapi.parseFromSearchResponse @@ -86,8 +88,6 @@ import org.opensearch.indexmanagement.opensearchapi.withClosableContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ISMIndexMetadata import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.util.OpenForTesting -import org.opensearch.core.rest.RestStatus -import org.opensearch.index.IndexNotFoundException import org.opensearch.search.builder.SearchSourceBuilder import org.opensearch.threadpool.Scheduler import org.opensearch.threadpool.ThreadPool @@ -119,7 +119,7 @@ class ManagedIndexCoordinator( private val metadataService: MetadataService, private val templateService: ISMTemplateService, private val indexMetadataProvider: IndexMetadataProvider, - private val xContentRegistry: NamedXContentRegistry + private val xContentRegistry: NamedXContentRegistry, ) : ClusterStateListener, CoroutineScope by CoroutineScope(SupervisorJob() + Dispatchers.Default + CoroutineName("ManagedIndexCoordinator")), LifecycleListener() { @@ -132,17 +132,26 @@ class ManagedIndexCoordinator( private var scheduledTemplateMigration: Scheduler.Cancellable? = null @Volatile private var lastFullSweepTimeNano = System.nanoTime() + @Volatile private var indexStateManagementEnabled = INDEX_STATE_MANAGEMENT_ENABLED.get(settings) + @Volatile private var metadataServiceEnabled = METADATA_SERVICE_ENABLED.get(settings) + @Volatile private var sweepPeriod = SWEEP_PERIOD.get(settings) + @Volatile private var retryPolicy = BackoffPolicy.constantBackoff(COORDINATOR_BACKOFF_MILLIS.get(settings), COORDINATOR_BACKOFF_COUNT.get(settings)) + @Volatile private var templateMigrationEnabled: Boolean = true + @Volatile private var templateMigrationEnabledSetting = TEMPLATE_MIGRATION_CONTROL.get(settings) + @Volatile private var jobInterval = JOB_INTERVAL.get(settings) + @Volatile private var jobJitter = JITTER.get(settings) @Volatile private var isClusterManager = false + @Volatile private var onClusterManagerTimeStamp: Long = 0L init { @@ -167,12 +176,17 @@ class ManagedIndexCoordinator( if (!metadataServiceEnabled) { logger.info("Canceling metadata moving job because of cluster setting update.") scheduledMoveMetadata?.cancel() - } else initMoveMetadata() + } else { + initMoveMetadata() + } } clusterService.clusterSettings.addSettingsUpdateConsumer(TEMPLATE_MIGRATION_CONTROL) { templateMigrationEnabled = it >= 0L - if (!templateMigrationEnabled) scheduledTemplateMigration?.cancel() - else initTemplateMigration(it) + if (!templateMigrationEnabled) { + scheduledTemplateMigration?.cancel() + } else { + initTemplateMigration(it) + } } clusterService.clusterSettings.addSettingsUpdateConsumer(COORDINATOR_BACKOFF_MILLIS, COORDINATOR_BACKOFF_COUNT) { millis, count -> retryPolicy = BackoffPolicy.constantBackoff(millis, count) @@ -327,7 +341,7 @@ class ManagedIndexCoordinator( @Suppress("NestedBlockDepth", "ComplexCondition") private suspend fun createManagedIndexRequests( clusterState: ClusterState, - indexNames: List + indexNames: List, ): List> { val updateManagedIndexReqs = mutableListOf>() if (indexNames.isEmpty()) return updateManagedIndexReqs @@ -358,8 +372,8 @@ class ManagedIndexCoordinator( policy.id, jobInterval, policy, - jobJitter - ) + jobJitter, + ), ) } } @@ -456,8 +470,8 @@ class ManagedIndexCoordinator( val searchRequest = SearchRequest() .source( SearchSourceBuilder().query( - QueryBuilders.existsQuery(ISM_TEMPLATE_FIELD) - ).size(MAX_HITS).seqNoAndPrimaryTerm(true) + QueryBuilders.existsQuery(ISM_TEMPLATE_FIELD), + ).size(MAX_HITS).seqNoAndPrimaryTerm(true), ) .indices(INDEX_MANAGEMENT_INDEX) .preference(Preference.PRIMARY_FIRST.type()) @@ -572,14 +586,15 @@ class ManagedIndexCoordinator( logger.info("Performing ISM template migration.") if (enableSetting == 0L) { - if (onClusterManagerTimeStamp != 0L) + if (onClusterManagerTimeStamp != 0L) { templateService.doMigration(Instant.ofEpochMilli(onClusterManagerTimeStamp)) - else { + } else { logger.error("No valid onClusterManager time cached, cancel ISM template migration job.") scheduledTemplateMigration?.cancel() } - } else + } else { templateService.doMigration(Instant.ofEpochMilli(enableSetting)) + } } catch (e: Exception) { logger.error("Failed to migrate ISM template", e) } @@ -612,7 +627,7 @@ class ManagedIndexCoordinator( // Get the matching policyIds for applicable indices val updateMatchingIndicesReqs = createManagedIndexRequests( - clusterService.state(), unManagedIndices.map { (indexName, _) -> indexName } + clusterService.state(), unManagedIndices.map { (indexName, _) -> indexName }, ) // check all managed indices, if the index has already been deleted @@ -716,7 +731,7 @@ class ManagedIndexCoordinator( mRes.forEach { if (it.response.isExists) { result[it.id] = contentParser(it.response.sourceAsBytesRef, xContentRegistry).parseWithType( - it.response.id, it.response.seqNo, it.response.primaryTerm, ManagedIndexConfig.Companion::parse + it.response.id, it.response.seqNo, it.response.primaryTerm, ManagedIndexConfig.Companion::parse, ) } } @@ -757,10 +772,12 @@ class ManagedIndexCoordinator( val bulkRequest = BulkRequest().add(deleteRequests) val bulkResponse: BulkResponse = client.suspendUntil { bulk(bulkRequest, it) } bulkResponse.forEach { - if (it.isFailed) logger.error( - "Failed to clear ManagedIndexMetadata for " + - "index uuid: [${it.id}], failureMessage: ${it.failureMessage}" - ) + if (it.isFailed) { + logger.error( + "Failed to clear ManagedIndexMetadata for " + + "index uuid: [${it.id}], failureMessage: ${it.failureMessage}", + ) + } } } } catch (e: Exception) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt index de2f4a3ed..89de1efa5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt @@ -31,13 +31,14 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper +import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.common.xcontent.XContentType import org.opensearch.index.engine.VersionConflictEngineException import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementIndices @@ -47,14 +48,14 @@ import org.opensearch.indexmanagement.indexstatemanagement.model.ErrorNotificati import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getManagedIndexMetadata +import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.ACTION_VALIDATION_ENABLED import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.ALLOW_LIST import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.ALLOW_LIST_NONE +import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.DEFAULT_ACTION_VALIDATION_ENABLED import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.DEFAULT_ISM_ENABLED import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.DEFAULT_JOB_INTERVAL -import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.DEFAULT_ACTION_VALIDATION_ENABLED import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.INDEX_STATE_MANAGEMENT_ENABLED import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.JOB_INTERVAL -import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.ACTION_VALIDATION_ENABLED import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE import org.opensearch.indexmanagement.indexstatemanagement.util.MetadataCheck import org.opensearch.indexmanagement.indexstatemanagement.util.checkMetadata @@ -97,7 +98,6 @@ import org.opensearch.jobscheduler.spi.LockModel import org.opensearch.jobscheduler.spi.ScheduledJobParameter import org.opensearch.jobscheduler.spi.ScheduledJobRunner import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.script.Script import org.opensearch.script.ScriptService import org.opensearch.script.TemplateScript @@ -126,10 +126,13 @@ object ManagedIndexRunner : private lateinit var indexMetadataProvider: IndexMetadataProvider private var indexStateManagementEnabled: Boolean = DEFAULT_ISM_ENABLED private var validationServiceEnabled: Boolean = DEFAULT_ACTION_VALIDATION_ENABLED + @Suppress("MagicNumber") private val savePolicyRetryPolicy = BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(250), 3) + @Suppress("MagicNumber") private val updateMetaDataRetryPolicy = BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(250), 3) + @Suppress("MagicNumber") private val errorNotificationRetryPolicy = BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(250), 3) private var jobInterval: Int = DEFAULT_JOB_INTERVAL @@ -308,8 +311,8 @@ object ManagedIndexRunner : val result = updateManagedIndexMetaData( managedIndexMetaData.copy( policyRetryInfo = PolicyRetryInfoMetaData(true, 0), - info = info - ) + info = info, + ), ) if (result.metadataSaved) { disableManagedIndexConfig(managedIndexConfig) @@ -321,7 +324,7 @@ object ManagedIndexRunner : val state = policy.getStateToExecute(managedIndexMetaData) val action: Action? = state?.getActionToExecute(managedIndexMetaData, indexMetadataProvider) val stepContext = StepContext( - managedIndexMetaData, clusterService, client, threadPool.threadContext, policy.user, scriptService, settings, jobContext.lockService + managedIndexMetaData, clusterService, client, threadPool.threadContext, policy.user, scriptService, settings, jobContext.lockService, ) val step: Step? = action?.getStepToExecute(stepContext) val currentActionMetaData = action?.getUpdatedActionMetadata(managedIndexMetaData, state.name) @@ -338,7 +341,7 @@ object ManagedIndexRunner : logger.error("Action=${action.type} has timed out") val updated = updateManagedIndexMetaData( managedIndexMetaData - .copy(actionMetaData = currentActionMetaData?.copy(failed = true), info = info) + .copy(actionMetaData = currentActionMetaData?.copy(failed = true), info = info), ) if (updated.metadataSaved) { disableManagedIndexConfig(managedIndexConfig) @@ -366,8 +369,8 @@ object ManagedIndexRunner : val info = mapOf("message" to "Previous action was not able to update IndexMetaData.") val updated = updateManagedIndexMetaData( managedIndexMetaData.copy( - policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info - ) + policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info, + ), ) if (updated.metadataSaved) { disableManagedIndexConfig(managedIndexConfig) @@ -383,8 +386,8 @@ object ManagedIndexRunner : val info = mapOf("message" to "Failed to execute action=${action?.type} as extension [$actionExtensionName] is not enabled.") val updated = updateManagedIndexMetaData( managedIndexMetaData.copy( - policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info - ) + policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info, + ), ) if (updated.metadataSaved) { disableManagedIndexConfig(managedIndexConfig) @@ -399,8 +402,8 @@ object ManagedIndexRunner : val info = mapOf("message" to "Attempted to execute action=${action.type} which is not allowed.") val updated = updateManagedIndexMetaData( managedIndexMetaData.copy( - policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info - ) + policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info, + ), ) if (updated.metadataSaved) { disableManagedIndexConfig(managedIndexConfig) @@ -418,8 +421,8 @@ object ManagedIndexRunner : if (validationServiceEnabled) { val validationResult = withClosableContext( IndexManagementSecurityContext( - managedIndexConfig.id, settings, threadPool.threadContext, managedIndexConfig.policy.user - ) + managedIndexConfig.id, settings, threadPool.threadContext, managedIndexConfig.policy.user, + ), ) { actionValidation.validate(action.type, stepContext.metadata.index) } @@ -439,8 +442,8 @@ object ManagedIndexRunner : // Step null check is done in getStartingManagedIndexMetaData withClosableContext( IndexManagementSecurityContext( - managedIndexConfig.id, settings, threadPool.threadContext, managedIndexConfig.policy.user - ) + managedIndexConfig.id, settings, threadPool.threadContext, managedIndexConfig.policy.user, + ), ) { step.preExecute(logger, stepContext.getUpdatedContext(startingManagedIndexMetaData)).execute().postExecute(logger) } @@ -519,7 +522,7 @@ object ManagedIndexRunner : return withContext(Dispatchers.IO) { val xcp = XContentHelper.createParser( xContentRegistry, LoggingDeprecationHandler.INSTANCE, - policySource, XContentType.JSON + policySource, XContentType.JSON, ) xcp.parseWithType(getResponse.id, getResponse.seqNo, getResponse.primaryTerm, Policy.Companion::parse) } @@ -547,7 +550,7 @@ object ManagedIndexRunner : private suspend fun savePolicyToManagedIndexConfig(managedIndexConfig: ManagedIndexConfig, policy: Policy): Boolean { val updatedManagedIndexConfig = managedIndexConfig.copy( policyID = policy.id, policy = policy, - policySeqNo = policy.seqNo, policyPrimaryTerm = policy.primaryTerm, changePolicy = null + policySeqNo = policy.seqNo, policyPrimaryTerm = policy.primaryTerm, changePolicy = null, ) val indexRequest = managedIndexConfigIndexRequest(updatedManagedIndexConfig) var savedPolicy = false @@ -584,12 +587,12 @@ object ManagedIndexRunner : private suspend fun getFailedInitializedManagedIndexMetaData( managedIndexMetaData: ManagedIndexMetaData?, managedIndexConfig: ManagedIndexConfig, - policyID: String + policyID: String, ): ManagedIndexMetaData { // we either haven't initialized any metadata yet or we have already initialized metadata but still have no policy return managedIndexMetaData?.copy( policyRetryInfo = PolicyRetryInfoMetaData(failed = true, consumedRetries = 0), - info = mapOf("message" to "Fail to load policy: $policyID") + info = mapOf("message" to "Fail to load policy: $policyID"), ) ?: ManagedIndexMetaData( index = managedIndexConfig.index, indexUuid = managedIndexConfig.indexUuid, @@ -604,7 +607,7 @@ object ManagedIndexRunner : actionMetaData = null, stepMetaData = null, policyRetryInfo = PolicyRetryInfoMetaData(failed = true, consumedRetries = 0), - info = mapOf("message" to "Fail to load policy: $policyID") + info = mapOf("message" to "Fail to load policy: $policyID"), ) } @@ -612,7 +615,7 @@ object ManagedIndexRunner : private suspend fun getInitializedManagedIndexMetaData( managedIndexMetaData: ManagedIndexMetaData?, managedIndexConfig: ManagedIndexConfig, - policy: Policy + policy: Policy, ): ManagedIndexMetaData { val state = managedIndexConfig.changePolicy?.state ?: policy.defaultState val stateMetaData = StateMetaData(state, Instant.now().toEpochMilli()) @@ -632,7 +635,7 @@ object ManagedIndexRunner : actionMetaData = null, stepMetaData = null, policyRetryInfo = PolicyRetryInfoMetaData(failed = false, consumedRetries = 0), - info = mapOf("message" to "Successfully initialized policy: ${policy.id}") + info = mapOf("message" to "Successfully initialized policy: ${policy.id}"), ) managedIndexMetaData.policySeqNo == null || managedIndexMetaData.policyPrimaryTerm == null -> // If there is seqNo and PrimaryTerm it is first time populating Policy. @@ -642,7 +645,7 @@ object ManagedIndexRunner : policyPrimaryTerm = policy.primaryTerm, stateMetaData = stateMetaData, policyRetryInfo = PolicyRetryInfoMetaData(failed = false, consumedRetries = 0), - info = mapOf("message" to "Successfully initialized policy: ${policy.id}") + info = mapOf("message" to "Successfully initialized policy: ${policy.id}"), ) // this is an edge case where a user deletes the job config or index and we already have a policySeqNo/primaryTerm // in the metadata, in this case we just want to say we successfully initialized the policy again but we will not @@ -653,7 +656,7 @@ object ManagedIndexRunner : // If existing PolicySeqNo and PolicyPrimaryTerm is equal to cached Policy then no issue. managedIndexMetaData.copy( policyRetryInfo = PolicyRetryInfoMetaData(failed = false, consumedRetries = 0), - info = mapOf("message" to "Successfully initialized policy: ${policy.id}") + info = mapOf("message" to "Successfully initialized policy: ${policy.id}"), ) else -> // else this means we either tried to load a policy with a different id, seqno, or primaryterm from what is @@ -664,8 +667,8 @@ object ManagedIndexRunner : "message" to "Fail to load policy: ${policy.id} with " + "seqNo ${policy.seqNo} and primaryTerm ${policy.primaryTerm} as it" + " does not match what's in the metadata [policyID=${managedIndexMetaData.policyID}," + - " policySeqNo=${managedIndexMetaData.policySeqNo}, policyPrimaryTerm=${managedIndexMetaData.policyPrimaryTerm}]" - ) + " policySeqNo=${managedIndexMetaData.policySeqNo}, policyPrimaryTerm=${managedIndexMetaData.policyPrimaryTerm}]", + ), ) } } @@ -677,7 +680,7 @@ object ManagedIndexRunner : private suspend fun updateManagedIndexMetaData( managedIndexMetaData: ManagedIndexMetaData, lastUpdateResult: UpdateMetadataResult? = null, - create: Boolean = false + create: Boolean = false, ): UpdateMetadataResult { var result = UpdateMetadataResult() if (!imIndices.attemptUpdateConfigIndexMapping()) { @@ -706,7 +709,7 @@ object ManagedIndexRunner : logger.error( "There was VersionConflictEngineException trying to update the metadata for " + "${managedIndexMetaData.index}. Message: ${e.message}", - e + e, ) } catch (e: Exception) { logger.error("Failed to save ManagedIndexMetaData for [index=${managedIndexMetaData.index}]", e) @@ -717,7 +720,7 @@ object ManagedIndexRunner : data class UpdateMetadataResult( val metadataSaved: Boolean = false, val seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - val primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + val primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ) /** @@ -728,9 +731,8 @@ object ManagedIndexRunner : private suspend fun initChangePolicy( managedIndexConfig: ManagedIndexConfig, managedIndexMetaData: ManagedIndexMetaData, - actionToExecute: Action? + actionToExecute: Action?, ) { - // should never happen since we only call this if there is a changePolicy, but we'll do it to make changePolicy non null val changePolicy = managedIndexConfig.changePolicy if (changePolicy == null) { @@ -745,14 +747,14 @@ object ManagedIndexRunner : val updatedManagedIndexMetaData = if (policy == null) { managedIndexMetaData.copy( info = mapOf("message" to "Failed to load change policy: ${changePolicy.policyID}"), - policyRetryInfo = PolicyRetryInfoMetaData(failed = true, consumedRetries = 0) + policyRetryInfo = PolicyRetryInfoMetaData(failed = true, consumedRetries = 0), ) } else { // if the action to execute is transition then set the actionMetaData to a new transition metadata to reflect we are // in transition (in case we triggered change policy from entering transition) or to reflect this is a new policy transition phase val newTransitionMetaData = ActionMetaData( TransitionsAction.name, Instant.now().toEpochMilli(), -1, - false, 0, 0, null + false, 0, 0, null, ) val actionMetaData = if (actionToExecute?.type == TransitionsAction.name) { newTransitionMetaData @@ -767,7 +769,7 @@ object ManagedIndexRunner : policyCompleted = false, policySeqNo = policy.seqNo, policyPrimaryTerm = policy.primaryTerm, - policyID = policy.id + policyID = policy.id, ) } @@ -786,11 +788,11 @@ object ManagedIndexRunner : } /* - * Try to update the ManagedIndexMetaData in cluster state, we need to do this first before updating the - * ManagedIndexConfig because if this fails we can fail early and still retry this whole process on the next - * execution whereas if we do the update to ManagedIndexConfig first we lose the ChangePolicy on the job and - * could fail to update the ManagedIndexMetaData which would put us in a bad state - * */ + * Try to update the ManagedIndexMetaData in cluster state, we need to do this first before updating the + * ManagedIndexConfig because if this fails we can fail early and still retry this whole process on the next + * execution whereas if we do the update to ManagedIndexConfig first we lose the ChangePolicy on the job and + * could fail to update the ManagedIndexMetaData which would put us in a bad state + * */ val updated = updateManagedIndexMetaData(updatedManagedIndexMetaData) if (!updated.metadataSaved || policy == null) return @@ -827,7 +829,7 @@ object ManagedIndexRunner : ErrorNotification.CHANNEL_TITLE, metadata, compiledMessage, - policy.user + policy.user, ) } } @@ -940,7 +942,7 @@ object ManagedIndexRunner : if (bulkItemResponse.isFailed) { logger.warn( "Failed to delete managed index job/metadata [id=${bulkItemResponse.id}] for ${managedIndexConfig.index}" + - " after a successful $actionType [result=${bulkItemResponse.failureMessage}]" + " after a successful $actionType [result=${bulkItemResponse.failureMessage}]", ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataService.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataService.kt index e061b3a06..a9967f410 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataService.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.indexstatemanagement import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteRequest import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse @@ -20,7 +19,9 @@ import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue +import org.opensearch.core.action.ActionListener import org.opensearch.core.index.Index +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getManagedIndexMetadata import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings @@ -32,7 +33,6 @@ import org.opensearch.indexmanagement.opensearchapi.retry import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.util.IndexManagementException import org.opensearch.indexmanagement.util.OpenForTesting -import org.opensearch.core.rest.RestStatus import java.lang.Exception /** @@ -45,7 +45,7 @@ class MetadataService( private val client: Client, private val clusterService: ClusterService, private val skipExecution: SkipExecution, - private val imIndices: IndexManagementIndices + private val imIndices: IndexManagementIndices, ) { private val logger = LogManager.getLogger(javaClass) @@ -63,7 +63,9 @@ class MetadataService( // used in coordinator sweep to cancel scheduled process @Volatile final var finishFlag = false private set - fun reenableMetadataService() { finishFlag = false } + fun reenableMetadataService() { + finishFlag = false + } @Volatile private var retryPolicy = BackoffPolicy.constantBackoff(TimeValue.timeValueMillis(50), 3) @@ -87,13 +89,17 @@ class MetadataService( if (!imIndices.indexManagementIndexExists()) { logger.info("ISM config index not exist, so we cancel the metadata migration job.") - finishFlag = true; runningLock = false; runTimeCounter = 0 + finishFlag = true + runningLock = false + runTimeCounter = 0 return } if (runTimeCounter > maxRunTime) { updateStatusSetting(-1) - finishFlag = true; runningLock = false; runTimeCounter = 0 + finishFlag = true + runningLock = false + runTimeCounter = 0 return } logger.info("Doing metadata migration $runTimeCounter time.") @@ -129,23 +135,27 @@ class MetadataService( if (counter++ > 2 && corruptManagedIndices.isEmpty()) { logger.info("Move Metadata succeed, set finish flag to true. Indices failed to get indexed: $failedToIndexIndices") updateStatusSetting(1) - finishFlag = true; runningLock = false; runTimeCounter = 0 + finishFlag = true + runningLock = false + runTimeCounter = 0 return } if (failedToCleanIndices.isNotEmpty()) { logger.info("Failed to clean indices: $failedToCleanIndices. Only clean cluster state metadata in this run.") cleanMetadatas(failedToCleanIndices.toList()) - finishFlag = false; runningLock = false + finishFlag = false + runningLock = false return } } else { - counter = 0; finishFlag = false // index metadata for indices which metadata hasn't been indexed + counter = 0 + finishFlag = false // index metadata for indices which metadata hasn't been indexed val bulkIndexReq = clusterStateManagedIndexMetadata.mapNotNull { it.value }.map { managedIndexMetadataIndexRequest( it, waitRefresh = false, // should be set at bulk request level - create = true // restrict this as create operation + create = true, // restrict this as create operation ) } // remove the part which gonna be indexed from last time failedToIndex @@ -156,7 +166,7 @@ class MetadataService( logger.info("success indexed: ${successfullyIndexedIndices.map { indexUuidMap[it] }}") logger.info( "failed indexed: ${failedToIndexIndices.map { indexUuidMap[it.key] }};" + - "failed reason: ${failedToIndexIndices.values.distinct()}" + "failed reason: ${failedToIndexIndices.values.distinct()}", ) } @@ -195,7 +205,7 @@ class MetadataService( if (!response.isAcknowledged) { logger.error("Update metadata migration setting to $status is not acknowledged") throw IndexManagementException.wrap( - Exception("Update metadata migration setting to $status is not acknowledged") + Exception("Update metadata migration setting to $status is not acknowledged"), ) } else { logger.info("Successfully metadata template migration setting to $status") diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt index 78ccfb299..c74f27c89 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt @@ -6,19 +6,19 @@ package org.opensearch.indexmanagement.indexstatemanagement import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.node.info.NodesInfoAction import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse import org.opensearch.action.admin.cluster.node.info.PluginsAndModules import org.opensearch.client.Client +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.util.OpenForTesting // TODO this can be moved to job scheduler, so that all extended plugin // can avoid running jobs in an upgrading cluster @OpenForTesting class SkipExecution( - private val client: Client + private val client: Client, ) { private val logger = LogManager.getLogger(javaClass) @@ -61,19 +61,23 @@ class SkipExecution( if ((versionSet.size + legacyVersionSet.size) > 1) { flag = true logger.info("There are multiple versions of Index Management plugins in the cluster: [$versionSet, $legacyVersionSet]") - } else flag = false + } else { + flag = false + } if (versionSet.isNotEmpty() && legacyVersionSet.isNotEmpty()) { hasLegacyPlugin = true logger.info("Found legacy plugin versions [$legacyVersionSet] and opensearch plugins versions [$versionSet] in the cluster") - } else hasLegacyPlugin = false + } else { + hasLegacyPlugin = false + } } override fun onFailure(e: Exception) { logger.error("Failed sweeping nodes for ISM plugin versions: $e") flag = false } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasAction.kt index 47111a823..7c8e68e59 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasAction.kt @@ -16,7 +16,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class AliasAction( val actions: List, - index: Int + index: Int, ) : Action(name, index) { /** @@ -28,10 +28,10 @@ class AliasAction( val allowedActionTypes = listOf(IndicesAliasesRequest.AliasActions.Type.ADD, IndicesAliasesRequest.AliasActions.Type.REMOVE) require(actions.all { it.actionType() in allowedActionTypes }) { "Only ADD and REMOVE actions are allowed." } require( - actions.all { it.indices().isNullOrEmpty() } + actions.all { it.indices().isNullOrEmpty() }, ) { "Alias action can only work on its applied index so don't accept index/indices parameter." } require( - actions.all { it.aliases().isNotEmpty() } + actions.all { it.aliases().isNotEmpty() }, ) { "At least one alias needs to be specified." } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationAction.kt index d1bf0d6df..5d8ca7662 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationAction.kt @@ -18,7 +18,7 @@ class AllocationAction( val include: Map, val exclude: Map, val waitFor: Boolean = false, - index: Int + index: Int, ) : Action(name, index) { init { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseAction.kt index 59d08ba68..e1758c62d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseAction.kt @@ -11,7 +11,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class CloseAction( - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteAction.kt index fdd325e81..c22c03d95 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteAction.kt @@ -11,7 +11,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class DeleteAction( - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeAction.kt index e4516b068..17b8f327f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeAction.kt @@ -17,7 +17,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class ForceMergeAction( val maxNumSegments: Int, - index: Int + index: Int, ) : Action(name, index) { init { @@ -33,7 +33,7 @@ class ForceMergeAction( private val stepNameToStep: LinkedHashMap = linkedMapOf( AttemptSetReadOnlyStep.name to attemptSetReadOnlyStep, AttemptCallForceMergeStep.name to attemptCallForceMergeStep, - WaitForForceMergeStep.name to waitForForceMergeStep + WaitForForceMergeStep.name to waitForForceMergeStep, ) @Suppress("ReturnCount") diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionParser.kt index 4eb14de2f..f0f0f26a3 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionParser.kt @@ -35,7 +35,7 @@ class ForceMergeActionParser : ActionParser() { return ForceMergeAction( requireNotNull(maxNumSegments) { "ForceMergeActionConfig maxNumSegments is null" }, - index + index, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityAction.kt index 4be14448b..693d861af 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityAction.kt @@ -15,7 +15,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class IndexPriorityAction( val indexPriority: Int, - index: Int + index: Int, ) : Action(name, index) { init { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionParser.kt index 2db7d6758..cc7c3c3ab 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionParser.kt @@ -35,7 +35,7 @@ class IndexPriorityActionParser : ActionParser() { return IndexPriorityAction( indexPriority = requireNotNull(indexPriority) { "$INDEX_PRIORITY_FIELD is null" }, - index = index + index = index, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationAction.kt index c361d080f..de232074c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationAction.kt @@ -20,7 +20,7 @@ class NotificationAction( val destination: Destination?, val channel: Channel?, val messageTemplate: Script, - index: Int + index: Int, ) : Action(name, index) { init { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionParser.kt index 760f81c28..5e3aed437 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionParser.kt @@ -9,10 +9,10 @@ import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken +import org.opensearch.indexmanagement.common.model.notification.Channel import org.opensearch.indexmanagement.indexstatemanagement.action.NotificationAction.Companion.CHANNEL_FIELD import org.opensearch.indexmanagement.indexstatemanagement.action.NotificationAction.Companion.DESTINATION_FIELD import org.opensearch.indexmanagement.indexstatemanagement.action.NotificationAction.Companion.MESSAGE_TEMPLATE_FIELD -import org.opensearch.indexmanagement.common.model.notification.Channel import org.opensearch.indexmanagement.indexstatemanagement.model.destination.Destination import org.opensearch.indexmanagement.spi.indexstatemanagement.Action import org.opensearch.indexmanagement.spi.indexstatemanagement.ActionParser @@ -50,7 +50,7 @@ class NotificationActionParser : ActionParser() { destination = destination, channel = channel, messageTemplate = requireNotNull(messageTemplate) { "NotificationAction message template is null" }, - index = index + index = index, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenAction.kt index de3247521..a01969317 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenAction.kt @@ -11,7 +11,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class OpenAction( - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyAction.kt index e17e1ae5c..e0c13f61c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyAction.kt @@ -11,7 +11,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class ReadOnlyAction( - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteAction.kt index 3da520302..5d4dc2fd5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteAction.kt @@ -11,7 +11,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class ReadWriteAction( - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountAction.kt index 88ef2f450..5ec5cb447 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountAction.kt @@ -15,7 +15,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class ReplicaCountAction( val numOfReplicas: Int, - index: Int + index: Int, ) : Action(name, index) { init { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionParser.kt index a92156167..90f4e1497 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionParser.kt @@ -34,7 +34,7 @@ class ReplicaCountActionParser : ActionParser() { return ReplicaCountAction( numOfReplicas = requireNotNull(numOfReplicas) { "$ReplicaCountAction.NUMBER_OF_REPLICAS_FIELD is null" }, - index = index + index = index, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverAction.kt index def34512a..a0509f1d8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverAction.kt @@ -5,9 +5,9 @@ package org.opensearch.indexmanagement.indexstatemanagement.action +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.unit.ByteSizeValue -import org.opensearch.common.unit.TimeValue import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.AttemptRolloverStep @@ -21,14 +21,16 @@ class RolloverAction( val minAge: TimeValue?, val minPrimaryShardSize: ByteSizeValue?, val copyAlias: Boolean = false, - index: Int + index: Int, ) : Action(name, index) { init { if (minSize != null) require(minSize.bytes > 0) { "RolloverAction minSize value must be greater than 0" } - if (minPrimaryShardSize != null) require(minPrimaryShardSize.bytes > 0) { - "RolloverActionConfig minPrimaryShardSize value must be greater than 0" + if (minPrimaryShardSize != null) { + require(minPrimaryShardSize.bytes > 0) { + "RolloverActionConfig minPrimaryShardSize value must be greater than 0" + } } if (minDocs != null) require(minDocs > 0) { "RolloverAction minDocs value must be greater than 0" } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionParser.kt index 5da00a714..bbd476611 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionParser.kt @@ -5,9 +5,9 @@ package org.opensearch.indexmanagement.indexstatemanagement.action +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.unit.ByteSizeValue -import org.opensearch.common.unit.TimeValue import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken import org.opensearch.indexmanagement.spi.indexstatemanagement.Action @@ -44,7 +44,7 @@ class RolloverActionParser : ActionParser() { RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD -> minPrimaryShardSize = ByteSizeValue.parseBytesSizeValue( xcp.text(), RolloverAction - .MIN_PRIMARY_SHARD_SIZE_FIELD + .MIN_PRIMARY_SHARD_SIZE_FIELD, ) RolloverAction.COPY_ALIAS_FIELD -> copyAlias = xcp.booleanValue() else -> throw IllegalArgumentException("Invalid field: [$fieldName] found in RolloverAction.") diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupAction.kt index 8adbf9f01..b735dc4e0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupAction.kt @@ -17,7 +17,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class RollupAction( val ismRollup: ISMRollup, - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkAction.kt index 0a599fd0c..0c15f3281 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkAction.kt @@ -30,7 +30,7 @@ class ShrinkAction( val aliases: List?, val switchAliases: Boolean = false, val forceUnsafe: Boolean?, - index: Int + index: Int, ) : Action(name, index) { init { val numSet = arrayOf(maxShardSize != null, percentageOfSourceShards != null, numNewShards != null).count { it } @@ -61,7 +61,7 @@ class ShrinkAction( AttemptMoveShardsStep.name to attemptMoveShardsStep, WaitForMoveShardsStep.name to waitForMoveShardsStep, AttemptShrinkStep.name to attemptShrinkStep, - WaitForShrinkStep.name to waitForShrinkStep + WaitForShrinkStep.name to waitForShrinkStep, ) override fun getSteps(): List = listOf(attemptMoveShardsStep, waitForMoveShardsStep, attemptShrinkStep, waitForShrinkStep) @@ -104,7 +104,9 @@ class ShrinkAction( if (maxShardSize != null) builder.field(MAX_SHARD_SIZE_FIELD, maxShardSize.stringRep) if (percentageOfSourceShards != null) builder.field(PERCENTAGE_OF_SOURCE_SHARDS_FIELD, percentageOfSourceShards) if (targetIndexTemplate != null) builder.field(TARGET_INDEX_TEMPLATE_FIELD, targetIndexTemplate) - if (aliases != null) { builder.aliasesField(aliases) } + if (aliases != null) { + builder.aliasesField(aliases) + } builder.field(SWITCH_ALIASES, switchAliases) if (forceUnsafe != null) builder.field(FORCE_UNSAFE_FIELD, forceUnsafe) builder.endObject() diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotAction.kt index 05489d8bf..ca7b22d50 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotAction.kt @@ -17,7 +17,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class SnapshotAction( val repository: String, val snapshot: String, - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionParser.kt index 97bf15c0d..c545e3cb2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionParser.kt @@ -42,7 +42,7 @@ class SnapshotActionParser : ActionParser() { return SnapshotAction( repository = requireNotNull(repository) { "SnapshotAction repository must be specified" }, snapshot = requireNotNull(snapshot) { "SnapshotAction snapshot must be specified" }, - index = index + index = index, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformAction.kt index 0de34c15b..5daf8bc86 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformAction.kt @@ -17,7 +17,7 @@ import org.opensearch.indexmanagement.transform.model.ISMTransform class TransformAction( val ismTransform: ISMTransform, - index: Int + index: Int, ) : Action(name, index) { companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionsAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionsAction.kt index 60f3a7929..6687d6179 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionsAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionsAction.kt @@ -14,7 +14,7 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext class TransitionsAction( val transitions: List, - val indexMetadataProvider: IndexMetadataProvider + val indexMetadataProvider: IndexMetadataProvider, ) : Action(name, -1) { private val attemptTransitionStep = AttemptTransitionStep(this) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServices.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServices.kt index f6e6f2b42..26b1aaab9 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServices.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServices.kt @@ -9,7 +9,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper -import org.opensearch.core.action.ActionListener import org.opensearch.action.ActionRequestValidationException import org.opensearch.action.DocWriteResponse import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest @@ -26,13 +25,15 @@ import org.opensearch.client.Client import org.opensearch.cluster.metadata.Template import org.opensearch.cluster.service.ClusterService import org.opensearch.common.io.stream.BytesStreamOutput -import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.action.ActionListener +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate @@ -43,7 +44,6 @@ import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.opensearchapi.retry import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.util.OpenForTesting -import org.opensearch.core.rest.RestStatus import java.time.Instant @OpenForTesting @@ -52,14 +52,16 @@ class ISMTemplateService( private val client: Client, private val clusterService: ClusterService, private val xContentRegistry: NamedXContentRegistry, - private val imIndices: IndexManagementIndices + private val imIndices: IndexManagementIndices, ) { private val logger = LogManager.getLogger(javaClass) @Volatile final var finishFlag = false private set - fun reenableTemplateMigration() { finishFlag = false } + fun reenableTemplateMigration() { + finishFlag = false + } @Volatile var runTimeCounter = 0 @@ -279,7 +281,7 @@ class ISMTemplateService( xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.sourceAsBytesRef, - XContentType.JSON + XContentType.JSON, ).use { xcp -> xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, Policy.Companion::parse) } @@ -308,8 +310,9 @@ class ISMTemplateService( var requests = mutableListOf() policiesToUpdate.forEach { policyID, (seqNo, priTerm) -> val ismTemplates = ismTemplateMap[policyID] - if (ismTemplates != null) + if (ismTemplates != null) { requests.add(updateISMTemplateRequest(policyID, ismTemplates, seqNo, priTerm)) + } } retryPolicy.retry(logger, listOf(RestStatus.TOO_MANY_REQUESTS)) { @@ -354,7 +357,7 @@ class ISMTemplateService( data class V1TemplateCache( val patterns: List, val order: Int, - val policyID: String + val policyID: String, ) typealias policyID = String diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ChangePolicy.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ChangePolicy.kt index 36b51af61..88899c2dd 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ChangePolicy.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ChangePolicy.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.model +import org.opensearch.commons.authuser.User import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable @@ -14,7 +15,6 @@ import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.authuser.User import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_USER import org.opensearch.indexmanagement.opensearchapi.optionalUserField import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StateMetaData @@ -35,7 +35,7 @@ data class ChangePolicy( val state: String?, val include: List, val isSafe: Boolean, - val user: User? = null + val user: User? = null, ) : Writeable, ToXContentObject { @Throws(IOException::class) @@ -46,7 +46,9 @@ data class ChangePolicy( isSafe = sin.readBoolean(), user = if (sin.readBoolean()) { User(sin) - } else null + } else { + null + }, ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -112,7 +114,7 @@ data class ChangePolicy( state, include.toList(), isSafe, - user + user, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ErrorNotification.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ErrorNotification.kt index 6fbef5edb..7df0a7d8a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ErrorNotification.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ErrorNotification.kt @@ -22,7 +22,7 @@ import java.io.IOException data class ErrorNotification( val destination: Destination?, val channel: Channel?, - val messageTemplate: Script + val messageTemplate: Script, ) : ToXContentObject, Writeable { init { @@ -44,7 +44,7 @@ data class ErrorNotification( constructor(sin: StreamInput) : this( sin.readOptionalWriteable(::Destination), sin.readOptionalWriteable(::Channel), - Script(sin) + Script(sin), ) @Throws(IOException::class) @@ -84,7 +84,7 @@ data class ErrorNotification( return ErrorNotification( destination = destination, channel = channel, - messageTemplate = requireNotNull(messageTemplate) { "ErrorNotification message template is null" } + messageTemplate = requireNotNull(messageTemplate) { "ErrorNotification message template is null" }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ExplainFilter.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ExplainFilter.kt index 7a2f7c1ca..b9da29072 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ExplainFilter.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ExplainFilter.kt @@ -24,7 +24,7 @@ data class ExplainFilter( val policyID: String? = null, val state: String? = null, val actionType: String? = null, - val failed: Boolean? = null + val failed: Boolean? = null, ) : ToXContentObject, Writeable { @Throws(IOException::class) @@ -32,7 +32,7 @@ data class ExplainFilter( policyID = sin.readOptionalString(), state = sin.readOptionalString(), actionType = sin.readOptionalString(), - failed = sin.readOptionalBoolean() + failed = sin.readOptionalBoolean(), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ISMTemplate.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ISMTemplate.kt index dde11627e..e8968e7b0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ISMTemplate.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ISMTemplate.kt @@ -23,7 +23,7 @@ import java.time.Instant data class ISMTemplate( val indexPatterns: List, val priority: Int, - val lastUpdatedTime: Instant + val lastUpdatedTime: Instant, ) : ToXContentObject, Writeable { init { @@ -43,7 +43,7 @@ data class ISMTemplate( constructor(sin: StreamInput) : this( sin.readStringList(), sin.readInt(), - sin.readInstant() + sin.readInstant(), ) @Throws(IOException::class) @@ -86,7 +86,7 @@ data class ISMTemplate( return ISMTemplate( indexPatterns = indexPatterns, priority = priority, - lastUpdatedTime = lastUpdatedTime ?: Instant.now() + lastUpdatedTime = lastUpdatedTime ?: Instant.now(), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt index 7e8d36268..4347d0c9c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt @@ -37,7 +37,7 @@ data class ManagedIndexConfig( val policyPrimaryTerm: Long?, val policy: Policy?, val changePolicy: ChangePolicy?, - val jobJitter: Double? + val jobJitter: Double?, ) : ScheduledJobParameter { init { @@ -109,7 +109,7 @@ data class ManagedIndexConfig( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): ManagedIndexConfig { var name: String? = null var index: String? = null @@ -180,10 +180,10 @@ data class ManagedIndexConfig( policy = policy?.copy( id = policyID, seqNo = policySeqNo ?: SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm = policyPrimaryTerm ?: SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm = policyPrimaryTerm ?: SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ), changePolicy = changePolicy, - jobJitter = jitter + jobJitter = jitter, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Policy.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Policy.kt index 1d96e0fc4..b389cc388 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Policy.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Policy.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.model +import org.opensearch.commons.authuser.User import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable @@ -14,7 +15,6 @@ import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.authuser.User import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_TYPE import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_USER @@ -39,7 +39,7 @@ data class Policy( val defaultState: String, val states: List, val ismTemplate: List? = null, - val user: User? = null + val user: User? = null, ) : ToXContentObject, Writeable { init { @@ -91,10 +91,14 @@ data class Policy( states = sin.readList(::State), ismTemplate = if (sin.readBoolean()) { sin.readList(::ISMTemplate) - } else null, + } else { + null + }, user = if (sin.readBoolean()) { User(sin) - } else null + } else { + null + }, ) @Throws(IOException::class) @@ -164,7 +168,7 @@ data class Policy( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): Policy { var description: String? = null var defaultState: String? = null @@ -225,7 +229,7 @@ data class Policy( defaultState = requireNotNull(defaultState) { "$DEFAULT_STATE_FIELD is null" }, states = states.toList(), ismTemplate = ismTemplates, - user = user + user = user, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/State.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/State.kt index 43be9a6d8..c703e7405 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/State.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/State.kt @@ -26,7 +26,7 @@ import java.io.IOException data class State( val name: String, val actions: List, - val transitions: List + val transitions: List, ) : ToXContentObject, Writeable { init { @@ -58,7 +58,7 @@ data class State( constructor(sin: StreamInput) : this( sin.readString(), sin.readList { ISMActionsParser.instance.fromStreamInput(it) }, - sin.readList(::Transition) + sin.readList(::Transition), ) @Throws(IOException::class) @@ -70,7 +70,7 @@ data class State( fun getActionToExecute( managedIndexMetaData: ManagedIndexMetaData, - indexMetadataProvider: IndexMetadataProvider + indexMetadataProvider: IndexMetadataProvider, ): Action? { var actionConfig: Action? val actionMetaData = managedIndexMetaData.actionMetaData @@ -140,7 +140,7 @@ data class State( return State( name = requireNotNull(name) { "State name is null" }, actions = actions.toList(), - transitions = transitions.toList() + transitions = transitions.toList(), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/StateFilter.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/StateFilter.kt index 615bac27a..cd9673631 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/StateFilter.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/StateFilter.kt @@ -17,7 +17,7 @@ data class StateFilter(val state: String) : Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( - state = sin.readString() + state = sin.readString(), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Transition.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Transition.kt index bab7bf1e1..3aa6ec1d8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Transition.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Transition.kt @@ -5,11 +5,11 @@ package org.opensearch.indexmanagement.indexstatemanagement.model +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable import org.opensearch.core.common.unit.ByteSizeValue -import org.opensearch.common.unit.TimeValue import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -22,7 +22,7 @@ import java.io.IOException data class Transition( val stateName: String, - val conditions: Conditions? + val conditions: Conditions?, ) : ToXContentObject, Writeable { override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -35,7 +35,7 @@ data class Transition( @Throws(IOException::class) constructor(sin: StreamInput) : this( stateName = sin.readString(), - conditions = sin.readOptionalWriteable(::Conditions) + conditions = sin.readOptionalWriteable(::Conditions), ) @Throws(IOException::class) @@ -68,7 +68,7 @@ data class Transition( return Transition( stateName = requireNotNull(name) { "Transition state name is null" }, - conditions = conditions + conditions = conditions, ) } } @@ -79,7 +79,7 @@ data class Conditions( val docCount: Long? = null, val size: ByteSizeValue? = null, val cron: CronSchedule? = null, - val rolloverAge: TimeValue? = null + val rolloverAge: TimeValue? = null, ) : ToXContentObject, Writeable { init { @@ -109,7 +109,7 @@ data class Conditions( docCount = sin.readOptionalLong(), size = sin.readOptionalWriteable(::ByteSizeValue), cron = sin.readOptionalWriteable(::CronSchedule), - rolloverAge = sin.readOptionalTimeValue() + rolloverAge = sin.readOptionalTimeValue(), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/ClusterStateManagedIndexConfig.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/ClusterStateManagedIndexConfig.kt index 4f63b5e4a..2b9074dc6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/ClusterStateManagedIndexConfig.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/ClusterStateManagedIndexConfig.kt @@ -21,5 +21,5 @@ data class ClusterStateManagedIndexConfig( val seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, val primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, val uuid: String, - val policyID: String + val policyID: String, ) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt index a84dba159..8fd996abc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt @@ -27,7 +27,7 @@ data class SweptManagedIndexConfig( val uuid: String, val policyID: String, val policy: Policy?, - val changePolicy: ChangePolicy? + val changePolicy: ChangePolicy?, ) { companion object { @@ -66,7 +66,7 @@ data class SweptManagedIndexConfig( uuid, policyID, policy, - changePolicy + changePolicy, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Chime.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Chime.kt index 802569f10..46af1b0f1 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Chime.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Chime.kt @@ -33,7 +33,7 @@ data class Chime(val url: String) : ToXContent, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( - sin.readString() + sin.readString(), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/CustomWebhook.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/CustomWebhook.kt index 6d5d9d4ce..3e1829d53 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/CustomWebhook.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/CustomWebhook.kt @@ -32,7 +32,7 @@ data class CustomWebhook( val queryParams: Map, val headerParams: Map, val username: String?, - val password: String? + val password: String?, ) : ToXContent, Writeable { init { @@ -64,7 +64,7 @@ data class CustomWebhook( suppressWarning(sin.readMap()), suppressWarning(sin.readMap()), sin.readOptionalString(), - sin.readOptionalString() + sin.readOptionalString(), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt index 32ff35b38..1d7772206 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt @@ -5,6 +5,10 @@ package org.opensearch.indexmanagement.indexstatemanagement.model.destination +import org.opensearch.commons.destination.message.LegacyBaseMessage +import org.opensearch.commons.destination.message.LegacyChimeMessage +import org.opensearch.commons.destination.message.LegacyCustomWebhookMessage +import org.opensearch.commons.destination.message.LegacySlackMessage import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable @@ -14,10 +18,6 @@ import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.destination.message.LegacyBaseMessage -import org.opensearch.commons.destination.message.LegacyChimeMessage -import org.opensearch.commons.destination.message.LegacyCustomWebhookMessage -import org.opensearch.commons.destination.message.LegacySlackMessage import org.opensearch.indexmanagement.opensearchapi.convertToMap import java.io.IOException @@ -31,7 +31,7 @@ data class Destination( val type: DestinationType, val chime: Chime?, val slack: Slack?, - val customWebhook: CustomWebhook? + val customWebhook: CustomWebhook?, ) : ToXContentObject, Writeable { override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -46,7 +46,7 @@ data class Destination( sin.readEnum(DestinationType::class.java), sin.readOptionalWriteable(::Chime), sin.readOptionalWriteable(::Slack), - sin.readOptionalWriteable(::CustomWebhook) + sin.readOptionalWriteable(::CustomWebhook), ) @Throws(IOException::class) @@ -94,7 +94,7 @@ data class Destination( type, chime, slack, - customWebhook + customWebhook, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Slack.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Slack.kt index c75759310..508194ec8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Slack.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/destination/Slack.kt @@ -33,7 +33,7 @@ data class Slack(val url: String) : ToXContent, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( - sin.readString() + sin.readString(), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/opensearchapi/OpenSearchExtensions.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/opensearchapi/OpenSearchExtensions.kt index cb7e4c6ad..3174eccc8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/opensearchapi/OpenSearchExtensions.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/opensearchapi/OpenSearchExtensions.kt @@ -20,12 +20,12 @@ import org.opensearch.client.Client import org.opensearch.cluster.ClusterState import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentHelper +import org.opensearch.common.xcontent.XContentType import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder -import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.common.xcontent.XContentType import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.DefaultIndexMetadataService @@ -105,7 +105,7 @@ suspend fun Client.getManagedIndexMetadata(indexUUID: String): Pair): List?>() diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyAction.kt index 2601b2b40..665a6c441 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyAction.kt @@ -6,8 +6,8 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.opensearch.client.node.NodeClient -import org.opensearch.core.common.Strings import org.opensearch.common.xcontent.XContentHelper +import org.opensearch.core.common.Strings import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ISM_BASE_URI import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.indexmanagement.indexstatemanagement.transport.action.addpolicy.AddPolicyAction @@ -35,12 +35,12 @@ class RestAddPolicyAction : BaseRestHandler() { return listOf( ReplacedRoute( POST, ADD_POLICY_BASE_URI, - POST, LEGACY_ADD_POLICY_BASE_URI + POST, LEGACY_ADD_POLICY_BASE_URI, ), ReplacedRoute( POST, "$ADD_POLICY_BASE_URI/{index}", - POST, "$LEGACY_ADD_POLICY_BASE_URI/{index}" - ) + POST, "$LEGACY_ADD_POLICY_BASE_URI/{index}", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyAction.kt index 8b2dc16a4..79fc4c059 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyAction.kt @@ -35,12 +35,12 @@ class RestChangePolicyAction : BaseRestHandler() { return listOf( ReplacedRoute( POST, CHANGE_POLICY_BASE_URI, - POST, LEGACY_CHANGE_POLICY_BASE_URI + POST, LEGACY_CHANGE_POLICY_BASE_URI, ), ReplacedRoute( POST, "$CHANGE_POLICY_BASE_URI/{index}", - POST, "$LEGACY_CHANGE_POLICY_BASE_URI/{index}" - ) + POST, "$LEGACY_CHANGE_POLICY_BASE_URI/{index}", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestDeletePolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestDeletePolicyAction.kt index f73c3bf4d..2945f12cf 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestDeletePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestDeletePolicyAction.kt @@ -30,8 +30,8 @@ class RestDeletePolicyAction : BaseRestHandler() { return listOf( ReplacedRoute( DELETE, "$POLICY_BASE_URI/{policyID}", - DELETE, "$LEGACY_POLICY_BASE_URI/{policyID}" - ) + DELETE, "$LEGACY_POLICY_BASE_URI/{policyID}", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainAction.kt index 5877a3da0..271f51b76 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainAction.kt @@ -7,8 +7,8 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.apache.logging.log4j.LogManager import org.opensearch.client.node.NodeClient -import org.opensearch.core.common.Strings import org.opensearch.common.logging.DeprecationLogger +import org.opensearch.core.common.Strings import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ISM_BASE_URI @@ -16,12 +16,12 @@ import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM import org.opensearch.indexmanagement.indexstatemanagement.model.ExplainFilter import org.opensearch.indexmanagement.indexstatemanagement.transport.action.explain.ExplainAction import org.opensearch.indexmanagement.indexstatemanagement.transport.action.explain.ExplainRequest -import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_EXPLAIN_VALIDATE_ACTION import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_EXPLAIN_SHOW_POLICY -import org.opensearch.indexmanagement.indexstatemanagement.util.SHOW_VALIDATE_ACTION +import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_EXPLAIN_VALIDATE_ACTION import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_JOB_SORT_FIELD import org.opensearch.indexmanagement.indexstatemanagement.util.SHOW_POLICY_QUERY_PARAM +import org.opensearch.indexmanagement.indexstatemanagement.util.SHOW_VALIDATE_ACTION import org.opensearch.indexmanagement.indexstatemanagement.util.TYPE_PARAM_KEY import org.opensearch.indexmanagement.indexstatemanagement.util.parseClusterManagerTimeout import org.opensearch.indexmanagement.util.getSearchParams @@ -51,20 +51,20 @@ class RestExplainAction : BaseRestHandler() { return listOf( ReplacedRoute( GET, EXPLAIN_BASE_URI, - GET, LEGACY_EXPLAIN_BASE_URI + GET, LEGACY_EXPLAIN_BASE_URI, ), ReplacedRoute( GET, "$EXPLAIN_BASE_URI/{index}", - GET, "$LEGACY_EXPLAIN_BASE_URI/{index}" + GET, "$LEGACY_EXPLAIN_BASE_URI/{index}", ), ReplacedRoute( POST, EXPLAIN_BASE_URI, - POST, LEGACY_EXPLAIN_BASE_URI + POST, LEGACY_EXPLAIN_BASE_URI, ), ReplacedRoute( POST, "$EXPLAIN_BASE_URI/{index}", - POST, "$LEGACY_EXPLAIN_BASE_URI/{index}" - ) + POST, "$LEGACY_EXPLAIN_BASE_URI/{index}", + ), ) } @@ -90,7 +90,7 @@ class RestExplainAction : BaseRestHandler() { } val clusterManagerTimeout = parseClusterManagerTimeout( - request, DeprecationLogger.getLogger(RestExplainAction::class.java), name + request, DeprecationLogger.getLogger(RestExplainAction::class.java), name, ) val explainRequest = ExplainRequest( @@ -101,7 +101,7 @@ class RestExplainAction : BaseRestHandler() { explainFilter, request.paramAsBoolean(SHOW_POLICY_QUERY_PARAM, DEFAULT_EXPLAIN_SHOW_POLICY), request.paramAsBoolean(SHOW_VALIDATE_ACTION, DEFAULT_EXPLAIN_VALIDATE_ACTION), - indexType + indexType, ) return RestChannelConsumer { channel -> diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestGetPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestGetPolicyAction.kt index c8d4acf87..aa9883ac8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestGetPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestGetPolicyAction.kt @@ -38,16 +38,16 @@ class RestGetPolicyAction : BaseRestHandler() { return listOf( ReplacedRoute( GET, POLICY_BASE_URI, - GET, LEGACY_POLICY_BASE_URI + GET, LEGACY_POLICY_BASE_URI, ), ReplacedRoute( GET, "$POLICY_BASE_URI/{policyID}", - GET, "$LEGACY_POLICY_BASE_URI/{policyID}" + GET, "$LEGACY_POLICY_BASE_URI/{policyID}", ), ReplacedRoute( HEAD, "$POLICY_BASE_URI/{policyID}", - HEAD, "$LEGACY_POLICY_BASE_URI/{policyID}" - ) + HEAD, "$LEGACY_POLICY_BASE_URI/{policyID}", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt index a75b5dfc6..3b53b1745 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt @@ -9,6 +9,7 @@ import org.opensearch.action.support.WriteRequest import org.opensearch.client.node.NodeClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_POLICY_BASE_URI @@ -31,14 +32,13 @@ import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.PUT import org.opensearch.rest.RestResponse -import org.opensearch.core.rest.RestStatus import org.opensearch.rest.action.RestResponseListener import java.io.IOException import java.time.Instant class RestIndexPolicyAction( settings: Settings, - val clusterService: ClusterService + val clusterService: ClusterService, ) : BaseRestHandler() { @Volatile private var allowList = ALLOW_LIST.get(settings) @@ -55,12 +55,12 @@ class RestIndexPolicyAction( return listOf( ReplacedRoute( PUT, POLICY_BASE_URI, - PUT, LEGACY_POLICY_BASE_URI + PUT, LEGACY_POLICY_BASE_URI, ), ReplacedRoute( PUT, "$POLICY_BASE_URI/{policyID}", - PUT, "$LEGACY_POLICY_BASE_URI/{policyID}" - ) + PUT, "$LEGACY_POLICY_BASE_URI/{policyID}", + ), ) } @@ -92,8 +92,8 @@ class RestIndexPolicyAction( channel.sendResponse( BytesRestResponse( RestStatus.FORBIDDEN, - "You have actions that are not allowed in your policy $disallowedActions" - ) + "You have actions that are not allowed in your policy $disallowedActions", + ), ) } } @@ -112,7 +112,7 @@ class RestIndexPolicyAction( } return restResponse } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyAction.kt index 33720ae70..a169a8481 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyAction.kt @@ -31,12 +31,12 @@ class RestRemovePolicyAction : BaseRestHandler() { return listOf( ReplacedRoute( POST, REMOVE_POLICY_BASE_URI, - POST, LEGACY_REMOVE_POLICY_BASE_URI + POST, LEGACY_REMOVE_POLICY_BASE_URI, ), ReplacedRoute( POST, "$REMOVE_POLICY_BASE_URI/{index}", - POST, "$LEGACY_REMOVE_POLICY_BASE_URI/{index}" - ) + POST, "$LEGACY_REMOVE_POLICY_BASE_URI/{index}", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexAction.kt index 7d92534a0..795832702 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexAction.kt @@ -6,9 +6,9 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.opensearch.client.node.NodeClient -import org.opensearch.core.common.Strings import org.opensearch.common.logging.DeprecationLogger import org.opensearch.common.xcontent.XContentHelper +import org.opensearch.core.common.Strings import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ISM_BASE_URI import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.indexmanagement.indexstatemanagement.transport.action.retryfailedmanagedindex.RetryFailedManagedIndexAction @@ -34,12 +34,12 @@ class RestRetryFailedManagedIndexAction : BaseRestHandler() { return listOf( ReplacedRoute( POST, RETRY_BASE_URI, - POST, LEGACY_RETRY_BASE_URI + POST, LEGACY_RETRY_BASE_URI, ), ReplacedRoute( POST, "$RETRY_BASE_URI/{index}", - POST, "$LEGACY_RETRY_BASE_URI/{index}" - ) + POST, "$LEGACY_RETRY_BASE_URI/{index}", + ), ) } @@ -62,13 +62,13 @@ class RestRetryFailedManagedIndexAction : BaseRestHandler() { val indexType = request.param(TYPE_PARAM_KEY, DEFAULT_INDEX_TYPE) val clusterManagerTimeout = parseClusterManagerTimeout( - request, DeprecationLogger.getLogger(RestRetryFailedManagedIndexAction::class.java), name + request, DeprecationLogger.getLogger(RestRetryFailedManagedIndexAction::class.java), name, ) val retryFailedRequest = RetryFailedManagedIndexRequest( indices.toList(), body["state"] as String?, clusterManagerTimeout, - indexType + indexType, ) return RestChannelConsumer { channel -> diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/LegacyOpenDistroManagedIndexSettings.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/LegacyOpenDistroManagedIndexSettings.kt index fa6d6a74b..49725692a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/LegacyOpenDistroManagedIndexSettings.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/LegacyOpenDistroManagedIndexSettings.kt @@ -27,7 +27,7 @@ class LegacyOpenDistroManagedIndexSettings { DEFAULT_ISM_ENABLED, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) // 0: migration is going on @@ -37,7 +37,7 @@ class LegacyOpenDistroManagedIndexSettings { "opendistro.index_state_management.metadata_migration.status", DEFAULT_METADATA_SERVICE_STATUS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) // 0: enabled, use onClusterManager time as ISM template last_updated_time @@ -49,7 +49,7 @@ class LegacyOpenDistroManagedIndexSettings { ManagedIndexSettings.DEFAULT_TEMPLATE_MIGRATION_TIMESTAMP, -2L, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val METADATA_SERVICE_ENABLED: Setting = Setting.boolSetting( @@ -57,21 +57,21 @@ class LegacyOpenDistroManagedIndexSettings { DEFAULT_METADATA_SERVICE_ENABLED, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val POLICY_ID: Setting = Setting.simpleString( "index.opendistro.index_state_management.policy_id", Setting.Property.IndexScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLOVER_ALIAS: Setting = Setting.simpleString( "index.opendistro.index_state_management.rollover_alias", Setting.Property.IndexScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLOVER_SKIP: Setting = Setting.boolSetting( @@ -79,14 +79,14 @@ class LegacyOpenDistroManagedIndexSettings { false, Setting.Property.IndexScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val AUTO_MANAGE: Setting = Setting.boolSetting( "index.opendistro.index_state_management.auto_manage", true, Setting.Property.IndexScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val JOB_INTERVAL: Setting = Setting.intSetting( @@ -95,7 +95,7 @@ class LegacyOpenDistroManagedIndexSettings { 1, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val SWEEP_PERIOD: Setting = Setting.timeSetting( @@ -104,7 +104,7 @@ class LegacyOpenDistroManagedIndexSettings { TimeValue.timeValueMinutes(5), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val COORDINATOR_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( @@ -112,7 +112,7 @@ class LegacyOpenDistroManagedIndexSettings { TimeValue.timeValueMillis(50), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val COORDINATOR_BACKOFF_COUNT: Setting = Setting.intSetting( @@ -121,7 +121,7 @@ class LegacyOpenDistroManagedIndexSettings { 0, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val HISTORY_ENABLED: Setting = Setting.boolSetting( @@ -129,7 +129,7 @@ class LegacyOpenDistroManagedIndexSettings { true, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val HISTORY_MAX_DOCS: Setting = Setting.longSetting( @@ -138,7 +138,7 @@ class LegacyOpenDistroManagedIndexSettings { 0L, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val HISTORY_INDEX_MAX_AGE: Setting = Setting.positiveTimeSetting( @@ -146,7 +146,7 @@ class LegacyOpenDistroManagedIndexSettings { TimeValue.timeValueHours(24), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val HISTORY_ROLLOVER_CHECK_PERIOD: Setting = Setting.positiveTimeSetting( @@ -154,7 +154,7 @@ class LegacyOpenDistroManagedIndexSettings { TimeValue.timeValueHours(8), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val HISTORY_RETENTION_PERIOD: Setting = Setting.positiveTimeSetting( @@ -162,7 +162,7 @@ class LegacyOpenDistroManagedIndexSettings { TimeValue(30, TimeUnit.DAYS), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val HISTORY_NUMBER_OF_SHARDS: Setting = Setting.intSetting( @@ -170,7 +170,7 @@ class LegacyOpenDistroManagedIndexSettings { 1, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val HISTORY_NUMBER_OF_REPLICAS: Setting = Setting.intSetting( @@ -178,7 +178,7 @@ class LegacyOpenDistroManagedIndexSettings { 1, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ALLOW_LIST: Setting> = Setting.listSetting( @@ -187,7 +187,7 @@ class LegacyOpenDistroManagedIndexSettings { Function.identity(), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val SNAPSHOT_DENY_LIST: Setting> = Setting.listSetting( @@ -196,7 +196,7 @@ class LegacyOpenDistroManagedIndexSettings { Function.identity(), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val RESTRICTED_INDEX_PATTERN = Setting.simpleString( @@ -204,7 +204,7 @@ class LegacyOpenDistroManagedIndexSettings { ManagedIndexSettings.DEFAULT_RESTRICTED_PATTERN, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/ManagedIndexSettings.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/ManagedIndexSettings.kt index 56bda817e..2dbca5b7e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/ManagedIndexSettings.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/settings/ManagedIndexSettings.kt @@ -26,14 +26,14 @@ class ManagedIndexSettings { "plugins.index_state_management.enabled", LegacyOpenDistroManagedIndexSettings.INDEX_STATE_MANAGEMENT_ENABLED, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ACTION_VALIDATION_ENABLED: Setting = Setting.boolSetting( "plugins.index_state_management.action_validation.enabled", DEFAULT_ACTION_VALIDATION_ENABLED, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) // 0: migration is going on @@ -43,7 +43,7 @@ class ManagedIndexSettings { "plugins.index_state_management.metadata_migration.status", LegacyOpenDistroManagedIndexSettings.METADATA_SERVICE_STATUS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) // 0: enabled, use onClusterManager time as ISM template last_updated_time @@ -55,42 +55,42 @@ class ManagedIndexSettings { LegacyOpenDistroManagedIndexSettings.TEMPLATE_MIGRATION_CONTROL, -2L, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val METADATA_SERVICE_ENABLED: Setting = Setting.boolSetting( "plugins.index_state_management.metadata_service.enabled", LegacyOpenDistroManagedIndexSettings.METADATA_SERVICE_ENABLED, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val POLICY_ID: Setting = Setting.simpleString( "index.plugins.index_state_management.policy_id", LegacyOpenDistroManagedIndexSettings.POLICY_ID, Setting.Property.IndexScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLOVER_ALIAS: Setting = Setting.simpleString( "index.plugins.index_state_management.rollover_alias", LegacyOpenDistroManagedIndexSettings.ROLLOVER_ALIAS, Setting.Property.IndexScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLOVER_SKIP: Setting = Setting.boolSetting( "index.plugins.index_state_management.rollover_skip", LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP, Setting.Property.IndexScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val AUTO_MANAGE: Setting = Setting.boolSetting( "index.plugins.index_state_management.auto_manage", LegacyOpenDistroManagedIndexSettings.AUTO_MANAGE, Setting.Property.IndexScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val JOB_INTERVAL: Setting = Setting.intSetting( @@ -98,7 +98,7 @@ class ManagedIndexSettings { LegacyOpenDistroManagedIndexSettings.JOB_INTERVAL, 1, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val SWEEP_PERIOD: Setting = Setting.timeSetting( @@ -106,21 +106,21 @@ class ManagedIndexSettings { LegacyOpenDistroManagedIndexSettings.SWEEP_PERIOD, TimeValue.timeValueMinutes(5), Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val SWEEP_SKIP_PERIOD: Setting = Setting.timeSetting( "plugins.index_state_management.coordinator.sweep_skip_period", TimeValue.timeValueMinutes(5), Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val COORDINATOR_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( "plugins.index_state_management.coordinator.backoff_millis", LegacyOpenDistroManagedIndexSettings.COORDINATOR_BACKOFF_MILLIS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val COORDINATOR_BACKOFF_COUNT: Setting = Setting.intSetting( @@ -128,14 +128,14 @@ class ManagedIndexSettings { LegacyOpenDistroManagedIndexSettings.COORDINATOR_BACKOFF_COUNT, 0, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val HISTORY_ENABLED: Setting = Setting.boolSetting( "plugins.index_state_management.history.enabled", LegacyOpenDistroManagedIndexSettings.HISTORY_ENABLED, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val HISTORY_MAX_DOCS: Setting = Setting.longSetting( @@ -143,42 +143,42 @@ class ManagedIndexSettings { LegacyOpenDistroManagedIndexSettings.HISTORY_MAX_DOCS, // 1 doc is ~10kb or less. This many doc is roughly 25gb 0L, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val HISTORY_INDEX_MAX_AGE: Setting = Setting.positiveTimeSetting( "plugins.index_state_management.history.max_age", LegacyOpenDistroManagedIndexSettings.HISTORY_INDEX_MAX_AGE, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val HISTORY_ROLLOVER_CHECK_PERIOD: Setting = Setting.positiveTimeSetting( "plugins.index_state_management.history.rollover_check_period", LegacyOpenDistroManagedIndexSettings.HISTORY_ROLLOVER_CHECK_PERIOD, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val HISTORY_RETENTION_PERIOD: Setting = Setting.positiveTimeSetting( "plugins.index_state_management.history.rollover_retention_period", LegacyOpenDistroManagedIndexSettings.HISTORY_RETENTION_PERIOD, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val HISTORY_NUMBER_OF_SHARDS: Setting = Setting.intSetting( "plugins.index_state_management.history.number_of_shards", LegacyOpenDistroManagedIndexSettings.HISTORY_NUMBER_OF_SHARDS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val HISTORY_NUMBER_OF_REPLICAS: Setting = Setting.intSetting( "plugins.index_state_management.history.number_of_replicas", LegacyOpenDistroManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ALLOW_LIST: Setting> = Setting.listSetting( @@ -186,7 +186,7 @@ class ManagedIndexSettings { LegacyOpenDistroManagedIndexSettings.ALLOW_LIST, Function.identity(), Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val SNAPSHOT_DENY_LIST: Setting> = Setting.listSetting( @@ -194,7 +194,7 @@ class ManagedIndexSettings { LegacyOpenDistroManagedIndexSettings.SNAPSHOT_DENY_LIST, Function.identity(), Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val JITTER: Setting = Setting.doubleSetting( @@ -203,14 +203,14 @@ class ManagedIndexSettings { 0.0, 1.0, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val RESTRICTED_INDEX_PATTERN = Setting.simpleString( "plugins.index_state_management.restricted_index_pattern", LegacyOpenDistroManagedIndexSettings.RESTRICTED_INDEX_PATTERN, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt index 6952416a0..b05737b21 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt @@ -51,7 +51,7 @@ class AttemptAliasActionsStep(private val action: AliasAction) : Step(name) { private fun handleResponse( response: AcknowledgedResponse, indexName: String, - actions: List + actions: List, ) { if (response.isAcknowledged) { stepStatus = StepStatus.COMPLETED @@ -66,7 +66,7 @@ class AttemptAliasActionsStep(private val action: AliasAction) : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } @@ -77,7 +77,7 @@ class AttemptAliasActionsStep(private val action: AliasAction) : Step(name) { const val name = "attempt_alias" fun getFailedMessage( index: String, - actions: List + actions: List, ) = "Failed to update alias [index=$index] for actions: [actions=$actions]" fun getSuccessMessage(index: String) = "Successfully updated alias [index=$index]" diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt index 4d18652b1..cac8ccc0a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt @@ -68,7 +68,7 @@ class AttemptAllocationStep(private val action: AllocationAction) : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt index 3e02ecb91..be69427c8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt @@ -78,7 +78,7 @@ class AttemptCloseStep : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt index 8019130a2..9b3032850 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt @@ -75,7 +75,7 @@ class AttemptDeleteStep : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt index 58b455d00..e526872de 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt @@ -14,6 +14,7 @@ import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest import org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.action.ForceMergeAction import org.opensearch.indexmanagement.opensearchapi.getUsefulCauseString import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -21,7 +22,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -36,7 +36,6 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam val context = this.context ?: return this val indexName = context.metadata.index try { - val startTime = Instant.now().toEpochMilli() val request = ForceMergeRequest(indexName).maxNumSegments(action.maxNumSegments) var response: ForceMergeResponse? = null @@ -69,7 +68,7 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam info = mapOf( "message" to getFailedMessage(indexName), "status" to shadowedResponse.status, - "shard_failures" to shadowedResponse.shardFailures.map { it.getUsefulCauseString() } + "shard_failures" to shadowedResponse.shardFailures.map { it.getUsefulCauseString() }, ) } } catch (e: RemoteTransportException) { @@ -99,7 +98,7 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam actionMetaData = currentActionMetaData?.copy(actionProperties = ActionProperties(maxNumSegments = action.maxNumSegments)), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt index 60399ec51..f082845bf 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt @@ -82,7 +82,7 @@ class AttemptSetReadOnlyStep(private val action: ForceMergeAction) : Step(name) currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) override fun isIdempotent() = true diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt index e07560975..6a70a6a92 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.step.forcemerge import org.apache.logging.log4j.LogManager import org.opensearch.action.admin.indices.stats.IndicesStatsRequest import org.opensearch.action.admin.indices.stats.IndicesStatsResponse +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.action.ForceMergeAction import org.opensearch.indexmanagement.opensearchapi.getUsefulCauseString import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -16,7 +17,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionPrope import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData -import org.opensearch.core.rest.RestStatus import java.time.Duration import java.time.Instant @@ -62,7 +62,7 @@ class WaitForForceMergeStep(private val action: ForceMergeAction) : Step(name, f if (timeWaitingForForceMerge.seconds > timeoutInSeconds) { logger.error( "Force merge on [$indexName] timed out with" + - " [$shardsStillMergingSegments] shards containing unmerged segments" + " [$shardsStillMergingSegments] shards containing unmerged segments", ) stepStatus = StepStatus.FAILED @@ -70,7 +70,7 @@ class WaitForForceMergeStep(private val action: ForceMergeAction) : Step(name, f } else { logger.debug( "Force merge still running on [$indexName] with" + - " [$shardsStillMergingSegments] shards containing unmerged segments" + " [$shardsStillMergingSegments] shards containing unmerged segments", ) stepStatus = StepStatus.CONDITION_NOT_MET @@ -89,7 +89,7 @@ class WaitForForceMergeStep(private val action: ForceMergeAction) : Step(name, f stepStatus = StepStatus.FAILED info = mapOf( "message" to "Unable to retrieve [${ActionProperties.Properties.MAX_NUM_SEGMENTS.key}]" + - " from ActionProperties=$actionProperties" + " from ActionProperties=$actionProperties", ) return null } @@ -119,7 +119,7 @@ class WaitForForceMergeStep(private val action: ForceMergeAction) : Step(name, f stepStatus = StepStatus.FAILED info = mapOf( "message" to message, - "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() } + "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) } catch (e: Exception) { val message = getFailedSegmentCheckMessage(indexName) @@ -145,14 +145,17 @@ class WaitForForceMergeStep(private val action: ForceMergeAction) : Step(name, f // if the step is completed set actionProperties back to null val currentActionMetaData = currentMetadata.actionMetaData val updatedActionMetaData = currentActionMetaData?.let { - if (stepStatus != StepStatus.COMPLETED) it - else currentActionMetaData.copy(actionProperties = null) + if (stepStatus != StepStatus.COMPLETED) { + it + } else { + currentActionMetaData.copy(actionProperties = null) + } } return currentMetadata.copy( actionMetaData = updatedActionMetaData, stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt index 1ce082aaf..d30bc9b3f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt @@ -68,7 +68,7 @@ class AttemptSetIndexPriorityStep(private val action: IndexPriorityAction) : Ste return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt index 22953bc61..2f667185d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt @@ -55,7 +55,7 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt index 2f9987d6e..c2ae52334 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt @@ -59,7 +59,7 @@ class AttemptOpenStep : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt index b821d5b59..fe63148b6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt @@ -65,7 +65,7 @@ class SetReadOnlyStep : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt index 91e4d1a54..20dc4cac1 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt @@ -30,7 +30,7 @@ class SetReadWriteStep : Step(name) { val updateSettingsRequest = UpdateSettingsRequest() .indices(indexName) .settings( - Settings.builder().put(SETTING_BLOCKS_WRITE, false) + Settings.builder().put(SETTING_BLOCKS_WRITE, false), ) val response: AcknowledgedResponse = context.client.admin().indices() .suspendUntil { updateSettings(updateSettingsRequest, it) } @@ -67,7 +67,7 @@ class SetReadWriteStep : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt index 4599668c8..9909b99c7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt @@ -67,7 +67,7 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt index 4c7356e07..38c796d78 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt @@ -13,11 +13,12 @@ import org.opensearch.action.admin.indices.rollover.RolloverRequest import org.opensearch.action.admin.indices.rollover.RolloverResponse import org.opensearch.action.admin.indices.stats.IndicesStatsRequest import org.opensearch.action.admin.indices.stats.IndicesStatsResponse -import org.opensearch.core.common.unit.ByteSizeValue import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.unit.TimeValue +import org.opensearch.core.common.unit.ByteSizeValue +import org.opensearch.core.rest.RestStatus import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.indexstatemanagement.action.RolloverAction import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getRolloverAlias @@ -29,7 +30,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -94,34 +94,34 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { RolloverAction.MIN_INDEX_AGE_FIELD to mapOf( "condition" to it.toString(), "current" to indexAgeTimeValue.toString(), - "creationDate" to indexCreationDate + "creationDate" to indexCreationDate, ) }, action.minDocs?.let { RolloverAction.MIN_DOC_COUNT_FIELD to mapOf( "condition" to it, - "current" to numDocs + "current" to numDocs, ) }, action.minSize?.let { RolloverAction.MIN_SIZE_FIELD to mapOf( "condition" to it.toString(), - "current" to indexSize.toString() + "current" to indexSize.toString(), ) }, action.minPrimaryShardSize?.let { RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD to mapOf( "condition" to it.toString(), "current" to largestPrimaryShardSize.toString(), - "shard" to largestPrimaryShard?.shardRouting?.id() + "shard" to largestPrimaryShard?.shardRouting?.id(), ) - } + }, ).toMap() if (action.evaluateConditions(indexAgeTimeValue, numDocs, indexSize, largestPrimaryShardSize)) { logger.info( "$indexName rollover conditions evaluated to true [indexCreationDate=$indexCreationDate," + - " numDocs=$numDocs, indexSize=${indexSize.bytes}, primaryShardSize=${largestPrimaryShardSize.bytes}]" + " numDocs=$numDocs, indexSize=${indexSize.bytes}, primaryShardSize=${largestPrimaryShardSize.bytes}]", ) executeRollover(context, rolloverTarget, isDataStream, conditions) copyAlias(clusterService, indexName, context.client, rolloverTarget, context.metadata) @@ -201,7 +201,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.FAILED info = mapOf( "message" to message, - "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() } + "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) @@ -217,7 +217,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { context: StepContext, rolloverTarget: String, isDataStream: Boolean, - conditions: Map> + conditions: Map>, ) { val indexName = context.metadata.index try { @@ -242,7 +242,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.COMPLETED info = listOfNotNull( "message" to message, - if (conditions.isEmpty()) null else "conditions" to conditions // don't show empty conditions object if no conditions specified + if (conditions.isEmpty()) null else "conditions" to conditions, // don't show empty conditions object if no conditions specified ).toMap() } else { val message = when { @@ -255,7 +255,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.FAILED info = listOfNotNull( "message" to message, - if (conditions.isEmpty()) null else "conditions" to conditions // don't show empty conditions object if no conditions specified + if (conditions.isEmpty()) null else "conditions" to conditions, // don't show empty conditions object if no conditions specified ).toMap() } } catch (e: RemoteTransportException) { @@ -280,7 +280,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { indexName: String, client: Client, rolloverTarget: String, - metadata: ManagedIndexMetaData + metadata: ManagedIndexMetaData, ) { if (!action.copyAlias) return @@ -295,7 +295,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.COMPLETED info = listOfNotNull( "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), - if (conditions != null) "conditions" to conditions else null + if (conditions != null) "conditions" to conditions else null, ).toMap() return } @@ -325,13 +325,13 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.COMPLETED info = listOfNotNull( "message" to getSuccessCopyAliasMessage(indexName, rolledOverIndexName), - if (conditions != null) "conditions" to conditions else null + if (conditions != null) "conditions" to conditions else null, ).toMap() } else { stepStatus = StepStatus.FAILED info = listOfNotNull( "message" to getCopyAliasNotAckMessage(indexName, rolledOverIndexName), - if (conditions != null) "conditions" to conditions else null + if (conditions != null) "conditions" to conditions else null, ).toMap() } } catch (e: IndexNotFoundException) { @@ -339,7 +339,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.FAILED info = listOfNotNull( "message" to getCopyAliasIndexNotFoundMessage(rolledOverIndexName), - if (conditions != null) "conditions" to conditions else null + if (conditions != null) "conditions" to conditions else null, ).toMap() } catch (e: Exception) { handleException(indexName, e, getFailedCopyAliasMessage(indexName, rolledOverIndexName), conditions) @@ -352,7 +352,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { rolledOver = if (currentMetadata.rolledOver == true) true else stepStatus == StepStatus.COMPLETED, rolledOverIndexName = if (currentMetadata.rolledOverIndexName != null) currentMetadata.rolledOverIndexName else newIndex, transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt index a5e767d64..95284798c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt @@ -103,7 +103,7 @@ class AttemptCreateRollupJobStep(private val action: RollupAction) : Step(name) actionMetaData = currentActionMetaData?.copy(actionProperties = ActionProperties(rollupId = rollupId)), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt index d7170c031..08856b5c4 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt @@ -104,12 +104,12 @@ class WaitForRollupCompletionStep : Step(name) { return currentMetadata.copy( actionMetaData = currentActionMetaData?.copy( actionProperties = currentActionProperties?.copy( - hasRollupFailed = hasRollupFailed - ) + hasRollupFailed = hasRollupFailed, + ), ), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptMoveShardsStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptMoveShardsStep.kt index 9754f5d8a..5fac6839e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptMoveShardsStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptMoveShardsStep.kt @@ -74,7 +74,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, action.targetIndexTemplate, context.metadata, indexName + DEFAULT_TARGET_SUFFIX, - context.scriptService + context.scriptService, ) if (targetIndexNameIsInvalid(context.clusterService, shrinkTargetIndexName)) return this @@ -129,7 +129,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, lock.seqNo, lock.lockTime.epochSecond, lock.lockDurationSeconds, - originalIndexSettings + originalIndexSettings, ) setToReadOnlyAndMoveIndexToNode(context, nodeName, lock) @@ -142,7 +142,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, private suspend fun getIndexStats( indexName: String, - client: Client + client: Client, ): Triple>? { val statsRequest = IndicesStatsRequest().indices(indexName) val statsResponse: IndicesStatsResponse = client.admin().indices().suspendUntil { @@ -154,7 +154,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, if (statsStore == null || statsDocs == null || statsShards == null) { setStepFailed( FAILURE_MESSAGE, - "Failed to move shards in shrink action as IndicesStatsResponse was missing some stats." + "Failed to move shards in shrink action as IndicesStatsResponse was missing some stats.", ) return null } @@ -174,7 +174,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, template: Script?, managedIndexMetaData: ManagedIndexMetaData, defaultValue: String, - scriptService: ScriptService + scriptService: ScriptService, ): String { if (template == null) return defaultValue val contextMap = managedIndexMetaData.convertToMap().filterKeys { key -> @@ -245,7 +245,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, private suspend fun setToReadOnlyAndMoveIndexToNode( stepContext: StepContext, node: String, - lock: LockModel + lock: LockModel, ): Boolean { val updateSettings = Settings.builder() .put(SETTING_BLOCKS_WRITE, true) @@ -277,7 +277,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, lockService: LockService, suitableNodes: List, jobIntervalSeconds: Long?, - indexName: String + indexName: String, ): Pair? { for (nodeName in suitableNodes) { val lockID = getShrinkJobID(nodeName) @@ -302,7 +302,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, private suspend fun findSuitableNodes( stepContext: StepContext, shardStats: Array, - indexSizeInBytes: Long + indexSizeInBytes: Long, ): List { val nodesStatsReq = NodesStatsRequest().addMetric(FS_METRIC) val nodeStatsResponse: NodesStatsResponse = stepContext.client.admin().cluster().suspendUntil { @@ -322,7 +322,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, val remainingDiskSpace = getNodeFreeDiskSpaceAfterShrink( node, indexSizeInBytes, - stepContext.clusterService.clusterSettings + stepContext.clusterService.clusterSettings, ) if (remainingDiskSpace > 0L) { nodesWithSpace.add(Tuple(remainingDiskSpace, node.node.name)) @@ -335,7 +335,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, } val shardIdToNodeList: Map> = getShardIdToNodeNameSet( shardStats, - stepContext.clusterService.state().nodes + stepContext.clusterService.state().nodes, ) // For each node, do a dry run of moving all shards to the node to make sure that there aren't any other blockers // to the allocation. @@ -349,11 +349,13 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, val currentShardNode = stepContext.clusterService.state().nodes[shard.shardRouting.currentNodeId()] // Don't attempt a dry run for shards which have a copy already on that node if (shardIdToNodeList[shardId.id]?.contains(targetNodeName) == true || requestedShardIds.contains( - shardId.id + shardId.id, ) - ) continue + ) { + continue + } clusterRerouteRequest.add( - MoveAllocationCommand(indexName, shardId.id, currentShardNode.name, targetNodeName) + MoveAllocationCommand(indexName, shardId.id, currentShardNode.name, targetNodeName), ) requestedShardIds.add(shardId.id) } @@ -370,7 +372,7 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, it.decisions().type().equals((Decision.Type.THROTTLE)) } logger.debug( - getShardMovingDecisionInfo(numNoDecisions, numYesDecisions, numThrottleDecisions, targetNodeName) + getShardMovingDecisionInfo(numNoDecisions, numYesDecisions, numThrottleDecisions, targetNodeName), ) // NO decision type is not counted; YES and THROTTLE decision type are available for shrink. if (numOfDecisions - numNoDecisions >= requestedShardIds.size) { @@ -455,12 +457,12 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, return currentMetadata.copy( actionMetaData = currentActionMetaData?.copy( actionProperties = ActionProperties( - shrinkActionProperties = shrinkActionProperties - ) + shrinkActionProperties = shrinkActionProperties, + ), ), stepMetaData = stepMetaData, transitionTo = null, - info = info + info = info, ) } @@ -494,14 +496,14 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, noCount: Int, yesCount: Int, throttleCount: Int, - node: String + node: String, ) = "Shard moving decisions on node $node, NO: $noCount, YES: $yesCount, THROTTLE: $throttleCount." // If we couldn't get the job interval for the lock, use the default of 12 hours. // Lock is 3x + 30 minutes the job interval to allow the next step's execution to extend the lock without losing it. // If user sets maximum jitter, it could be 2x the job interval before the next step is executed. private fun getShrinkLockDuration( - jobInterval: Long? + jobInterval: Long?, ) = jobInterval?.let { (it * JOB_INTERVAL_LOCK_MULTIPLIER) + LOCK_BUFFER_SECONDS } ?: DEFAULT_LOCK_INTERVAL diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptShrinkStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptShrinkStep.kt index 87dba6361..930e9cd38 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptShrinkStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/AttemptShrinkStep.kt @@ -110,7 +110,7 @@ class AttemptShrinkStep(private val action: ShrinkAction) : ShrinkStep(name, tru Settings.builder() .put(AttemptMoveShardsStep.ROUTING_SETTING, shrinkActionProperties.nodeName) .put(INDEX_NUMBER_OF_SHARDS, shrinkActionProperties.targetNumShards) - .build() + .build(), ) action.aliases?.forEach { req.targetIndexRequest.alias(it) } val resizeResponse: ResizeResponse = context.client.admin().indices().suspendUntil { resizeIndex(req, it) } @@ -125,12 +125,12 @@ class AttemptShrinkStep(private val action: ShrinkAction) : ShrinkStep(name, tru return currentMetadata.copy( actionMetaData = currentMetadata.actionMetaData?.copy( actionProperties = ActionProperties( - shrinkActionProperties = shrinkActionProperties - ) + shrinkActionProperties = shrinkActionProperties, + ), ), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt index d45845cb1..e0baae6a0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt @@ -26,7 +26,7 @@ abstract class ShrinkStep( name: String, private val cleanupSettings: Boolean, private val cleanupLock: Boolean, - private val cleanupTargetIndex: Boolean + private val cleanupTargetIndex: Boolean, ) : Step(name) { protected val logger: Logger = LogManager.getLogger(javaClass) protected var stepStatus = StepStatus.STARTING @@ -74,7 +74,7 @@ abstract class ShrinkStep( if (lock == null) { cleanupAndFail( "Failed to renew lock on node [${localShrinkActionProperties.nodeName}]", - "Shrink action failed to renew lock on node [${localShrinkActionProperties.nodeName}]" + "Shrink action failed to renew lock on node [${localShrinkActionProperties.nodeName}]", ) return null } @@ -141,7 +141,7 @@ abstract class ShrinkStep( } } else { logger.error( - "Shrink action failed to delete target index [$targetIndexName] after a failure due to a null client in the step context" + "Shrink action failed to delete target index [$targetIndexName] after a failure due to a null client in the step context", ) } } catch (e: Exception) { @@ -157,7 +157,7 @@ abstract class ShrinkStep( if (!released) logger.error("Failed to release Shrink action lock on node [${shrinkActionProperties.nodeName}]") } else { logger.error( - "Shrink action failed to release lock on node [${shrinkActionProperties.nodeName}] due to uninitialized metadata values." + "Shrink action failed to release lock on node [${shrinkActionProperties.nodeName}] due to uninitialized metadata values.", ) } } catch (e: Exception) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForMoveShardsStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForMoveShardsStep.kt index 943f59279..fe26fad3d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForMoveShardsStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForMoveShardsStep.kt @@ -100,12 +100,12 @@ class WaitForMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, return currentMetadata.copy( actionMetaData = currentMetadata.actionMetaData?.copy( actionProperties = ActionProperties( - shrinkActionProperties = shrinkActionProperties - ) + shrinkActionProperties = shrinkActionProperties, + ), ), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } @@ -113,7 +113,7 @@ class WaitForMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, stepContext: StepContext, numShardsNotOnNode: Int, numShardsNotInSync: Int, - nodeToMoveOnto: String + nodeToMoveOnto: String, ) { val managedIndexMetadata = stepContext.metadata val indexName = managedIndexMetadata.index @@ -125,7 +125,7 @@ class WaitForMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name, } else { logger.debug( "Shrink action move shards step running on [$indexName], [$numShardsNotOnNode] shards need to be moved, " + - "[$numShardsNotInSync] shards need an in sync replica." + "[$numShardsNotInSync] shards need an in sync replica.", ) info = mapOf("message" to getTimeoutDelay(nodeToMoveOnto)) stepStatus = StepStatus.CONDITION_NOT_MET diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt index 1c6e446e1..4e00d8286 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt @@ -74,7 +74,7 @@ class WaitForShrinkStep(private val action: ShrinkAction) : ShrinkStep(name, tru if (!response.isAcknowledged) { cleanupAndFail( getFailureMessage(index), - "Shrink action to clear the allocation settings on index [$index] following shrinking." + "Shrink action to clear the allocation settings on index [$index] following shrinking.", ) return false } @@ -102,7 +102,6 @@ class WaitForShrinkStep(private val action: ShrinkAction) : ShrinkStep(name, tru } suspend fun switchAliases(context: StepContext, shrinkActionProperties: ShrinkActionProperties): Boolean { - val sourceIndexName = context.metadata.index val targetIndexName = shrinkActionProperties.targetIndexName @@ -163,12 +162,12 @@ class WaitForShrinkStep(private val action: ShrinkAction) : ShrinkStep(name, tru return currentMetadata.copy( actionMetaData = currentMetadata.actionMetaData?.copy( actionProperties = ActionProperties( - shrinkActionProperties = shrinkActionProperties - ) + shrinkActionProperties = shrinkActionProperties, + ), ), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt index 4256cd0aa..692bc4a0c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt @@ -10,6 +10,7 @@ import org.opensearch.ExceptionsHelper import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse import org.opensearch.common.regex.Regex +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.action.SnapshotAction import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.SNAPSHOT_DENY_LIST import org.opensearch.indexmanagement.opensearchapi.convertToMap @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData -import org.opensearch.core.rest.RestStatus import org.opensearch.script.Script import org.opensearch.script.ScriptService import org.opensearch.script.ScriptType @@ -57,7 +57,7 @@ class AttemptSnapshotStep(private val action: SnapshotAction) : Step(name) { } val snapshotNameSuffix = "-".plus( LocalDateTime.now(ZoneId.of("UTC")) - .format(DateTimeFormatter.ofPattern("uuuu.MM.dd-HH:mm:ss.SSS", Locale.ROOT)) + .format(DateTimeFormatter.ofPattern("uuuu.MM.dd-HH:mm:ss.SSS", Locale.ROOT)), ) val snapshotScript = Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, snapshot, mapOf()) @@ -133,7 +133,7 @@ class AttemptSnapshotStep(private val action: SnapshotAction) : Step(name) { template: Script, managedIndexMetaData: ManagedIndexMetaData, defaultValue: String, - scriptService: ScriptService + scriptService: ScriptService, ): String { val contextMap = managedIndexMetaData.convertToMap().filterKeys { key -> key in validTopContextFields @@ -150,7 +150,7 @@ class AttemptSnapshotStep(private val action: SnapshotAction) : Step(name) { actionMetaData = currentActionMetaData?.copy(actionProperties = ActionProperties(snapshotName = snapshotName)), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt index 6018dd2d3..d71de58a6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt @@ -101,7 +101,7 @@ class WaitForSnapshotStep(private val action: SnapshotAction) : Step(name) { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt index 806803e3c..c55d04e1e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt @@ -28,7 +28,7 @@ import org.opensearch.indexmanagement.transform.action.start.StartTransformReque import org.opensearch.transport.RemoteTransportException class AttemptCreateTransformJobStep( - private val action: TransformAction + private val action: TransformAction, ) : Step(name) { private val logger = LogManager.getLogger(javaClass) @@ -109,7 +109,7 @@ class AttemptCreateTransformJobStep( actionMetaData = currentActionMetaData?.copy(actionProperties = ActionProperties(transformActionProperties = transformActionProperties)), stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt index 78aa41f3d..3fccb8a58 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt @@ -113,7 +113,7 @@ class WaitForTransformCompletionStep : Step(name) { actionMetaData = currentMetadata.actionMetaData, stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = info + info = info, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt index a71fa1f18..a0e6e241e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt @@ -11,6 +11,7 @@ import org.opensearch.action.admin.indices.stats.IndicesStatsRequest import org.opensearch.action.admin.indices.stats.IndicesStatsResponse import org.opensearch.cluster.service.ClusterService import org.opensearch.core.common.unit.ByteSizeValue +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider import org.opensearch.indexmanagement.indexstatemanagement.action.TransitionsAction import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getOldestRolloverTime @@ -22,7 +23,6 @@ import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -87,7 +87,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) stepStatus = StepStatus.FAILED info = mapOf( "message" to message, - "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() } + "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) return this } @@ -107,7 +107,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) if (stateName != null) { logger.info( "$indexName transition conditions evaluated to true [indexCreationDate=$indexCreationDate," + - " numDocs=$numDocs, indexSize=${indexSize?.bytes},stepStartTime=${stepStartTime.toEpochMilli()}]" + " numDocs=$numDocs, indexSize=${indexSize?.bytes},stepStartTime=${stepStartTime.toEpochMilli()}]", ) stepStatus = StepStatus.COMPLETED message = getSuccessMessage(indexName, stateName) @@ -140,7 +140,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) policyCompleted = policyCompleted, transitionTo = stateName, stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), - info = info + info = info, ) } @@ -150,7 +150,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) indexMetadataProvider: IndexMetadataProvider, clusterService: ClusterService, indexName: String, - inCluster: Boolean + inCluster: Boolean, ): Long { try { // If we do have an index creation date cached already then use that diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/ISMStatusResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/ISMStatusResponse.kt index 96bbffec6..69639829e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/ISMStatusResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/ISMStatusResponse.kt @@ -23,7 +23,7 @@ open class ISMStatusResponse : ActionResponse, ToXContentObject { constructor( updated: Int, - failedIndices: List + failedIndices: List, ) : super() { this.updated = updated this.failedIndices = failedIndices @@ -32,7 +32,7 @@ open class ISMStatusResponse : ActionResponse, ToXContentObject { @Throws(IOException::class) constructor(sin: StreamInput) : this( updated = sin.readInt(), - failedIndices = sin.readList(::FailedIndex) + failedIndices = sin.readList(::FailedIndex), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/AddPolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/AddPolicyRequest.kt index 99304e00c..3ff2e1115 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/AddPolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/AddPolicyRequest.kt @@ -16,14 +16,14 @@ import java.io.IOException class AddPolicyRequest( val indices: List, val policyID: String, - val indexType: String + val indexType: String, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( indices = sin.readStringList(), policyID = sin.readString(), - indexType = sin.readString() + indexType = sin.readString(), ) override fun validate(): ActionRequestValidationException? { @@ -33,7 +33,7 @@ class AddPolicyRequest( } else if (indexType != DEFAULT_INDEX_TYPE && indices.size > 1) { validationException = ValidateActions.addValidationError( MULTIPLE_INDICES_CUSTOM_INDEX_TYPE_ERROR, - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/TransportAddPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/TransportAddPolicyAction.kt index da4e81d77..e0f16ef25 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/TransportAddPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/addpolicy/TransportAddPolicyAction.kt @@ -13,7 +13,6 @@ import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchSecurityException import org.opensearch.OpenSearchStatusException import org.opensearch.OpenSearchTimeoutException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.state.ClusterStateRequest import org.opensearch.action.admin.cluster.state.ClusterStateResponse import org.opensearch.action.bulk.BulkRequest @@ -34,8 +33,10 @@ import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User -import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.action.ActionListener import org.opensearch.core.index.Index +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.DefaultIndexMetadataService import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider @@ -60,7 +61,6 @@ import org.opensearch.indexmanagement.util.IndexUtils import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource import org.opensearch.indexmanagement.util.SecurityUtils.Companion.validateUserConfiguration -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.time.Duration @@ -76,13 +76,15 @@ class TransportAddPolicyAction @Inject constructor( val settings: Settings, val clusterService: ClusterService, val xContentRegistry: NamedXContentRegistry, - val indexMetadataProvider: IndexMetadataProvider + val indexMetadataProvider: IndexMetadataProvider, ) : HandledTransportAction( - AddPolicyAction.NAME, transportService, actionFilters, ::AddPolicyRequest + AddPolicyAction.NAME, transportService, actionFilters, ::AddPolicyRequest, ) { @Volatile private var jobInterval = ManagedIndexSettings.JOB_INTERVAL.get(settings) + @Volatile private var jobJitter = ManagedIndexSettings.JITTER.get(settings) + @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) init { @@ -116,8 +118,8 @@ class TransportAddPolicyAction @Inject constructor( fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) if (!validateUserConfiguration(user, filterByEnabled, actionListener)) { return @@ -208,7 +210,7 @@ class TransportAddPolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } else { getPolicy() @@ -244,7 +246,7 @@ class TransportAddPolicyAction @Inject constructor( IndexUtils.checkAndUpdateConfigIndexMapping( clusterService.state(), client.admin().indices(), - ActionListener.wrap(::onUpdateMapping, ::onFailure) + ActionListener.wrap(::onUpdateMapping, ::onFailure), ) } @@ -258,8 +260,8 @@ class TransportAddPolicyAction @Inject constructor( actionListener.onFailure( OpenSearchStatusException( "Unable to create or update $INDEX_MANAGEMENT_INDEX with newest mapping.", - RestStatus.INTERNAL_SERVER_ERROR - ) + RestStatus.INTERNAL_SERVER_ERROR, + ), ) } } @@ -291,8 +293,8 @@ class TransportAddPolicyAction @Inject constructor( failedIndices.add( FailedIndex( indicesToAdd[docId] as String, docId, - "This index already has a policy, use the update policy API to update index policies" - ) + "This index already has a policy, use the update policy API to update index policies", + ), ) indicesToAdd.remove(docId) } @@ -304,7 +306,7 @@ class TransportAddPolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } @@ -325,7 +327,7 @@ class TransportAddPolicyAction @Inject constructor( val bulkReq = BulkRequest().timeout(TimeValue.timeValueMillis(bulkReqTimeout)) indicesToAdd.forEach { (uuid, name) -> bulkReq.add( - managedIndexConfigIndexRequest(name, uuid, request.policyID, jobInterval, policy = policy.copy(user = this.user), jobJitter) + managedIndexConfigIndexRequest(name, uuid, request.policyID, jobInterval, policy = policy.copy(user = this.user), jobJitter), ) } @@ -339,8 +341,8 @@ class TransportAddPolicyAction @Inject constructor( failedIndices.add( FailedIndex( indicesToAdd[docId] as String, docId, - "Failed to add policy due to: ${it.failureMessage}" - ) + "Failed to add policy due to: ${it.failureMessage}", + ), ) indicesToAdd.remove(docId) } @@ -358,7 +360,7 @@ class TransportAddPolicyAction @Inject constructor( actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } } - } + }, ) } else { actionListener.onResponse(ISMStatusResponse(0, failedIndices)) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/ChangePolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/ChangePolicyRequest.kt index cc53f6d78..9f1d205c2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/ChangePolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/ChangePolicyRequest.kt @@ -17,14 +17,14 @@ import java.io.IOException class ChangePolicyRequest( val indices: List, val changePolicy: ChangePolicy, - val indexType: String + val indexType: String, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( indices = sin.readStringList(), changePolicy = ChangePolicy(sin), - indexType = sin.readString() + indexType = sin.readString(), ) override fun validate(): ActionRequestValidationException? { @@ -34,7 +34,7 @@ class ChangePolicyRequest( } else if (indexType != DEFAULT_INDEX_TYPE && indices.size > 1) { validationException = ValidateActions.addValidationError( MULTIPLE_INDICES_CUSTOM_INDEX_TYPE_ERROR, - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt index 7dca57343..022305923 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt @@ -12,7 +12,6 @@ import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchSecurityException import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.state.ClusterStateRequest import org.opensearch.action.admin.cluster.state.ClusterStateResponse import org.opensearch.action.bulk.BulkRequest @@ -30,10 +29,12 @@ import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener import org.opensearch.core.index.Index +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.DefaultIndexMetadataService import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider @@ -64,7 +65,6 @@ import org.opensearch.indexmanagement.util.NO_ID import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource import org.opensearch.indexmanagement.util.SecurityUtils.Companion.validateUserConfiguration -import org.opensearch.core.rest.RestStatus import org.opensearch.search.fetch.subphase.FetchSourceContext import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -80,9 +80,9 @@ class TransportChangePolicyAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, val xContentRegistry: NamedXContentRegistry, - val indexMetadataProvider: IndexMetadataProvider + val indexMetadataProvider: IndexMetadataProvider, ) : HandledTransportAction( - ChangePolicyAction.NAME, transportService, actionFilters, ::ChangePolicyRequest + ChangePolicyAction.NAME, transportService, actionFilters, ::ChangePolicyRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -101,7 +101,7 @@ class TransportChangePolicyAction @Inject constructor( private val client: NodeClient, private val actionListener: ActionListener, private val request: ChangePolicyRequest, - private val user: User? = buildUser(client.threadPool().threadContext) + private val user: User? = buildUser(client.threadPool().threadContext), ) { private val failedIndices = mutableListOf() @@ -116,8 +116,8 @@ class TransportChangePolicyAction @Inject constructor( fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) if (user == null) { getPolicy() @@ -142,14 +142,14 @@ class TransportChangePolicyAction @Inject constructor( when (e is OpenSearchSecurityException) { true -> OpenSearchStatusException( "User doesn't have required index permissions on one or more requested indices: ${e.localizedMessage}", - RestStatus.FORBIDDEN + RestStatus.FORBIDDEN, ) false -> e - } - ) + }, + ), ) } - } + }, ) } @@ -183,7 +183,7 @@ class TransportChangePolicyAction @Inject constructor( IndexUtils.checkAndUpdateConfigIndexMapping( clusterService.state(), client.admin().indices(), - ActionListener.wrap(::onUpdateMapping, ::onFailure) + ActionListener.wrap(::onUpdateMapping, ::onFailure), ) } @@ -192,8 +192,8 @@ class TransportChangePolicyAction @Inject constructor( actionListener.onFailure( OpenSearchStatusException( "Could not update ${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX} with new mapping.", - RestStatus.FAILED_DEPENDENCY - ) + RestStatus.FAILED_DEPENDENCY, + ), ) return } @@ -251,14 +251,14 @@ class TransportChangePolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } private fun getManagedIndexMetadata() { client.multiGet( buildMgetMetadataRequest(indicesToUpdate.toList().map { it.first }), - ActionListener.wrap(::onMgetMetadataResponse, ::onFailure) + ActionListener.wrap(::onMgetMetadataResponse, ::onFailure), ) } @@ -284,8 +284,8 @@ class TransportChangePolicyAction @Inject constructor( failedIndices.add( FailedIndex( indexName, indexUuid, - "Failed to get managed index metadata, $mgetFailure" - ) + "Failed to get managed index metadata, $mgetFailure", + ), ) // if there exists a transitionTo on the ManagedIndexMetaData then we will // fail as they might not of meant to add a ChangePolicy when it's on the next state @@ -293,8 +293,8 @@ class TransportChangePolicyAction @Inject constructor( failedIndices.add( FailedIndex( indexName, indexUuid, - RestChangePolicyAction.INDEX_IN_TRANSITION - ) + RestChangePolicyAction.INDEX_IN_TRANSITION, + ), ) // else if there is no ManagedIndexMetaData yet then the managed index has not initialized and we can change the policy safely managedIndexMetadata == null -> { @@ -302,8 +302,8 @@ class TransportChangePolicyAction @Inject constructor( failedIndices.add( FailedIndex( indexName, indexUuid, - "Cannot change policy until metadata has finished migrating" - ) + "Cannot change policy until metadata has finished migrating", + ), ) } else { managedIndicesToUpdate.add(indexName to indexUuid) @@ -326,7 +326,7 @@ class TransportChangePolicyAction @Inject constructor( } else { client.multiGet( mgetManagedIndexConfigRequest(managedIndicesToUpdate.map { (_, indexUuid) -> indexUuid }.toTypedArray()), - ActionListener.wrap(::onMultiGetResponse, ::onFailure) + ActionListener.wrap(::onMultiGetResponse, ::onFailure), ) } } @@ -346,7 +346,7 @@ class TransportChangePolicyAction @Inject constructor( foundManagedIndices.add(it.response.id) contentParser(it.response.sourceAsBytesRef).parseWithType( NO_ID, it.response.seqNo, - it.response.primaryTerm, SweptManagedIndexConfig.Companion::parse + it.response.primaryTerm, SweptManagedIndexConfig.Companion::parse, ) } else { null @@ -383,7 +383,7 @@ class TransportChangePolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } @@ -408,15 +408,15 @@ class TransportChangePolicyAction @Inject constructor( "${ManagedIndexConfig.MANAGED_INDEX_TYPE}.${ManagedIndexConfig.INDEX_UUID_FIELD}", "${ManagedIndexConfig.MANAGED_INDEX_TYPE}.${ManagedIndexConfig.POLICY_ID_FIELD}", "${ManagedIndexConfig.MANAGED_INDEX_TYPE}.${ManagedIndexConfig.POLICY_FIELD}", - "${ManagedIndexConfig.MANAGED_INDEX_TYPE}.${ManagedIndexConfig.CHANGE_POLICY_FIELD}" + "${ManagedIndexConfig.MANAGED_INDEX_TYPE}.${ManagedIndexConfig.CHANGE_POLICY_FIELD}", ) val excludes = emptyArray() val fetchSourceContext = FetchSourceContext(true, includes, excludes) managedIndexUuids.forEach { request.add( MultiGetRequest.Item( - IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, it - ).fetchSourceContext(fetchSourceContext).routing(it) + IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, it, + ).fetchSourceContext(fetchSourceContext).routing(it), ) } return request diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/DeletePolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/DeletePolicyRequest.kt index ded140242..e0ef7f663 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/DeletePolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/DeletePolicyRequest.kt @@ -18,7 +18,7 @@ class DeletePolicyRequest(val policyID: String, val refreshPolicy: WriteRequest. @Throws(IOException::class) constructor(sin: StreamInput) : this( policyID = sin.readString(), - refreshPolicy = sin.readEnum(WriteRequest.RefreshPolicy::class.java) + refreshPolicy = sin.readEnum(WriteRequest.RefreshPolicy::class.java), ) override fun validate(): ActionRequestValidationException? { @@ -26,7 +26,7 @@ class DeletePolicyRequest(val policyID: String, val refreshPolicy: WriteRequest. if (policyID.isBlank()) { validationException = ValidateActions.addValidationError( "Missing policy ID", - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/TransportDeletePolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/TransportDeletePolicyAction.kt index 9be3966af..43696ada9 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/TransportDeletePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/deletepolicy/TransportDeletePolicyAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.del import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.delete.DeleteRequest import org.opensearch.action.delete.DeleteResponse import org.opensearch.action.get.GetRequest @@ -20,16 +19,17 @@ import org.opensearch.client.node.NodeClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.lang.IllegalArgumentException @@ -43,9 +43,9 @@ class TransportDeletePolicyAction @Inject constructor( actionFilters: ActionFilters, val clusterService: ClusterService, val settings: Settings, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - DeletePolicyAction.NAME, transportService, actionFilters, ::DeletePolicyRequest + DeletePolicyAction.NAME, transportService, actionFilters, ::DeletePolicyRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -64,14 +64,14 @@ class TransportDeletePolicyAction @Inject constructor( private val client: Client, private val actionListener: ActionListener, private val request: DeletePolicyRequest, - private val user: User? = buildUser(client.threadPool().threadContext) + private val user: User? = buildUser(client.threadPool().threadContext), ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) client.threadPool().threadContext.stashContext().use { getPolicy() @@ -106,7 +106,7 @@ class TransportDeletePolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequest.kt index cbbddf03b..7b7642abb 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequest.kt @@ -8,9 +8,9 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.exp import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.action.ValidateActions +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput -import org.opensearch.common.unit.TimeValue import org.opensearch.indexmanagement.common.model.rest.SearchParams import org.opensearch.indexmanagement.indexstatemanagement.model.ExplainFilter import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE @@ -36,7 +36,7 @@ class ExplainRequest : ActionRequest { explainFilter: ExplainFilter?, showPolicy: Boolean, validateAction: Boolean, - indexType: String + indexType: String, ) : super() { this.indices = indices this.local = local @@ -57,7 +57,7 @@ class ExplainRequest : ActionRequest { explainFilter = sin.readOptionalWriteable(::ExplainFilter), showPolicy = sin.readBoolean(), validateAction = sin.readBoolean(), - indexType = sin.readString() + indexType = sin.readString(), ) override fun validate(): ActionRequestValidationException? { @@ -65,7 +65,7 @@ class ExplainRequest : ActionRequest { if (indexType != DEFAULT_INDEX_TYPE && indices.size > 1) { validationException = ValidateActions.addValidationError( MULTIPLE_INDICES_CUSTOM_INDEX_TYPE_ERROR, - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponse.kt index 7ba09b4f0..48b1cb027 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponse.kt @@ -40,7 +40,7 @@ open class ExplainResponse : ActionResponse, ToXContentObject { totalManagedIndices: Int, enabledState: Map, policies: Map, - validationResults: List + validationResults: List, ) : super() { this.indexNames = indexNames this.indexPolicyIDs = indexPolicyIDs @@ -59,7 +59,7 @@ open class ExplainResponse : ActionResponse, ToXContentObject { totalManagedIndices = sin.readInt(), enabledState = sin.readMap(StreamInput::readString, StreamInput::readBoolean), policies = sin.readMap(StreamInput::readString, ::Policy), - validationResults = sin.readList { ValidationResult.fromStreamInput(it) } + validationResults = sin.readList { ValidationResult.fromStreamInput(it) }, ) @Throws(IOException::class) @@ -71,12 +71,12 @@ open class ExplainResponse : ActionResponse, ToXContentObject { out.writeMap( enabledState, { _out, key -> _out.writeString(key) }, - { _out, enable -> _out.writeBoolean(enable) } + { _out, enable -> _out.writeBoolean(enable) }, ) out.writeMap( policies, { _out, key -> _out.writeString(key) }, - { _out, policy -> policy.writeTo(_out) } + { _out, policy -> policy.writeTo(_out) }, ) out.writeCollection(validationResults) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/TransportExplainAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/TransportExplainAction.kt index c671a3fd4..9872d4626 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/TransportExplainAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/TransportExplainAction.kt @@ -11,7 +11,6 @@ import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchSecurityException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.state.ClusterStateRequest import org.opensearch.action.admin.cluster.state.ClusterStateResponse import org.opensearch.action.get.GetResponse @@ -29,21 +28,22 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.index.IndexNotFoundException import org.opensearch.index.query.Operator import org.opensearch.index.query.QueryBuilders import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX +import org.opensearch.indexmanagement.common.model.rest.SearchParams import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexCoordinator.Companion.MAX_HITS +import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner.actionValidation import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy -import org.opensearch.indexmanagement.common.model.rest.SearchParams -import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner.actionValidation import org.opensearch.indexmanagement.indexstatemanagement.model.filterByPolicyID import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getManagedIndexMetadata import org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex.ManagedIndexAction @@ -83,9 +83,9 @@ class TransportExplainAction @Inject constructor( actionFilters: ActionFilters, val clusterService: ClusterService, val xContentRegistry: NamedXContentRegistry, - val indexMetadataProvider: IndexMetadataProvider + val indexMetadataProvider: IndexMetadataProvider, ) : HandledTransportAction( - ExplainAction.NAME, transportService, actionFilters, ::ExplainRequest + ExplainAction.NAME, transportService, actionFilters, ::ExplainRequest, ) { override fun doExecute(task: Task, request: ExplainRequest, listener: ActionListener) { @@ -103,7 +103,7 @@ class TransportExplainAction @Inject constructor( private val client: NodeClient, private val actionListener: ActionListener, private val request: ExplainRequest, - private val user: User? = buildUser(client.threadPool().threadContext) + private val user: User? = buildUser(client.threadPool().threadContext), ) { private val indices: List = request.indices private val explainAll: Boolean = indices.isEmpty() @@ -130,8 +130,8 @@ class TransportExplainAction @Inject constructor( fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) // Use the indexMetadataProvider to get the index names and uuids corresponding to this index type CoroutineScope(Dispatchers.IO).launch { @@ -164,7 +164,7 @@ class TransportExplainAction @Inject constructor( QueryBuilders .queryStringQuery(params.queryString) .field(MANAGED_INDEX_NAME_KEYWORD_FIELD) - .defaultOperator(Operator.AND) + .defaultOperator(Operator.AND), ).filter(QueryBuilders.termsQuery(MANAGED_INDEX_INDEX_UUID_FIELD, indexUUIDs)) .filterByPolicyID(request.explainFilter) @@ -201,7 +201,7 @@ class TransportExplainAction @Inject constructor( "index" to managedIndex.index, "index_uuid" to managedIndex.indexUuid, "policy_id" to managedIndex.policyID, - "enabled" to managedIndex.enabled.toString() + "enabled" to managedIndex.enabled.toString(), ) if (showPolicy) { managedIndex.policy?.let { appliedPolicies[managedIndex.index] = it } @@ -219,7 +219,7 @@ class TransportExplainAction @Inject constructor( indexNames.clear() sendResponse( indexNames, indexMetadatas, indexPolicyIDs, enabledState, - totalManagedIndices, appliedPolicies, validationResults + totalManagedIndices, appliedPolicies, validationResults, ) return } else { @@ -248,13 +248,13 @@ class TransportExplainAction @Inject constructor( indexNames.clear() sendResponse( indexNames, indexMetadatas, indexPolicyIDs, - enabledState, totalManagedIndices, appliedPolicies, validationResults + enabledState, totalManagedIndices, appliedPolicies, validationResults, ) return } actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } } @@ -280,7 +280,7 @@ class TransportExplainAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } else { getMetadataMap(null, threadContext) @@ -328,7 +328,7 @@ class TransportExplainAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } @@ -337,7 +337,7 @@ class TransportExplainAction @Inject constructor( indices: Map, metadataMap: Map, clusterStateIndexMetadatas: Map?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ) { // cluster state response will not resist the sort order // so use the order from previous search result saved in indexNames @@ -422,7 +422,7 @@ class TransportExplainAction @Inject constructor( } sendResponse( filteredIndices, filteredMetadata, filteredPolicies, enabledStatus, - totalManagedIndices, filteredAppliedPolicies, filteredValidationResult + totalManagedIndices, filteredAppliedPolicies, filteredValidationResult, ) } } @@ -442,15 +442,16 @@ class TransportExplainAction @Inject constructor( @Suppress("ReturnCount") private fun getMetadata(response: GetResponse?): ManagedIndexMetaData? { - if (response == null || response.sourceAsBytesRef == null) + if (response == null || response.sourceAsBytesRef == null) { return null + } try { val xcp = XContentHelper.createParser( xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.sourceAsBytesRef, - XContentType.JSON + XContentType.JSON, ) return ManagedIndexMetaData.parseWithType(xcp, response.id, response.seqNo, response.primaryTerm) } catch (e: Exception) { @@ -466,7 +467,7 @@ class TransportExplainAction @Inject constructor( xContentRegistry, LoggingDeprecationHandler.INSTANCE, hit.sourceRef, - XContentType.JSON + XContentType.JSON, ).parseWithType(parse = ManagedIndexConfig.Companion::parse) } } @@ -477,7 +478,7 @@ class TransportExplainAction @Inject constructor( const val METADATA_CORRUPT_WARNING = "Managed index's metadata is corrupt, please use remove policy API to clean it." val metadataStatusToInfo = mapOf( MetadataCheck.PENDING to mapOf("message" to METADATA_MOVING_WARNING), - MetadataCheck.CORRUPT to mapOf("message" to METADATA_CORRUPT_WARNING) + MetadataCheck.CORRUPT to mapOf("message" to METADATA_CORRUPT_WARNING), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesRequest.kt index 0bf74d646..7580184af 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesRequest.kt @@ -17,14 +17,14 @@ class GetPoliciesRequest : ActionRequest { val searchParams: SearchParams constructor( - searchParams: SearchParams + searchParams: SearchParams, ) : super() { this.searchParams = searchParams } @Throws(IOException::class) constructor(sin: StreamInput) : this( - searchParams = SearchParams(sin) + searchParams = SearchParams(sin), ) override fun validate(): ActionRequestValidationException? { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponse.kt index 16dff5fe4..8387e9252 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponse.kt @@ -27,7 +27,7 @@ class GetPoliciesResponse : ActionResponse, ToXContentObject { constructor( policies: List, - totalPolicies: Int + totalPolicies: Int, ) : super() { this.policies = policies this.totalPolicies = totalPolicies @@ -36,7 +36,7 @@ class GetPoliciesResponse : ActionResponse, ToXContentObject { @Throws(IOException::class) constructor(sin: StreamInput) : this( policies = sin.readList(::Policy), - totalPolicies = sin.readInt() + totalPolicies = sin.readInt(), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyRequest.kt index 5e9762ed9..94475b8e6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyRequest.kt @@ -22,7 +22,7 @@ class GetPolicyRequest : ActionRequest { constructor( policyID: String, version: Long, - fetchSrcContext: FetchSourceContext + fetchSrcContext: FetchSourceContext, ) : super() { this.policyID = policyID this.version = version @@ -33,7 +33,7 @@ class GetPolicyRequest : ActionRequest { constructor(sin: StreamInput) : this( policyID = sin.readString(), version = sin.readLong(), - fetchSrcContext = FetchSourceContext(sin) + fetchSrcContext = FetchSourceContext(sin), ) override fun validate(): ActionRequestValidationException? { @@ -41,7 +41,7 @@ class GetPolicyRequest : ActionRequest { if (policyID.isBlank()) { validationException = ValidateActions.addValidationError( "Missing policy ID", - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponse.kt index 54c64be1f..ef26f489d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponse.kt @@ -34,7 +34,7 @@ class GetPolicyResponse : ActionResponse, ToXContentObject { version: Long, seqNo: Long, primaryTerm: Long, - policy: Policy? + policy: Policy?, ) : super() { this.id = id this.version = version @@ -49,7 +49,7 @@ class GetPolicyResponse : ActionResponse, ToXContentObject { version = sin.readLong(), seqNo = sin.readLong(), primaryTerm = sin.readLong(), - policy = sin.readOptionalWriteable(::Policy) + policy = sin.readOptionalWriteable(::Policy), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt index 9aaa9c91c..8f94c5b4b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.get import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper -import org.opensearch.core.action.ActionListener import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters @@ -17,8 +16,9 @@ import org.opensearch.cluster.routing.Preference import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.index.IndexNotFoundException import org.opensearch.index.query.Operator import org.opensearch.index.query.QueryBuilders @@ -40,9 +40,9 @@ class TransportGetPoliciesAction @Inject constructor( actionFilters: ActionFilters, val clusterService: ClusterService, val settings: Settings, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - GetPoliciesAction.NAME, transportService, actionFilters, ::GetPoliciesRequest + GetPoliciesAction.NAME, transportService, actionFilters, ::GetPoliciesRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -56,12 +56,12 @@ class TransportGetPoliciesAction @Inject constructor( override fun doExecute( task: Task, getPoliciesRequest: GetPoliciesRequest, - actionListener: ActionListener + actionListener: ActionListener, ) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val params = getPoliciesRequest.searchParams val user = buildUser(client.threadPool().threadContext) @@ -78,7 +78,7 @@ class TransportGetPoliciesAction @Inject constructor( QueryBuilders .queryStringQuery(params.queryString) .defaultOperator(Operator.AND) - .field("policy.policy_id.keyword") + .field("policy.policy_id.keyword"), ) val searchSourceBuilder = SearchSourceBuilder() @@ -111,7 +111,7 @@ class TransportGetPoliciesAction @Inject constructor( } actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt index a54d3868e..eda3e5d29 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.get import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse import org.opensearch.action.support.ActionFilters @@ -17,16 +16,17 @@ import org.opensearch.client.node.NodeClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse import org.opensearch.indexmanagement.settings.IndexManagementSettings.Companion.FILTER_BY_BACKEND_ROLES import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.lang.IllegalArgumentException @@ -38,9 +38,9 @@ class TransportGetPolicyAction @Inject constructor( actionFilters: ActionFilters, val clusterService: ClusterService, val settings: Settings, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - GetPolicyAction.NAME, transportService, actionFilters, ::GetPolicyRequest + GetPolicyAction.NAME, transportService, actionFilters, ::GetPolicyRequest, ) { @Volatile private var filterByEnabled = FILTER_BY_BACKEND_ROLES.get(settings) @@ -60,13 +60,13 @@ class TransportGetPolicyAction @Inject constructor( private val client: NodeClient, private val actionListener: ActionListener, private val request: GetPolicyRequest, - private val user: User? = buildUser(client.threadPool().threadContext) + private val user: User? = buildUser(client.threadPool().threadContext), ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val getRequest = GetRequest(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, request.policyID) .version(request.version) @@ -82,7 +82,7 @@ class TransportGetPolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequest.kt index e4a04f788..42a7614cf 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequest.kt @@ -28,7 +28,7 @@ class IndexPolicyRequest : ActionRequest { policy: Policy, seqNo: Long, primaryTerm: Long, - refreshPolicy: WriteRequest.RefreshPolicy + refreshPolicy: WriteRequest.RefreshPolicy, ) : super() { this.policyID = policyID this.policy = policy @@ -43,7 +43,7 @@ class IndexPolicyRequest : ActionRequest { policy = Policy(sin), seqNo = sin.readLong(), primaryTerm = sin.readLong(), - refreshPolicy = sin.readEnum(WriteRequest.RefreshPolicy::class.java) + refreshPolicy = sin.readEnum(WriteRequest.RefreshPolicy::class.java), ) override fun validate(): ActionRequestValidationException? { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponse.kt index f1453058b..e8ad90ff9 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.ind import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.util._VERSION -import org.opensearch.core.rest.RestStatus import java.io.IOException class IndexPolicyResponse : ActionResponse, ToXContentObject { @@ -36,7 +36,7 @@ class IndexPolicyResponse : ActionResponse, ToXContentObject { primaryTerm: Long, seqNo: Long, policy: Policy, - status: RestStatus + status: RestStatus, ) : super() { this.id = id this.version = version @@ -53,7 +53,7 @@ class IndexPolicyResponse : ActionResponse, ToXContentObject { primaryTerm = sin.readLong(), seqNo = sin.readLong(), policy = Policy(sin), - status = sin.readEnum(RestStatus::class.java) + status = sin.readEnum(RestStatus::class.java), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt index 75a916281..dca44d275 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/TransportIndexPolicyAction.kt @@ -9,7 +9,6 @@ import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException import org.opensearch.ResourceAlreadyExistsException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteRequest import org.opensearch.action.index.IndexRequest import org.opensearch.action.index.IndexResponse @@ -26,10 +25,12 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.ValidationException import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentFactory import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.index.query.QueryBuilders import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementIndices @@ -49,7 +50,6 @@ import org.opensearch.indexmanagement.util.IndexManagementException import org.opensearch.indexmanagement.util.IndexUtils import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.validateUserConfiguration -import org.opensearch.core.rest.RestStatus import org.opensearch.search.builder.SearchSourceBuilder import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -67,7 +67,7 @@ class TransportIndexPolicyAction @Inject constructor( val xContentRegistry: NamedXContentRegistry, var awarenessReplicaBalance: AwarenessReplicaBalance, ) : HandledTransportAction( - IndexPolicyAction.NAME, transportService, actionFilters, ::IndexPolicyRequest + IndexPolicyAction.NAME, transportService, actionFilters, ::IndexPolicyRequest, ) { @Volatile @@ -87,14 +87,14 @@ class TransportIndexPolicyAction @Inject constructor( private val client: NodeClient, private val actionListener: ActionListener, private val request: IndexPolicyRequest, - private val user: User? = buildUser(client.threadPool().threadContext) + private val user: User? = buildUser(client.threadPool().threadContext), ) { fun start() { validate() log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) client.threadPool().threadContext.stashContext().use { if (!validateUserConfiguration(user, filterByEnabled, actionListener)) { @@ -143,15 +143,17 @@ class TransportIndexPolicyAction @Inject constructor( val reqTemplates = request.policy.ismTemplate if (reqTemplates != null) { validateISMTemplates(reqTemplates) - } else putPolicy() + } else { + putPolicy() + } } else { log.error("Unable to create or update ${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX} with newest mapping.") actionListener.onFailure( OpenSearchStatusException( "Unable to create or update ${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX} with newest mapping.", - RestStatus.INTERNAL_SERVER_ERROR - ) + RestStatus.INTERNAL_SERVER_ERROR, + ), ) } } @@ -177,8 +179,8 @@ class TransportIndexPolicyAction @Inject constructor( val searchRequest = SearchRequest() .source( SearchSourceBuilder().query( - QueryBuilders.existsQuery(ISM_TEMPLATE_FIELD) - ).size(MAX_HITS).seqNoAndPrimaryTerm(true) + QueryBuilders.existsQuery(ISM_TEMPLATE_FIELD), + ).size(MAX_HITS).seqNoAndPrimaryTerm(true), ) .indices(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) .preference(Preference.PRIMARY_FIRST.type()) @@ -201,9 +203,9 @@ class TransportIndexPolicyAction @Inject constructor( actionListener.onFailure( IndexManagementException.wrap( IllegalArgumentException( - errorMessage - ) - ) + errorMessage, + ), + ), ) return } @@ -215,13 +217,13 @@ class TransportIndexPolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } private fun putPolicy() { val policy = request.policy.copy( - schemaVersion = IndexUtils.indexManagementConfigSchemaVersion, user = this.user + schemaVersion = IndexUtils.indexManagementConfigSchemaVersion, user = this.user, ) val indexRequest = IndexRequest(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) @@ -246,8 +248,8 @@ class TransportIndexPolicyAction @Inject constructor( actionListener.onFailure( OpenSearchStatusException( failureReasons.toString(), - response.status() - ) + response.status(), + ), ) return } @@ -258,8 +260,8 @@ class TransportIndexPolicyAction @Inject constructor( response.primaryTerm, response.seqNo, request.policy, - response.status() - ) + response.status(), + ), ) } @@ -268,7 +270,7 @@ class TransportIndexPolicyAction @Inject constructor( // provide a direct message asking user to use seqNo and primaryTerm actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/managedIndex/TransportManagedIndexAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/managedIndex/TransportManagedIndexAction.kt index 4e82b38bc..6daf5035d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/managedIndex/TransportManagedIndexAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/managedIndex/TransportManagedIndexAction.kt @@ -5,12 +5,12 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex -import org.opensearch.core.action.ActionListener import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.HandledTransportAction import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject +import org.opensearch.core.action.ActionListener import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -22,7 +22,7 @@ class TransportManagedIndexAction @Inject constructor( actionFilters: ActionFilters, val clusterService: ClusterService, ) : HandledTransportAction( - ManagedIndexAction.NAME, transportService, actionFilters, ::ManagedIndexRequest + ManagedIndexAction.NAME, transportService, actionFilters, ::ManagedIndexRequest, ) { override fun doExecute(task: Task, request: ManagedIndexRequest, listener: ActionListener) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/RemovePolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/RemovePolicyRequest.kt index 66caa4d74..29115ecd0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/RemovePolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/RemovePolicyRequest.kt @@ -15,13 +15,13 @@ import java.io.IOException class RemovePolicyRequest( val indices: List, - val indexType: String + val indexType: String, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( indices = sin.readStringList(), - indexType = sin.readString() + indexType = sin.readString(), ) override fun validate(): ActionRequestValidationException? { @@ -31,7 +31,7 @@ class RemovePolicyRequest( } else if (indexType != DEFAULT_INDEX_TYPE && indices.size > 1) { validationException = ValidateActions.addValidationError( MULTIPLE_INDICES_CUSTOM_INDEX_TYPE_ERROR, - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/TransportRemovePolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/TransportRemovePolicyAction.kt index 2c74e4b1a..ed3812e27 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/TransportRemovePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/removepolicy/TransportRemovePolicyAction.kt @@ -12,7 +12,6 @@ import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchSecurityException import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.state.ClusterStateRequest import org.opensearch.action.admin.cluster.state.ClusterStateResponse import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest @@ -34,7 +33,9 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener import org.opensearch.core.index.Index +import org.opensearch.core.rest.RestStatus import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.DefaultIndexMetadataService @@ -52,7 +53,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.removeClusterSta import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ISMIndexMetadata import org.opensearch.indexmanagement.util.IndexManagementException import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -61,9 +61,9 @@ class TransportRemovePolicyAction @Inject constructor( val client: NodeClient, transportService: TransportService, actionFilters: ActionFilters, - val indexMetadataProvider: IndexMetadataProvider + val indexMetadataProvider: IndexMetadataProvider, ) : HandledTransportAction( - RemovePolicyAction.NAME, transportService, actionFilters, ::RemovePolicyRequest + RemovePolicyAction.NAME, transportService, actionFilters, ::RemovePolicyRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -76,7 +76,7 @@ class TransportRemovePolicyAction @Inject constructor( private val client: NodeClient, private val actionListener: ActionListener, private val request: RemovePolicyRequest, - private val user: User? = buildUser(client.threadPool().threadContext) + private val user: User? = buildUser(client.threadPool().threadContext), ) { private val failedIndices: MutableList = mutableListOf() @@ -88,8 +88,8 @@ class TransportRemovePolicyAction @Inject constructor( fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) if (user == null) { getIndicesToRemove() @@ -114,14 +114,14 @@ class TransportRemovePolicyAction @Inject constructor( when (e is OpenSearchSecurityException) { true -> OpenSearchStatusException( "User doesn't have required index permissions on one or more requested indices: ${e.localizedMessage}", - RestStatus.FORBIDDEN + RestStatus.FORBIDDEN, ) false -> e - } - ) + }, + ), ) } - } + }, ) } @@ -187,7 +187,7 @@ class TransportRemovePolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } } @@ -213,8 +213,8 @@ class TransportRemovePolicyAction @Inject constructor( FailedIndex( name, uuid, - "This index does not have a policy to remove" - ) + "This index does not have a policy to remove", + ), ) } actionListener.onResponse(ISMStatusResponse(0, failedIndices)) @@ -227,8 +227,8 @@ class TransportRemovePolicyAction @Inject constructor( failedIndices.add( FailedIndex( indicesToRemove[docId] as String, docId, - "This index does not have a policy to remove" - ) + "This index does not have a policy to remove", + ), ) indicesToRemove.remove(docId) } @@ -244,7 +244,7 @@ class TransportRemovePolicyAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } @@ -268,8 +268,8 @@ class TransportRemovePolicyAction @Inject constructor( UpdateSettingsRequest().indices(*readOnlyIndices.map { indices[it] }.toTypedArray()) .settings( Settings.builder().put(ManagedIndexSettings.AUTO_MANAGE.key, false) - .put(INDEX_READ_ONLY_SETTING.key, true) - ) + .put(INDEX_READ_ONLY_SETTING.key, true), + ), ) } if (readOnlyAllowDeleteIndices.isNotEmpty()) { @@ -277,14 +277,14 @@ class TransportRemovePolicyAction @Inject constructor( UpdateSettingsRequest().indices(*readOnlyAllowDeleteIndices.map { indices[it] }.toTypedArray()) .settings( Settings.builder().put(ManagedIndexSettings.AUTO_MANAGE.key, false) - .put(INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.key, true) - ) + .put(INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.key, true), + ), ) } if (normalIndices.isNotEmpty()) { updateSettingReqsList.add( UpdateSettingsRequest().indices(*normalIndices.map { indices[it] }.toTypedArray()) - .settings(Settings.builder().put(ManagedIndexSettings.AUTO_MANAGE.key, false)) + .settings(Settings.builder().put(ManagedIndexSettings.AUTO_MANAGE.key, false)), ) } @@ -303,8 +303,8 @@ class TransportRemovePolicyAction @Inject constructor( if (!response.isAcknowledged) { actionListener.onFailure( IndexManagementException.wrap( - Exception("Failed to remove policy because ISM auto_manage setting update requests are not fully acknowledged.") - ) + Exception("Failed to remove policy because ISM auto_manage setting update requests are not fully acknowledged."), + ), ) return } @@ -319,11 +319,11 @@ class TransportRemovePolicyAction @Inject constructor( val ex = ExceptionsHelper.unwrapCause(t) as Exception actionListener.onFailure( IndexManagementException.wrap( - Exception("Failed to remove policy because ISM auto_manage setting update requests failed with exception:", ex) - ) + Exception("Failed to remove policy because ISM auto_manage setting update requests failed with exception:", ex), + ), ) } - } + }, ) } @@ -343,8 +343,8 @@ class TransportRemovePolicyAction @Inject constructor( FailedIndex( indicesToRemove[docId] as String, docId, - "Failed to remove policy" - ) + "Failed to remove policy", + ), ) indicesToRemove.remove(docId) } @@ -363,8 +363,8 @@ class TransportRemovePolicyAction @Inject constructor( failedIndices.add( FailedIndex( name, uuid, - "Failed to remove policy due to ClusterBlockingException: ${t.message}" - ) + "Failed to remove policy due to ClusterBlockingException: ${t.message}", + ), ) } actionListener.onResponse(ISMStatusResponse(0, failedIndices)) @@ -372,7 +372,7 @@ class TransportRemovePolicyAction @Inject constructor( actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } } - } + }, ) } else { actionListener.onResponse(ISMStatusResponse(0, failedIndices)) @@ -392,8 +392,8 @@ class TransportRemovePolicyAction @Inject constructor( failedIndices.add( FailedIndex( indicesToRemove[docId] as String, docId, - "Failed to clean metadata due to: ${it.failureMessage}" - ) + "Failed to clean metadata due to: ${it.failureMessage}", + ), ) indicesToRemove.remove(docId) } @@ -404,11 +404,11 @@ class TransportRemovePolicyAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure( IndexManagementException.wrap( - Exception("Failed to clean metadata for remove policy indices.", e) - ) + Exception("Failed to clean metadata for remove policy indices.", e), + ), ) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequest.kt index b6d6eea60..7af2c79c5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequest.kt @@ -8,9 +8,9 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.ret import org.opensearch.action.ActionRequest import org.opensearch.action.ActionRequestValidationException import org.opensearch.action.ValidateActions +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput -import org.opensearch.common.unit.TimeValue import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE import java.io.IOException @@ -18,7 +18,7 @@ class RetryFailedManagedIndexRequest( val indices: List, val startState: String?, val clusterManagerTimeout: TimeValue, - val indexType: String + val indexType: String, ) : ActionRequest() { @Throws(IOException::class) @@ -26,7 +26,7 @@ class RetryFailedManagedIndexRequest( indices = sin.readStringList(), startState = sin.readOptionalString(), clusterManagerTimeout = sin.readTimeValue(), - indexType = sin.readString() + indexType = sin.readString(), ) override fun validate(): ActionRequestValidationException? { @@ -36,7 +36,7 @@ class RetryFailedManagedIndexRequest( } else if (indexType != DEFAULT_INDEX_TYPE && indices.size > 1) { validationException = ValidateActions.addValidationError( MULTIPLE_INDICES_CUSTOM_INDEX_TYPE_ERROR, - validationException + validationException, ) } return validationException diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/TransportRetryFailedManagedIndexAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/TransportRetryFailedManagedIndexAction.kt index fd21528eb..53495434c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/TransportRetryFailedManagedIndexAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/TransportRetryFailedManagedIndexAction.kt @@ -12,7 +12,6 @@ import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchSecurityException import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.state.ClusterStateRequest import org.opensearch.action.admin.cluster.state.ClusterStateResponse import org.opensearch.action.bulk.BulkRequest @@ -28,11 +27,13 @@ import org.opensearch.client.node.NodeClient import org.opensearch.cluster.block.ClusterBlockException import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.common.inject.Inject -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener import org.opensearch.core.index.Index +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.DefaultIndexMetadataService @@ -53,7 +54,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedInde import org.opensearch.indexmanagement.spi.indexstatemanagement.model.PolicyRetryInfoMetaData import org.opensearch.indexmanagement.util.IndexManagementException import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -64,9 +64,9 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( val client: NodeClient, transportService: TransportService, actionFilters: ActionFilters, - val indexMetadataProvider: IndexMetadataProvider + val indexMetadataProvider: IndexMetadataProvider, ) : HandledTransportAction( - RetryFailedManagedIndexAction.NAME, transportService, actionFilters, ::RetryFailedManagedIndexRequest + RetryFailedManagedIndexAction.NAME, transportService, actionFilters, ::RetryFailedManagedIndexRequest, ) { override fun doExecute(task: Task, request: RetryFailedManagedIndexRequest, listener: ActionListener) { RetryFailedManagedIndexHandler(client, listener, request).start() @@ -76,7 +76,7 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( private val client: NodeClient, private val actionListener: ActionListener, private val request: RetryFailedManagedIndexRequest, - private val user: User? = buildUser(client.threadPool().threadContext) + private val user: User? = buildUser(client.threadPool().threadContext), ) { private val failedIndices: MutableList = mutableListOf() private val listOfMetadata: MutableList = mutableListOf() @@ -90,8 +90,8 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) if (user == null) { // Security plugin is not enabled @@ -117,14 +117,14 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( when (e is OpenSearchSecurityException) { true -> OpenSearchStatusException( "User doesn't have required index permissions on one or more requested indices: ${e.localizedMessage}", - RestStatus.FORBIDDEN + RestStatus.FORBIDDEN, ) false -> e - } - ) + }, + ), ) } - } + }, ) } @@ -177,7 +177,7 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } } @@ -207,14 +207,14 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( // get back metadata from config index client.multiGet( buildMgetMetadataRequest(indicesToRetry.toList().map { it.first }), - ActionListener.wrap(::onMgetMetadataResponse, ::onFailure) + ActionListener.wrap(::onMgetMetadataResponse, ::onFailure), ) } override fun onFailure(t: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(t) as Exception) } - } + }, ) } @@ -276,12 +276,12 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( failed = false, consumedRetries = 0, lastRetryTime = null, - startTime = null + startTime = null, ), transitionTo = request.startState, - info = mapOf("message" to "Pending retry of failed managed index") - ) - ) + info = mapOf("message" to "Pending retry of failed managed index"), + ), + ), ) } } @@ -322,7 +322,7 @@ class TransportRetryFailedManagedIndexAction @Inject constructor( failedIndices.addAll( listOfIndexToMetadata.map { FailedIndex(it.first.name, it.first.uuid, "Failed to update due to ClusterBlockException. ${e.message}") - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/TransportUpdateManagedIndexMetaDataAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/TransportUpdateManagedIndexMetaDataAction.kt index 79cd20aaa..427371475 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/TransportUpdateManagedIndexMetaDataAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/TransportUpdateManagedIndexMetaDataAction.kt @@ -6,7 +6,6 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.updateindexmetadata import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction import org.opensearch.action.support.master.AcknowledgedResponse @@ -23,6 +22,7 @@ import org.opensearch.cluster.metadata.Metadata import org.opensearch.cluster.service.ClusterService import org.opensearch.common.Priority import org.opensearch.common.inject.Inject +import org.opensearch.core.action.ActionListener import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.Writeable import org.opensearch.core.index.Index @@ -38,7 +38,7 @@ class TransportUpdateManagedIndexMetaDataAction @Inject constructor( transportService: TransportService, actionFilters: ActionFilters, val indexMetadataProvider: IndexMetadataProvider, - indexNameExpressionResolver: IndexNameExpressionResolver + indexNameExpressionResolver: IndexNameExpressionResolver, ) : TransportClusterManagerNodeAction( UpdateManagedIndexMetaDataAction.INSTANCE.name(), transportService, @@ -46,7 +46,7 @@ class TransportUpdateManagedIndexMetaDataAction @Inject constructor( threadPool, actionFilters, Writeable.Reader { UpdateManagedIndexMetaDataRequest(it) }, - indexNameExpressionResolver + indexNameExpressionResolver, ) { private val log = LogManager.getLogger(javaClass) @@ -79,7 +79,7 @@ class TransportUpdateManagedIndexMetaDataAction @Inject constructor( override fun masterOperation( request: UpdateManagedIndexMetaDataRequest, state: ClusterState, - listener: ActionListener + listener: ActionListener, ) { clusterService.submitStateUpdateTask( IndexManagementPlugin.OLD_PLUGIN_NAME, @@ -91,7 +91,7 @@ class TransportUpdateManagedIndexMetaDataAction @Inject constructor( override fun clusterStateProcessed(source: String, oldState: ClusterState, newState: ClusterState) = listener.onResponse(AcknowledgedResponse(true)) - } + }, ) } @@ -126,7 +126,7 @@ class TransportUpdateManagedIndexMetaDataAction @Inject constructor( if (currentState.metadata.hasIndex(pair.first.name)) { metaDataBuilder.put( IndexMetadata.builder(currentState.metadata.index(pair.first)) - .putCustom(ManagedIndexMetaData.MANAGED_INDEX_METADATA_TYPE, pair.second.toMap()) + .putCustom(ManagedIndexMetaData.MANAGED_INDEX_METADATA_TYPE, pair.second.toMap()), ) } else { log.debug("No IndexMetadata found for [${pair.first.name}] when updating ManagedIndexMetaData") @@ -152,7 +152,7 @@ class TransportUpdateManagedIndexMetaDataAction @Inject constructor( companion object { data class ManagedIndexMetaDataTask( val indicesToAddManagedIndexMetaDataTo: List>, - val indicesToRemoveManagedIndexMetaDataFrom: List + val indicesToRemoveManagedIndexMetaDataFrom: List, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/UpdateManagedIndexMetaDataRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/UpdateManagedIndexMetaDataRequest.kt index 5d5d31b69..b8b7067b5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/UpdateManagedIndexMetaDataRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/updateindexmetadata/UpdateManagedIndexMetaDataRequest.kt @@ -33,7 +33,7 @@ class UpdateManagedIndexMetaDataRequest : AcknowledgedRequest> = listOf(), - indicesToRemoveManagedIndexMetaDataFrom: List = listOf() + indicesToRemoveManagedIndexMetaDataFrom: List = listOf(), ) { this.indicesToAddManagedIndexMetaDataTo = indicesToAddManagedIndexMetaDataTo this.indicesToRemoveManagedIndexMetaDataFrom = indicesToRemoveManagedIndexMetaDataFrom @@ -45,7 +45,7 @@ class UpdateManagedIndexMetaDataRequest : AcknowledgedRequest, - currentManagedIndexUuids: List + currentManagedIndexUuids: List, ): List { return currentManagedIndexUuids.filter { currentManagedIndex -> !currentIndexUuids.contains(currentManagedIndex) @@ -198,7 +197,7 @@ fun getSweptManagedIndexSearchRequest(scroll: Boolean = false, size: Int = Manag .size(size) .seqNoAndPrimaryTerm(true) .fetchSource(emptyArray(), emptyArray()) - .query(boolQueryBuilder) + .query(boolQueryBuilder), ) .preference(Preference.PRIMARY_FIRST.type()) if (scroll) req.scroll(TimeValue.timeValueMinutes(1)) @@ -253,7 +252,7 @@ fun RolloverAction.evaluateConditions( indexAgeTimeValue: TimeValue, numDocs: Long, indexSize: ByteSizeValue, - primaryShardSize: ByteSizeValue + primaryShardSize: ByteSizeValue, ): Boolean { if (this.minDocs == null && this.minAge == null && @@ -310,13 +309,13 @@ fun Action.hasTimedOut(actionMetaData: ActionMetaData?): Boolean { fun ManagedIndexMetaData.getStartingManagedIndexMetaData( state: State?, action: Action?, - step: Step? + step: Step?, ): ManagedIndexMetaData { // State can be null if the transition_to state or the current metadata state is not found in the policy if (state == null) { return this.copy( policyRetryInfo = PolicyRetryInfoMetaData(true, 0), - info = mapOf("message" to "Failed to find state=${this.transitionTo ?: this.stateMetaData} in policy=${this.policyID}") + info = mapOf("message" to "Failed to find state=${this.transitionTo ?: this.stateMetaData} in policy=${this.policyID}"), ) } @@ -325,7 +324,7 @@ fun ManagedIndexMetaData.getStartingManagedIndexMetaData( if (action == null || step == null) { return this.copy( policyRetryInfo = PolicyRetryInfoMetaData(true, 0), - info = mapOf("message" to "Failed to find action=${this.actionMetaData} in state=${this.stateMetaData}") + info = mapOf("message" to "Failed to find action=${this.actionMetaData} in state=${this.stateMetaData}"), ) } @@ -337,19 +336,19 @@ fun ManagedIndexMetaData.getStartingManagedIndexMetaData( stateMetaData = updatedStateMetaData, actionMetaData = updatedActionMetaData, stepMetaData = updatedStepMetaData, - info = mapOf("message" to "Starting action ${action.type} and working on ${step.name}") + info = mapOf("message" to "Starting action ${action.type} and working on ${step.name}"), ) } @Suppress("ReturnCount") fun ManagedIndexMetaData.getCompletedManagedIndexMetaData( action: Action, - step: Step + step: Step, ): ManagedIndexMetaData { val updatedStepMetaData = step.getUpdatedManagedIndexMetadata(this) val actionMetaData = updatedStepMetaData.actionMetaData ?: return this.copy( policyRetryInfo = PolicyRetryInfoMetaData(true, 0), - info = mapOf("message" to "Failed due to ActionMetaData being null") + info = mapOf("message" to "Failed due to ActionMetaData being null"), ) val updatedActionMetaData = if (updatedStepMetaData.stepMetaData?.stepStatus == Step.StepStatus.FAILED) { @@ -359,7 +358,7 @@ fun ManagedIndexMetaData.getCompletedManagedIndexMetaData( else -> actionMetaData.copy( failed = false, consumedRetries = actionMetaData.consumedRetries + 1, - lastRetryTime = Instant.now().toEpochMilli() + lastRetryTime = Instant.now().toEpochMilli(), ) } } else { @@ -374,7 +373,7 @@ fun ManagedIndexMetaData.getCompletedManagedIndexMetaData( stepMetaData = updatedStepMetaData.stepMetaData, transitionTo = updatedStepMetaData.transitionTo, policyRetryInfo = updatedStepMetaData.policyRetryInfo, - info = updatedStepMetaData.info + info = updatedStepMetaData.info, ) } @@ -496,7 +495,7 @@ fun checkMetadata( clusterStateMetadata: ManagedIndexMetaData?, configIndexMetadata: Any?, currentIndexUuid: String?, - logger: Logger + logger: Logger, ): MetadataCheck { // indexUuid saved in ISM metadata may be outdated // if an index restored from snapshot @@ -534,7 +533,9 @@ fun checkMetadata( } enum class MetadataCheck { - PENDING, CORRUPT, SUCCESS + PENDING, + CORRUPT, + SUCCESS, } // private val baseMessageLogger = LogManager.getLogger(BaseMessage::class.java) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/NotificationUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/NotificationUtils.kt index b943e08ee..5eb76abbc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/NotificationUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/NotificationUtils.kt @@ -4,6 +4,7 @@ */ @file:JvmName("NotificationUtils") + package org.opensearch.indexmanagement.indexstatemanagement.util import org.opensearch.client.Client @@ -15,11 +16,11 @@ import org.opensearch.commons.notifications.action.LegacyPublishNotificationRequ import org.opensearch.commons.notifications.action.LegacyPublishNotificationResponse import org.opensearch.commons.notifications.model.EventSource import org.opensearch.commons.notifications.model.SeverityType +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.common.model.notification.Channel import org.opensearch.indexmanagement.common.model.notification.validateResponseStatus import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData -import org.opensearch.core.rest.RestStatus /** * Extension function for publishing a notification to a legacy destination. @@ -35,7 +36,7 @@ suspend fun LegacyBaseMessage.publishLegacyNotification(client: Client) { this.publishLegacyNotification( (client as NodeClient), LegacyPublishNotificationRequest(baseMessage), - it + it, ) } validateResponseStatus(RestStatus.fromCode(res.destinationResponse.statusCode), res.destinationResponse.responseContent) @@ -50,7 +51,7 @@ suspend fun Channel.sendNotification( title: String, managedIndexMetaData: ManagedIndexMetaData, compiledMessage: String, - user: User? + user: User?, ) { val eventSource = managedIndexMetaData.getEventSource(title) this.sendNotification(client, eventSource, compiledMessage, user) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/RestHandlerUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/RestHandlerUtils.kt index 9dcb48a8b..67303098e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/RestHandlerUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/RestHandlerUtils.kt @@ -4,6 +4,7 @@ */ @file:Suppress("TopLevelPropertyNaming", "MatchingDeclarationName") + package org.opensearch.indexmanagement.indexstatemanagement.util import org.apache.logging.log4j.Logger @@ -11,16 +12,16 @@ import org.opensearch.OpenSearchParseException import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.Client +import org.opensearch.common.logging.DeprecationLogger +import org.opensearch.common.unit.TimeValue +import org.opensearch.common.xcontent.XContentFactory import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.logging.DeprecationLogger -import org.opensearch.common.unit.TimeValue +import org.opensearch.core.index.Index import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentFragment import org.opensearch.core.xcontent.XContentBuilder -import org.opensearch.common.xcontent.XContentFactory -import org.opensearch.core.index.Index import org.opensearch.indexmanagement.indexstatemanagement.model.ChangePolicy import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.transport.action.updateindexmetadata.UpdateManagedIndexMetaDataAction @@ -98,7 +99,7 @@ data class FailedIndex(val name: String, val uuid: String, val reason: String) : constructor(sin: StreamInput) : this( name = sin.readString(), uuid = sin.readString(), - reason = sin.readString() + reason = sin.readString(), ) override fun writeTo(out: StreamOutput) { @@ -112,7 +113,7 @@ data class FailedIndex(val name: String, val uuid: String, val reason: String) : * Gets the XContentBuilder for partially updating a [ManagedIndexConfig]'s ChangePolicy */ fun getPartialChangePolicyBuilder( - changePolicy: ChangePolicy? + changePolicy: ChangePolicy?, ): XContentBuilder { val builder = XContentFactory.jsonBuilder() .startObject() diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtils.kt index 121fae408..129cbf90d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtils.kt @@ -43,7 +43,7 @@ suspend fun issueUpdateSettingsRequest(client: Client, indexName: String, settin suspend fun releaseShrinkLock( shrinkActionProperties: ShrinkActionProperties, - lockService: LockService + lockService: LockService, ): Boolean { val lock: LockModel = getShrinkLockModel(shrinkActionProperties) return lockService.suspendUntil { release(lock, it) } @@ -52,7 +52,7 @@ suspend fun releaseShrinkLock( suspend fun deleteShrinkLock( shrinkActionProperties: ShrinkActionProperties, lockService: LockService, - logger: Logger + logger: Logger, ): Boolean { val lockID = getShrinkLockID(shrinkActionProperties.nodeName) logger.info("Deleting lock: $lockID") @@ -62,7 +62,7 @@ suspend fun deleteShrinkLock( suspend fun renewShrinkLock( shrinkActionProperties: ShrinkActionProperties, lockService: LockService, - logger: Logger + logger: Logger, ): LockModel? { val lock: LockModel = getShrinkLockModel(shrinkActionProperties) return try { @@ -74,7 +74,7 @@ suspend fun renewShrinkLock( } fun getShrinkLockModel( - shrinkActionProperties: ShrinkActionProperties + shrinkActionProperties: ShrinkActionProperties, ): LockModel { return getShrinkLockModel( shrinkActionProperties.nodeName, @@ -82,7 +82,7 @@ fun getShrinkLockModel( shrinkActionProperties.lockEpochSecond, shrinkActionProperties.lockPrimaryTerm, shrinkActionProperties.lockSeqNo, - shrinkActionProperties.lockDurationSecond + shrinkActionProperties.lockDurationSecond, ) } @@ -93,7 +93,7 @@ fun getShrinkLockModel( lockEpochSecond: Long, lockPrimaryTerm: Long, lockSeqNo: Long, - lockDurationSecond: Long + lockDurationSecond: Long, ): LockModel { val jobID = getShrinkJobID(nodeName) val lockCreationInstant: Instant = Instant.ofEpochSecond(lockEpochSecond) @@ -104,7 +104,7 @@ fun getShrinkLockModel( lockDurationSecond, false, lockSeqNo, - lockPrimaryTerm + lockPrimaryTerm, ) } @@ -118,7 +118,7 @@ fun getUpdatedShrinkActionProperties(shrinkActionProperties: ShrinkActionPropert lock.seqNo, lock.lockTime.epochSecond, lock.lockDurationSeconds, - shrinkActionProperties.originalIndexSettings + shrinkActionProperties.originalIndexSettings, ) } @@ -144,19 +144,21 @@ fun getFreeBytesThresholdHigh(clusterSettings: ClusterSettings, totalNodeBytes: return if (diskThresholdPercent > 0.001) { // If the user set value is 95%, diskThresholdPercent will be returned as 5% from the DiskThresholdSettings object ((diskThresholdPercent / 100) * totalNodeBytes).toLong() - } else diskThresholdBytes.bytes + } else { + diskThresholdBytes.bytes + } } fun getDiskSettings(clusterSettings: ClusterSettings): Settings { return Settings.builder().put( CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.key, - clusterSettings.get(CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING) + clusterSettings.get(CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING), ).put( CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.key, - clusterSettings.get(CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING) + clusterSettings.get(CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING), ).put( CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.key, - clusterSettings.get(CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING) + clusterSettings.get(CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING), ).build() } @@ -182,7 +184,7 @@ fun getNodeFreeDiskSpaceAfterShrink(node: NodeStats, indexSizeInBytes: Long, clu suspend fun isIndexGreen( client: Client, indexName: String, - timeout: TimeValue = TimeValue(AttemptMoveShardsStep.THIRTY_SECONDS_IN_MILLIS) + timeout: TimeValue = TimeValue(AttemptMoveShardsStep.THIRTY_SECONDS_IN_MILLIS), ): Boolean { // get index health, waiting for a green status val healthReq = ClusterHealthRequest().indices(indexName).waitForGreenStatus().timeout(timeout) @@ -205,7 +207,7 @@ suspend fun resetReadOnlyAndRouting(index: String, client: Client, originalSetti fun getShrinkLockID(nodeName: String): String { return LockModel.generateLockId( INDEX_MANAGEMENT_INDEX, - getShrinkJobID(nodeName) + getShrinkJobID(nodeName), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ActionValidation.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ActionValidation.kt index 3486c5956..4a0a1fa97 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ActionValidation.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ActionValidation.kt @@ -7,15 +7,15 @@ package org.opensearch.indexmanagement.indexstatemanagement.validation import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings -import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ValidationResult +import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.monitor.jvm.JvmService @OpenForTesting class ActionValidation( val settings: Settings, val clusterService: ClusterService, - val jvmService: JvmService + val jvmService: JvmService, ) { @Suppress("ComplexMethod") diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateClose.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateClose.kt index aa65fe967..0b78544f3 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateClose.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateClose.kt @@ -18,7 +18,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateClose( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateDelete.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateDelete.kt index 70ce78d58..72f2adafc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateDelete.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateDelete.kt @@ -19,7 +19,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateDelete( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateForceMerge.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateForceMerge.kt index 14a8328c7..1ec3a74cb 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateForceMerge.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateForceMerge.kt @@ -8,16 +8,16 @@ package org.opensearch.indexmanagement.indexstatemanagement.validation import org.apache.logging.log4j.LogManager import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings -import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate import org.opensearch.indexmanagement.transform.settings.TransformSettings +import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.monitor.jvm.JvmService @OpenForTesting class ValidateForceMerge( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateIndexPriority.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateIndexPriority.kt index 1ecde743e..36d311ee6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateIndexPriority.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateIndexPriority.kt @@ -14,15 +14,15 @@ import org.apache.logging.log4j.LogManager import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings -import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate +import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.monitor.jvm.JvmService @OpenForTesting class ValidateIndexPriority( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateNothing.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateNothing.kt index 596c46edd..eef9808b8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateNothing.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateNothing.kt @@ -7,15 +7,15 @@ package org.opensearch.indexmanagement.indexstatemanagement.validation import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings -import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate +import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.monitor.jvm.JvmService @OpenForTesting class ValidateNothing( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { // skips validation diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateOpen.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateOpen.kt index 3c9668fec..c71ff828c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateOpen.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateOpen.kt @@ -21,7 +21,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateOpen( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadOnly.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadOnly.kt index ab2d02abd..1f51884f5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadOnly.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadOnly.kt @@ -22,7 +22,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateReadOnly( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadWrite.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadWrite.kt index 78521bb56..73dc3228b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadWrite.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReadWrite.kt @@ -21,7 +21,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateReadWrite( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReplicaCount.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReplicaCount.kt index 0e9410248..45257eafa 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReplicaCount.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateReplicaCount.kt @@ -22,7 +22,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateReplicaCount( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateRollover.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateRollover.kt index aaa0ea4cb..e3d6f021d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateRollover.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateRollover.kt @@ -10,15 +10,15 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getRolloverAlias import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getRolloverSkip -import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate +import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.monitor.jvm.JvmService @OpenForTesting class ValidateRollover( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateSnapshot.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateSnapshot.kt index 91febd570..12f96f19a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateSnapshot.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateSnapshot.kt @@ -23,7 +23,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateSnapshot( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateTransition.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateTransition.kt index 9faeff20f..2a51f26ba 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateTransition.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/validation/ValidateTransition.kt @@ -18,7 +18,7 @@ import org.opensearch.monitor.jvm.JvmService class ValidateTransition( settings: Settings, clusterService: ClusterService, - jvmService: JvmService + jvmService: JvmService, ) : Validate(settings, clusterService, jvmService) { private val logger = LogManager.getLogger(javaClass) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/opensearchapi/OpenSearchExtensions.kt b/src/main/kotlin/org/opensearch/indexmanagement/opensearchapi/OpenSearchExtensions.kt index 80f460028..b4e91af8f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/opensearchapi/OpenSearchExtensions.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/opensearchapi/OpenSearchExtensions.kt @@ -15,35 +15,36 @@ import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.alias.Alias import org.opensearch.action.bulk.BackoffPolicy import org.opensearch.action.get.GetResponse import org.opensearch.action.search.SearchResponse import org.opensearch.client.OpenSearchClient -import org.opensearch.core.common.io.stream.StreamInput -import org.opensearch.core.common.io.stream.StreamOutput -import org.opensearch.core.common.io.stream.Writeable import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.core.xcontent.XContentParserUtils -import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.InjectSecurity import org.opensearch.commons.authuser.User import org.opensearch.commons.notifications.NotificationsPluginInterface +import org.opensearch.core.action.ActionListener import org.opensearch.core.action.support.DefaultShardOperationFailedException import org.opensearch.core.common.bytes.BytesReference +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.common.io.stream.Writeable import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.MediaType import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token +import org.opensearch.core.xcontent.XContentParserUtils +import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.indexstatemanagement.action.ShrinkAction import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate @@ -53,7 +54,6 @@ import org.opensearch.indexmanagement.util.NO_ID import org.opensearch.indexmanagement.util.SecurityUtils.Companion.DEFAULT_INJECT_ROLES import org.opensearch.indexmanagement.util.SecurityUtils.Companion.INTERNAL_REQUEST import org.opensearch.jobscheduler.spi.utils.LockService -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.RemoteTransportException import java.io.IOException import java.time.Instant @@ -69,14 +69,14 @@ fun contentParser(bytesReference: BytesReference, xContentRegistry: NamedXConten xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytesReference, - XContentType.JSON + XContentType.JSON, ) } /** Convert an object to maps and lists representation */ fun ToXContent.convertToMap(): Map { val bytesReference = org.opensearch.core.xcontent.XContentHelper.toXContent( - this, XContentType.JSON, ToXContent.EMPTY_PARAMS, false + this, XContentType.JSON, ToXContent.EMPTY_PARAMS, false, ) return XContentHelper.convertToMap(bytesReference, false, XContentType.JSON as (MediaType)).v2() } @@ -126,7 +126,7 @@ fun XContentBuilder.optionalUserField(name: String, user: User?): XContentBuilde fun parseFromSearchResponse( response: SearchResponse, xContentRegistry: NamedXContentRegistry = NamedXContentRegistry.EMPTY, - parse: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T + parse: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T, ): List { return response.hits.hits.map { val id = it.id @@ -143,13 +143,13 @@ fun parseFromSearchResponse( fun parseFromGetResponse( response: GetResponse, xContentRegistry: NamedXContentRegistry = NamedXContentRegistry.EMPTY, - parse: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T + parse: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T, ): T { val xcp = XContentHelper.createParser( xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.sourceAsBytesRef, - XContentType.JSON + XContentType.JSON, ) return xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, parse) } @@ -169,7 +169,7 @@ fun parseFromGetResponse( suspend fun BackoffPolicy.retry( logger: Logger, retryOn: List = emptyList(), - block: suspend (backoff: TimeValue) -> T + block: suspend (backoff: TimeValue) -> T, ): T { val iter = iterator() var backoff: TimeValue = TimeValue.ZERO @@ -267,7 +267,7 @@ fun XContentParser.parseWithType( id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, - parse: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T + parse: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T, ): T { ensureExpectedToken(Token.START_OBJECT, nextToken(), this) ensureExpectedToken(Token.FIELD_NAME, nextToken(), this) @@ -281,7 +281,7 @@ class IndexManagementSecurityContext( private val id: String, settings: Settings, private val threadContext: ThreadContext, - private val user: User? + private val user: User?, ) : ThreadContextElement { companion object Key : CoroutineContext.Key @@ -312,7 +312,7 @@ class IndexManagementSecurityContext( suspend fun withClosableContext( context: IndexManagementSecurityContext, - block: suspend CoroutineScope.() -> T + block: suspend CoroutineScope.() -> T, ): T { try { return withContext(context) { block() } @@ -322,7 +322,11 @@ suspend fun withClosableContext( } fun XContentBuilder.optionalField(name: String, value: Any?): XContentBuilder { - return if (value != null) { this.field(name, value) } else this + return if (value != null) { + this.field(name, value) + } else { + this + } } fun XContentBuilder.optionalInfoField(name: String, info: SMMetadata.Info?): XContentBuilder { @@ -332,7 +336,9 @@ fun XContentBuilder.optionalInfoField(name: String, info: SMMetadata.Info?): XCo } else { this } - } else this + } else { + this + } } inline fun XContentParser.nullValueHandler(block: XContentParser.() -> T): T? { @@ -350,7 +356,11 @@ inline fun XContentParser.parseArray(block: XContentParser.() -> T): List // similar to readOptionalWriteable fun StreamInput.readOptionalValue(reader: Writeable.Reader): T? { - return if (readBoolean()) { reader.read(this) } else null + return if (readBoolean()) { + reader.read(this) + } else { + null + } } fun StreamOutput.writeOptionalValue(value: T, writer: Writeable.Writer) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerResponse.kt index f4722644c..4c1028e0d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerResponse.kt @@ -5,8 +5,8 @@ package org.opensearch.indexmanagement.refreshanalyzer -import org.opensearch.core.action.support.DefaultShardOperationFailedException import org.opensearch.action.support.broadcast.BroadcastResponse +import org.opensearch.core.action.support.DefaultShardOperationFailedException import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.xcontent.ConstructingObjectParser @@ -32,9 +32,9 @@ class RefreshSearchAnalyzerResponse : BroadcastResponse { successfulShards: Int, failedShards: Int, shardFailures: List, - shardResponses: List + shardResponses: List, ) : super( - totalShards, successfulShards, failedShards, shardFailures + totalShards, successfulShards, failedShards, shardFailures, ) { this.shardResponses = shardResponses.toMutableList() this.shardFailures = shardFailures.toMutableList() @@ -80,9 +80,9 @@ class RefreshSearchAnalyzerResponse : BroadcastResponse { val response = arg[0] as RefreshSearchAnalyzerResponse RefreshSearchAnalyzerResponse( response.totalShards, response.successfulShards, response.failedShards, - response.shardFailures, response.shardResponses + response.shardFailures, response.shardResponses, ) - } + }, ) init { declareBroadcastFields(PARSER) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt index 3f1e83f0c..c99afe6f5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt @@ -29,12 +29,12 @@ class RestRefreshSearchAnalyzerAction : BaseRestHandler() { return listOf( ReplacedRoute( POST, REFRESH_SEARCH_ANALYZER_BASE_URI, - POST, LEGACY_REFRESH_SEARCH_ANALYZER_BASE_URI + POST, LEGACY_REFRESH_SEARCH_ANALYZER_BASE_URI, ), ReplacedRoute( POST, "$REFRESH_SEARCH_ANALYZER_BASE_URI/{index}", - POST, "$LEGACY_REFRESH_SEARCH_ANALYZER_BASE_URI/{index}" - ) + POST, "$LEGACY_REFRESH_SEARCH_ANALYZER_BASE_URI/{index}", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/TransportRefreshSearchAnalyzerAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/TransportRefreshSearchAnalyzerAction.kt index 28473d451..8d17ab077 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/TransportRefreshSearchAnalyzerAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/TransportRefreshSearchAnalyzerAction.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.refreshanalyzer import org.apache.logging.log4j.LogManager import org.opensearch.action.support.ActionFilters -import org.opensearch.core.action.support.DefaultShardOperationFailedException import org.opensearch.action.support.broadcast.node.TransportBroadcastByNodeAction import org.opensearch.cluster.ClusterState import org.opensearch.cluster.block.ClusterBlockException @@ -17,6 +16,7 @@ import org.opensearch.cluster.routing.ShardRouting import org.opensearch.cluster.routing.ShardsIterator import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject +import org.opensearch.core.action.support.DefaultShardOperationFailedException import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.Writeable import org.opensearch.index.analysis.AnalysisRegistry @@ -30,7 +30,8 @@ class TransportRefreshSearchAnalyzerAction : TransportBroadcastByNodeAction< RefreshSearchAnalyzerRequest, RefreshSearchAnalyzerResponse, - RefreshSearchAnalyzerShardResponse> { + RefreshSearchAnalyzerShardResponse, + > { private val log = LogManager.getLogger(javaClass) @@ -41,7 +42,7 @@ class TransportRefreshSearchAnalyzerAction : indicesService: IndicesService, actionFilters: ActionFilters, analysisRegistry: AnalysisRegistry, - indexNameExpressionResolver: IndexNameExpressionResolver? + indexNameExpressionResolver: IndexNameExpressionResolver?, ) : super( RefreshSearchAnalyzerAction.NAME, clusterService, @@ -49,7 +50,7 @@ class TransportRefreshSearchAnalyzerAction : actionFilters, indexNameExpressionResolver, Writeable.Reader { RefreshSearchAnalyzerRequest() }, - ThreadPool.Names.MANAGEMENT + ThreadPool.Names.MANAGEMENT, ) { this.analysisRegistry = analysisRegistry this.indicesService = indicesService @@ -70,7 +71,7 @@ class TransportRefreshSearchAnalyzerAction : failedShards: Int, shardResponses: List, shardFailures: List, - clusterState: ClusterState + clusterState: ClusterState, ): RefreshSearchAnalyzerResponse { return RefreshSearchAnalyzerResponse(totalShards, successfulShards, failedShards, shardFailures, shardResponses) } @@ -86,7 +87,7 @@ class TransportRefreshSearchAnalyzerAction : val reloadedAnalyzers: List = indexShard.mapperService().reloadSearchAnalyzers(analysisRegistry) log.info( "Reload successful, index: ${shardRouting.shardId().index.name}, shard: ${shardRouting.shardId().id}, " + - "is_primary: ${shardRouting.primary()}" + "is_primary: ${shardRouting.primary()}", ) return RefreshSearchAnalyzerShardResponse(shardRouting.shardId(), reloadedAnalyzers) } @@ -102,8 +103,7 @@ class TransportRefreshSearchAnalyzerAction : return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE) } - override fun checkRequestBlock(state: ClusterState, request: RefreshSearchAnalyzerRequest?, concreteIndices: Array?): - ClusterBlockException? { + override fun checkRequestBlock(state: ClusterState, request: RefreshSearchAnalyzerRequest?, concreteIndices: Array?): ClusterBlockException? { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupIndexer.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupIndexer.kt index 55db96c21..e504f9b44 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupIndexer.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupIndexer.kt @@ -40,7 +40,7 @@ import org.opensearch.transport.RemoteTransportException class RollupIndexer( settings: Settings, clusterService: ClusterService, - private val client: Client + private val client: Client, ) { private val logger = LogManager.getLogger(javaClass) @@ -63,7 +63,7 @@ class RollupIndexer( retryIngestPolicy.retry(logger, listOf(RestStatus.TOO_MANY_REQUESTS)) { if (it.seconds >= (Rollup.ROLLUP_LOCK_DURATION_SECONDS / 2)) { throw ExceptionsHelper.convertToOpenSearchException( - IllegalStateException("Cannot retry ingestion with a delay more than half of the rollup lock TTL") + IllegalStateException("Cannot retry ingestion with a delay more than half of the rollup lock TTL"), ) } val bulkRequest = BulkRequest().add(requestsToRetry) @@ -139,6 +139,6 @@ sealed class RollupIndexResult { data class Success(val stats: RollupStats) : RollupIndexResult() data class Failure( val message: String = "An error occurred while indexing to the rollup target index", - val cause: Exception + val cause: Exception, ) : RollupIndexResult() } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperService.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperService.kt index 8ac3b365e..b0711da47 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperService.kt @@ -50,7 +50,7 @@ import org.opensearch.transport.RemoteTransportException class RollupMapperService( val client: Client, val clusterService: ClusterService, - private val indexNameExpressionResolver: IndexNameExpressionResolver + private val indexNameExpressionResolver: IndexNameExpressionResolver, ) { private val logger = LogManager.getLogger(javaClass) @@ -69,7 +69,7 @@ class RollupMapperService( private suspend fun validateAndAttemptToUpdateTargetIndex( rollup: Rollup, targetIndexResolvedName: String, - hasLegacyPlugin: Boolean + hasLegacyPlugin: Boolean, ): RollupJobValidationResult { if (rollup.isTargetIndexAlias()) { val aliasValidationResult = validateTargetIndexAlias(rollup, targetIndexResolvedName) @@ -94,7 +94,6 @@ class RollupMapperService( */ @Suppress("ReturnCount") suspend fun validateTargetIndexAlias(rollup: Rollup, targetIndexResolvedName: String): RollupJobValidationResult { - val errorMessage: String if (!RollupFieldValueExpressionResolver.indexAliasUtils.hasAlias(targetIndexResolvedName)) { @@ -190,6 +189,7 @@ class RollupMapperService( } return resp.isAcknowledged } + @Suppress("ReturnCount") suspend fun prepareTargetIndex(rollup: Rollup, targetIndexResolvedName: String, hasLegacyPlugin: Boolean): RollupJobValidationResult { var errorMessage = "" @@ -287,8 +287,9 @@ class RollupMapperService( val issues = mutableSetOf() // Validate source fields in dimensions rollup.dimensions.forEach { dimension -> - if (!isFieldInMappings(dimension.sourceField, indexMappingSource)) + if (!isFieldInMappings(dimension.sourceField, indexMappingSource)) { issues.add("missing field ${dimension.sourceField}") + } when (dimension) { is DateHistogram -> { @@ -305,8 +306,9 @@ class RollupMapperService( // Validate source fields in metrics rollup.metrics.forEach { metric -> - if (!isFieldInMappings(metric.sourceField, indexMappingSource)) + if (!isFieldInMappings(metric.sourceField, indexMappingSource)) { issues.add("missing field ${metric.sourceField}") + } // TODO: Validate field type for metrics, // are all Numeric field types valid? diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataService.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataService.kt index 41eb84a6a..d73264a77 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataService.kt @@ -86,9 +86,9 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont RollupMetadata( rollupID = rollup.id, lastUpdatedTime = Instant.now(), status = RollupMetadata.Status.FAILED, failureReason = "Not able to get the rollup metadata [${rollup.metadataID}]", - stats = RollupStats(0, 0, 0, 0, 0) + stats = RollupStats(0, 0, 0, 0, 0), ), - false + false, ) } } @@ -119,8 +119,8 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont return MetadataResult.Success( metadata.copy( continuous = continuousMetadata, - status = RollupMetadata.Status.STARTED - ) + status = RollupMetadata.Status.STARTED, + ), ) } @@ -129,20 +129,20 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont MetadataResult.Success( RollupMetadata( rollupID = rollup.id, lastUpdatedTime = Instant.now(), status = RollupMetadata.Status.INIT, - stats = RollupStats(0, 0, 0, 0, 0) - ) + stats = RollupStats(0, 0, 0, 0, 0), + ), ) // This updates the metadata for a non-continuous rollup after an execution of the composite search and ingestion of rollup data private fun getUpdatedNonContinuousMetadata( metadata: RollupMetadata, - internalComposite: InternalComposite + internalComposite: InternalComposite, ): RollupMetadata { val afterKey = internalComposite.afterKey() return metadata.copy( afterKey = afterKey, lastUpdatedTime = Instant.now(), - status = if (afterKey == null) RollupMetadata.Status.FINISHED else RollupMetadata.Status.STARTED + status = if (afterKey == null) RollupMetadata.Status.FINISHED else RollupMetadata.Status.STARTED, ) } @@ -165,8 +165,8 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont continuous = ContinuousMetadata(nextWindowStartTime, nextWindowEndTime), status = RollupMetadata.Status.INIT, failureReason = null, - stats = RollupStats(0, 0, 0, 0, 0) - ) + stats = RollupStats(0, 0, 0, 0, 0), + ), ) } @@ -264,21 +264,25 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont private fun getUpdatedContinuousMetadata( rollup: Rollup, metadata: RollupMetadata, - internalComposite: InternalComposite + internalComposite: InternalComposite, ): RollupMetadata { val afterKey = internalComposite.afterKey() // TODO: get rid of !! val nextStart = if (afterKey == null) { getShiftedTime(metadata.continuous!!.nextWindowStartTime, rollup) - } else metadata.continuous!!.nextWindowStartTime + } else { + metadata.continuous!!.nextWindowStartTime + } val nextEnd = if (afterKey == null) { getShiftedTime(metadata.continuous.nextWindowEndTime, rollup) - } else metadata.continuous.nextWindowEndTime + } else { + metadata.continuous.nextWindowEndTime + } return metadata.copy( afterKey = internalComposite.afterKey(), lastUpdatedTime = Instant.now(), continuous = ContinuousMetadata(nextStart, nextEnd), - status = RollupMetadata.Status.STARTED + status = RollupMetadata.Status.STARTED, ) } @@ -302,7 +306,9 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont return if (rollupMetadata != null) { MetadataResult.Success(rollupMetadata!!) - } else MetadataResult.NoMetadata + } else { + MetadataResult.NoMetadata + } } catch (e: RemoteTransportException) { val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception logger.error("$errorMessage: $unwrappedException") @@ -348,14 +354,14 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont status = RollupMetadata.Status.FAILED, failureReason = reason, lastUpdatedTime = Instant.now(), - stats = RollupStats(0, 0, 0, 0, 0) + stats = RollupStats(0, 0, 0, 0, 0), ) } else { // Update the given existing metadata updatedMetadata = existingMetadata.copy( status = RollupMetadata.Status.FAILED, failureReason = reason, - lastUpdatedTime = Instant.now() + lastUpdatedTime = Instant.now(), ) } @@ -397,8 +403,8 @@ class RollupMetadataService(val client: Client, val xContentRegistry: NamedXCont seqNo = response.seqNo, primaryTerm = response.primaryTerm, status = status, - failureReason = failureReason - ) + failureReason = failureReason, + ), ) } catch (e: RemoteTransportException) { val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupRunner.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupRunner.kt index e4725fb28..7b1327d84 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupRunner.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupRunner.kt @@ -11,13 +11,13 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.bulk.BackoffPolicy import org.opensearch.action.support.WriteRequest import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue +import org.opensearch.core.action.ActionListener import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.indexstatemanagement.SkipExecution import org.opensearch.indexmanagement.opensearchapi.IndexManagementSecurityContext @@ -55,7 +55,7 @@ object RollupRunner : private val logger = LogManager.getLogger(javaClass) private val backoffPolicy = BackoffPolicy.exponentialBackoff( TimeValue.timeValueMillis(RollupSettings.DEFAULT_ACQUIRE_LOCK_RETRY_DELAY), - RollupSettings.DEFAULT_ACQUIRE_LOCK_RETRY_COUNT + RollupSettings.DEFAULT_ACQUIRE_LOCK_RETRY_COUNT, ) private lateinit var clusterService: ClusterService @@ -116,7 +116,7 @@ object RollupRunner : } fun registerMetadataServices( - rollupMetadataService: RollupMetadataService + rollupMetadataService: RollupMetadataService, ): RollupRunner { this.rollupMetadataService = rollupMetadataService return this @@ -187,10 +187,10 @@ object RollupRunner : // TODO: Clean up runner // TODO: Scenario: The rollup job is finished, but I (the user) want to redo it all again /* - * TODO situations: - * There is a rollup.metadataID and doc but theres no job in target index? - * -> index was deleted and recreated as rollup -> just recreate (but we would have to start over)? Or move to FAILED? - * */ + * TODO situations: + * There is a rollup.metadataID and doc but theres no job in target index? + * -> index was deleted and recreated as rollup -> just recreate (but we would have to start over)? Or move to FAILED? + * */ @Suppress("ReturnCount", "NestedBlockDepth", "ComplexMethod", "LongMethod", "ThrowsCount") private suspend fun runRollupJob(job: Rollup, context: JobExecutionContext, lock: LockModel) { logger.debug("Running rollup job [${job.id}]") @@ -233,7 +233,7 @@ object RollupRunner : is RollupJobResult.Success -> updatableJob = updateRollupJobResult.rollup is RollupJobResult.Failure -> { logger.error( - "Failed to update the rollup job [${updatableJob.id}] with metadata id [${metadata.id}]", updateRollupJobResult.cause + "Failed to update the rollup job [${updatableJob.id}] with metadata id [${metadata.id}]", updateRollupJobResult.cause, ) return // Exit runner early } @@ -241,7 +241,7 @@ object RollupRunner : } val result = withClosableContext( - IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user) + IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user), ) { rollupMapperService.attemptCreateRollupTargetIndex(updatableJob, clusterConfigurationProvider.hasLegacyPlugin) } @@ -261,7 +261,7 @@ object RollupRunner : do { try { val rollupSearchResult = withClosableContext( - IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user) + IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user), ) { rollupSearchService.executeCompositeSearch(updatableJob, metadata) } @@ -270,7 +270,7 @@ object RollupRunner : val compositeRes: InternalComposite = rollupSearchResult.searchResponse.aggregations.get(updatableJob.id) metadata = metadata.incrementStats(rollupSearchResult.searchResponse, compositeRes) val rollupIndexResult = withClosableContext( - IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user) + IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user), ) { rollupIndexer.indexRollups(updatableJob, compositeRes) } @@ -287,10 +287,10 @@ object RollupRunner : is RollupResult.Success -> { metadata = rollupMetadataService.updateMetadata( updatableJob, - metadata.mergeStats(rollupResult.stats), rollupResult.internalComposite + metadata.mergeStats(rollupResult.stats), rollupResult.internalComposite, ) updatableJob = withClosableContext( - IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, null) + IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, null), ) { client.suspendUntil { listener: ActionListener -> execute(GetRollupAction.INSTANCE, GetRollupRequest(updatableJob.id, null, "_local"), listener) @@ -299,7 +299,7 @@ object RollupRunner : } is RollupResult.Failure -> { rollupMetadataService.updateMetadata( - metadata.copy(status = RollupMetadata.Status.FAILED, failureReason = rollupResult.cause.message) + metadata.copy(status = RollupMetadata.Status.FAILED, failureReason = rollupResult.cause.message), ) } } @@ -356,7 +356,7 @@ object RollupRunner : private suspend fun updateRollupJob(job: Rollup, metadata: RollupMetadata): RollupJobResult { try { return withClosableContext( - IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, null) + IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, null), ) { val req = IndexRollupRequest(rollup = job, refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE) val res: IndexRollupResponse = client.suspendUntil { execute(IndexRollupAction.INSTANCE, req, it) } @@ -384,7 +384,7 @@ object RollupRunner : @Suppress("ReturnCount", "ComplexMethod") private suspend fun isJobValid(job: Rollup): RollupJobValidationResult { return withClosableContext( - IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user) + IndexManagementSecurityContext(job.id, settings, threadPool.threadContext, job.user), ) { var metadata: RollupMetadata? = null if (job.metadataID != null) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupSearchService.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupSearchService.kt index 91b575a0b..0157a90d2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupSearchService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/RollupSearchService.kt @@ -8,16 +8,16 @@ package org.opensearch.indexmanagement.rollup import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchSecurityException -import org.opensearch.core.action.ActionListener import org.opensearch.action.bulk.BackoffPolicy import org.opensearch.action.search.SearchPhaseExecutionException import org.opensearch.action.search.SearchResponse import org.opensearch.action.search.TransportSearchAction.SEARCH_CANCEL_AFTER_TIME_INTERVAL_SETTING import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService -import org.opensearch.core.common.breaker.CircuitBreakingException import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue +import org.opensearch.core.action.ActionListener +import org.opensearch.core.common.breaker.CircuitBreakingException import org.opensearch.indexmanagement.opensearchapi.retry import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.rollup.model.Rollup @@ -39,7 +39,7 @@ import kotlin.math.pow class RollupSearchService( settings: Settings, clusterService: ClusterService, - val client: Client + val client: Client, ) { private val logger = LogManager.getLogger(javaClass) @@ -108,10 +108,12 @@ class RollupSearchService( val decay = 2f.pow(retryCount++) client.suspendUntil { listener: ActionListener -> val pageSize = max(1, job.pageSize.div(decay.toInt())) - if (decay > 1) logger.warn( - "Composite search failed for rollup, retrying [#${retryCount - 1}] -" + - " reducing page size of composite aggregation from ${job.pageSize} to $pageSize" - ) + if (decay > 1) { + logger.warn( + "Composite search failed for rollup, retrying [#${retryCount - 1}] -" + + " reducing page size of composite aggregation from ${job.pageSize} to $pageSize", + ) + } val searchRequest = job.copy(pageSize = pageSize).getRollupSearchRequest(metadata) val cancelTimeoutTimeValue = TimeValue.timeValueMinutes(getCancelAfterTimeInterval(cancelAfterTimeInterval.minutes)) @@ -119,7 +121,7 @@ class RollupSearchService( search(searchRequest, listener) } - } + }, ) } catch (e: SearchPhaseExecutionException) { logger.error(e.message, e.cause) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/delete/TransportDeleteRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/delete/TransportDeleteRollupAction.kt index b61f70d8b..cfab4fca8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/delete/TransportDeleteRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/delete/TransportDeleteRollupAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.rollup.action.delete import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.delete.DeleteRequest import org.opensearch.action.delete.DeleteResponse import org.opensearch.action.get.GetRequest @@ -19,16 +18,17 @@ import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.rollup.util.parseRollup import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.util.SecurityUtils import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.lang.Exception @@ -40,9 +40,9 @@ class TransportDeleteRollupAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - DeleteRollupAction.NAME, transportService, actionFilters, ::DeleteRollupRequest + DeleteRollupAction.NAME, transportService, actionFilters, ::DeleteRollupRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -62,14 +62,14 @@ class TransportDeleteRollupAction @Inject constructor( private val client: Client, private val actionListener: ActionListener, private val request: DeleteRollupRequest, - private val user: User? = SecurityUtils.buildUser(client.threadPool().threadContext) + private val user: User? = SecurityUtils.buildUser(client.threadPool().threadContext), ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) client.threadPool().threadContext.stashContext().use { getRollup() @@ -104,7 +104,7 @@ class TransportDeleteRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/ExplainRollupResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/ExplainRollupResponse.kt index 69ad4e260..952755163 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/ExplainRollupResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/ExplainRollupResponse.kt @@ -34,7 +34,7 @@ class ExplainRollupResponse : ActionResponse, ToXContentObject { idsToExplain[it.readString()] = if (sin.readBoolean()) ExplainRollup(it) else null } idsToExplain.toMap() - } + }, ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/TransportExplainRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/TransportExplainRollupAction.kt index 0d90fee45..c1b50ab52 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/TransportExplainRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/explain/TransportExplainRollupAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.rollup.action.explain import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.ResourceNotFoundException -import org.opensearch.core.action.ActionListener import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters @@ -18,6 +17,7 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.IdsQueryBuilder import org.opensearch.index.query.WildcardQueryBuilder @@ -42,9 +42,9 @@ class TransportExplainRollupAction @Inject constructor( val client: Client, val settings: Settings, val clusterService: ClusterService, - actionFilters: ActionFilters + actionFilters: ActionFilters, ) : HandledTransportAction( - ExplainRollupAction.NAME, transportService, actionFilters, ::ExplainRollupRequest + ExplainRollupAction.NAME, transportService, actionFilters, ::ExplainRollupRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -61,8 +61,8 @@ class TransportExplainRollupAction @Inject constructor( override fun doExecute(task: Task, request: ExplainRollupRequest, actionListener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val ids = request.rollupIDs // Instantiate concrete ids to metadata map by removing wildcard matches @@ -105,7 +105,8 @@ class TransportExplainRollupAction @Inject constructor( val metadata = contentParser(it.sourceRef) .parseWithType(it.id, it.seqNo, it.primaryTerm, RollupMetadata.Companion::parse) idsToExplain.computeIfPresent(metadata.rollupID) { _, - explainRollup -> + explainRollup, + -> explainRollup.copy(metadata = metadata) } } @@ -124,7 +125,7 @@ class TransportExplainRollupAction @Inject constructor( else -> actionListener.onFailure(e) } } - } + }, ) } @@ -139,7 +140,7 @@ class TransportExplainRollupAction @Inject constructor( else -> actionListener.onFailure(e) } } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupRequest.kt index 95f319ff1..d5b3fc5b9 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupRequest.kt @@ -21,7 +21,7 @@ class GetRollupRequest : ActionRequest { constructor( id: String, srcContext: FetchSourceContext? = null, - preference: String? = null + preference: String? = null, ) : super() { this.id = id this.srcContext = srcContext @@ -32,7 +32,7 @@ class GetRollupRequest : ActionRequest { constructor(sin: StreamInput) : this( id = sin.readString(), srcContext = if (sin.readBoolean()) FetchSourceContext(sin) else null, - preference = sin.readOptionalString() + preference = sin.readOptionalString(), ) override fun validate(): ActionRequestValidationException? { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupResponse.kt index 526fa15b7..ca5c21d68 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.rollup.action.get import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.util._VERSION -import org.opensearch.core.rest.RestStatus import java.io.IOException class GetRollupResponse : ActionResponse, ToXContentObject { @@ -35,7 +35,7 @@ class GetRollupResponse : ActionResponse, ToXContentObject { seqNo: Long, primaryTerm: Long, status: RestStatus, - rollup: Rollup? + rollup: Rollup?, ) : super() { this.id = id this.version = version @@ -52,7 +52,7 @@ class GetRollupResponse : ActionResponse, ToXContentObject { seqNo = sin.readLong(), primaryTerm = sin.readLong(), status = sin.readEnum(RestStatus::class.java), - rollup = if (sin.readBoolean()) Rollup(sin) else null + rollup = if (sin.readBoolean()) Rollup(sin) else null, ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsRequest.kt index e5f78662b..2b86f1e20 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsRequest.kt @@ -25,7 +25,7 @@ class GetRollupsRequest : ActionRequest { from: Int = DEFAULT_FROM, size: Int = DEFAULT_SIZE, sortField: String = DEFAULT_SORT_FIELD, - sortDirection: String = DEFAULT_SORT_DIRECTION + sortDirection: String = DEFAULT_SORT_DIRECTION, ) : super() { this.searchString = searchString this.from = from @@ -40,7 +40,7 @@ class GetRollupsRequest : ActionRequest { from = sin.readInt(), size = sin.readInt(), sortField = sin.readString(), - sortDirection = sin.readString() + sortDirection = sin.readString(), ) override fun validate(): ActionRequestValidationException? = null diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsResponse.kt index d4a58291a..79100e3e5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/GetRollupsResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.rollup.action.get import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -17,7 +18,6 @@ import org.opensearch.indexmanagement.rollup.model.Rollup.Companion.ROLLUP_TYPE import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO -import org.opensearch.core.rest.RestStatus import java.io.IOException class GetRollupsResponse : ActionResponse, ToXContentObject { @@ -28,7 +28,7 @@ class GetRollupsResponse : ActionResponse, ToXContentObject { constructor( rollups: List, totalRollups: Int, - status: RestStatus + status: RestStatus, ) : super() { this.rollups = rollups this.totalRollups = totalRollups @@ -39,7 +39,7 @@ class GetRollupsResponse : ActionResponse, ToXContentObject { constructor(sin: StreamInput) : this( rollups = sin.readList(::Rollup), totalRollups = sin.readInt(), - status = sin.readEnum(RestStatus::class.java) + status = sin.readEnum(RestStatus::class.java), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupAction.kt index 76e6a18b9..1e6e419c7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupAction.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.rollup.action.get import org.apache.logging.log4j.LogManager import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse import org.opensearch.action.support.ActionFilters @@ -16,15 +15,16 @@ import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.rollup.util.parseRollup import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.util.SecurityUtils import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.lang.Exception @@ -35,9 +35,9 @@ class TransportGetRollupAction @Inject constructor( actionFilters: ActionFilters, val settings: Settings, val clusterService: ClusterService, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction ( - GetRollupAction.NAME, transportService, actionFilters, ::GetRollupRequest + GetRollupAction.NAME, transportService, actionFilters, ::GetRollupRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -53,8 +53,8 @@ class TransportGetRollupAction @Inject constructor( override fun doExecute(task: Task, request: GetRollupRequest, listener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val getRequest = GetRequest(INDEX_MANAGEMENT_INDEX, request.id).preference(request.preference) val user = buildUser(client.threadPool().threadContext) @@ -90,7 +90,7 @@ class TransportGetRollupAction @Inject constructor( override fun onFailure(e: Exception) { listener.onFailure(e) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupsAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupsAction.kt index ba7da1895..19271527d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupsAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/get/TransportGetRollupsAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.rollup.action.get import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters @@ -17,8 +16,10 @@ import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.ExistsQueryBuilder import org.opensearch.index.query.WildcardQueryBuilder @@ -29,7 +30,6 @@ import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.util.SecurityUtils.Companion.addUserFilter import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser -import org.opensearch.core.rest.RestStatus import org.opensearch.search.builder.SearchSourceBuilder import org.opensearch.search.sort.SortOrder import org.opensearch.tasks.Task @@ -42,9 +42,9 @@ class TransportGetRollupsAction @Inject constructor( actionFilters: ActionFilters, val clusterService: ClusterService, val settings: Settings, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction ( - GetRollupsAction.NAME, transportService, actionFilters, ::GetRollupsRequest + GetRollupsAction.NAME, transportService, actionFilters, ::GetRollupsRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -59,8 +59,8 @@ class TransportGetRollupsAction @Inject constructor( override fun doExecute(task: Task, request: GetRollupsRequest, listener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val searchString = request.searchString.trim() val from = request.from @@ -97,15 +97,15 @@ class TransportGetRollupsAction @Inject constructor( listener.onFailure( OpenSearchStatusException( "Failed to parse rollups", - RestStatus.INTERNAL_SERVER_ERROR, ExceptionsHelper.unwrapCause(e) - ) + RestStatus.INTERNAL_SERVER_ERROR, ExceptionsHelper.unwrapCause(e), + ), ) } } } override fun onFailure(e: Exception) = listener.onFailure(e) - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupRequest.kt index 3983621f7..8896f0600 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupRequest.kt @@ -27,7 +27,7 @@ class IndexRollupRequest : IndexRequest { constructor( rollup: Rollup, - refreshPolicy: WriteRequest.RefreshPolicy + refreshPolicy: WriteRequest.RefreshPolicy, ) { this.rollup = rollup if (rollup.seqNo == SequenceNumbers.UNASSIGNED_SEQ_NO || rollup.primaryTerm == SequenceNumbers.UNASSIGNED_PRIMARY_TERM) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupResponse.kt index 30f2ecccc..1fd220815 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/IndexRollupResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.rollup.action.index import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.util._VERSION -import org.opensearch.core.rest.RestStatus import java.io.IOException class IndexRollupResponse : ActionResponse, ToXContentObject { @@ -35,7 +35,7 @@ class IndexRollupResponse : ActionResponse, ToXContentObject { seqNo: Long, primaryTerm: Long, status: RestStatus, - rollup: Rollup + rollup: Rollup, ) : super() { this.id = id this.version = version @@ -52,7 +52,7 @@ class IndexRollupResponse : ActionResponse, ToXContentObject { seqNo = sin.readLong(), primaryTerm = sin.readLong(), status = sin.readEnum(RestStatus::class.java), - rollup = Rollup(sin) + rollup = Rollup(sin), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/TransportIndexRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/TransportIndexRollupAction.kt index ccfcfcad8..aca54b65d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/TransportIndexRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/index/TransportIndexRollupAction.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.rollup.action.index import org.apache.logging.log4j.LogManager import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteRequest import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse @@ -20,11 +19,13 @@ import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory.jsonBuilder import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.rollup.model.Rollup @@ -35,7 +36,6 @@ import org.opensearch.indexmanagement.util.IndexUtils import org.opensearch.indexmanagement.util.SecurityUtils import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.validateUserConfiguration -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -48,9 +48,9 @@ class TransportIndexRollupAction @Inject constructor( val indexManagementIndices: IndexManagementIndices, val clusterService: ClusterService, val settings: Settings, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - IndexRollupAction.NAME, transportService, actionFilters, ::IndexRollupRequest + IndexRollupAction.NAME, transportService, actionFilters, ::IndexRollupRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -71,14 +71,14 @@ class TransportIndexRollupAction @Inject constructor( private val client: Client, private val actionListener: ActionListener, private val request: IndexRollupRequest, - private val user: User? = buildUser(client.threadPool().threadContext, request.rollup.user) + private val user: User? = buildUser(client.threadPool().threadContext, request.rollup.user), ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) client.threadPool().threadContext.stashContext().use { if (!validateUserConfiguration(user, filterByEnabled, actionListener)) { @@ -96,8 +96,8 @@ class TransportIndexRollupAction @Inject constructor( return actionListener.onFailure( OpenSearchStatusException( "target_index value is invalid: ${request.rollup.targetIndex}", - RestStatus.BAD_REQUEST - ) + RestStatus.BAD_REQUEST, + ), ) } putRollup() @@ -141,8 +141,8 @@ class TransportIndexRollupAction @Inject constructor( return actionListener.onFailure( OpenSearchStatusException( "target_index value is invalid: ${request.rollup.targetIndex}", - RestStatus.BAD_REQUEST - ) + RestStatus.BAD_REQUEST, + ), ) } putRollup() @@ -176,8 +176,8 @@ class TransportIndexRollupAction @Inject constructor( actionListener.onResponse( IndexRollupResponse( response.id, response.version, response.seqNo, response.primaryTerm, status, - rollup.copy(seqNo = response.seqNo, primaryTerm = response.primaryTerm) - ) + rollup.copy(seqNo = response.seqNo, primaryTerm = response.primaryTerm), + ), ) } } @@ -185,7 +185,7 @@ class TransportIndexRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(e) } - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/mapping/TransportUpdateRollupMappingAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/mapping/TransportUpdateRollupMappingAction.kt index f17e45ecf..a2f10ffb9 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/mapping/TransportUpdateRollupMappingAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/mapping/TransportUpdateRollupMappingAction.kt @@ -6,7 +6,6 @@ package org.opensearch.indexmanagement.rollup.action.mapping import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction @@ -17,14 +16,15 @@ import org.opensearch.cluster.block.ClusterBlockException import org.opensearch.cluster.block.ClusterBlockLevel import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.service.ClusterService -import org.opensearch.core.common.bytes.BytesReference import org.opensearch.common.inject.Inject -import org.opensearch.core.common.io.stream.StreamInput -import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.core.xcontent.MediaType import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.action.ActionListener +import org.opensearch.core.common.bytes.BytesReference +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.common.io.stream.Writeable +import org.opensearch.core.xcontent.MediaType import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT_TYPE import org.opensearch.indexmanagement.rollup.util.RollupFieldValueExpressionResolver import org.opensearch.indexmanagement.util.IndexUtils.Companion._META @@ -38,7 +38,7 @@ class TransportUpdateRollupMappingAction @Inject constructor( transportService: TransportService, actionFilters: ActionFilters, indexNameExpressionResolver: IndexNameExpressionResolver, - val client: Client + val client: Client, ) : TransportClusterManagerNodeAction( UpdateRollupMappingAction.INSTANCE.name(), transportService, @@ -46,7 +46,7 @@ class TransportUpdateRollupMappingAction @Inject constructor( threadPool, actionFilters, Writeable.Reader { UpdateRollupMappingRequest(it) }, - indexNameExpressionResolver + indexNameExpressionResolver, ) { private val log = LogManager.getLogger(javaClass) @@ -60,7 +60,7 @@ class TransportUpdateRollupMappingAction @Inject constructor( override fun masterOperation( request: UpdateRollupMappingRequest, state: ClusterState, - listener: ActionListener + listener: ActionListener, ) { val targetIndexResolvedName = RollupFieldValueExpressionResolver.resolve(request.rollup, request.rollup.targetIndex) val index = state.metadata.index(targetIndexResolvedName) @@ -82,7 +82,7 @@ class TransportUpdateRollupMappingAction @Inject constructor( val rollup = XContentHelper.convertToMap( BytesReference.bytes(request.rollup.toXContent(XContentFactory.jsonBuilder(), XCONTENT_WITHOUT_TYPE)), false, - XContentType.JSON as (MediaType) + XContentType.JSON as (MediaType), ).v2() val metaMappings = mutableMapOf() // TODO: Clean this up @@ -104,7 +104,7 @@ class TransportUpdateRollupMappingAction @Inject constructor( if ((rollups as Map<*, *>).containsKey(request.rollup.id)) { log.debug("Meta rollup mappings already contain rollup ${request.rollup.id} for index [$index]") return listener.onFailure( - IllegalStateException("Meta rollup mappings already contain rollup ${request.rollup.id} for index [$index]") + IllegalStateException("Meta rollup mappings already contain rollup ${request.rollup.id} for index [$index]"), ) } @@ -128,7 +128,7 @@ class TransportUpdateRollupMappingAction @Inject constructor( override fun onFailure(e: Exception) { listener.onFailure(e) } - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/start/TransportStartRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/start/TransportStartRollupAction.kt index 47320ed4f..584b1cbcc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/start/TransportStartRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/start/TransportStartRollupAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.rollup.action.start import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteResponse import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse @@ -22,11 +21,13 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.rollup.model.Rollup @@ -35,7 +36,6 @@ import org.opensearch.indexmanagement.rollup.util.parseRollup import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.lang.IllegalArgumentException @@ -48,9 +48,9 @@ class TransportStartRollupAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - StartRollupAction.NAME, transportService, actionFilters, ::StartRollupRequest + StartRollupAction.NAME, transportService, actionFilters, ::StartRollupRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -66,8 +66,8 @@ class TransportStartRollupAction @Inject constructor( override fun doExecute(task: Task, request: StartRollupRequest, actionListener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val getReq = GetRequest(INDEX_MANAGEMENT_INDEX, request.id()) val user: User? = buildUser(client.threadPool().threadContext) @@ -106,7 +106,7 @@ class TransportStartRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } @@ -118,9 +118,9 @@ class TransportStartRollupAction @Inject constructor( mapOf( Rollup.ROLLUP_TYPE to mapOf( Rollup.ENABLED_FIELD to true, - Rollup.ENABLED_TIME_FIELD to now, Rollup.LAST_UPDATED_TIME_FIELD to now - ) - ) + Rollup.ENABLED_TIME_FIELD to now, Rollup.LAST_UPDATED_TIME_FIELD to now, + ), + ), ) client.update( request, @@ -140,7 +140,7 @@ class TransportStartRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -158,7 +158,7 @@ class TransportStartRollupAction @Inject constructor( val metadata = response.sourceAsBytesRef?.let { val xcp = XContentHelper.createParser( NamedXContentRegistry.EMPTY, - LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON, ) xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, RollupMetadata.Companion::parse) } @@ -175,7 +175,7 @@ class TransportStartRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -192,9 +192,9 @@ class TransportStartRollupAction @Inject constructor( mapOf( RollupMetadata.ROLLUP_METADATA_TYPE to mapOf( RollupMetadata.STATUS_FIELD to updatedStatus.type, - RollupMetadata.FAILURE_REASON to null, RollupMetadata.LAST_UPDATED_FIELD to now - ) - ) + RollupMetadata.FAILURE_REASON to null, RollupMetadata.LAST_UPDATED_FIELD to now, + ), + ), ) .routing(rollup.id) client.update( @@ -207,7 +207,7 @@ class TransportStartRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/stop/TransportStopRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/stop/TransportStopRollupAction.kt index 4b4487c17..2c881cc15 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/stop/TransportStopRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/action/stop/TransportStopRollupAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.rollup.action.stop import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteResponse import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse @@ -22,10 +21,12 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.rollup.model.Rollup @@ -34,7 +35,6 @@ import org.opensearch.indexmanagement.rollup.util.parseRollup import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.lang.IllegalArgumentException @@ -59,9 +59,9 @@ class TransportStopRollupAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - StopRollupAction.NAME, transportService, actionFilters, ::StopRollupRequest + StopRollupAction.NAME, transportService, actionFilters, ::StopRollupRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -79,8 +79,8 @@ class TransportStopRollupAction @Inject constructor( log.debug("Executing StopRollupAction on ${request.id()}") log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val getRequest = GetRequest(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, request.id()) val user = buildUser(client.threadPool().threadContext) @@ -114,7 +114,7 @@ class TransportStopRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } @@ -132,7 +132,7 @@ class TransportStopRollupAction @Inject constructor( val metadata = response.sourceAsBytesRef?.let { val xcp = XContentHelper.createParser( NamedXContentRegistry.EMPTY, - LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON, ) xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, RollupMetadata.Companion::parse) } @@ -148,7 +148,7 @@ class TransportStopRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -164,7 +164,7 @@ class TransportStopRollupAction @Inject constructor( rollup: Rollup, metadata: RollupMetadata, request: StopRollupRequest, - actionListener: ActionListener + actionListener: ActionListener, ) { val now = Instant.now().toEpochMilli() val updatedStatus = when (metadata.status) { @@ -172,16 +172,19 @@ class TransportStopRollupAction @Inject constructor( RollupMetadata.Status.FINISHED, RollupMetadata.Status.FAILED -> metadata.status RollupMetadata.Status.RETRY -> RollupMetadata.Status.FAILED } - val failureReason = if (metadata.status == RollupMetadata.Status.RETRY) - "Stopped a rollup that was in retry, rolling back to failed status" else null + val failureReason = if (metadata.status == RollupMetadata.Status.RETRY) { + "Stopped a rollup that was in retry, rolling back to failed status" + } else { + null + } val updateRequest = UpdateRequest(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, rollup.metadataID) .doc( mapOf( RollupMetadata.ROLLUP_METADATA_TYPE to mapOf( RollupMetadata.STATUS_FIELD to updatedStatus.type, - RollupMetadata.FAILURE_REASON to failureReason, RollupMetadata.LAST_UPDATED_FIELD to now - ) - ) + RollupMetadata.FAILURE_REASON to failureReason, RollupMetadata.LAST_UPDATED_FIELD to now, + ), + ), ) .routing(rollup.id) client.update( @@ -198,7 +201,7 @@ class TransportStopRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -209,9 +212,9 @@ class TransportStopRollupAction @Inject constructor( mapOf( Rollup.ROLLUP_TYPE to mapOf( Rollup.ENABLED_FIELD to false, - Rollup.ENABLED_TIME_FIELD to null, Rollup.LAST_UPDATED_TIME_FIELD to now - ) - ) + Rollup.ENABLED_TIME_FIELD to null, Rollup.LAST_UPDATED_TIME_FIELD to now, + ), + ), ) .routing(rollup.id) client.update( @@ -223,7 +226,7 @@ class TransportStopRollupAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilter.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilter.kt index f870d4fb2..21f00f77f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilter.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilter.kt @@ -6,9 +6,7 @@ package org.opensearch.indexmanagement.rollup.actionfilter import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.fieldcaps.FieldCapabilities import org.opensearch.action.fieldcaps.FieldCapabilitiesRequest import org.opensearch.action.fieldcaps.FieldCapabilitiesResponse @@ -18,6 +16,8 @@ import org.opensearch.action.support.IndicesOptions import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse import org.opensearch.indexmanagement.GuiceHolder import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.rollup.model.RollupFieldMapping @@ -35,7 +35,7 @@ private val logger = LogManager.getLogger(FieldCapsFilter::class.java) class FieldCapsFilter( val clusterService: ClusterService, val settings: Settings, - private val indexNameExpressionResolver: IndexNameExpressionResolver + private val indexNameExpressionResolver: IndexNameExpressionResolver, ) : ActionFilter { @Volatile private var shouldIntercept = RollupSettings.ROLLUP_DASHBOARDS.get(settings) @@ -51,7 +51,7 @@ class FieldCapsFilter( action: String, request: Request, listener: ActionListener, - chain: ActionFilterChain + chain: ActionFilterChain, ) { if (request is FieldCapabilitiesRequest && shouldIntercept) { val indices = request.indices().map { it.toString() }.toTypedArray() @@ -112,7 +112,7 @@ class FieldCapsFilter( override fun onFailure(e: Exception) { listener.onFailure(e) } - } + }, ) } else { chain.proceed(task, action, request, listener) @@ -168,7 +168,7 @@ class FieldCapsFilter( private fun rewriteResponse( indices: Array, fields: Map>, - rollupIndices: Set + rollupIndices: Set, ): ActionResponse { val filteredIndicesFields = expandIndicesInFields(indices, fields) val rollupIndicesFields = populateRollupIndicesFields(rollupIndices) @@ -193,7 +193,7 @@ class FieldCapsFilter( fieldName, type, isSearchable, true, fieldMappingIndexMap.getValue(fieldMapping) .toTypedArray(), - null, null, mapOf>() + null, null, mapOf>(), ) } @@ -206,7 +206,7 @@ class FieldCapsFilter( clusterService.state(), IndicesOptions.lenientExpand(), true, - rollup.sourceIndex + rollup.sourceIndex, ) sourceIndices.forEach { val mappings = clusterService.state().metadata.index(it).mapping()?.sourceAsMap ?: return rollupFieldMappings @@ -254,7 +254,7 @@ class FieldCapsFilter( private fun expandIndicesInFields( indices: Array, - fields: Map> + fields: Map>, ): Map> { val expandedResponse = mutableMapOf>() fields.keys.forEach { field -> @@ -268,7 +268,7 @@ class FieldCapsFilter( fieldCaps.name, fieldCaps.type, fieldCaps.isSearchable, fieldCaps .isAggregatable, - rewrittenIndices, fieldCaps.nonSearchableIndices(), fieldCaps.nonAggregatableIndices(), fieldCaps.meta() + rewrittenIndices, fieldCaps.nonSearchableIndices(), fieldCaps.nonAggregatableIndices(), fieldCaps.meta(), ) } } @@ -278,7 +278,7 @@ class FieldCapsFilter( private fun mergeFields( f1: Map>, - f2: Map> + f2: Map>, ): Map> { val mergedResponses = mutableMapOf>() val fields = f1.keys.union(f2.keys) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/SerDeHelper.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/SerDeHelper.kt index 5d75b4379..202644d0a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/SerDeHelper.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/SerDeHelper.kt @@ -23,13 +23,13 @@ import org.opensearch.core.common.io.stream.Writeable class ISMFieldCapabilitiesIndexResponse( private val indexName: String, private val responseMap: Map, - private val canMatch: Boolean + private val canMatch: Boolean, ) : Writeable { constructor(sin: StreamInput) : this( indexName = sin.readString(), responseMap = sin.readMap({ it.readString() }, { ISMIndexFieldCapabilities(it) }), - canMatch = sin.readBoolean() + canMatch = sin.readBoolean(), ) override fun writeTo(out: StreamOutput) { @@ -37,7 +37,7 @@ class ISMFieldCapabilitiesIndexResponse( out.writeMap( responseMap, { writer, value -> writer.writeString(value) }, - { writer, value -> value.writeTo(writer) } + { writer, value -> value.writeTo(writer) }, ) out.writeBoolean(canMatch) } @@ -46,7 +46,7 @@ class ISMFieldCapabilitiesIndexResponse( class ISMFieldCapabilitiesResponse( val indices: Array, val responseMap: Map>, - val indexResponses: List + val indexResponses: List, ) { fun toFieldCapabilitiesResponse(): FieldCapabilitiesResponse { @@ -55,7 +55,7 @@ class ISMFieldCapabilitiesResponse( out.writeMap( responseMap, { writer, value -> writer.writeString(value) }, - { writer, value -> writer.writeMap(value, { w, v -> w.writeString(v) }, { w, v -> v.writeTo(w) }) } + { writer, value -> writer.writeMap(value, { w, v -> w.writeString(v) }, { w, v -> v.writeTo(w) }) }, ) out.writeList(indexResponses) val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) @@ -83,7 +83,7 @@ class ISMFieldCapabilities( private val indices: Array?, private val nonSearchableIndices: Array?, private val nonAggregatableIndices: Array?, - private val meta: Map> + private val meta: Map>, ) : Writeable { override fun writeTo(out: StreamOutput) { @@ -97,7 +97,7 @@ class ISMFieldCapabilities( out.writeMap( meta, { writer, value -> writer.writeString(value) }, - { writer, value -> writer.writeCollection(value) { w, v -> w.writeString(v) } } + { writer, value -> writer.writeCollection(value) { w, v -> w.writeString(v) } }, ) } @@ -109,7 +109,7 @@ class ISMFieldCapabilities( indices = sin.readOptionalStringArray(), nonSearchableIndices = sin.readOptionalStringArray(), nonAggregatableIndices = sin.readOptionalStringArray(), - meta = sin.readMap({ it.readString() }, { it.readSet { it.readString() } }) + meta = sin.readMap({ it.readString() }, { it.readSet { it.readString() } }), ) } @@ -118,7 +118,7 @@ class ISMIndexFieldCapabilities( private val type: String, private val isSearchable: Boolean, private val isAggregatable: Boolean, - private val meta: Map + private val meta: Map, ) : Writeable { constructor(sin: StreamInput) : this( @@ -126,7 +126,7 @@ class ISMIndexFieldCapabilities( type = sin.readString(), isSearchable = sin.readBoolean(), isAggregatable = sin.readBoolean(), - meta = sin.readMap({ it.readString() }, { it.readString() }) + meta = sin.readMap({ it.readString() }, { it.readString() }), ) override fun writeTo(out: StreamOutput) { @@ -137,7 +137,7 @@ class ISMIndexFieldCapabilities( out.writeMap( meta, { writer, value: String -> writer.writeString(value) }, - { writer, value: String -> writer.writeString(value) } + { writer, value: String -> writer.writeString(value) }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptor.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptor.kt index ffd1e4bd7..c65584afe 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptor.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptor.kt @@ -55,12 +55,13 @@ import org.opensearch.transport.TransportRequestHandler class RollupInterceptor( val clusterService: ClusterService, val settings: Settings, - val indexNameExpressionResolver: IndexNameExpressionResolver + val indexNameExpressionResolver: IndexNameExpressionResolver, ) : TransportInterceptor { private val logger = LogManager.getLogger(javaClass) @Volatile private var searchEnabled = RollupSettings.ROLLUP_SEARCH_ENABLED.get(settings) + @Volatile private var searchAllJobs = RollupSettings.ROLLUP_SEARCH_ALL_JOBS.get(settings) init { @@ -77,7 +78,7 @@ class RollupInterceptor( action: String, executor: String, forceExecution: Boolean, - actualHandler: TransportRequestHandler + actualHandler: TransportRequestHandler, ): TransportRequestHandler { return object : TransportRequestHandler { override fun messageReceived(request: T, channel: TransportChannel, task: Task) { @@ -97,7 +98,7 @@ class RollupInterceptor( ?: throw IllegalArgumentException("No rollup job associated with target_index") val queryFieldMappings = getQueryMetadata( request.source().query(), - getConcreteSourceIndex(rollupJob.sourceIndex, indexNameExpressionResolver, clusterService.state()) + getConcreteSourceIndex(rollupJob.sourceIndex, indexNameExpressionResolver, clusterService.state()), ) val aggregationFieldMappings = getAggregationMetadata(request.source().aggregations()?.aggregatorFactories) val fieldMappings = queryFieldMappings + aggregationFieldMappings @@ -135,9 +136,9 @@ class RollupInterceptor( } /* - * Validate that all indices have rollup job which matches field mappings from request - * TODO return compiled list of issues here instead of just throwing exception - * */ + * Validate that all indices have rollup job which matches field mappings from request + * TODO return compiled list of issues here instead of just throwing exception + * */ private fun validateIndicies(concreteIndices: Array, fieldMappings: Set): Map> { var allMatchingRollupJobs: Map> = mapOf() for (concreteIndex in concreteIndices) { @@ -156,7 +157,7 @@ class RollupInterceptor( @Suppress("ComplexMethod") private fun getAggregationMetadata( aggregationBuilders: Collection?, - fieldMappings: MutableSet = mutableSetOf() + fieldMappings: MutableSet = mutableSetOf(), ): Set { aggregationBuilders?.forEach { when (it) { @@ -197,7 +198,7 @@ class RollupInterceptor( private fun getQueryMetadata( query: QueryBuilder?, concreteSourceIndexName: String?, - fieldMappings: MutableSet = mutableSetOf() + fieldMappings: MutableSet = mutableSetOf(), ): Set { if (query == null) { return fieldMappings @@ -236,7 +237,7 @@ class RollupInterceptor( query.zeroTermsQuery() != MatchQuery.DEFAULT_ZERO_TERMS_QUERY ) { throw IllegalArgumentException( - "The ${query.name} query is currently not supported with analyzer/slop/zero_terms_query in rollups" + "The ${query.name} query is currently not supported with analyzer/slop/zero_terms_query in rollups", ) } fieldMappings.add(RollupFieldMapping(RollupFieldMapping.Companion.FieldType.DIMENSION, query.fieldName(), Dimension.Type.TERMS.type)) @@ -265,7 +266,7 @@ class RollupInterceptor( @Suppress("ComplexMethod") private fun findMatchingRollupJobs( fieldMappings: Set, - rollupJobs: List + rollupJobs: List, ): Pair>, Set> { val rollupFieldMappings = rollupJobs.map { rollup -> rollup to rollup.populateFieldMappings() @@ -275,8 +276,11 @@ class RollupInterceptor( val unknownFields = mutableSetOf() fieldMappings.forEach { - if (it.mappingType == UNKNOWN_MAPPING) unknownFields.add(it.fieldName) - else knownFieldMappings.add(it) + if (it.mappingType == UNKNOWN_MAPPING) { + unknownFields.add(it.fieldName) + } else { + knownFieldMappings.add(it) + } } val potentialRollupFieldMappings = rollupFieldMappings.filterValues { @@ -294,8 +298,11 @@ class RollupInterceptor( // Adding to the issue if cannot find defined field mapping or if the field is missing fieldMappings.forEach { - if (!allFields.contains(it.fieldName)) issues.add(it.toIssue(true)) - else if (it.mappingType != UNKNOWN_MAPPING && !allFieldMappings.contains(it)) issues.add(it.toIssue()) + if (!allFields.contains(it.fieldName)) { + issues.add(it.toIssue(true)) + } else if (it.mappingType != UNKNOWN_MAPPING && !allFieldMappings.contains(it)) { + issues.add(it.toIssue()) + } } } @@ -312,8 +319,11 @@ class RollupInterceptor( // Picking the job with largest rollup window for now return sortedRollups.reduce { matched, new -> - if (getEstimateRollupInterval(matched) > getEstimateRollupInterval(new)) matched - else new + if (getEstimateRollupInterval(matched) > getEstimateRollupInterval(new)) { + matched + } else { + new + } } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ExplainRollup.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ExplainRollup.kt index fc9763ac3..05b84db6e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ExplainRollup.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ExplainRollup.kt @@ -15,13 +15,13 @@ import java.io.IOException data class ExplainRollup( val metadataID: String? = null, - val metadata: RollupMetadata? = null + val metadata: RollupMetadata? = null, ) : ToXContentObject, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( metadataID = sin.readOptionalString(), - metadata = if (sin.readBoolean()) RollupMetadata(sin) else null + metadata = if (sin.readBoolean()) RollupMetadata(sin) else null, ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollup.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollup.kt index faa7b2244..35df4771f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollup.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollup.kt @@ -6,6 +6,7 @@ package org.opensearch.indexmanagement.rollup.model import org.apache.commons.codec.digest.DigestUtils +import org.opensearch.commons.authuser.User import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable @@ -14,7 +15,6 @@ import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils -import org.opensearch.commons.authuser.User import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Dimension @@ -31,7 +31,7 @@ data class ISMRollup( val targetIndex: String, val pageSize: Int, val dimensions: List, - val metrics: List + val metrics: List, ) : ToXContentObject, Writeable { // TODO: This can be moved to a common place, since this is shared between Rollup and ISMRollup @@ -80,7 +80,7 @@ data class ISMRollup( continuous = false, dimensions = dimensions, metrics = metrics, - user = user + user = user, ) } @@ -99,12 +99,12 @@ data class ISMRollup( Dimension.Type.DATE_HISTOGRAM -> DateHistogram(sin) Dimension.Type.TERMS -> Terms(sin) Dimension.Type.HISTOGRAM -> Histogram(sin) - } + }, ) } dimensionsList.toList() }, - metrics = sin.readList(::RollupMetrics) + metrics = sin.readList(::RollupMetrics), ) override fun toString(): String { @@ -146,7 +146,7 @@ data class ISMRollup( @JvmStatic @Throws(IOException::class) fun parse( - xcp: XContentParser + xcp: XContentParser, ): ISMRollup { var description = "" var targetIndex = "" @@ -168,7 +168,7 @@ data class ISMRollup( XContentParserUtils.ensureExpectedToken( XContentParser.Token.START_ARRAY, xcp.currentToken(), - xcp + xcp, ) while (xcp.nextToken() != XContentParser.Token.END_ARRAY) { dimensions.add(Dimension.parse(xcp)) @@ -178,7 +178,7 @@ data class ISMRollup( XContentParserUtils.ensureExpectedToken( XContentParser.Token.START_ARRAY, xcp.currentToken(), - xcp + xcp, ) while (xcp.nextToken() != XContentParser.Token.END_ARRAY) { metrics.add(RollupMetrics.parse(xcp)) @@ -193,7 +193,7 @@ data class ISMRollup( pageSize = pageSize, dimensions = dimensions, metrics = metrics, - targetIndex = targetIndex + targetIndex = targetIndex, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt index 9cf07f9b8..8cfef5579 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.rollup.model +import org.opensearch.commons.authuser.User import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable @@ -13,7 +14,6 @@ import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.authuser.User import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Dimension @@ -54,7 +54,7 @@ data class Rollup( val continuous: Boolean, val dimensions: List, val metrics: List, - val user: User? = null + val user: User? = null, ) : ScheduledJobParameter, Writeable { init { @@ -142,7 +142,7 @@ data class Rollup( Dimension.Type.DATE_HISTOGRAM -> DateHistogram(sin) Dimension.Type.TERMS -> Terms(sin) Dimension.Type.HISTOGRAM -> Histogram(sin) - } + }, ) } dimensionsList.toList() @@ -150,7 +150,9 @@ data class Rollup( metrics = sin.readList(::RollupMetrics), user = if (sin.readBoolean()) { User(sin) - } else null + } else { + null + }, ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -216,7 +218,8 @@ data class Rollup( companion object { // TODO: Move this enum to Job Scheduler plugin enum class ScheduleType { - CRON, INTERVAL; + CRON, + INTERVAL, } const val ROLLUP_LOCK_DURATION_SECONDS = 1800L // 30 minutes const val ROLLUP_TYPE = "rollup" @@ -241,9 +244,10 @@ data class Rollup( const val MINIMUM_PAGE_SIZE = 1 const val MAXIMUM_PAGE_SIZE = 10_000 const val ROLLUP_DOC_ID_FIELD = "$ROLLUP_TYPE.$_ID" + /* - * _doc_count has to be in root of document so that core's aggregator would pick it up and use it - * */ + * _doc_count has to be in root of document so that core's aggregator would pick it up and use it + * */ const val ROLLUP_DOC_COUNT_FIELD = "_doc_count" const val ROLLUP_DOC_SCHEMA_VERSION_FIELD = "$ROLLUP_TYPE._$SCHEMA_VERSION_FIELD" const val USER_FIELD = "user" @@ -256,7 +260,7 @@ data class Rollup( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): Rollup { var schedule: Schedule? = null var schemaVersion: Long = IndexUtils.DEFAULT_SCHEMA_VERSION @@ -281,7 +285,9 @@ data class Rollup( xcp.nextToken() when (fieldName) { - ROLLUP_ID_FIELD -> { requireNotNull(xcp.text()) { "The rollup_id field is null" } /* Just used for searching */ } + ROLLUP_ID_FIELD -> { + requireNotNull(xcp.text()) { "The rollup_id field is null" } // Just used for searching + } ENABLED_FIELD -> enabled = xcp.booleanValue() SCHEDULE_FIELD -> schedule = ScheduleParser.parse(xcp) SCHEMA_VERSION_FIELD -> schemaVersion = xcp.longValue() @@ -351,7 +357,7 @@ data class Rollup( continuous = continuous, dimensions = dimensions, metrics = metrics, - user = user + user = user, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupFieldMapping.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupFieldMapping.kt index 0bfe12132..86f98cf5f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupFieldMapping.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupFieldMapping.kt @@ -19,10 +19,13 @@ data class RollupFieldMapping(val fieldType: FieldType, val fieldName: String, v } fun toIssue(isFieldMissing: Boolean = false): String { - return if (isFieldMissing || mappingType == UNKNOWN_MAPPING) return "missing field $fieldName" - else when (fieldType) { - FieldType.METRIC -> "missing $mappingType aggregation on $fieldName" - else -> "missing $mappingType grouping on $fieldName" + return if (isFieldMissing || mappingType == UNKNOWN_MAPPING) { + return "missing field $fieldName" + } else { + when (fieldType) { + FieldType.METRIC -> "missing $mappingType aggregation on $fieldName" + else -> "missing $mappingType grouping on $fieldName" + } } } @@ -30,7 +33,8 @@ data class RollupFieldMapping(val fieldType: FieldType, val fieldName: String, v const val UNKNOWN_MAPPING = "unknown" enum class FieldType(val type: String) { DIMENSION(DIMENSIONS_FIELD), - METRIC(METRICS_FIELD); + METRIC(METRICS_FIELD), + ; override fun toString(): String { return type diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetadata.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetadata.kt index 8c8a32ee7..910059ce5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetadata.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetadata.kt @@ -26,13 +26,13 @@ import java.util.Locale data class ContinuousMetadata( val nextWindowStartTime: Instant, - val nextWindowEndTime: Instant + val nextWindowEndTime: Instant, ) : ToXContentObject, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( nextWindowStartTime = sin.readInstant(), - nextWindowEndTime = sin.readInstant() + nextWindowEndTime = sin.readInstant(), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -73,7 +73,7 @@ data class ContinuousMetadata( return ContinuousMetadata( nextWindowStartTime = requireNotNull(windowStartTime) { "Next window start time must not be null for a continuous job" }, - nextWindowEndTime = requireNotNull(windowEndTime) { "Next window end time must not be null for a continuous job" } + nextWindowEndTime = requireNotNull(windowEndTime) { "Next window end time must not be null for a continuous job" }, ) } } @@ -84,7 +84,7 @@ data class RollupStats( val documentsProcessed: Long, val rollupsIndexed: Long, val indexTimeInMillis: Long, - val searchTimeInMillis: Long + val searchTimeInMillis: Long, ) : ToXContentObject, Writeable { @Throws(IOException::class) @@ -93,7 +93,7 @@ data class RollupStats( documentsProcessed = sin.readLong(), rollupsIndexed = sin.readLong(), indexTimeInMillis = sin.readLong(), - searchTimeInMillis = sin.readLong() + searchTimeInMillis = sin.readLong(), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -150,7 +150,7 @@ data class RollupStats( documentsProcessed = requireNotNull(documentsProcessed) { "Documents processed must not be null" }, rollupsIndexed = requireNotNull(rollupsIndexed) { "Rollups indexed must not be null" }, indexTimeInMillis = requireNotNull(indexTimeInMillis) { "Index time in millis must not be null" }, - searchTimeInMillis = requireNotNull(searchTimeInMillis) { "Search time in millis must not be null" } + searchTimeInMillis = requireNotNull(searchTimeInMillis) { "Search time in millis must not be null" }, ) } } @@ -166,7 +166,7 @@ data class RollupMetadata( val continuous: ContinuousMetadata? = null, val status: Status, val failureReason: String? = null, - val stats: RollupStats + val stats: RollupStats, ) : ToXContentObject, Writeable { enum class Status(val type: String) { @@ -175,7 +175,8 @@ data class RollupMetadata( STOPPED("stopped"), FINISHED("finished"), FAILED("failed"), - RETRY("retry"); + RETRY("retry"), + ; override fun toString(): String { return type @@ -193,7 +194,7 @@ data class RollupMetadata( continuous = if (sin.readBoolean()) ContinuousMetadata(sin) else null, status = sin.readEnum(Status::class.java), failureReason = sin.readOptionalString(), - stats = RollupStats(sin) + stats = RollupStats(sin), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -245,7 +246,7 @@ data class RollupMetadata( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): RollupMetadata { var rollupID: String? = null var afterKey: Map? = null @@ -281,7 +282,7 @@ data class RollupMetadata( continuous = continuous, status = requireNotNull(status) { "Status must not be null" }, failureReason = failureReason, - stats = requireNotNull(stats) { "Stats must not be null" } + stats = requireNotNull(stats) { "Stats must not be null" }, ) } @@ -297,8 +298,8 @@ fun RollupMetadata.incrementStats(response: SearchResponse, internalComposite: I pagesProcessed = stats.pagesProcessed + 1L, documentsProcessed = stats.documentsProcessed + internalComposite.buckets.fold(0L) { acc, internalBucket -> acc + internalBucket.docCount }, - searchTimeInMillis = stats.searchTimeInMillis + response.took.millis - ) + searchTimeInMillis = stats.searchTimeInMillis + response.took.millis, + ), ) } @@ -309,7 +310,7 @@ fun RollupMetadata.mergeStats(stats: RollupStats): RollupMetadata { documentsProcessed = this.stats.documentsProcessed + stats.documentsProcessed, rollupsIndexed = this.stats.rollupsIndexed + stats.rollupsIndexed, indexTimeInMillis = this.stats.indexTimeInMillis + stats.indexTimeInMillis, - searchTimeInMillis = this.stats.searchTimeInMillis + stats.searchTimeInMillis - ) + searchTimeInMillis = this.stats.searchTimeInMillis + stats.searchTimeInMillis, + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetrics.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetrics.kt index 26286ae0c..4bcbdb349 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetrics.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/RollupMetrics.kt @@ -25,7 +25,7 @@ import java.io.IOException data class RollupMetrics( val sourceField: String, val targetField: String, - val metrics: List + val metrics: List, ) : ToXContentObject, Writeable { init { @@ -52,11 +52,11 @@ data class RollupMetrics( Metric.Type.MIN -> Min(it) Metric.Type.SUM -> Sum(it) Metric.Type.VALUE_COUNT -> ValueCount(it) - } + }, ) } metricsList.toList() - } + }, ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -128,7 +128,7 @@ data class RollupMetrics( return RollupMetrics( sourceField = requireNotNull(sourceField) { "Source field must not be null" }, targetField = requireNotNull(targetField) { "Target field must not be null" }, - metrics = metrics.toList() + metrics = metrics.toList(), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/metric/Metric.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/metric/Metric.kt index 1fe96dcf5..9d92f3eca 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/metric/Metric.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/metric/Metric.kt @@ -19,7 +19,8 @@ abstract class Metric(val type: Type) : ToXContentObject, Writeable { SUM("sum"), MAX("max"), MIN("min"), - VALUE_COUNT("value_count"); + VALUE_COUNT("value_count"), + ; override fun toString(): String { return type diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryParserExt.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryParserExt.kt index ed1168e8f..5b6d5ce4a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryParserExt.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryParserExt.kt @@ -54,8 +54,11 @@ class QueryStringQueryParserExt : QueryStringQueryParser { if (field == null || Regex.isSimpleMatchPattern(field)) { hasLonelyTerms = true } else { - if (field == EXISTS && queryText?.isNotEmpty() == true) discoveredFields.add(queryText) - else discoveredFields.add(field) + if (field == EXISTS && queryText?.isNotEmpty() == true) { + discoveredFields.add(queryText) + } else { + discoveredFields.add(field) + } } } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryUtil.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryUtil.kt index a82197d5a..830fcafde 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryUtil.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryUtil.kt @@ -24,7 +24,7 @@ object QueryStringQueryUtil { fun rewriteQueryStringQuery( queryBuilder: QueryBuilder, - concreteIndexName: String + concreteIndexName: String, ): QueryStringQueryBuilder { val qsqBuilder = queryBuilder as QueryStringQueryBuilder // Parse query_string query and extract all discovered fields @@ -126,7 +126,7 @@ object QueryStringQueryUtil { } else { val resolvedFields = QueryParserHelper.resolveMappingFields( context, - QueryParserHelper.parseFieldsAndWeights(defaultFields) + QueryParserHelper.parseFieldsAndWeights(defaultFields), ) otherFields = resolvedFields QueryStringQueryParserExt(context, resolvedFields, isLenient) @@ -156,11 +156,17 @@ object QueryStringQueryUtil { queryParser.phraseSlop = qsqBuilder.phraseSlop() queryParser.setQuoteFieldSuffix(qsqBuilder.quoteFieldSuffix()) queryParser.allowLeadingWildcard = - if (qsqBuilder.allowLeadingWildcard() == null) context.queryStringAllowLeadingWildcard() - else qsqBuilder.allowLeadingWildcard() + if (qsqBuilder.allowLeadingWildcard() == null) { + context.queryStringAllowLeadingWildcard() + } else { + qsqBuilder.allowLeadingWildcard() + } queryParser.setAnalyzeWildcard( - if (qsqBuilder.analyzeWildcard() == null) context.queryStringAnalyzeWildcard() - else qsqBuilder.analyzeWildcard() + if (qsqBuilder.analyzeWildcard() == null) { + context.queryStringAnalyzeWildcard() + } else { + qsqBuilder.analyzeWildcard() + }, ) queryParser.enablePositionIncrements = qsqBuilder.enablePositionIncrements() queryParser.setFuzziness(qsqBuilder.fuzziness()) @@ -185,7 +191,7 @@ object QueryStringQueryUtil { @Suppress("EmptyCatchBlock", "LoopWithTooManyJumpStatements") fun resolveMatchPatternFields( context: QueryShardContext, - pattern: String = "*" + pattern: String = "*", ): Map { val allFields = context.simpleMatchToIndexNames(pattern) val fields: MutableMap = HashMap() diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupAction.kt index a97672a26..86a62f5d2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupAction.kt @@ -30,8 +30,8 @@ class RestDeleteRollupAction : BaseRestHandler() { return listOf( ReplacedRoute( DELETE, "$ROLLUP_JOBS_BASE_URI/{rollupID}", - DELETE, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}" - ) + DELETE, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupAction.kt index bce23b1ce..d71bcade7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupAction.kt @@ -28,8 +28,8 @@ class RestExplainRollupAction : BaseRestHandler() { return listOf( ReplacedRoute( GET, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_explain", - GET, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_explain" - ) + GET, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_explain", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupAction.kt index 013b4bfaa..ae174b510 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupAction.kt @@ -36,16 +36,16 @@ class RestGetRollupAction : BaseRestHandler() { return listOf( ReplacedRoute( GET, ROLLUP_JOBS_BASE_URI, - GET, LEGACY_ROLLUP_JOBS_BASE_URI + GET, LEGACY_ROLLUP_JOBS_BASE_URI, ), ReplacedRoute( GET, "$ROLLUP_JOBS_BASE_URI/{rollupID}", - GET, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}" + GET, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}", ), ReplacedRoute( HEAD, "$ROLLUP_JOBS_BASE_URI/{rollupID}", - HEAD, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}" - ) + HEAD, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}", + ), ) } @@ -67,7 +67,7 @@ class RestGetRollupAction : BaseRestHandler() { from, size, sortField, - sortDirection + sortDirection, ) client.execute(GetRollupsAction.INSTANCE, req, RestToXContentListener(channel)) } else { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupAction.kt index 28e807c20..b09f1d2cb 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupAction.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.action.support.WriteRequest import org.opensearch.client.node.NodeClient +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI @@ -29,7 +30,6 @@ import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.PUT import org.opensearch.rest.RestResponse -import org.opensearch.core.rest.RestStatus import org.opensearch.rest.action.RestResponseListener import java.io.IOException import java.time.Instant @@ -44,12 +44,12 @@ class RestIndexRollupAction : BaseRestHandler() { return listOf( ReplacedRoute( PUT, ROLLUP_JOBS_BASE_URI, - PUT, LEGACY_ROLLUP_JOBS_BASE_URI + PUT, LEGACY_ROLLUP_JOBS_BASE_URI, ), ReplacedRoute( PUT, "$ROLLUP_JOBS_BASE_URI/{rollupID}", - PUT, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}" - ) + PUT, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}", + ), ) } @@ -80,8 +80,7 @@ class RestIndexRollupAction : BaseRestHandler() { } } - private fun indexRollupResponse(channel: RestChannel): - RestResponseListener { + private fun indexRollupResponse(channel: RestChannel): RestResponseListener { return object : RestResponseListener(channel) { @Throws(Exception::class) override fun buildResponse(response: IndexRollupResponse): RestResponse { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupAction.kt index ece151c24..f2692ed76 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupAction.kt @@ -30,8 +30,8 @@ class RestStartRollupAction : BaseRestHandler() { return listOf( ReplacedRoute( POST, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_start", - POST, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_start" - ) + POST, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_start", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupAction.kt index f4de4d63b..57447ce3b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupAction.kt @@ -30,8 +30,8 @@ class RestStopRollupAction : BaseRestHandler() { return listOf( ReplacedRoute( POST, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_stop", - POST, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_stop" - ) + POST, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_stop", + ), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/LegacyOpenDistroRollupSettings.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/LegacyOpenDistroRollupSettings.kt index a0e74e81b..2979c8738 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/LegacyOpenDistroRollupSettings.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/LegacyOpenDistroRollupSettings.kt @@ -25,7 +25,7 @@ class LegacyOpenDistroRollupSettings { DEFAULT_ROLLUP_ENABLED, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLUP_SEARCH_ENABLED: Setting = Setting.boolSetting( @@ -33,7 +33,7 @@ class LegacyOpenDistroRollupSettings { true, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLUP_INDEX: Setting = Setting.boolSetting( @@ -41,7 +41,7 @@ class LegacyOpenDistroRollupSettings { false, Setting.Property.IndexScope, Setting.Property.InternalIndex, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLUP_INGEST_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( @@ -49,7 +49,7 @@ class LegacyOpenDistroRollupSettings { TimeValue.timeValueMillis(1000), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLUP_INGEST_BACKOFF_COUNT: Setting = Setting.intSetting( @@ -57,7 +57,7 @@ class LegacyOpenDistroRollupSettings { 5, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLUP_SEARCH_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( @@ -65,7 +65,7 @@ class LegacyOpenDistroRollupSettings { TimeValue.timeValueMillis(1000), Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLUP_SEARCH_BACKOFF_COUNT: Setting = Setting.intSetting( @@ -73,7 +73,7 @@ class LegacyOpenDistroRollupSettings { 5, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) val ROLLUP_DASHBOARDS: Setting = Setting.boolSetting( @@ -81,7 +81,7 @@ class LegacyOpenDistroRollupSettings { DEFAULT_ROLLUP_ENABLED, Setting.Property.NodeScope, Setting.Property.Dynamic, - Setting.Property.Deprecated + Setting.Property.Deprecated, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/RollupSettings.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/RollupSettings.kt index 22238fd6d..bc7228853 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/RollupSettings.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/settings/RollupSettings.kt @@ -26,63 +26,63 @@ class RollupSettings { "plugins.rollup.enabled", LegacyOpenDistroRollupSettings.ROLLUP_ENABLED, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_SEARCH_ENABLED: Setting = Setting.boolSetting( "plugins.rollup.search.enabled", LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_ENABLED, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_INDEX: Setting = Setting.boolSetting( "index.plugins.rollup_index", LegacyOpenDistroRollupSettings.ROLLUP_INDEX, Setting.Property.IndexScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_INGEST_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( "plugins.rollup.ingest.backoff_millis", LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_MILLIS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_INGEST_BACKOFF_COUNT: Setting = Setting.intSetting( "plugins.rollup.ingest.backoff_count", LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_COUNT, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_SEARCH_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( "plugins.rollup.search.backoff_millis", LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_BACKOFF_MILLIS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_SEARCH_BACKOFF_COUNT: Setting = Setting.intSetting( "plugins.rollup.search.backoff_count", LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_BACKOFF_COUNT, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_SEARCH_ALL_JOBS: Setting = Setting.boolSetting( "plugins.rollup.search.search_all_jobs", DEFAULT_SEARCH_ALL_JOBS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val ROLLUP_DASHBOARDS: Setting = Setting.boolSetting( "plugins.rollup.dashboards.enabled", LegacyOpenDistroRollupSettings.ROLLUP_DASHBOARDS, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/QueryShardContextFactory.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/QueryShardContextFactory.kt index 26689b393..cf4dcc42e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/QueryShardContextFactory.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/QueryShardContextFactory.kt @@ -9,15 +9,15 @@ import org.opensearch.Version import org.opensearch.client.Client import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.cluster.service.ClusterService -import org.opensearch.core.common.io.stream.NamedWriteableRegistry import org.opensearch.common.regex.Regex import org.opensearch.common.settings.IndexScopedSettings import org.opensearch.common.settings.Settings import org.opensearch.common.settings.SettingsModule import org.opensearch.common.util.BigArrays +import org.opensearch.core.common.io.stream.NamedWriteableRegistry +import org.opensearch.core.index.Index import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.env.Environment -import org.opensearch.core.index.Index import org.opensearch.index.IndexSettings import org.opensearch.index.mapper.MapperService import org.opensearch.index.query.QueryShardContext @@ -48,7 +48,7 @@ object QueryShardContextFactory { scriptService: ScriptService, xContentRegistry: NamedXContentRegistry, namedWriteableRegistry: NamedWriteableRegistry, - environment: Environment + environment: Environment, ) { this.client = client this.clusterService = clusterService @@ -80,7 +80,7 @@ object QueryShardContextFactory { val settingsModule = SettingsModule( nodeSettings, additionalSettings, - pluginsService.pluginSettingsFilter, emptySet() + pluginsService.pluginSettingsFilter, emptySet(), ) val indexScopedSettings: IndexScopedSettings = settingsModule.indexScopedSettings val idxSettings = newIndexSettings(index, indexSettings, indexScopedSettings) @@ -97,7 +97,7 @@ object QueryShardContextFactory { mapperRegistry, { createShardContext(null) }, { false }, - scriptService + scriptService, ) // In order to be able to call toQuery method on QueryBuilder, we need to setup mappings in MapperService mapperService.merge("_doc", indexMetadata?.mapping()?.source(), MapperService.MergeReason.MAPPING_UPDATE) @@ -119,7 +119,7 @@ object QueryShardContextFactory { null, { pattern -> Regex.simpleMatch(pattern, index?.name) }, { true }, - null + null, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/RollupUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/RollupUtils.kt index 502cc181f..46edba76e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/RollupUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/util/RollupUtils.kt @@ -13,10 +13,10 @@ import org.opensearch.cluster.ClusterState import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken import org.opensearch.common.xcontent.XContentType import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentParser.Token +import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.BoostingQueryBuilder import org.opensearch.index.query.ConstantScoreQueryBuilder @@ -114,7 +114,7 @@ fun Rollup.getCompositeAggregationBuilder(afterKey: Map?): Composit is Average -> { listOf( SumAggregationBuilder(metric.targetFieldWithType(agg) + ".sum").field(metric.sourceField), - ValueCountAggregationBuilder(metric.targetFieldWithType(agg) + ".value_count").field(metric.sourceField) + ValueCountAggregationBuilder(metric.targetFieldWithType(agg) + ".value_count").field(metric.sourceField), ) } is Sum -> listOf(SumAggregationBuilder(metric.targetFieldWithType(agg)).field(metric.sourceField)) @@ -231,20 +231,20 @@ fun Rollup.rewriteAggregationBuilder(aggregationBuilder: AggregationBuilder): Ag "state.sums += doc[\"${this.findMatchingMetricField(aggregationBuilder.field()) + ".sum"}\"].value; " + "state.counts += doc[\"${this.findMatchingMetricField(aggregationBuilder.field()) + ".value_count"}\"" + "].value", - emptyMap() - ) + emptyMap(), + ), ) .combineScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, - "def d = new double[2]; d[0] = state.sums; d[1] = state.counts; return d", emptyMap() - ) + "def d = new double[2]; d[0] = state.sums; d[1] = state.counts; return d", emptyMap(), + ), ) .reduceScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, - "double sum = 0; double count = 0; for (a in states) { sum += a[0]; count += a[1]; } return sum/count", emptyMap() - ) + "double sum = 0; double count = 0; for (a in states) { sum += a[0]; count += a[1]; } return sum/count", emptyMap(), + ), ) } is MaxAggregationBuilder -> { @@ -257,32 +257,32 @@ fun Rollup.rewriteAggregationBuilder(aggregationBuilder: AggregationBuilder): Ag } is ValueCountAggregationBuilder -> { /* - * A value count aggs of a pre-computed value count is incorrect as it just returns the number of - * pre-computed value counts instead of their sum. Unfortunately can't just use the sum aggregation - * because I was not able to find a way to cast the result of that to a long (instead of the returned float) - * and the 3893 vs 3893.0 was bothering me.. so this is the next best I can think of. Hopefully there is a better - * way and we can use that in the future. - * */ + * A value count aggs of a pre-computed value count is incorrect as it just returns the number of + * pre-computed value counts instead of their sum. Unfortunately can't just use the sum aggregation + * because I was not able to find a way to cast the result of that to a long (instead of the returned float) + * and the 3893 vs 3893.0 was bothering me.. so this is the next best I can think of. Hopefully there is a better + * way and we can use that in the future. + * */ ScriptedMetricAggregationBuilder(aggregationBuilder.name) .initScript(Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "state.valueCounts = []", emptyMap())) .mapScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "state.valueCounts.add(doc[\"${this.findMatchingMetricField(aggregationBuilder.field())}\"].value)", - emptyMap() - ) + emptyMap(), + ), ) .combineScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, - "long valueCount = 0; for (vc in state.valueCounts) { valueCount += vc } return valueCount", emptyMap() - ) + "long valueCount = 0; for (vc in state.valueCounts) { valueCount += vc } return valueCount", emptyMap(), + ), ) .reduceScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, - "long valueCount = 0; for (vc in states) { valueCount += vc } return valueCount", emptyMap() - ) + "long valueCount = 0; for (vc in states) { valueCount += vc } return valueCount", emptyMap(), + ), ) } // We do nothing otherwise, the validation logic should have already verified so not throwing an exception @@ -294,7 +294,7 @@ fun Rollup.rewriteAggregationBuilder(aggregationBuilder: AggregationBuilder): Ag fun Rollup.rewriteQueryBuilder( queryBuilder: QueryBuilder, fieldNameMappingTypeMap: Map, - concreteIndexName: String = "" + concreteIndexName: String = "", ): QueryBuilder { return when (queryBuilder) { is TermQueryBuilder -> { @@ -409,7 +409,7 @@ fun Rollup.populateFieldMappings(): Set { fun SearchSourceBuilder.rewriteSearchSourceBuilder( jobs: Set, fieldNameMappingTypeMap: Map, - concreteIndexName: String + concreteIndexName: String, ): SearchSourceBuilder { val ssb = SearchSourceBuilder() // can use first() here as all jobs in the set will have a superset of the query's terms @@ -447,7 +447,7 @@ fun SearchSourceBuilder.rewriteSearchSourceBuilder( fun SearchSourceBuilder.rewriteSearchSourceBuilder( job: Rollup, fieldNameMappingTypeMap: Map, - concreteIndexName: String + concreteIndexName: String, ): SearchSourceBuilder { return this.rewriteSearchSourceBuilder(setOf(job), fieldNameMappingTypeMap, concreteIndexName) } @@ -456,13 +456,13 @@ fun Rollup.getInitialDocValues(docCount: Long): MutableMap = mutableMapOf( Rollup.ROLLUP_DOC_ID_FIELD to this.id, Rollup.ROLLUP_DOC_COUNT_FIELD to docCount, - Rollup.ROLLUP_DOC_SCHEMA_VERSION_FIELD to this.schemaVersion + Rollup.ROLLUP_DOC_SCHEMA_VERSION_FIELD to this.schemaVersion, ) fun parseRollup(response: GetResponse, xContentRegistry: NamedXContentRegistry = NamedXContentRegistry.EMPTY): Rollup { val xcp = XContentHelper.createParser( xContentRegistry, LoggingDeprecationHandler.INSTANCE, - response.sourceAsBytesRef, XContentType.JSON + response.sourceAsBytesRef, XContentType.JSON, ) return xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, Rollup.Companion::parse) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/settings/IndexManagementSettings.kt b/src/main/kotlin/org/opensearch/indexmanagement/settings/IndexManagementSettings.kt index a96442808..a6a038a6b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/settings/IndexManagementSettings.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/settings/IndexManagementSettings.kt @@ -15,7 +15,7 @@ class IndexManagementSettings { "plugins.index_management.filter_by_backend_roles", false, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunner.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunner.kt index b15491c1e..bfc6446f2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunner.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunner.kt @@ -13,25 +13,25 @@ import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager import org.opensearch.action.bulk.BackoffPolicy import org.opensearch.client.Client -import org.opensearch.common.unit.TimeValue -import org.opensearch.indexmanagement.snapshotmanagement.engine.SMStateMachine -import org.opensearch.indexmanagement.snapshotmanagement.engine.states.SMState -import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy -import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata -import org.opensearch.cluster.service.ClusterService -import org.opensearch.common.settings.Settings import org.opensearch.cluster.health.ClusterHealthStatus import org.opensearch.cluster.health.ClusterStateHealth +import org.opensearch.cluster.service.ClusterService +import org.opensearch.common.settings.Settings +import org.opensearch.common.unit.TimeValue +import org.opensearch.core.rest.RestStatus import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementIndices +import org.opensearch.indexmanagement.snapshotmanagement.engine.SMStateMachine +import org.opensearch.indexmanagement.snapshotmanagement.engine.states.SMState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.creationTransitions import org.opensearch.indexmanagement.snapshotmanagement.engine.states.deletionTransitions +import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata +import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.util.acquireLockForScheduledJob import org.opensearch.indexmanagement.util.releaseLockForScheduledJob import org.opensearch.jobscheduler.spi.JobExecutionContext import org.opensearch.jobscheduler.spi.ScheduledJobParameter import org.opensearch.jobscheduler.spi.ScheduledJobRunner -import org.opensearch.core.rest.RestStatus import org.opensearch.threadpool.ThreadPool import java.time.Instant.now @@ -66,7 +66,7 @@ object SMRunner : private const val EXPONENTIAL_BACKOFF_MILLIS = 1000L private val backoffPolicy: BackoffPolicy = BackoffPolicy.exponentialBackoff( - TimeValue.timeValueMillis(EXPONENTIAL_BACKOFF_MILLIS), MAX_NUMBER_OF_RETRIES + TimeValue.timeValueMillis(EXPONENTIAL_BACKOFF_MILLIS), MAX_NUMBER_OF_RETRIES, ) override fun runJob(job: ScheduledJobParameter, context: JobExecutionContext) { @@ -134,7 +134,7 @@ object SMRunner : // TODO SM more granular error checking val res = client.indexMetadata( initMetadata, job.id, create = true, - seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ) if (res.status() != RestStatus.CREATED) { log.error("Metadata initialization response status is ${res.status()}, expecting CREATED 201.") @@ -156,15 +156,15 @@ object SMRunner : creation = SMMetadata.WorkflowMetadata( SMState.CREATION_START, SMMetadata.Trigger( - time = job.creation.schedule.getNextExecutionTime(now) - ) + time = job.creation.schedule.getNextExecutionTime(now), + ), ), deletion = job.deletion?.let { SMMetadata.WorkflowMetadata( SMState.DELETION_START, SMMetadata.Trigger( - time = job.deletion.schedule.getNextExecutionTime(now) - ) + time = job.deletion.schedule.getNextExecutionTime(now), + ), ) }, ) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMUtils.kt index e3f381971..bed4ebc20 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMUtils.kt @@ -4,6 +4,7 @@ */ @file:Suppress("TooManyFunctions") + package org.opensearch.indexmanagement.snapshotmanagement import org.apache.logging.log4j.LogManager @@ -17,15 +18,17 @@ import org.opensearch.action.get.GetResponse import org.opensearch.action.index.IndexRequest import org.opensearch.action.index.IndexResponse import org.opensearch.client.Client -import org.opensearch.core.common.Strings import org.opensearch.common.time.DateFormatter +import org.opensearch.common.time.DateFormatters import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.common.Strings +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.parseWithType @@ -39,11 +42,10 @@ import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companio import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companion.SM_DOC_ID_SUFFIX import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companion.SM_METADATA_ID_SUFFIX import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companion.SM_TYPE -import org.opensearch.snapshots.SnapshotsService import org.opensearch.jobscheduler.spi.schedule.Schedule -import org.opensearch.core.rest.RestStatus import org.opensearch.snapshots.SnapshotInfo import org.opensearch.snapshots.SnapshotMissingException +import org.opensearch.snapshots.SnapshotsService import org.opensearch.transport.RemoteTransportException import java.time.Instant import java.time.Instant.now @@ -51,7 +53,6 @@ import java.time.ZoneId import java.time.format.DateTimeFormatter import java.time.temporal.ChronoUnit import java.util.Locale -import org.opensearch.common.time.DateFormatters private val log = LogManager.getLogger("o.i.s.SnapshotManagementHelper") @@ -240,7 +241,7 @@ suspend fun Client.getSnapshots( val snapshots = try { getSnapshots( name, - job.snapshotConfig["repository"] as String + job.snapshotConfig["repository"] as String, ) } catch (ex: SnapshotMissingException) { snapshotMissingMsg?.let { log.warn(snapshotMissingMsg) } @@ -269,7 +270,7 @@ fun tryUpdatingNextExecutionTime( nextTime: Instant, schedule: Schedule, workflowType: WorkflowType, - log: Logger + log: Logger, ): UpdateNextExecutionTimeResult { val now = now() return if (!now.isBefore(nextTime)) { @@ -322,7 +323,7 @@ fun validateSMPolicyName(policyName: String) { } if (!Strings.validFileName(policyName)) { errorMessages.add( - "Policy name must not contain the following characters " + Strings.INVALID_FILENAME_CHARS + "." + "Policy name must not contain the following characters " + Strings.INVALID_FILENAME_CHARS + ".", ) } if (errorMessages.isNotEmpty()) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestBaseIndexSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestBaseIndexSMPolicyHandler.kt index 32ca9f9c1..f886dcdce 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestBaseIndexSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestBaseIndexSMPolicyHandler.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.api.resthandler import org.opensearch.action.support.WriteRequest import org.opensearch.client.node.NodeClient +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.SM_POLICIES_URI @@ -23,7 +24,6 @@ import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BytesRestResponse import org.opensearch.rest.RestRequest import org.opensearch.rest.RestResponse -import org.opensearch.core.rest.RestStatus import org.opensearch.rest.action.RestResponseListener import java.time.Instant @@ -57,7 +57,7 @@ abstract class RestBaseIndexSMPolicyHandler : BaseRestHandler() { } return restResponse } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestCreateSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestCreateSMPolicyHandler.kt index ee731d834..1c4f450fc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestCreateSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestCreateSMPolicyHandler.kt @@ -18,7 +18,7 @@ class RestCreateSMPolicyHandler : RestBaseIndexSMPolicyHandler() { override fun routes(): List { return listOf( - Route(RestRequest.Method.POST, "$SM_POLICIES_URI/{policyName}") + Route(RestRequest.Method.POST, "$SM_POLICIES_URI/{policyName}"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestDeleteSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestDeleteSMPolicyHandler.kt index 672a6ff73..f894b1ac6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestDeleteSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestDeleteSMPolicyHandler.kt @@ -25,7 +25,7 @@ class RestDeleteSMPolicyHandler : BaseRestHandler() { override fun routes(): List { return listOf( - Route(RestRequest.Method.DELETE, "$SM_POLICIES_URI/{policyName}") + Route(RestRequest.Method.DELETE, "$SM_POLICIES_URI/{policyName}"), ) } @@ -45,7 +45,7 @@ class RestDeleteSMPolicyHandler : BaseRestHandler() { client.execute( SMActions.DELETE_SM_POLICY_ACTION_TYPE, DeleteSMPolicyRequest(smPolicyNameToDocId(policyName)).setRefreshPolicy(refreshPolicy), - RestToXContentListener(it) + RestToXContentListener(it), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestExplainSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestExplainSMPolicyHandler.kt index deff23cd7..79f45b126 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestExplainSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestExplainSMPolicyHandler.kt @@ -27,7 +27,7 @@ class RestExplainSMPolicyHandler : BaseRestHandler() { override fun routes(): List { return listOf( - Route(GET, "$SM_POLICIES_URI/{policyName}/_explain") + Route(GET, "$SM_POLICIES_URI/{policyName}/_explain"), ) } @@ -40,7 +40,7 @@ class RestExplainSMPolicyHandler : BaseRestHandler() { client.execute( SMActions.EXPLAIN_SM_POLICY_ACTION_TYPE, ExplainSMPolicyRequest(policyNames), - RestToXContentListener(it) + RestToXContentListener(it), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestGetSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestGetSMPolicyHandler.kt index 8149c2da7..b646c87d2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestGetSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestGetSMPolicyHandler.kt @@ -7,8 +7,8 @@ package org.opensearch.indexmanagement.snapshotmanagement.api.resthandler import org.opensearch.client.node.NodeClient import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.SM_POLICIES_URI -import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICY_ACTION_TYPE import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICIES_ACTION_TYPE +import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICY_ACTION_TYPE import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.GetSMPoliciesRequest import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.GetSMPolicyRequest import org.opensearch.indexmanagement.snapshotmanagement.smPolicyNameToDocId @@ -29,7 +29,7 @@ class RestGetSMPolicyHandler : BaseRestHandler() { override fun routes(): List { return listOf( Route(GET, "$SM_POLICIES_URI/{policyName}"), - Route(GET, "$SM_POLICIES_URI/") + Route(GET, "$SM_POLICIES_URI/"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStartSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStartSMPolicyHandler.kt index a5ea32102..7841b44a2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStartSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStartSMPolicyHandler.kt @@ -27,7 +27,7 @@ class RestStartSMPolicyHandler : BaseRestHandler() { override fun routes(): List { return listOf( - Route(RestRequest.Method.POST, "$SM_POLICIES_URI/{policyName}/_start") + Route(RestRequest.Method.POST, "$SM_POLICIES_URI/{policyName}/_start"), ) } @@ -39,7 +39,7 @@ class RestStartSMPolicyHandler : BaseRestHandler() { return RestChannelConsumer { client.execute( SMActions.START_SM_POLICY_ACTION_TYPE, - indexReq, RestToXContentListener(it) + indexReq, RestToXContentListener(it), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStopSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStopSMPolicyHandler.kt index 5bd29a1d4..bd87c5cdf 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStopSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestStopSMPolicyHandler.kt @@ -27,7 +27,7 @@ class RestStopSMPolicyHandler : BaseRestHandler() { override fun routes(): List { return listOf( - Route(RestRequest.Method.POST, "$SM_POLICIES_URI/{policyName}/_stop") + Route(RestRequest.Method.POST, "$SM_POLICIES_URI/{policyName}/_stop"), ) } @@ -39,7 +39,7 @@ class RestStopSMPolicyHandler : BaseRestHandler() { return RestChannelConsumer { client.execute( SMActions.STOP_SM_POLICY_ACTION_TYPE, - indexReq, RestToXContentListener(it) + indexReq, RestToXContentListener(it), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestUpdateSMPolicyHandler.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestUpdateSMPolicyHandler.kt index 3c13076e8..15aa9a60f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestUpdateSMPolicyHandler.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/resthandler/RestUpdateSMPolicyHandler.kt @@ -18,7 +18,7 @@ class RestUpdateSMPolicyHandler : RestBaseIndexSMPolicyHandler() { override fun routes(): List { return listOf( - Route(RestRequest.Method.PUT, "$SM_POLICIES_URI/{policyName}") + Route(RestRequest.Method.PUT, "$SM_POLICIES_URI/{policyName}"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/BaseTransportAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/BaseTransportAction.kt index 2adcbdc0f..9d3091734 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/BaseTransportAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/BaseTransportAction.kt @@ -10,20 +10,20 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.HandledTransportAction import org.opensearch.client.Client -import org.opensearch.core.common.io.stream.Writeable import org.opensearch.common.util.concurrent.ThreadContext.StoredContext import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse +import org.opensearch.core.common.io.stream.Writeable +import org.opensearch.core.rest.RestStatus import org.opensearch.index.engine.VersionConflictEngineException import org.opensearch.indexmanagement.util.IndexManagementException import org.opensearch.indexmanagement.util.SecurityUtils -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -34,7 +34,7 @@ abstract class BaseTransportAction, ) : HandledTransportAction( - name, transportService, actionFilters, requestReader + name, transportService, actionFilters, requestReader, ) { private val log = LogManager.getLogger(javaClass) @@ -43,11 +43,11 @@ abstract class BaseTransportAction + listener: ActionListener, ) { log.debug( "user and roles string from thread context: " + - client.threadPool().threadContext.getTransient(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT) + client.threadPool().threadContext.getTransient(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT), ) val user: User? = SecurityUtils.buildUser(client.threadPool().threadContext) coroutineScope.launch { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/SMActions.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/SMActions.kt index f694c269b..7e8e54105 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/SMActions.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/SMActions.kt @@ -10,13 +10,13 @@ import org.opensearch.action.delete.DeleteResponse import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.indexmanagement.snapshotmanagement.api.transport.delete.TransportDeleteSMPolicyAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.explain.ExplainSMPolicyResponse +import org.opensearch.indexmanagement.snapshotmanagement.api.transport.explain.TransportExplainSMAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.GetSMPoliciesResponse import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.GetSMPolicyResponse +import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.TransportGetSMPoliciesAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.TransportGetSMPolicyAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.index.IndexSMPolicyResponse import org.opensearch.indexmanagement.snapshotmanagement.api.transport.index.TransportIndexSMPolicyAction -import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.TransportGetSMPoliciesAction -import org.opensearch.indexmanagement.snapshotmanagement.api.transport.explain.TransportExplainSMAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.start.TransportStartSMAction import org.opensearch.indexmanagement.snapshotmanagement.api.transport.stop.TransportStopSMAction diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/delete/TransportDeleteSMPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/delete/TransportDeleteSMPolicyAction.kt index 03853b603..36fc7a959 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/delete/TransportDeleteSMPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/delete/TransportDeleteSMPolicyAction.kt @@ -15,6 +15,7 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.commons.authuser.User +import org.opensearch.core.rest.RestStatus import org.opensearch.index.engine.VersionConflictEngineException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -23,7 +24,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions import org.opensearch.indexmanagement.snapshotmanagement.getSMPolicy import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManagementSettings.Companion.FILTER_BY_BACKEND_ROLES import org.opensearch.indexmanagement.util.SecurityUtils.Companion.verifyUserHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.TransportService class TransportDeleteSMPolicyAction @Inject constructor( @@ -33,7 +33,7 @@ class TransportDeleteSMPolicyAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, ) : BaseTransportAction( - DELETE_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::DeleteSMPolicyRequest + DELETE_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::DeleteSMPolicyRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -49,7 +49,7 @@ class TransportDeleteSMPolicyAction @Inject constructor( override suspend fun executeRequest( request: DeleteSMPolicyRequest, user: User?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ): DeleteResponse { val smPolicy = client.getSMPolicy(request.id()) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyRequest.kt index 4e2d6cd7b..0b757a31c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyRequest.kt @@ -11,7 +11,7 @@ import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput class ExplainSMPolicyRequest( - val policyNames: Array + val policyNames: Array, ) : ActionRequest() { override fun validate(): ActionRequestValidationException? { return null diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyResponse.kt index 1bc775c6d..673266efc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/ExplainSMPolicyResponse.kt @@ -36,7 +36,7 @@ class ExplainSMPolicyResponse : ActionResponse, ToXContentObject { policiesToExplain[it.readString()] = sin.readOptionalValue(::ExplainSMPolicy) } policiesToExplain.toMap() - } + }, ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/TransportExplainSMAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/TransportExplainSMAction.kt index dcd1e5fa1..cc58951f4 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/TransportExplainSMAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/explain/TransportExplainSMAction.kt @@ -15,9 +15,10 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext +import org.opensearch.commons.authuser.User +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.authuser.User import org.opensearch.index.IndexNotFoundException import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.ExistsQueryBuilder @@ -39,7 +40,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companio import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManagementSettings.Companion.FILTER_BY_BACKEND_ROLES import org.opensearch.indexmanagement.snapshotmanagement.smMetadataDocIdToPolicyName import org.opensearch.indexmanagement.util.SecurityUtils -import org.opensearch.core.rest.RestStatus import org.opensearch.search.builder.SearchSourceBuilder import org.opensearch.search.fetch.subphase.FetchSourceContext import org.opensearch.transport.TransportService @@ -51,7 +51,7 @@ class TransportExplainSMAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, ) : BaseTransportAction( - SMActions.EXPLAIN_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::ExplainSMPolicyRequest + SMActions.EXPLAIN_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::ExplainSMPolicyRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -67,7 +67,7 @@ class TransportExplainSMAction @Inject constructor( override suspend fun executeRequest( request: ExplainSMPolicyRequest, user: User?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ): ExplainSMPolicyResponse { val policyNames = request.policyNames.toSet() @@ -109,7 +109,7 @@ class TransportExplainSMAction @Inject constructor( // Only return the name and enabled field val includes = arrayOf( "${SMPolicy.SM_TYPE}.$NAME_FIELD", - "${SMPolicy.SM_TYPE}.$ENABLED_FIELD" + "${SMPolicy.SM_TYPE}.$ENABLED_FIELD", ) val fetchSourceContext = FetchSourceContext(true, includes, arrayOf()) val searchSourceBuilder = SearchSourceBuilder().size(MAX_HITS).query(queryBuilder).fetchSource(fetchSourceContext) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesRequest.kt index 5464556d9..c86fcd49c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesRequest.kt @@ -15,7 +15,7 @@ import java.io.IOException class GetSMPoliciesRequest(val searchParams: SearchParams) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( - searchParams = SearchParams(sin) + searchParams = SearchParams(sin), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesResponse.kt index d49b86917..5c4eaeed4 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPoliciesResponse.kt @@ -20,12 +20,12 @@ import org.opensearch.indexmanagement.util._SEQ_NO // totalPolicies may differ from the length of the policies field if the size parameter is introduced class GetSMPoliciesResponse( val policies: List, - val totalPolicies: Long + val totalPolicies: Long, ) : ActionResponse(), ToXContentObject { constructor(sin: StreamInput) : this( policies = sin.readList(::SMPolicy), - totalPolicies = sin.readLong() + totalPolicies = sin.readLong(), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyRequest.kt index 439d93f2e..ee3c2e396 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyRequest.kt @@ -11,7 +11,7 @@ import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput class GetSMPolicyRequest( - val policyID: String + val policyID: String, ) : ActionRequest() { override fun validate(): ActionRequestValidationException? { return null diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyResponse.kt index e02acfd7b..b01d09919 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/GetSMPolicyResponse.kt @@ -24,7 +24,7 @@ class GetSMPolicyResponse( val version: Long, val seqNo: Long, val primaryTerm: Long, - val policy: SMPolicy + val policy: SMPolicy, ) : ActionResponse(), ToXContentObject { constructor(sin: StreamInput) : this( @@ -32,7 +32,7 @@ class GetSMPolicyResponse( version = sin.readLong(), seqNo = sin.readLong(), primaryTerm = sin.readLong(), - policy = SMPolicy(sin) + policy = SMPolicy(sin), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPoliciesAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPoliciesAction.kt index bcc927a09..ad3491647 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPoliciesAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPoliciesAction.kt @@ -6,6 +6,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.api.transport.get import org.apache.logging.log4j.LogManager +import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse @@ -16,8 +17,8 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.commons.authuser.User +import org.opensearch.core.rest.RestStatus import org.opensearch.index.IndexNotFoundException -import org.opensearch.ExceptionsHelper import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.ExistsQueryBuilder import org.opensearch.index.query.Operator @@ -33,7 +34,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManagementSettings.Companion.FILTER_BY_BACKEND_ROLES import org.opensearch.indexmanagement.snapshotmanagement.util.SM_POLICY_NAME_KEYWORD import org.opensearch.indexmanagement.util.SecurityUtils -import org.opensearch.core.rest.RestStatus import org.opensearch.search.builder.SearchSourceBuilder import org.opensearch.transport.TransportService @@ -44,7 +44,7 @@ class TransportGetSMPoliciesAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, ) : BaseTransportAction( - GET_SM_POLICIES_ACTION_NAME, transportService, client, actionFilters, ::GetSMPoliciesRequest + GET_SM_POLICIES_ACTION_NAME, transportService, client, actionFilters, ::GetSMPoliciesRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -60,7 +60,7 @@ class TransportGetSMPoliciesAction @Inject constructor( override suspend fun executeRequest( request: GetSMPoliciesRequest, user: User?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ): GetSMPoliciesResponse { val searchParams = request.searchParams val (policies, totalPoliciesCount) = getAllPolicies(searchParams, user) @@ -92,7 +92,7 @@ class TransportGetSMPoliciesAction @Inject constructor( .must( QueryBuilders.queryStringQuery(searchParams.queryString) .defaultOperator(Operator.AND) - .field(SM_POLICY_NAME_KEYWORD) + .field(SM_POLICY_NAME_KEYWORD), ) // Add user filter if enabled diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPolicyAction.kt index dbfc4f857..15376e707 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/get/TransportGetSMPolicyAction.kt @@ -16,6 +16,7 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.commons.authuser.User +import org.opensearch.core.rest.RestStatus import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -24,7 +25,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions import org.opensearch.indexmanagement.snapshotmanagement.parseSMPolicy import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManagementSettings.Companion.FILTER_BY_BACKEND_ROLES import org.opensearch.indexmanagement.util.SecurityUtils.Companion.verifyUserHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.TransportService class TransportGetSMPolicyAction @Inject constructor( @@ -34,7 +34,7 @@ class TransportGetSMPolicyAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, ) : BaseTransportAction( - GET_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::GetSMPolicyRequest + GET_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::GetSMPolicyRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -50,7 +50,7 @@ class TransportGetSMPolicyAction @Inject constructor( override suspend fun executeRequest( request: GetSMPolicyRequest, user: User?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ): GetSMPolicyResponse { val getRequest = GetRequest(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, request.policyID) val getResponse: GetResponse = try { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyRequest.kt index 03662cf14..3d9e56843 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyRequest.kt @@ -23,7 +23,7 @@ class IndexSMPolicyRequest : IndexRequest { constructor( policy: SMPolicy, create: Boolean, - refreshPolicy: WriteRequest.RefreshPolicy + refreshPolicy: WriteRequest.RefreshPolicy, ) : super() { this.policy = policy this.create(create) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyResponse.kt index 3b4fe8331..ae7861fd6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/IndexSMPolicyResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.api.transport.index import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.util._VERSION -import org.opensearch.core.rest.RestStatus class IndexSMPolicyResponse( val id: String, @@ -26,7 +26,7 @@ class IndexSMPolicyResponse( val seqNo: Long, val primaryTerm: Long, val policy: SMPolicy, - val status: RestStatus + val status: RestStatus, ) : ActionResponse(), ToXContentObject { constructor(sin: StreamInput) : this( @@ -35,7 +35,7 @@ class IndexSMPolicyResponse( seqNo = sin.readLong(), primaryTerm = sin.readLong(), policy = SMPolicy(sin), - status = sin.readEnum(RestStatus::class.java) + status = sin.readEnum(RestStatus::class.java), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/TransportIndexSMPolicyAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/TransportIndexSMPolicyAction.kt index d26e082e3..168107b63 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/TransportIndexSMPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/index/TransportIndexSMPolicyAction.kt @@ -13,9 +13,9 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.commons.authuser.User +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -34,7 +34,7 @@ class TransportIndexSMPolicyAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, ) : BaseTransportAction( - INDEX_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::IndexSMPolicyRequest + INDEX_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::IndexSMPolicyRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -50,7 +50,7 @@ class TransportIndexSMPolicyAction @Inject constructor( override suspend fun executeRequest( request: IndexSMPolicyRequest, user: User?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ): IndexSMPolicyResponse { // If filterBy is enabled and security is disabled or if filter by is enabled and backend role are empty an exception will be thrown SecurityUtils.validateUserConfiguration(user, filterByEnabled) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/start/TransportStartSMAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/start/TransportStartSMAction.kt index ac802a290..a685fd12c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/start/TransportStartSMAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/start/TransportStartSMAction.kt @@ -18,6 +18,7 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.commons.authuser.User +import org.opensearch.core.rest.RestStatus import org.opensearch.index.engine.VersionConflictEngineException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -27,7 +28,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.getSMPolicy import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManagementSettings.Companion.FILTER_BY_BACKEND_ROLES import org.opensearch.indexmanagement.util.SecurityUtils.Companion.verifyUserHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.TransportService import java.time.Instant @@ -38,7 +38,7 @@ class TransportStartSMAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, ) : BaseTransportAction( - SMActions.START_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::StartSMRequest + SMActions.START_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::StartSMRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -54,7 +54,7 @@ class TransportStartSMAction @Inject constructor( override suspend fun executeRequest( request: StartSMRequest, user: User?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ): AcknowledgedResponse { val smPolicy = client.getSMPolicy(request.id()) @@ -75,9 +75,9 @@ class TransportStartSMAction @Inject constructor( SMPolicy.SM_TYPE to mapOf( SMPolicy.ENABLED_FIELD to true, SMPolicy.ENABLED_TIME_FIELD to now, - SMPolicy.LAST_UPDATED_TIME_FIELD to now - ) - ) + SMPolicy.LAST_UPDATED_TIME_FIELD to now, + ), + ), ) val updateResponse: UpdateResponse = try { client.suspendUntil { update(updateRequest, it) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/stop/TransportStopSMAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/stop/TransportStopSMAction.kt index 08626ef43..a54bf27eb 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/stop/TransportStopSMAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/api/transport/stop/TransportStopSMAction.kt @@ -18,6 +18,7 @@ import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.commons.authuser.User +import org.opensearch.core.rest.RestStatus import org.opensearch.index.engine.VersionConflictEngineException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -27,7 +28,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.getSMPolicy import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManagementSettings.Companion.FILTER_BY_BACKEND_ROLES import org.opensearch.indexmanagement.util.SecurityUtils.Companion.verifyUserHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.TransportService import java.time.Instant @@ -38,7 +38,7 @@ class TransportStopSMAction @Inject constructor( val clusterService: ClusterService, val settings: Settings, ) : BaseTransportAction( - SMActions.STOP_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::StopSMRequest + SMActions.STOP_SM_POLICY_ACTION_NAME, transportService, client, actionFilters, ::StopSMRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -54,7 +54,7 @@ class TransportStopSMAction @Inject constructor( override suspend fun executeRequest( request: StopSMRequest, user: User?, - threadContext: ThreadContext.StoredContext + threadContext: ThreadContext.StoredContext, ): AcknowledgedResponse { val smPolicy = client.getSMPolicy(request.id()) @@ -75,9 +75,9 @@ class TransportStopSMAction @Inject constructor( SMPolicy.SM_TYPE to mapOf( SMPolicy.ENABLED_FIELD to false, SMPolicy.ENABLED_TIME_FIELD to null, - SMPolicy.LAST_UPDATED_TIME_FIELD to now - ) - ) + SMPolicy.LAST_UPDATED_TIME_FIELD to now, + ), + ), ) val updateResponse: UpdateResponse = try { client.suspendUntil { update(updateRequest, it) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachine.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachine.kt index 058eeb7d5..fa4153ef5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachine.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachine.kt @@ -10,21 +10,21 @@ import org.apache.logging.log4j.Logger import org.opensearch.action.bulk.BackoffPolicy import org.opensearch.client.Client import org.opensearch.common.settings.Settings -import org.opensearch.commons.ConfigConstants -import org.opensearch.indexmanagement.opensearchapi.IndexManagementSecurityContext -import org.opensearch.indexmanagement.opensearchapi.withClosableContext import org.opensearch.common.unit.TimeValue +import org.opensearch.commons.ConfigConstants import org.opensearch.indexmanagement.IndexManagementIndices +import org.opensearch.indexmanagement.opensearchapi.IndexManagementSecurityContext import org.opensearch.indexmanagement.opensearchapi.retry +import org.opensearch.indexmanagement.opensearchapi.withClosableContext import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementException import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementException.ExceptionKey import org.opensearch.indexmanagement.snapshotmanagement.engine.states.SMResult import org.opensearch.indexmanagement.snapshotmanagement.engine.states.SMState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.WorkflowType import org.opensearch.indexmanagement.snapshotmanagement.indexMetadata -import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata.LatestExecution.Status.TIME_LIMIT_EXCEEDED +import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.util.OpenForTesting import org.opensearch.threadpool.ThreadPool import java.time.Instant.now @@ -65,25 +65,25 @@ class SMStateMachine( log.debug("Start executing {}.", currentState) log.debug( "User and roles string from thread context: ${threadPool.threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) result = withClosableContext( IndexManagementSecurityContext( - job.id, settings, threadPool.threadContext, job.user - ) + job.id, settings, threadPool.threadContext, job.user, + ), ) { log.debug( "User and roles string from thread context: ${threadPool.threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) currentState.instance.execute(this@SMStateMachine) as SMResult } log.debug( "User and roles string from thread context: ${threadPool.threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) when (result) { @@ -93,7 +93,7 @@ class SMStateMachine( result.metadataToSave .setCurrentState(currentState) .resetRetry() - .build() + .build(), ) // break the nextStates loop, to avoid executing other lateral states break @@ -104,7 +104,7 @@ class SMStateMachine( result.metadataToSave .setCurrentState(prevState) .resetRetry() - .build() + .build(), ) // can still execute other lateral states if exists } @@ -145,7 +145,7 @@ class SMStateMachine( job.policyName, message, job.user, - log + log, ) } else { job.notificationConfig?.sendFailureNotification(client, job.policyName, message, job.user, log) @@ -178,7 +178,7 @@ class SMStateMachine( log.warn(errorMessage) metadataBuilder.setLatestExecution( status = SMMetadata.LatestExecution.Status.FAILED, - endTime = now() + endTime = now(), ).resetWorkflow() } } @@ -221,7 +221,7 @@ class SMStateMachine( } private val updateMetaDataRetryPolicy = BackoffPolicy.exponentialBackoff( - TimeValue.timeValueMillis(EXPONENTIAL_BACKOFF_MILLIS), MAX_NUMBER_OF_RETRIES + TimeValue.timeValueMillis(EXPONENTIAL_BACKOFF_MILLIS), MAX_NUMBER_OF_RETRIES, ) /** diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/SMState.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/SMState.kt index 00630bd5e..61101eb8f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/SMState.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/SMState.kt @@ -5,13 +5,13 @@ package org.opensearch.indexmanagement.snapshotmanagement.engine.states +import org.opensearch.indexmanagement.snapshotmanagement.engine.states.creation.CreatingState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.creation.CreationConditionMetState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.creation.CreationFinishedState -import org.opensearch.indexmanagement.snapshotmanagement.engine.states.creation.CreatingState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.creation.CreationStartState +import org.opensearch.indexmanagement.snapshotmanagement.engine.states.deletion.DeletingState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.deletion.DeletionConditionMetState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.deletion.DeletionFinishedState -import org.opensearch.indexmanagement.snapshotmanagement.engine.states.deletion.DeletingState import org.opensearch.indexmanagement.snapshotmanagement.engine.states.deletion.DeletionStartState import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingState.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingState.kt index bc591a486..8d9ff0d29 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingState.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingState.kt @@ -11,12 +11,12 @@ import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotReques import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse import org.opensearch.client.ClusterAdminClient import org.opensearch.indexmanagement.opensearchapi.suspendUntil -import org.opensearch.indexmanagement.snapshotmanagement.engine.SMStateMachine -import org.opensearch.indexmanagement.snapshotmanagement.generateSnapshotName import org.opensearch.indexmanagement.snapshotmanagement.addSMPolicyInSnapshotMetadata +import org.opensearch.indexmanagement.snapshotmanagement.engine.SMStateMachine import org.opensearch.indexmanagement.snapshotmanagement.engine.states.SMResult import org.opensearch.indexmanagement.snapshotmanagement.engine.states.State import org.opensearch.indexmanagement.snapshotmanagement.engine.states.WorkflowType +import org.opensearch.indexmanagement.snapshotmanagement.generateSnapshotName import org.opensearch.indexmanagement.snapshotmanagement.getSnapshots import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata import org.opensearch.snapshots.ConcurrentSnapshotExecutionException @@ -58,7 +58,7 @@ object CreatingState : State { if (snapshotName != null) { log.info("Already created snapshot [$snapshotName] during this execution period starting at $latestExecutionStartTime.") metadataBuilder.setLatestExecution( - status = SMMetadata.LatestExecution.Status.IN_PROGRESS + status = SMMetadata.LatestExecution.Status.IN_PROGRESS, ).setCreationStarted(snapshotName) return SMResult.Next(metadataBuilder) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationConditionMetState.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationConditionMetState.kt index 60f5c0a5f..4f4daabb3 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationConditionMetState.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationConditionMetState.kt @@ -26,7 +26,7 @@ object CreationConditionMetState : State { val nextCreationTime = metadata.creation.trigger.time val updateNextTimeResult = tryUpdatingNextExecutionTime( - metadataBuilder, nextCreationTime, job.creation.schedule, WorkflowType.CREATION, log + metadataBuilder, nextCreationTime, job.creation.schedule, WorkflowType.CREATION, log, ) if (!updateNextTimeResult.updated) { return SMResult.Stay(metadataBuilder) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedState.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedState.kt index 0ad464908..f98ad3032 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedState.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedState.kt @@ -77,7 +77,7 @@ object CreationFinishedState : State { job.creation.timeLimit?.let { timeLimit -> if (timeLimit.isExceed(metadata.creation.latestExecution.startTime)) { return timeLimitExceeded( - timeLimit, metadataBuilder, WorkflowType.CREATION, log + timeLimit, metadataBuilder, WorkflowType.CREATION, log, ) } } @@ -99,7 +99,7 @@ object CreationFinishedState : State { // TODO may want to notify user that we skipped the execution because snapshot creation time is longer than execution schedule val result = tryUpdatingNextExecutionTime( metadataBuilder, metadata.creation.trigger.time, job.creation.schedule, - WorkflowType.CREATION, log + WorkflowType.CREATION, log, ) if (result.updated) { metadataBuilder = result.metadataBuilder diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingState.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingState.kt index 69ed735b6..b1139a2e6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingState.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingState.kt @@ -43,7 +43,7 @@ object DeletingState : State { if (job.deletion == null) { log.warn("Policy deletion config becomes null before trying to delete old snapshots. Reset.") return SMResult.Fail( - metadataBuilder.resetDeletion(), WorkflowType.DELETION, forceReset = true + metadataBuilder.resetDeletion(), WorkflowType.DELETION, forceReset = true, ) } @@ -55,19 +55,20 @@ object DeletingState : State { getSnapshotsErrorMessage(), ) metadataBuilder = getSnapshotsRes.metadataBuilder - if (getSnapshotsRes.failed) + if (getSnapshotsRes.failed) { return SMResult.Fail(metadataBuilder, WorkflowType.DELETION) + } val getSnapshots = getSnapshotsRes.snapshots snapshotsToDelete = filterByDeleteCondition( getSnapshots.filter { it.state() != SnapshotState.IN_PROGRESS }, - job.deletion.condition, log + job.deletion.condition, log, ) if (snapshotsToDelete.isNotEmpty()) { try { val req = DeleteSnapshotRequest( job.snapshotConfig["repository"] as String, - *snapshotsToDelete.toTypedArray() + *snapshotsToDelete.toTypedArray(), ) client.admin().cluster().suspendUntil { deleteSnapshot(req, it) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetState.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetState.kt index b0470291c..9a57bb027 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetState.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetState.kt @@ -30,7 +30,7 @@ object DeletionConditionMetState : State { if (job.deletion == null) { log.warn("Policy deletion config becomes null before checking if delete schedule met. Reset.") return SMResult.Fail( - metadataBuilder.resetDeletion(), WorkflowType.DELETION, forceReset = true + metadataBuilder.resetDeletion(), WorkflowType.DELETION, forceReset = true, ) } @@ -44,7 +44,7 @@ object DeletionConditionMetState : State { metadata.deletion.trigger.time } val updateNextTimeResult = tryUpdatingNextExecutionTime( - metadataBuilder, nextDeletionTime, job.deletion.schedule, WorkflowType.DELETION, log + metadataBuilder, nextDeletionTime, job.deletion.schedule, WorkflowType.DELETION, log, ) if (!updateNextTimeResult.updated) { return SMResult.Stay(metadataBuilder) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionFinishedState.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionFinishedState.kt index 8de31780c..5d5329c19 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionFinishedState.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionFinishedState.kt @@ -44,8 +44,9 @@ object DeletionFinishedState : State { getSnapshotExceptionInDeletionWorkflow(snapshotsStartedDeletion), ) metadataBuilder = getSnapshotsRes.metadataBuilder - if (getSnapshotsRes.failed) + if (getSnapshotsRes.failed) { return SMResult.Fail(metadataBuilder, WorkflowType.DELETION) + } val getSnapshots = getSnapshotsRes.snapshots val existingSnapshotsNameSet = getSnapshots.map { it.snapshotId().name }.toSet() @@ -72,7 +73,7 @@ object DeletionFinishedState : State { // TODO may want to notify user that we skipped the execution because snapshot deletion time is longer than execution schedule job.deletion?.let { val result = tryUpdatingNextExecutionTime( - metadataBuilder, metadata.deletion.trigger.time, job.deletion.schedule, WorkflowType.DELETION, log + metadataBuilder, metadata.deletion.trigger.time, job.deletion.schedule, WorkflowType.DELETION, log, ) if (result.updated) { metadataBuilder = result.metadataBuilder diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/ExplainSMPolicy.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/ExplainSMPolicy.kt index b1f6288c9..58ab17138 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/ExplainSMPolicy.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/ExplainSMPolicy.kt @@ -16,13 +16,13 @@ import java.io.IOException data class ExplainSMPolicy( val metadata: SMMetadata? = null, - val enabled: Boolean? = null + val enabled: Boolean? = null, ) : ToXContentFragment, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( metadata = if (sin.readBoolean()) SMMetadata(sin) else null, - enabled = sin.readOptionalBoolean() + enabled = sin.readOptionalBoolean(), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/NotificationConfig.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/NotificationConfig.kt index 88b38df8d..aa962fe32 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/NotificationConfig.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/NotificationConfig.kt @@ -7,6 +7,9 @@ package org.opensearch.indexmanagement.snapshotmanagement.model import org.apache.logging.log4j.Logger import org.opensearch.client.Client +import org.opensearch.commons.authuser.User +import org.opensearch.commons.notifications.model.EventSource +import org.opensearch.commons.notifications.model.SeverityType import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable @@ -16,9 +19,6 @@ import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.authuser.User -import org.opensearch.commons.notifications.model.EventSource -import org.opensearch.commons.notifications.model.SeverityType import org.opensearch.indexmanagement.common.model.notification.Channel import java.io.IOException @@ -40,7 +40,7 @@ data class NotificationConfig( @Throws(IOException::class) constructor(sin: StreamInput) : this( Channel(sin), - Conditions(sin) + Conditions(sin), ) @Throws(IOException::class) @@ -78,7 +78,7 @@ data class NotificationConfig( policyName: String, message: String, user: User?, - log: Logger + log: Logger, ) { if (this.conditions.timeLimitExceeded) { try { @@ -130,7 +130,7 @@ data class NotificationConfig( return NotificationConfig( channel = requireNotNull(channel) { "Snapshot Management notification channel must not be null" }, - conditions = conditions ?: Conditions() + conditions = conditions ?: Conditions(), ) } } @@ -139,7 +139,7 @@ data class NotificationConfig( val creation: Boolean = true, val deletion: Boolean = false, val failure: Boolean = false, - val timeLimitExceeded: Boolean = false + val timeLimitExceeded: Boolean = false, ) : Writeable, ToXContent { override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMMetadata.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMMetadata.kt index e42486a6f..6f9d11265 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMMetadata.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMMetadata.kt @@ -68,7 +68,7 @@ data class SMMetadata( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): SMMetadata { var policySeqNo: Long? = null var policyPrimaryTerm: Long? = null @@ -96,7 +96,7 @@ data class SMMetadata( deletion = deletion, id = id, seqNo = seqNo, - primaryTerm = primaryTerm + primaryTerm = primaryTerm, ) } @@ -372,7 +372,7 @@ data class SMMetadata( } constructor(sin: StreamInput) : this( - time = sin.readInstant() + time = sin.readInstant(), ) override fun writeTo(out: StreamOutput) { @@ -408,13 +408,13 @@ data class SMMetadata( } return Retry( - count = requireNotNull(count) { "count field in Retry must not be null." } + count = requireNotNull(count) { "count field in Retry must not be null." }, ) } } constructor(sin: StreamInput) : this( - count = sin.readInt() + count = sin.readInt(), ) override fun writeTo(out: StreamOutput) { @@ -444,15 +444,15 @@ data class SMMetadata( WorkflowType.CREATION -> { metadata = metadata.copy( creation = metadata.creation.copy( - currentState = state - ) + currentState = state, + ), ) } WorkflowType.DELETION -> { metadata = metadata.copy( deletion = metadata.deletion?.copy( - currentState = state - ) + currentState = state, + ), ) } } @@ -500,7 +500,7 @@ data class SMMetadata( fun resetDeletion(): Builder { metadata = metadata.copy( - deletion = null + deletion = null, ) return this } @@ -514,7 +514,7 @@ data class SMMetadata( message: String? = null, updateCause: Boolean = true, cause: Exception? = null, - endTime: Instant? = null + endTime: Instant? = null, ): Builder { val messageWithTime = if (message != null) preFixTimeStamp(message) else null val causeWithTime = if (cause != null) preFixTimeStamp(SnapshotManagementException.getUserErrorMessage(cause).message) else null @@ -528,8 +528,8 @@ data class SMMetadata( info = Info( message = messageWithTime, cause = causeWithTime, - ) - ) + ), + ), ) } else { // if started is not null, latestExecution should never be null @@ -541,19 +541,19 @@ data class SMMetadata( cause = if (updateCause) causeWithTime else metadata.creation.latestExecution?.info?.cause, ), endTime = endTime, - ) + ), ) } } metadata = when (workflowType) { WorkflowType.CREATION -> { metadata.copy( - creation = getUpdatedWorkflowMetadata(metadata.creation) + creation = getUpdatedWorkflowMetadata(metadata.creation), ) } WorkflowType.DELETION -> { metadata.copy( - deletion = metadata.deletion?.let { getUpdatedWorkflowMetadata(it) } + deletion = metadata.deletion?.let { getUpdatedWorkflowMetadata(it) }, ) } } @@ -591,15 +591,15 @@ data class SMMetadata( WorkflowType.CREATION -> { metadata = metadata.copy( creation = metadata.creation.copy( - retry = Retry(count = count) - ) + retry = Retry(count = count), + ), ) } WorkflowType.DELETION -> { metadata = metadata.copy( deletion = metadata.deletion?.copy( - retry = Retry(count = count) - ) + retry = Retry(count = count), + ), ) } } @@ -613,8 +613,8 @@ data class SMMetadata( if (metadata.creation.retry != null) { metadata = metadata.copy( creation = metadata.creation.copy( - retry = null - ) + retry = null, + ), ) } } @@ -622,8 +622,8 @@ data class SMMetadata( if (metadata.deletion?.retry != null) { metadata = metadata.copy( deletion = metadata.deletion?.copy( - retry = null - ) + retry = null, + ), ) } } @@ -643,9 +643,9 @@ data class SMMetadata( metadata = metadata.copy( creation = metadata.creation.copy( trigger = metadata.creation.trigger.copy( - time = time - ) - ) + time = time, + ), + ), ) return this } @@ -654,7 +654,7 @@ data class SMMetadata( metadata = metadata.copy( creation = metadata.creation.copy( started = if (snapshot == null) null else listOf(snapshot), - ) + ), ) return this } @@ -665,18 +665,18 @@ data class SMMetadata( metadata = metadata.copy( deletion = deletion.copy( trigger = deletion.trigger.copy( - time = time - ) - ) + time = time, + ), + ), ) } else { metadata = metadata.copy( deletion = WorkflowMetadata( SMState.DELETION_START, Trigger( - time = time + time = time, ), - ) + ), ) } return this @@ -686,7 +686,7 @@ data class SMMetadata( metadata = metadata.copy( deletion = metadata.deletion?.copy( started = snapshots, - ) + ), ) return this } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMPolicy.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMPolicy.kt index 358b84c80..2d240c594 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMPolicy.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/SMPolicy.kt @@ -5,16 +5,16 @@ package org.opensearch.indexmanagement.snapshotmanagement.model +import org.opensearch.common.unit.TimeValue +import org.opensearch.commons.authuser.User import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.unit.TimeValue import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.commons.authuser.User import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_TYPE import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_USER @@ -23,10 +23,10 @@ import org.opensearch.indexmanagement.opensearchapi.nullValueHandler import org.opensearch.indexmanagement.opensearchapi.optionalField import org.opensearch.indexmanagement.opensearchapi.optionalTimeField import org.opensearch.indexmanagement.opensearchapi.optionalUserField -import org.opensearch.indexmanagement.snapshotmanagement.smPolicyNameToMetadataDocId import org.opensearch.indexmanagement.snapshotmanagement.smDocIdToPolicyName -import org.opensearch.indexmanagement.util.IndexUtils +import org.opensearch.indexmanagement.snapshotmanagement.smPolicyNameToMetadataDocId import org.opensearch.indexmanagement.snapshotmanagement.validateDateFormat +import org.opensearch.indexmanagement.util.IndexUtils import org.opensearch.jobscheduler.spi.ScheduledJobParameter import org.opensearch.jobscheduler.spi.schedule.CronSchedule import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule @@ -184,7 +184,7 @@ data class SMPolicy( // If user doesn't provide delete schedule, use the creation schedule if (deletion != null && !deletion.scheduleProvided) { deletion = deletion.copy( - schedule = creation.schedule + schedule = creation.schedule, ) } @@ -210,7 +210,7 @@ data class SMPolicy( seqNo = seqNo, primaryTerm = primaryTerm, notificationConfig = notificationConfig, - user = user + user = user, ) } } @@ -229,7 +229,7 @@ data class SMPolicy( seqNo = sin.readLong(), primaryTerm = sin.readLong(), notificationConfig = sin.readOptionalWriteable { NotificationConfig(it) }, - user = sin.readOptionalWriteable(::User) + user = sin.readOptionalWriteable(::User), ) override fun writeTo(out: StreamOutput) { @@ -281,7 +281,7 @@ data class SMPolicy( return Creation( schedule = requireNotNull(schedule) { "schedule field must not be null" }, - timeLimit = timeLimit + timeLimit = timeLimit, ) } } @@ -416,7 +416,7 @@ data class SMPolicy( constructor(sin: StreamInput) : this( maxCount = sin.readOptionalInt(), maxAge = sin.readOptionalTimeValue(), - minCount = sin.readInt() + minCount = sin.readInt(), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/settings/SnapshotManagementSettings.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/settings/SnapshotManagementSettings.kt index 0e86a687e..22979faf8 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/settings/SnapshotManagementSettings.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/settings/SnapshotManagementSettings.kt @@ -14,7 +14,7 @@ class SnapshotManagementSettings { "plugins.snapshot_management.filter_by_backend_roles", false, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/util/RestHandlerUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/util/RestHandlerUtils.kt index 0efb080de..135507f53 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/util/RestHandlerUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/util/RestHandlerUtils.kt @@ -4,6 +4,7 @@ */ @file:Suppress("TopLevelPropertyNaming", "MatchingDeclarationName") + package org.opensearch.indexmanagement.snapshotmanagement.util import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companion.NAME_FIELD diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/TargetIndexMappingService.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/TargetIndexMappingService.kt index 0d29502a5..bd55f0198 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/TargetIndexMappingService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/TargetIndexMappingService.kt @@ -9,11 +9,11 @@ import org.apache.logging.log4j.LogManager import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse import org.opensearch.client.Client -import org.opensearch.core.common.bytes.BytesReference import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.common.bytes.BytesReference import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser @@ -119,7 +119,7 @@ object TargetIndexMappingService { NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytesReference, - XContentType.JSON + XContentType.JSON, ) loop@while (!xcp.isClosed) { val token = xcp.currentToken() @@ -223,7 +223,6 @@ object TargetIndexMappingService { ) { val iterator = aggBuilders.iterator() while (iterator.hasNext()) { - val aggBuilder = iterator.next() val targetIdxFieldName = aggBuilder.name val fullPath = parentPath?.plus(".")?.plus(targetIdxFieldName) ?: targetIdxFieldName diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformIndexer.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformIndexer.kt index 904c6c6cd..74617cfa3 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformIndexer.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformIndexer.kt @@ -19,19 +19,19 @@ import org.opensearch.action.index.IndexRequest import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.opensearchapi.retry import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.transform.exceptions.TransformIndexException import org.opensearch.indexmanagement.transform.settings.TransformSettings import org.opensearch.indexmanagement.transform.util.TransformContext -import org.opensearch.core.rest.RestStatus import org.opensearch.transport.RemoteTransportException @Suppress("ComplexMethod") class TransformIndexer( settings: Settings, private val clusterService: ClusterService, - private val client: Client + private val client: Client, ) { private val logger = LogManager.getLogger(javaClass) @@ -39,14 +39,14 @@ class TransformIndexer( @Volatile private var backoffPolicy = BackoffPolicy.constantBackoff( TransformSettings.TRANSFORM_JOB_INDEX_BACKOFF_MILLIS.get(settings), - TransformSettings.TRANSFORM_JOB_INDEX_BACKOFF_COUNT.get(settings) + TransformSettings.TRANSFORM_JOB_INDEX_BACKOFF_COUNT.get(settings), ) init { // To update the retry policy with updated settings clusterService.clusterSettings.addSettingsUpdateConsumer( TransformSettings.TRANSFORM_JOB_INDEX_BACKOFF_MILLIS, - TransformSettings.TRANSFORM_JOB_INDEX_BACKOFF_COUNT + TransformSettings.TRANSFORM_JOB_INDEX_BACKOFF_COUNT, ) { millis, count -> backoffPolicy = BackoffPolicy.constantBackoff(millis, count) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformMetadataService.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformMetadataService.kt index e03f5001a..afe2b8850 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformMetadataService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformMetadataService.kt @@ -17,11 +17,11 @@ import org.opensearch.action.index.IndexRequest import org.opensearch.action.index.IndexResponse import org.opensearch.client.Client import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -71,7 +71,7 @@ class TransformMetadataService(private val client: Client, val xContentRegistry: lastUpdatedAt = Instant.now(), status = TransformMetadata.Status.INIT, stats = TransformStats(0, 0, 0, 0, 0), - continuousStats = if (transform.continuous) ContinuousTransformStats(null, null) else null + continuousStats = if (transform.continuous) ContinuousTransformStats(null, null) else null, ) return writeMetadata(metadata) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformProcessedBucketLog.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformProcessedBucketLog.kt index adc2489ef..20bdf061e 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformProcessedBucketLog.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformProcessedBucketLog.kt @@ -38,8 +38,11 @@ class TransformProcessedBucketLog { val md5Crypt = MessageDigest.getInstance("MD5") bucket.entries.sortedBy { it.key }.onEach { entry -> md5Crypt.update( - if (entry.value == null) "null".toByteArray() - else entry.value.toString().toByteArray() + if (entry.value == null) { + "null".toByteArray() + } else { + entry.value.toString().toByteArray() + }, ) } return BigInteger(1, md5Crypt.digest()).toString(HEX_RADIX) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformRunner.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformRunner.kt index 799b49e39..55d35fd24 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformRunner.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformRunner.kt @@ -16,8 +16,8 @@ import org.opensearch.client.Client import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.index.shard.ShardId +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.opensearchapi.IndexManagementSecurityContext import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.opensearchapi.withClosableContext @@ -62,7 +62,7 @@ object TransformRunner : settings: Settings, indexNameExpressionResolver: IndexNameExpressionResolver, jvmService: JvmService, - threadPool: ThreadPool + threadPool: ThreadPool, ): TransformRunner { this.clusterService = clusterService this.client = client @@ -110,7 +110,7 @@ object TransformRunner : var bucketsToTransform = BucketsToTransform(HashSet(), metadata) val transformContext = TransformContext( - TransformLockManager(transform, context) + TransformLockManager(transform, context), ) // Acquires the lock if there is no running job execution for the given transform; Lock is acquired per transform @@ -145,7 +145,7 @@ object TransformRunner : newGlobalCheckpoints = transformSearchService.getShardsGlobalCheckpoint(transform.sourceIndex) bucketsToTransform = bucketsToTransform.initializeShardsToSearch( metadata.shardIDToGlobalCheckpoint, - newGlobalCheckpoints + newGlobalCheckpoints, ) } // If there are shards to search do it here @@ -182,7 +182,7 @@ object TransformRunner : currentMetadata = currentMetadata.copy( lastUpdatedAt = Instant.now(), status = TransformMetadata.Status.FAILED, - failureReason = e.localizedMessage + failureReason = e.localizedMessage, ) } finally { transformLockManager.lock?.let { @@ -190,7 +190,7 @@ object TransformRunner : if (transform.continuous && currentMetadata.status != TransformMetadata.Status.FAILED) { currentMetadata = currentMetadata.copy( shardIDToGlobalCheckpoint = newGlobalCheckpoints, - continuousStats = ContinuousTransformStats(newGlobalCheckpointTime, null) + continuousStats = ContinuousTransformStats(newGlobalCheckpointTime, null), ) } transformMetadataService.writeMetadata(currentMetadata, true) @@ -206,7 +206,7 @@ object TransformRunner : private suspend fun getBucketsToTransformIteration( transform: Transform, bucketsToTransform: BucketsToTransform, - transformContext: TransformContext + transformContext: TransformContext, ): BucketsToTransform { var currentBucketsToTransform = bucketsToTransform val currentShard = bucketsToTransform.currentShard @@ -219,7 +219,7 @@ object TransformRunner : transform, currentBucketsToTransform.metadata.afterKey, currentShard, - transformContext + transformContext, ) } currentBucketsToTransform.modifiedBuckets.addAll(shardLevelModifiedBuckets.modifiedBuckets) @@ -229,11 +229,11 @@ object TransformRunner : metadata = currentBucketsToTransform.metadata.copy( stats = currentBucketsToTransform.metadata.stats.copy( pagesProcessed = currentBucketsToTransform.metadata.stats.pagesProcessed + 1, - searchTimeInMillis = mergedSearchTime + searchTimeInMillis = mergedSearchTime, ), - afterKey = shardLevelModifiedBuckets.afterKey + afterKey = shardLevelModifiedBuckets.afterKey, ), - currentShard = currentShard + currentShard = currentShard, ) } // If finished with this shard, go to the next @@ -256,7 +256,9 @@ object TransformRunner : val failureMessage = "Failed validation - ${validationResult.issues}" val failureMetadata = transformMetadata.copy(status = TransformMetadata.Status.FAILED, failureReason = failureMessage) transformMetadataService.writeMetadata(failureMetadata, true) - } else transformMetadata + } else { + transformMetadata + } } /** @@ -267,15 +269,14 @@ object TransformRunner : private suspend fun computeBucketsIteration( transform: Transform, metadata: TransformMetadata, - transformContext: TransformContext + transformContext: TransformContext, ): TransformMetadata { - val transformSearchResult = withTransformSecurityContext(transform) { transformSearchService.executeCompositeSearch( transform, metadata.afterKey, null, - transformContext + transformContext, ) } val indexTimeInMillis = withTransformSecurityContext(transform) { @@ -286,12 +287,12 @@ object TransformRunner : val updatedStats = stats.copy( pagesProcessed = stats.pagesProcessed, indexTimeInMillis = stats.indexTimeInMillis + indexTimeInMillis, - documentsIndexed = transformSearchResult.docsToIndex.size.toLong() + documentsIndexed = transformSearchResult.docsToIndex.size.toLong(), ) return metadata.mergeStats(updatedStats).copy( afterKey = afterKey, lastUpdatedAt = Instant.now(), - status = if (afterKey == null) TransformMetadata.Status.FINISHED else TransformMetadata.Status.STARTED + status = if (afterKey == null) TransformMetadata.Status.FINISHED else TransformMetadata.Status.STARTED, ) } @@ -299,7 +300,7 @@ object TransformRunner : transform: Transform, metadata: TransformMetadata, modifiedBuckets: MutableSet>, - transformContext: TransformContext + transformContext: TransformContext, ): TransformMetadata { val updatedMetadata = if (modifiedBuckets.isNotEmpty()) { val transformSearchResult = withTransformSecurityContext(transform) { @@ -312,13 +313,15 @@ object TransformRunner : val updatedStats = stats.copy( pagesProcessed = if (transform.continuous) 0 else stats.pagesProcessed, indexTimeInMillis = stats.indexTimeInMillis + indexTimeInMillis, - documentsIndexed = transformSearchResult.docsToIndex.size.toLong() + documentsIndexed = transformSearchResult.docsToIndex.size.toLong(), ) metadata.mergeStats(updatedStats).copy( lastUpdatedAt = Instant.now(), - status = TransformMetadata.Status.STARTED + status = TransformMetadata.Status.STARTED, ) - } else metadata.copy(lastUpdatedAt = Instant.now(), status = TransformMetadata.Status.STARTED) + } else { + metadata.copy(lastUpdatedAt = Instant.now(), status = TransformMetadata.Status.STARTED) + } return updatedMetadata } @@ -329,17 +332,17 @@ object TransformRunner : private suspend fun updateTransform(transform: Transform): Transform { val request = IndexTransformRequest( transform = transform.copy(updatedAt = Instant.now()), - refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE + refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE, ) return withClosableContext( - IndexManagementSecurityContext(transform.id, settings, threadPool.threadContext, null) + IndexManagementSecurityContext(transform.id, settings, threadPool.threadContext, null), ) { val response: IndexTransformResponse = client.suspendUntil { execute(IndexTransformAction.INSTANCE, request, it) } return@withClosableContext transform.copy( seqNo = response.seqNo, - primaryTerm = response.primaryTerm + primaryTerm = response.primaryTerm, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformSearchService.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformSearchService.kt index 58e050645..6e58d89af 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformSearchService.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformSearchService.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.transform import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchSecurityException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.stats.IndicesStatsAction import org.opensearch.action.admin.indices.stats.IndicesStatsRequest import org.opensearch.action.admin.indices.stats.IndicesStatsResponse @@ -23,14 +22,16 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.action.ActionListener import org.opensearch.core.index.Index +import org.opensearch.core.index.shard.ShardId +import org.opensearch.core.rest.RestStatus import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.ExistsQueryBuilder import org.opensearch.index.query.QueryBuilder import org.opensearch.index.query.QueryBuilders import org.opensearch.index.query.RangeQueryBuilder import org.opensearch.index.seqno.SequenceNumbers -import org.opensearch.core.index.shard.ShardId import org.opensearch.indexmanagement.common.model.dimension.Dimension import org.opensearch.indexmanagement.opensearchapi.retry import org.opensearch.indexmanagement.opensearchapi.suspendUntil @@ -41,14 +42,13 @@ import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.transform.model.TransformSearchResult import org.opensearch.indexmanagement.transform.model.TransformStats import org.opensearch.indexmanagement.transform.opensearchapi.retryTransformSearch +import org.opensearch.indexmanagement.transform.settings.TransformSettings.Companion.MINIMUM_CANCEL_AFTER_TIME_INTERVAL_SECONDS import org.opensearch.indexmanagement.transform.settings.TransformSettings.Companion.TRANSFORM_JOB_SEARCH_BACKOFF_COUNT import org.opensearch.indexmanagement.transform.settings.TransformSettings.Companion.TRANSFORM_JOB_SEARCH_BACKOFF_MILLIS import org.opensearch.indexmanagement.transform.util.TransformContext import org.opensearch.indexmanagement.util.IndexUtils.Companion.LUCENE_MAX_CLAUSES import org.opensearch.indexmanagement.util.IndexUtils.Companion.ODFE_MAGIC_NULL import org.opensearch.indexmanagement.util.IndexUtils.Companion.hashToFixedSize -import org.opensearch.core.rest.RestStatus -import org.opensearch.indexmanagement.transform.settings.TransformSettings.Companion.MINIMUM_CANCEL_AFTER_TIME_INTERVAL_SECONDS import org.opensearch.search.aggregations.Aggregation import org.opensearch.search.aggregations.bucket.composite.CompositeAggregation import org.opensearch.search.aggregations.bucket.composite.CompositeAggregationBuilder @@ -72,7 +72,7 @@ import kotlin.math.pow class TransformSearchService( val settings: Settings, val clusterService: ClusterService, - private val client: Client + private val client: Client, ) { private var logger = LogManager.getLogger(javaClass) @@ -127,7 +127,7 @@ class TransformSearchService( transform: Transform, afterKey: Map?, currentShard: ShardNewDocuments, - transformContext: TransformContext + transformContext: TransformContext, ): BucketSearchResult { try { var retryAttempt = 0 @@ -143,7 +143,7 @@ class TransformSearchService( if (retryAttempt > 1) { logger.debug( "Attempt [${retryAttempt - 1}] to get modified buckets for transform [${transform.id}]. Attempting " + - "again with reduced page size [$pageSize]" + "again with reduced page size [$pageSize]", ) } if (searchRequestTimeoutInSeconds == null) { @@ -182,14 +182,15 @@ class TransformSearchService( transform: Transform, afterKey: Map? = null, modifiedBuckets: MutableSet>? = null, - transformContext: TransformContext + transformContext: TransformContext, ): TransformSearchResult { try { var pageSize: Int = - if (modifiedBuckets.isNullOrEmpty()) + if (modifiedBuckets.isNullOrEmpty()) { transform.pageSize - else + } else { modifiedBuckets.size + } var retryAttempt = 0 val searchStart = Instant.now().epochSecond @@ -208,7 +209,7 @@ class TransformSearchService( if (retryAttempt > 1) { logger.debug( "Attempt [${retryAttempt - 1}] of composite search failed for transform [${transform.id}]. Attempting " + - "again with reduced page size [$pageSize]" + "again with reduced page size [$pageSize]", ) } val request = getSearchServiceRequest(transform, afterKey, pageSize, modifiedBuckets, searchRequestTimeoutInSeconds) @@ -222,7 +223,7 @@ class TransformSearchService( transform, searchResponse, modifiedBuckets = modifiedBuckets, - targetIndexDateFieldMappings = transformContext.getTargetIndexDateFieldMappings() + targetIndexDateFieldMappings = transformContext.getTargetIndexDateFieldMappings(), ) } catch (e: TransformSearchServiceException) { throw e @@ -258,7 +259,7 @@ class TransformSearchService( afterKey: Map? = null, pageSize: Int, modifiedBuckets: MutableSet>? = null, - timeoutInSeconds: Long? = null + timeoutInSeconds: Long? = null, ): SearchRequest { val sources = mutableListOf>() transform.groups.forEach { group -> sources.add(group.toSourceBuilder().missingBucket(true)) } @@ -277,7 +278,7 @@ class TransformSearchService( private fun getQueryWithModifiedBuckets( originalQuery: QueryBuilder, modifiedBuckets: MutableSet>, - groups: List + groups: List, ): QueryBuilder { val query: BoolQueryBuilder = QueryBuilders.boolQuery().must(originalQuery).minimumShouldMatch(1) modifiedBuckets.forEach { bucket -> @@ -315,7 +316,7 @@ class TransformSearchService( index: String, query: QueryBuilder, aggregationBuilder: CompositeAggregationBuilder, - timeoutInSeconds: Long? = null + timeoutInSeconds: Long? = null, ): SearchRequest { val searchSourceBuilder = SearchSourceBuilder() .trackTotalHits(false) @@ -336,7 +337,7 @@ class TransformSearchService( afterKey: Map? = null, pageSize: Int, currentShard: ShardNewDocuments, - timeoutInSeconds: Long? + timeoutInSeconds: Long?, ): SearchRequest { val rangeQuery = getSeqNoRangeQuery(currentShard.from, currentShard.to) val query = QueryBuilders.boolQuery().filter(rangeQuery).must(transform.dataSelectionQuery) @@ -395,7 +396,7 @@ class TransformSearchService( // Gathers and returns from the bucket search response the modified buckets from the query, the afterkey, and the search time private fun convertBucketSearchResponse( transform: Transform, - searchResponse: SearchResponse + searchResponse: SearchResponse, ): BucketSearchResult { val aggs = searchResponse.aggregations.get(transform.id) as CompositeAggregation val modifiedBuckets = aggs.buckets.map { it.key }.toMutableSet() @@ -428,7 +429,7 @@ class TransformSearchService( aggregation.aggregation() } else -> throw TransformSearchServiceException( - "Found aggregation [${aggregation.name}] of type [${aggregation.type}] in composite result that is not currently supported" + "Found aggregation [${aggregation.name}] of type [${aggregation.type}] in composite result that is not currently supported", ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformValidator.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformValidator.kt index a7ee2586e..c93e225fc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformValidator.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/TransformValidator.kt @@ -31,10 +31,11 @@ class TransformValidator( private val clusterService: ClusterService, private val client: Client, val settings: Settings, - private val jvmService: JvmService + private val jvmService: JvmService, ) { @Volatile private var circuitBreakerEnabled = TransformSettings.TRANSFORM_CIRCUIT_BREAKER_ENABLED.get(settings) + @Volatile private var circuitBreakerJvmThreshold = TransformSettings.TRANSFORM_CIRCUIT_BREAKER_JVM_THRESHOLD.get(settings) init { @@ -45,6 +46,7 @@ class TransformValidator( circuitBreakerJvmThreshold = it } } + /** * // TODO: When FGAC is supported in transform should check the user has the correct permissions * Validates the provided transform. Validation checks include the following: diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/DeleteTransformsRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/DeleteTransformsRequest.kt index 9f28d15cc..0c7dbd7d7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/DeleteTransformsRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/DeleteTransformsRequest.kt @@ -14,13 +14,13 @@ import java.io.IOException class DeleteTransformsRequest( val ids: List, - val force: Boolean + val force: Boolean, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( ids = sin.readStringList(), - force = sin.readBoolean() + force = sin.readBoolean(), ) override fun validate(): ActionRequestValidationException? { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/TransportDeleteTransformsAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/TransportDeleteTransformsAction.kt index 30f3d64d5..460b6fb80 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/TransportDeleteTransformsAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/delete/TransportDeleteTransformsAction.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.transform.action.delete import org.apache.logging.log4j.LogManager import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.bulk.BulkRequest import org.opensearch.action.bulk.BulkResponse import org.opensearch.action.delete.DeleteRequest @@ -20,16 +19,17 @@ import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.search.fetch.subphase.FetchSourceContext import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -41,12 +41,13 @@ class TransportDeleteTransformsAction @Inject constructor( val settings: Settings, val clusterService: ClusterService, val xContentRegistry: NamedXContentRegistry, - actionFilters: ActionFilters + actionFilters: ActionFilters, ) : HandledTransportAction( - DeleteTransformsAction.NAME, transportService, actionFilters, ::DeleteTransformsRequest + DeleteTransformsAction.NAME, transportService, actionFilters, ::DeleteTransformsRequest, ) { private val log = LogManager.getLogger(javaClass) + @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) init { @@ -64,14 +65,14 @@ class TransportDeleteTransformsAction @Inject constructor( val client: Client, val request: DeleteTransformsRequest, val actionListener: ActionListener, - val user: User? = buildUser(client.threadPool().threadContext) + val user: User? = buildUser(client.threadPool().threadContext), ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) // Use Multi-Get Request val getRequest = MultiGetRequest() @@ -90,8 +91,8 @@ class TransportDeleteTransformsAction @Inject constructor( if (response.responses.first().isFailed) { actionListener.onFailure( OpenSearchStatusException( - "Cluster missing system index $INDEX_MANAGEMENT_INDEX, cannot execute the request", RestStatus.BAD_REQUEST - ) + "Cluster missing system index $INDEX_MANAGEMENT_INDEX, cannot execute the request", RestStatus.BAD_REQUEST, + ), ) return } @@ -103,7 +104,7 @@ class TransportDeleteTransformsAction @Inject constructor( } override fun onFailure(e: Exception) = actionListener.onFailure(e) - } + }, ) } } @@ -135,8 +136,8 @@ class TransportDeleteTransformsAction @Inject constructor( if (noPermission.isNotEmpty()) { actionListener.onFailure( OpenSearchStatusException( - "Don't have permission to delete some/all transforms in [${request.ids}]", RestStatus.FORBIDDEN - ) + "Don't have permission to delete some/all transforms in [${request.ids}]", RestStatus.FORBIDDEN, + ), ) return } @@ -144,8 +145,8 @@ class TransportDeleteTransformsAction @Inject constructor( if (notTransform.isNotEmpty()) { actionListener.onFailure( OpenSearchStatusException( - "Cannot find transforms $notTransform", RestStatus.BAD_REQUEST - ) + "Cannot find transforms $notTransform", RestStatus.BAD_REQUEST, + ), ) return } @@ -153,8 +154,8 @@ class TransportDeleteTransformsAction @Inject constructor( if (enabledIDs.isNotEmpty()) { actionListener.onFailure( OpenSearchStatusException( - "$enabledIDs transform(s) are enabled, please disable them before deleting them or set force flag", RestStatus.CONFLICT - ) + "$enabledIDs transform(s) are enabled, please disable them before deleting them or set force flag", RestStatus.CONFLICT, + ), ) return } @@ -173,7 +174,7 @@ class TransportDeleteTransformsAction @Inject constructor( } override fun onFailure(e: Exception) = actionListener.onFailure(e) - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/ExplainTransformResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/ExplainTransformResponse.kt index 1035863fb..e23f4e247 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/ExplainTransformResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/ExplainTransformResponse.kt @@ -16,7 +16,7 @@ import java.io.IOException class ExplainTransformResponse( val idsToExplain: Map, - private val failedToExplain: Map + private val failedToExplain: Map, ) : ActionResponse(), ToXContentObject { internal fun getIdsToExplain(): Map { @@ -33,7 +33,7 @@ class ExplainTransformResponse( } idsToExplain.toMap() }, - failedToExplain = sin.readMap({ it.readString() }, { it.readString() }) + failedToExplain = sin.readMap({ it.readString() }, { it.readString() }), ) @Throws(IOException::class) @@ -47,7 +47,7 @@ class ExplainTransformResponse( out.writeMap( failedToExplain, { writer, value: String -> writer.writeString(value) }, - { writer, value: String -> writer.writeString(value) } + { writer, value: String -> writer.writeString(value) }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/TransportExplainTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/TransportExplainTransformAction.kt index 591b348c9..2519f828c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/TransportExplainTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/explain/TransportExplainTransformAction.kt @@ -11,22 +11,22 @@ import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.ResourceNotFoundException -import org.opensearch.core.action.ActionListener import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.HandledTransportAction import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService -import org.opensearch.core.common.bytes.BytesReference import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.core.xcontent.XContentParser import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.common.bytes.BytesReference +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.XContentParser import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.IdsQueryBuilder import org.opensearch.index.query.WildcardQueryBuilder @@ -49,9 +49,9 @@ class TransportExplainTransformAction @Inject constructor( actionFilters: ActionFilters, val clusterService: ClusterService, val settings: Settings, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - ExplainTransformAction.NAME, transportService, actionFilters, ::ExplainTransformRequest + ExplainTransformAction.NAME, transportService, actionFilters, ::ExplainTransformRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -68,8 +68,8 @@ class TransportExplainTransformAction @Inject constructor( override fun doExecute(task: Task, request: ExplainTransformRequest, actionListener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val ids = request.transformIDs // Instantiate concrete ids to metadata map by removing wildcard matches @@ -159,13 +159,13 @@ class TransportExplainTransformAction @Inject constructor( explainTransform.copy( metadata = metadata.copy( shardIDToGlobalCheckpoint = null, - continuousStats = continuousStats - ) + continuousStats = continuousStats, + ), ) } } } - } + }, ) } @@ -181,7 +181,7 @@ class TransportExplainTransformAction @Inject constructor( else -> actionListener.onFailure(e) } } - } + }, ) } } @@ -189,7 +189,7 @@ class TransportExplainTransformAction @Inject constructor( private fun contentParser(bytesReference: BytesReference): XContentParser { return XContentHelper.createParser( xContentRegistry, - LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformRequest.kt index 80b7f2157..21a951a5a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformRequest.kt @@ -16,14 +16,14 @@ import java.io.IOException class GetTransformRequest( val id: String, val srcContext: FetchSourceContext? = null, - val preference: String? = null + val preference: String? = null, ) : ActionRequest() { @Throws(IOException::class) constructor(sin: StreamInput) : this( id = sin.readString(), srcContext = if (sin.readBoolean()) FetchSourceContext(sin) else null, - preference = sin.readOptionalString() + preference = sin.readOptionalString(), ) override fun validate(): ActionRequestValidationException? { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformResponse.kt index 27adaf5d3..bbd79a58b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.transform.action.get import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.util._VERSION -import org.opensearch.core.rest.RestStatus import java.io.IOException class GetTransformResponse( @@ -27,7 +27,7 @@ class GetTransformResponse( val seqNo: Long, val primaryTerm: Long, val status: RestStatus, - val transform: Transform? + val transform: Transform?, ) : ActionResponse(), ToXContentObject { @Throws(IOException::class) @@ -37,7 +37,7 @@ class GetTransformResponse( seqNo = sin.readLong(), primaryTerm = sin.readLong(), status = sin.readEnum(RestStatus::class.java), - transform = if (sin.readBoolean()) Transform(sin) else null + transform = if (sin.readBoolean()) Transform(sin) else null, ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsRequest.kt index cfdaa8375..8eac3dbcd 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsRequest.kt @@ -17,7 +17,7 @@ class GetTransformsRequest( val from: Int = DEFAULT_FROM, val size: Int = DEFAULT_SIZE, val sortField: String = DEFAULT_SORT_FIELD, - val sortDirection: String = DEFAULT_SORT_DIRECTION + val sortDirection: String = DEFAULT_SORT_DIRECTION, ) : ActionRequest() { @Throws(IOException::class) @@ -26,7 +26,7 @@ class GetTransformsRequest( from = sin.readInt(), size = sin.readInt(), sortField = sin.readString(), - sortDirection = sin.readString() + sortDirection = sin.readString(), ) override fun validate(): ActionRequestValidationException? = null diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsResponse.kt index bdef75c1d..74648afa5 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/GetTransformsResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.transform.action.get import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -17,20 +18,19 @@ import org.opensearch.indexmanagement.transform.model.Transform.Companion.TRANSF import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO -import org.opensearch.core.rest.RestStatus import java.io.IOException class GetTransformsResponse( val transforms: List, val totalTransforms: Int, - val status: RestStatus + val status: RestStatus, ) : ActionResponse(), ToXContentObject { @Throws(IOException::class) constructor(sin: StreamInput) : this( transforms = sin.readList(::Transform), totalTransforms = sin.readInt(), - status = sin.readEnum(RestStatus::class.java) + status = sin.readEnum(RestStatus::class.java), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformAction.kt index 6808f58df..5f4ea101f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.transform.action.get import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse import org.opensearch.action.support.ActionFilters @@ -17,15 +16,16 @@ import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse import org.opensearch.indexmanagement.settings.IndexManagementSettings import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -35,9 +35,9 @@ class TransportGetTransformAction @Inject constructor( val settings: Settings, val clusterService: ClusterService, actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction ( - GetTransformAction.NAME, transportService, actionFilters, ::GetTransformRequest + GetTransformAction.NAME, transportService, actionFilters, ::GetTransformRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -53,8 +53,8 @@ class TransportGetTransformAction @Inject constructor( override fun doExecute(task: Task, request: GetTransformRequest, listener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val user = buildUser(client.threadPool().threadContext) val getRequest = GetRequest(INDEX_MANAGEMENT_INDEX, request.id).preference(request.preference) @@ -92,8 +92,8 @@ class TransportGetTransformAction @Inject constructor( OpenSearchStatusException( "Failed to parse transform", RestStatus.INTERNAL_SERVER_ERROR, - ExceptionsHelper.unwrapCause(e) - ) + ExceptionsHelper.unwrapCause(e), + ), ) } } @@ -101,7 +101,7 @@ class TransportGetTransformAction @Inject constructor( override fun onFailure(e: Exception) { listener.onFailure(e) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformsAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformsAction.kt index 97ee0512a..9a0b725ac 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformsAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/get/TransportGetTransformsAction.kt @@ -6,21 +6,21 @@ package org.opensearch.indexmanagement.transform.action.get import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener -import org.opensearch.core.action.ActionResponse import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.HandledTransportAction import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService -import org.opensearch.core.common.bytes.BytesReference import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.core.xcontent.XContentParser import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse +import org.opensearch.core.common.bytes.BytesReference +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.XContentParser import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.ExistsQueryBuilder import org.opensearch.index.query.WildcardQueryBuilder @@ -40,9 +40,9 @@ class TransportGetTransformsAction @Inject constructor( val settings: Settings, val clusterService: ClusterService, actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction ( - GetTransformsAction.NAME, transportService, actionFilters, ::GetTransformsRequest + GetTransformsAction.NAME, transportService, actionFilters, ::GetTransformsRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -57,8 +57,8 @@ class TransportGetTransformsAction @Inject constructor( override fun doExecute(task: Task, request: GetTransformsRequest, listener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val searchString = request.searchString.trim() val from = request.from @@ -82,7 +82,7 @@ class TransportGetTransformsAction @Inject constructor( searchSourceBuilder, listener as ActionListener, Transform.TRANSFORM_TYPE, - ::contentParser + ::contentParser, ) } } @@ -90,7 +90,7 @@ class TransportGetTransformsAction @Inject constructor( private fun contentParser(bytesReference: BytesReference): XContentParser { return XContentHelper.createParser( xContentRegistry, - LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformRequest.kt index d0e26dc95..efa3480d7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformRequest.kt @@ -27,7 +27,7 @@ class IndexTransformRequest : IndexRequest { constructor( transform: Transform, - refreshPolicy: WriteRequest.RefreshPolicy + refreshPolicy: WriteRequest.RefreshPolicy, ) { this.transform = transform if (transform.seqNo == SequenceNumbers.UNASSIGNED_SEQ_NO || transform.primaryTerm == SequenceNumbers.UNASSIGNED_PRIMARY_TERM) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformResponse.kt index f6d9fd44d..41828c62a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/IndexTransformResponse.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.transform.action.index import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.util._VERSION -import org.opensearch.core.rest.RestStatus import java.io.IOException class IndexTransformResponse( @@ -27,7 +27,7 @@ class IndexTransformResponse( val seqNo: Long, val primaryTerm: Long, val status: RestStatus, - val transform: Transform + val transform: Transform, ) : ActionResponse(), ToXContentObject { @Throws(IOException::class) @@ -37,7 +37,7 @@ class IndexTransformResponse( seqNo = sin.readLong(), primaryTerm = sin.readLong(), status = sin.readEnum(RestStatus::class.java), - transform = Transform(sin) + transform = Transform(sin), ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/TransportIndexTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/TransportIndexTransformAction.kt index 708bfa1d2..2a25568e1 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/TransportIndexTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/index/TransportIndexTransformAction.kt @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.transform.action.index import org.apache.logging.log4j.LogManager import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteRequest import org.opensearch.action.admin.indices.mapping.get.GetMappingsAction import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest @@ -25,11 +24,13 @@ import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.NamedXContentRegistry -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory.jsonBuilder import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse @@ -40,7 +41,6 @@ import org.opensearch.indexmanagement.util.IndexUtils import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource import org.opensearch.indexmanagement.util.SecurityUtils.Companion.validateUserConfiguration -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -53,9 +53,9 @@ class TransportIndexTransformAction @Inject constructor( val indexNameExpressionResolver: IndexNameExpressionResolver, val clusterService: ClusterService, val settings: Settings, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - IndexTransformAction.NAME, transportService, actionFilters, ::IndexTransformRequest + IndexTransformAction.NAME, transportService, actionFilters, ::IndexTransformRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -76,21 +76,21 @@ class TransportIndexTransformAction @Inject constructor( private val client: Client, private val actionListener: ActionListener, private val request: IndexTransformRequest, - private val user: User? = buildUser(client.threadPool().threadContext, request.transform.user) + private val user: User? = buildUser(client.threadPool().threadContext, request.transform.user), ) { fun start() { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) client.threadPool().threadContext.stashContext().use { if (!validateUserConfiguration(user, filterByEnabled, actionListener)) { return } indexManagementIndices.checkAndUpdateIMConfigIndex( - ActionListener.wrap(::onConfigIndexAcknowledgedResponse, actionListener::onFailure) + ActionListener.wrap(::onConfigIndexAcknowledgedResponse, actionListener::onFailure), ) } } @@ -168,8 +168,8 @@ class TransportIndexTransformAction @Inject constructor( actionListener.onResponse( IndexTransformResponse( response.id, response.version, response.seqNo, response.primaryTerm, status, - transform.copy(seqNo = response.seqNo, primaryTerm = response.primaryTerm) - ) + transform.copy(seqNo = response.seqNo, primaryTerm = response.primaryTerm), + ), ) } } @@ -177,7 +177,7 @@ class TransportIndexTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(e) } - } + }, ) } @@ -186,7 +186,7 @@ class TransportIndexTransformAction @Inject constructor( indexNameExpressionResolver.concreteIndexNames( clusterService.state(), IndicesOptions.lenientExpand(), true, request.transform - .sourceIndex + .sourceIndex, ) if (concreteIndices.isEmpty()) { actionListener.onFailure(OpenSearchStatusException("No specified source index exist in the cluster", RestStatus.NOT_FOUND)) @@ -211,7 +211,7 @@ class TransportIndexTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(e) } - } + }, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformRequest.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformRequest.kt index 1c65421e4..f592ddf22 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformRequest.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformRequest.kt @@ -13,11 +13,11 @@ import org.opensearch.indexmanagement.transform.model.Transform import java.io.IOException class PreviewTransformRequest( - val transform: Transform + val transform: Transform, ) : ActionRequest() { constructor(sin: StreamInput) : this( - transform = Transform(sin) + transform = Transform(sin), ) override fun validate(): ActionRequestValidationException? { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformResponse.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformResponse.kt index e9120829c..f3b11a03d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformResponse.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/PreviewTransformResponse.kt @@ -8,14 +8,14 @@ package org.opensearch.indexmanagement.transform.action.preview import org.opensearch.core.action.ActionResponse import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.ToXContentObject import org.opensearch.core.xcontent.XContentBuilder -import org.opensearch.core.rest.RestStatus class PreviewTransformResponse( val documents: List>, - val status: RestStatus + val status: RestStatus, ) : ActionResponse(), ToXContentObject { constructor(sin: StreamInput) : this( @@ -27,7 +27,7 @@ class PreviewTransformResponse( } documentList.toList() }, - status = sin.readEnum(RestStatus::class.java) + status = sin.readEnum(RestStatus::class.java), ) override fun writeTo(out: StreamOutput) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/TransportPreviewTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/TransportPreviewTransformAction.kt index bb4f9219e..295aa33ef 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/TransportPreviewTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/preview/TransportPreviewTransformAction.kt @@ -11,7 +11,6 @@ import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.mapping.get.GetMappingsAction import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse @@ -26,6 +25,8 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.opensearchapi.IndexManagementSecurityContext import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.opensearchapi.withClosableContext @@ -34,7 +35,6 @@ import org.opensearch.indexmanagement.transform.TransformSearchService import org.opensearch.indexmanagement.transform.TransformValidator import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.util.SecurityUtils -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService @@ -44,9 +44,9 @@ class TransportPreviewTransformAction @Inject constructor( val settings: Settings, private val client: Client, private val clusterService: ClusterService, - private val indexNameExpressionResolver: IndexNameExpressionResolver + private val indexNameExpressionResolver: IndexNameExpressionResolver, ) : HandledTransportAction( - PreviewTransformAction.NAME, transportService, actionFilters, ::PreviewTransformRequest + PreviewTransformAction.NAME, transportService, actionFilters, ::PreviewTransformRequest, ) { private val log = LogManager.getLogger(javaClass) @@ -55,8 +55,8 @@ class TransportPreviewTransformAction @Inject constructor( override fun doExecute(task: Task, request: PreviewTransformRequest, listener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val transform = request.transform @@ -83,7 +83,7 @@ class TransportPreviewTransformAction @Inject constructor( CoroutineScope(Dispatchers.IO).launch { withClosableContext( - IndexManagementSecurityContext("PreviewTransformHandler", settings, client.threadPool().threadContext, user) + IndexManagementSecurityContext("PreviewTransformHandler", settings, client.threadPool().threadContext, user), ) { executeSearch(searchRequest, transform, listener) } @@ -93,7 +93,7 @@ class TransportPreviewTransformAction @Inject constructor( override fun onFailure(e: Exception) { listener.onFailure(e) } - } + }, ) } @@ -118,7 +118,7 @@ class TransportPreviewTransformAction @Inject constructor( val targetIndexDateFieldMappings = TargetIndexMappingService.getTargetMappingsForDates(transform) val transformSearchResult = TransformSearchService.convertResponse( transform = transform, searchResponse = response, waterMarkDocuments = false, - targetIndexDateFieldMappings = targetIndexDateFieldMappings + targetIndexDateFieldMappings = targetIndexDateFieldMappings, ) val formattedResult = transformSearchResult.docsToIndex.map { it.sourceAsMap() @@ -127,8 +127,8 @@ class TransportPreviewTransformAction @Inject constructor( } catch (e: Exception) { listener.onFailure( OpenSearchStatusException( - "Failed to parse the transformed results", RestStatus.INTERNAL_SERVER_ERROR, ExceptionsHelper.unwrapCause(e) - ) + "Failed to parse the transformed results", RestStatus.INTERNAL_SERVER_ERROR, ExceptionsHelper.unwrapCause(e), + ), ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/start/TransportStartTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/start/TransportStartTransformAction.kt index 9fe33feed..f9e7be551 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/start/TransportStartTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/start/TransportStartTransformAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.transform.action.start import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteResponse import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse @@ -22,10 +21,12 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse import org.opensearch.indexmanagement.opensearchapi.parseWithType @@ -34,7 +35,6 @@ import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.time.Instant @@ -46,9 +46,9 @@ class TransportStartTransformAction @Inject constructor( val settings: Settings, val clusterService: ClusterService, actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - StartTransformAction.NAME, transportService, actionFilters, ::StartTransformRequest + StartTransformAction.NAME, transportService, actionFilters, ::StartTransformRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -64,8 +64,8 @@ class TransportStartTransformAction @Inject constructor( override fun doExecute(task: Task, request: StartTransformRequest, actionListener: ActionListener) { log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val getRequest = GetRequest(INDEX_MANAGEMENT_INDEX, request.id()) val user = buildUser(client.threadPool().threadContext) @@ -105,7 +105,7 @@ class TransportStartTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } @@ -113,16 +113,16 @@ class TransportStartTransformAction @Inject constructor( private fun updateTransformJob( transform: Transform, request: StartTransformRequest, - actionListener: ActionListener + actionListener: ActionListener, ) { val now = Instant.now().toEpochMilli() request.index(INDEX_MANAGEMENT_INDEX).doc( mapOf( Transform.TRANSFORM_TYPE to mapOf( Transform.ENABLED_FIELD to true, - Transform.ENABLED_AT_FIELD to now, Transform.UPDATED_AT_FIELD to now - ) - ) + Transform.ENABLED_AT_FIELD to now, Transform.UPDATED_AT_FIELD to now, + ), + ), ) client.update( request, @@ -143,7 +143,7 @@ class TransportStartTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -159,15 +159,15 @@ class TransportStartTransformAction @Inject constructor( val metadata = response.sourceAsBytesRef?.let { val xcp = XContentHelper.createParser( NamedXContentRegistry.EMPTY, - LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON, ) xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, TransformMetadata.Companion::parse) } if (metadata == null) { actionListener.onFailure( OpenSearchStatusException( - "Metadata doc missing for transform [${req.id()}]", RestStatus.NOT_FOUND - ) + "Metadata doc missing for transform [${req.id()}]", RestStatus.NOT_FOUND, + ), ) } else { updateTransformMetadata(transform, metadata, actionListener) @@ -178,7 +178,7 @@ class TransportStartTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -195,9 +195,9 @@ class TransportStartTransformAction @Inject constructor( mapOf( TransformMetadata.TRANSFORM_METADATA_TYPE to mapOf( TransformMetadata.STATUS_FIELD to updatedStatus.type, - TransformMetadata.FAILURE_REASON to null, TransformMetadata.LAST_UPDATED_AT_FIELD to now - ) - ) + TransformMetadata.FAILURE_REASON to null, TransformMetadata.LAST_UPDATED_AT_FIELD to now, + ), + ), ) .routing(transform.id) client.update( @@ -210,7 +210,7 @@ class TransportStartTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/stop/TransportStopTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/stop/TransportStopTransformAction.kt index 71cbb006e..d69c148e6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/action/stop/TransportStopTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/action/stop/TransportStopTransformAction.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.transform.action.stop import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteResponse import org.opensearch.action.get.GetRequest import org.opensearch.action.get.GetResponse @@ -22,10 +21,12 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.inject.Inject import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.ConfigConstants +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.opensearchapi.parseFromGetResponse @@ -35,7 +36,6 @@ import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.util.SecurityUtils.Companion.buildUser import org.opensearch.indexmanagement.util.SecurityUtils.Companion.userHasPermissionForResource -import org.opensearch.core.rest.RestStatus import org.opensearch.tasks.Task import org.opensearch.transport.TransportService import java.time.Instant @@ -59,9 +59,9 @@ class TransportStopTransformAction @Inject constructor( val settings: Settings, val clusterService: ClusterService, actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + val xContentRegistry: NamedXContentRegistry, ) : HandledTransportAction( - StopTransformAction.NAME, transportService, actionFilters, ::StopTransformRequest + StopTransformAction.NAME, transportService, actionFilters, ::StopTransformRequest, ) { @Volatile private var filterByEnabled = IndexManagementSettings.FILTER_BY_BACKEND_ROLES.get(settings) @@ -78,8 +78,8 @@ class TransportStopTransformAction @Inject constructor( log.debug("Executing StopTransformAction on ${request.id()}") log.debug( "User and roles string from thread context: ${client.threadPool().threadContext.getTransient( - ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT - )}" + ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, + )}", ) val getRequest = GetRequest(INDEX_MANAGEMENT_INDEX, request.id()) val user = buildUser(client.threadPool().threadContext) @@ -115,7 +115,7 @@ class TransportStopTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } @@ -123,7 +123,7 @@ class TransportStopTransformAction @Inject constructor( private fun retrieveAndUpdateTransformMetadata( transform: Transform, request: StopTransformRequest, - actionListener: ActionListener + actionListener: ActionListener, ) { val req = GetRequest(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, transform.metadataId).routing(transform.id) client.get( @@ -137,7 +137,7 @@ class TransportStopTransformAction @Inject constructor( val metadata = response.sourceAsBytesRef?.let { val xcp = XContentHelper.createParser( NamedXContentRegistry.EMPTY, - LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, it, XContentType.JSON, ) xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, TransformMetadata.Companion::parse) } @@ -153,7 +153,7 @@ class TransportStopTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -168,7 +168,7 @@ class TransportStopTransformAction @Inject constructor( transform: Transform, metadata: TransformMetadata, request: StopTransformRequest, - actionListener: ActionListener + actionListener: ActionListener, ) { val now = Instant.now().toEpochMilli() val updatedStatus = when (metadata.status) { @@ -181,9 +181,9 @@ class TransportStopTransformAction @Inject constructor( mapOf( TransformMetadata.TRANSFORM_METADATA_TYPE to mapOf( TransformMetadata.STATUS_FIELD to updatedStatus.type, - TransformMetadata.LAST_UPDATED_AT_FIELD to now - ) - ) + TransformMetadata.LAST_UPDATED_AT_FIELD to now, + ), + ), ) .routing(transform.id) client.update( @@ -200,7 +200,7 @@ class TransportStopTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } @@ -211,9 +211,9 @@ class TransportStopTransformAction @Inject constructor( mapOf( Transform.TRANSFORM_TYPE to mapOf( Transform.ENABLED_FIELD to false, - Transform.ENABLED_AT_FIELD to null, Transform.UPDATED_AT_FIELD to now - ) - ) + Transform.ENABLED_AT_FIELD to null, Transform.UPDATED_AT_FIELD to now, + ), + ), ) client.update( request, @@ -224,7 +224,7 @@ class TransportStopTransformAction @Inject constructor( override fun onFailure(e: Exception) { actionListener.onFailure(ExceptionsHelper.unwrapCause(e) as Exception) } - } + }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ContinuousTransformStats.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ContinuousTransformStats.kt index 884a9eca5..a68d43994 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ContinuousTransformStats.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ContinuousTransformStats.kt @@ -19,13 +19,13 @@ import java.time.Instant data class ContinuousTransformStats( val lastTimestamp: Instant?, - val documentsBehind: Map? + val documentsBehind: Map?, ) : ToXContentObject, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( lastTimestamp = if (sin.readBoolean()) sin.readInstant() else null, - documentsBehind = if (sin.readBoolean()) sin.readMap({ it.readString() }, { it.readLong() }) else null + documentsBehind = if (sin.readBoolean()) sin.readMap({ it.readString() }, { it.readLong() }) else null, ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ExplainTransform.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ExplainTransform.kt index ad52a21b1..f73faa597 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ExplainTransform.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ExplainTransform.kt @@ -16,13 +16,13 @@ import java.io.IOException data class ExplainTransform( val metadataID: String? = null, - val metadata: TransformMetadata? = null + val metadata: TransformMetadata? = null, ) : ToXContentObject, Writeable { @Throws(IOException::class) constructor(sin: StreamInput) : this( metadataID = sin.readOptionalString(), - metadata = if (sin.readBoolean()) TransformMetadata(sin) else null + metadata = if (sin.readBoolean()) TransformMetadata(sin) else null, ) @Throws(IOException::class) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransform.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransform.kt index ecc092ac9..6c949c547 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransform.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransform.kt @@ -42,7 +42,7 @@ data class ISMTransform( val pageSize: Int, val dataSelectionQuery: QueryBuilder = MatchAllQueryBuilder(), val groups: List, - val aggregations: AggregatorFactories.Builder = AggregatorFactories.builder() + val aggregations: AggregatorFactories.Builder = AggregatorFactories.builder(), ) : ToXContentObject, Writeable { init { @@ -92,7 +92,7 @@ data class ISMTransform( continuous = false, groups = this.groups, aggregations = this.aggregations, - user = user + user = user, ) } @@ -112,12 +112,12 @@ data class ISMTransform( Dimension.Type.DATE_HISTOGRAM -> DateHistogram(sin) Dimension.Type.TERMS -> Terms(sin) Dimension.Type.HISTOGRAM -> Histogram(sin) - } + }, ) } dimensionList.toList() }, - aggregations = requireNotNull(sin.readOptionalWriteable { AggregatorFactories.Builder(it) }) { "Aggregations cannot be null" } + aggregations = requireNotNull(sin.readOptionalWriteable { AggregatorFactories.Builder(it) }) { "Aggregations cannot be null" }, ) override fun toString(): String { @@ -180,7 +180,7 @@ data class ISMTransform( val sourceParser = XContentType.JSON.xContent().createParser( registry, LoggingDeprecationHandler.INSTANCE, BytesReference - .bytes(xContentBuilder).streamInput() + .bytes(xContentBuilder).streamInput(), ) dataSelectionQuery = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser) } @@ -201,7 +201,7 @@ data class ISMTransform( pageSize = pageSize, dataSelectionQuery = dataSelectionQuery, groups = groups, - aggregations = aggregations + aggregations = aggregations, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/Transform.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/Transform.kt index db3145e08..a506c15b4 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/Transform.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/Transform.kt @@ -9,24 +9,25 @@ import org.opensearch.action.admin.indices.stats.IndicesStatsAction import org.opensearch.action.admin.indices.stats.IndicesStatsRequest import org.opensearch.action.admin.indices.stats.IndicesStatsResponse import org.opensearch.client.Client +import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.common.xcontent.XContentType +import org.opensearch.commons.authuser.User import org.opensearch.core.common.bytes.BytesReference import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable -import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.core.index.shard.ShardId +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentBuilder -import org.opensearch.common.xcontent.XContentFactory import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.common.xcontent.XContentType -import org.opensearch.commons.authuser.User import org.opensearch.index.query.AbstractQueryBuilder import org.opensearch.index.query.MatchAllQueryBuilder import org.opensearch.index.query.QueryBuilder import org.opensearch.index.seqno.SequenceNumbers -import org.opensearch.core.index.shard.ShardId import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Dimension import org.opensearch.indexmanagement.common.model.dimension.Histogram @@ -45,7 +46,6 @@ import org.opensearch.jobscheduler.spi.schedule.CronSchedule import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule import org.opensearch.jobscheduler.spi.schedule.Schedule import org.opensearch.jobscheduler.spi.schedule.ScheduleParser -import org.opensearch.core.rest.RestStatus import org.opensearch.search.aggregations.AggregatorFactories import java.io.IOException import java.time.Instant @@ -70,7 +70,7 @@ data class Transform( val groups: List, val aggregations: AggregatorFactories.Builder = AggregatorFactories.builder(), val continuous: Boolean = false, - val user: User? = null + val user: User? = null, ) : ScheduledJobParameter, Writeable { init { @@ -174,12 +174,12 @@ data class Transform( mutableMapOf( TRANSFORM_DOC_ID_FIELD to this.id, DOC_COUNT to docCount, - TRANSFORM_DOC_COUNT_FIELD to docCount + TRANSFORM_DOC_COUNT_FIELD to docCount, ) } else { mutableMapOf( DOC_COUNT to docCount, - TRANSFORM_DOC_COUNT_FIELD to docCount + TRANSFORM_DOC_COUNT_FIELD to docCount, ) } } @@ -189,19 +189,21 @@ data class Transform( val response: IndicesStatsResponse = client.suspendUntil { execute(IndicesStatsAction.INSTANCE, indicesStatsRequest, it) } val shardIDsToGlobalCheckpoint = if (response.status == RestStatus.OK) { TransformSearchService.convertIndicesStatsResponse(response) - } else return null + } else { + return null + } return ContinuousTransformStats( metadata.continuousStats?.lastTimestamp, getDocumentsBehind( metadata.shardIDToGlobalCheckpoint, - shardIDsToGlobalCheckpoint - ) + shardIDsToGlobalCheckpoint, + ), ) } private fun getDocumentsBehind( oldShardIDsToGlobalCheckpoint: Map?, - newShardIDsToGlobalCheckpoint: Map? + newShardIDsToGlobalCheckpoint: Map?, ): MutableMap { val documentsBehind: MutableMap = HashMap() if (newShardIDsToGlobalCheckpoint == null) { @@ -251,7 +253,7 @@ data class Transform( Dimension.Type.DATE_HISTOGRAM -> DateHistogram(sin) Dimension.Type.TERMS -> Terms(sin) Dimension.Type.HISTOGRAM -> Histogram(sin) - } + }, ) } dimensionList.toList() @@ -260,12 +262,15 @@ data class Transform( continuous = sin.readBoolean(), user = if (sin.readBoolean()) { User(sin) - } else null + } else { + null + }, ) companion object { enum class ScheduleType { - CRON, INTERVAL; + CRON, + INTERVAL, } val supportedAggregations = listOf("sum", "max", "min", "value_count", "avg", "scripted_metric", "percentiles") @@ -292,6 +297,7 @@ data class Transform( const val MINIMUM_JOB_INTERVAL = 1 const val TRANSFORM_DOC_ID_FIELD = "$TRANSFORM_TYPE._id" const val DOC_COUNT = "_doc_count" + // Keeping the field in order to be backward compatible const val TRANSFORM_DOC_COUNT_FIELD = "$TRANSFORM_TYPE._doc_count" const val CONTINUOUS_FIELD = "continuous" @@ -304,7 +310,7 @@ data class Transform( xcp: XContentParser, id: String = NO_ID, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): Transform { var schedule: Schedule? = null var schemaVersion: Long = IndexUtils.DEFAULT_SCHEMA_VERSION @@ -346,7 +352,7 @@ data class Transform( val sourceParser = XContentType.JSON.xContent().createParser( registry, LoggingDeprecationHandler.INSTANCE, BytesReference - .bytes(xContentBuilder).streamInput() + .bytes(xContentBuilder).streamInput(), ) dataSelectionQuery = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser) } @@ -412,7 +418,7 @@ data class Transform( groups = groups, aggregations = aggregations, continuous = continuous, - user = user + user = user, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformMetadata.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformMetadata.kt index a45505878..189c22548 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformMetadata.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformMetadata.kt @@ -33,7 +33,7 @@ data class TransformMetadata( val failureReason: String? = null, val stats: TransformStats, val shardIDToGlobalCheckpoint: Map? = null, - val continuousStats: ContinuousTransformStats? = null + val continuousStats: ContinuousTransformStats? = null, ) : ToXContentObject, Writeable { enum class Status(val type: String) { @@ -41,7 +41,8 @@ data class TransformMetadata( STARTED("started"), STOPPED("stopped"), FINISHED("finished"), - FAILED("failed"); + FAILED("failed"), + ; override fun toString(): String { return type @@ -60,7 +61,7 @@ data class TransformMetadata( failureReason = sin.readOptionalString(), stats = TransformStats(sin), shardIDToGlobalCheckpoint = if (sin.readBoolean()) sin.readMap({ ShardId(it) }, { it.readLong() }) else null, - continuousStats = if (sin.readBoolean()) ContinuousTransformStats(sin) else null + continuousStats = if (sin.readBoolean()) ContinuousTransformStats(sin) else null, ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -105,8 +106,8 @@ data class TransformMetadata( documentsIndexed = this.stats.documentsIndexed + stats.documentsIndexed, documentsProcessed = this.stats.documentsProcessed + stats.documentsProcessed, indexTimeInMillis = this.stats.indexTimeInMillis + stats.indexTimeInMillis, - searchTimeInMillis = this.stats.searchTimeInMillis + stats.searchTimeInMillis - ) + searchTimeInMillis = this.stats.searchTimeInMillis + stats.searchTimeInMillis, + ), ) } @@ -128,7 +129,7 @@ data class TransformMetadata( xcp: XContentParser, id: String, seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): TransformMetadata { var transformId: String? = null var afterkey: Map? = null @@ -169,7 +170,7 @@ data class TransformMetadata( failureReason = failureReason, stats = requireNotNull(stats) { "Stats must not be null" }, shardIDToGlobalCheckpoint = shardIDToGlobalCheckpoint, - continuousStats = continuousStats + continuousStats = continuousStats, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformSearchResult.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformSearchResult.kt index 0b833965a..39c308d9f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformSearchResult.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformSearchResult.kt @@ -19,12 +19,12 @@ data class BucketsToTransform( fun BucketsToTransform.initializeShardsToSearch( originalGlobalCheckpoints: Map?, - currentShardIdToGlobalCheckpoint: Map + currentShardIdToGlobalCheckpoint: Map, ): BucketsToTransform { val shardsToSearch = getShardsToSearch(originalGlobalCheckpoints, currentShardIdToGlobalCheckpoint).iterator() return this.copy( shardsToSearch = shardsToSearch, - currentShard = if (shardsToSearch.hasNext()) shardsToSearch.next() else null + currentShard = if (shardsToSearch.hasNext()) shardsToSearch.next() else null, ) } @@ -43,7 +43,7 @@ private fun getShardsToSearch(oldShardIDToMaxSeqNo: Map?, newShar data class BucketSearchResult( val modifiedBuckets: MutableSet>, val afterKey: Map? = null, - val searchTimeInMillis: Long = 0 + val searchTimeInMillis: Long = 0, ) data class ShardNewDocuments(val shardId: ShardId, val from: Long?, val to: Long) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformStats.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformStats.kt index 3b68a61b4..3bf55c2d4 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformStats.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/model/TransformStats.kt @@ -20,7 +20,7 @@ data class TransformStats( val documentsProcessed: Long, val documentsIndexed: Long, val indexTimeInMillis: Long, - val searchTimeInMillis: Long + val searchTimeInMillis: Long, ) : ToXContentObject, Writeable { @Throws(IOException::class) @@ -29,7 +29,7 @@ data class TransformStats( documentsProcessed = sin.readLong(), documentsIndexed = sin.readLong(), indexTimeInMillis = sin.readLong(), - searchTimeInMillis = sin.readLong() + searchTimeInMillis = sin.readLong(), ) override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -86,7 +86,7 @@ data class TransformStats( documentsProcessed = requireNotNull(documentsProcessed) { "Documents processed must not be null" }, documentsIndexed = requireNotNull(documentsIndexed) { "Documents indexed must not be null" }, indexTimeInMillis = requireNotNull(indexTimeInMillis) { "Index time in millis must not be null" }, - searchTimeInMillis = requireNotNull(searchTimeInMillis) { "Search time in millis must not be null" } + searchTimeInMillis = requireNotNull(searchTimeInMillis) { "Search time in millis must not be null" }, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/OpenSearchExtensions.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/OpenSearchExtensions.kt index 48897a2c7..3dbf2370c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/OpenSearchExtensions.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/OpenSearchExtensions.kt @@ -10,10 +10,10 @@ import org.apache.logging.log4j.Logger import org.opensearch.OpenSearchException import org.opensearch.action.bulk.BackoffPolicy import org.opensearch.common.unit.TimeValue -import org.opensearch.indexmanagement.opensearchapi.isRetryable -import org.opensearch.indexmanagement.transform.util.TransformLockManager import org.opensearch.core.rest.RestStatus import org.opensearch.core.tasks.TaskCancelledException +import org.opensearch.indexmanagement.opensearchapi.isRetryable +import org.opensearch.indexmanagement.transform.util.TransformLockManager import java.util.regex.Pattern /** @@ -39,7 +39,7 @@ suspend fun BackoffPolicy.retryTransformSearch( logger: Logger, transformLockManager: TransformLockManager, retryOn: List = emptyList(), - block: suspend (backoff: TimeValue) -> T + block: suspend (backoff: TimeValue) -> T, ): T { val iter = iterator() var backoff: TimeValue = TimeValue.ZERO diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformAction.kt index 34cda3053..c3c6ce2f7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformAction.kt @@ -23,7 +23,7 @@ class RestDeleteTransformAction : BaseRestHandler() { override fun routes(): List { return listOf( - Route(DELETE, "$TRANSFORM_BASE_URI/{transformID}") + Route(DELETE, "$TRANSFORM_BASE_URI/{transformID}"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformAction.kt index bf311671d..9879a8828 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformAction.kt @@ -31,7 +31,7 @@ class RestGetTransformAction : BaseRestHandler() { return listOf( Route(GET, TRANSFORM_BASE_URI), Route(GET, "$TRANSFORM_BASE_URI/{transformID}"), - Route(HEAD, "$TRANSFORM_BASE_URI/{transformID}") + Route(HEAD, "$TRANSFORM_BASE_URI/{transformID}"), ) } @@ -53,7 +53,7 @@ class RestGetTransformAction : BaseRestHandler() { from, size, sortField, - sortDirection + sortDirection, ) client.execute(GetTransformsAction.INSTANCE, req, RestToXContentListener(channel)) } else { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformAction.kt index d68061809..fad8c163a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformAction.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.transform.resthandler import org.opensearch.action.support.WriteRequest import org.opensearch.client.node.NodeClient +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI @@ -27,7 +28,6 @@ import org.opensearch.rest.RestHandler import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.PUT import org.opensearch.rest.RestResponse -import org.opensearch.core.rest.RestStatus import org.opensearch.rest.action.RestResponseListener import java.io.IOException import java.time.Instant @@ -37,7 +37,7 @@ class RestIndexTransformAction : BaseRestHandler() { override fun routes(): List { return listOf( RestHandler.Route(PUT, TRANSFORM_BASE_URI), - RestHandler.Route(PUT, "$TRANSFORM_BASE_URI/{transformID}") + RestHandler.Route(PUT, "$TRANSFORM_BASE_URI/{transformID}"), ) } @@ -68,8 +68,7 @@ class RestIndexTransformAction : BaseRestHandler() { } } - private fun indexTransformResponse(channel: RestChannel): - RestResponseListener { + private fun indexTransformResponse(channel: RestChannel): RestResponseListener { return object : RestResponseListener(channel) { @Throws(Exception::class) override fun buildResponse(response: IndexTransformResponse): RestResponse { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformAction.kt index e96735a5f..c0d5b0142 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformAction.kt @@ -23,7 +23,7 @@ class RestPreviewTransformAction : BaseRestHandler() { override fun routes(): List { return listOf( RestHandler.Route(POST, TRANSFORM_BASE_URI), - RestHandler.Route(POST, "$TRANSFORM_BASE_URI/_preview") + RestHandler.Route(POST, "$TRANSFORM_BASE_URI/_preview"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformAction.kt index 9cfc1d97c..d0ee8b47b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformAction.kt @@ -22,7 +22,7 @@ class RestStartTransformAction : BaseRestHandler() { override fun routes(): List { return listOf( - Route(POST, "$TRANSFORM_BASE_URI/{transformID}/_start") + Route(POST, "$TRANSFORM_BASE_URI/{transformID}/_start"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformAction.kt index a48034e5c..2e6d7ffe7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformAction.kt @@ -22,7 +22,7 @@ class RestStopTransformAction : BaseRestHandler() { override fun routes(): List { return listOf( - Route(POST, "$TRANSFORM_BASE_URI/{transformID}/_stop") + Route(POST, "$TRANSFORM_BASE_URI/{transformID}/_stop"), ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/settings/TransformSettings.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/settings/TransformSettings.kt index abfdc1b1f..f1023b01d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/settings/TransformSettings.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/settings/TransformSettings.kt @@ -20,35 +20,35 @@ class TransformSettings { "plugins.transform.internal.search.backoff_count", 5, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val TRANSFORM_JOB_SEARCH_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( "plugins.transform.internal.search.backoff_millis", TimeValue.timeValueMillis(1000), Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val TRANSFORM_JOB_INDEX_BACKOFF_COUNT: Setting = Setting.intSetting( "plugins.transform.internal.index.backoff_count", 5, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val TRANSFORM_JOB_INDEX_BACKOFF_MILLIS: Setting = Setting.positiveTimeSetting( "plugins.transform.internal.index.backoff_millis", TimeValue.timeValueMillis(1000), Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val TRANSFORM_CIRCUIT_BREAKER_ENABLED: Setting = Setting.boolSetting( "plugins.transform.circuit_breaker.enabled", true, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) val TRANSFORM_CIRCUIT_BREAKER_JVM_THRESHOLD: Setting = Setting.intSetting( @@ -57,7 +57,7 @@ class TransformSettings { 0, 100, Setting.Property.NodeScope, - Setting.Property.Dynamic + Setting.Property.Dynamic, ) } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/transform/util/TransformLockManager.kt b/src/main/kotlin/org/opensearch/indexmanagement/transform/util/TransformLockManager.kt index 0a06ef18b..64cae16ca 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/transform/util/TransformLockManager.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/transform/util/TransformLockManager.kt @@ -24,18 +24,19 @@ import java.time.Instant @OpenForTesting class TransformLockManager( private val transformJob: Transform, - val context: JobExecutionContext + val context: JobExecutionContext, ) { private val logger = LogManager.getLogger(javaClass) private val exponentialBackoffPolicy = BackoffPolicy.exponentialBackoff( TimeValue.timeValueMillis(TransformSettings.DEFAULT_RENEW_LOCK_RETRY_DELAY), - TransformSettings.DEFAULT_RENEW_LOCK_RETRY_COUNT + TransformSettings.DEFAULT_RENEW_LOCK_RETRY_COUNT, ) var lock: LockModel? = null protected set fun lockExpirationInSeconds() = lock?.let { it.lockTime.epochSecond + it.lockDurationSeconds - Instant.now().epochSecond } + /** * Util method to attempt to get the lock on the requested scheduled job using the backoff policy. * If failed to acquire the lock using backoff policy will return a null lock otherwise returns acquired lock. diff --git a/src/main/kotlin/org/opensearch/indexmanagement/util/IndexManagementException.kt b/src/main/kotlin/org/opensearch/indexmanagement/util/IndexManagementException.kt index 9242c71a9..7cf0c92fc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/util/IndexManagementException.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/util/IndexManagementException.kt @@ -7,10 +7,10 @@ package org.opensearch.indexmanagement.util import org.opensearch.OpenSearchException import org.opensearch.OpenSearchStatusException -import org.opensearch.core.common.Strings import org.opensearch.common.ValidationException -import org.opensearch.index.IndexNotFoundException +import org.opensearch.core.common.Strings import org.opensearch.core.rest.RestStatus +import org.opensearch.index.IndexNotFoundException import java.lang.IllegalArgumentException class IndexManagementException(message: String, val status: RestStatus, ex: Exception) : OpenSearchException(message, ex) { @@ -22,7 +22,6 @@ class IndexManagementException(message: String, val status: RestStatus, ex: Exce companion object { @JvmStatic fun wrap(ex: Exception): OpenSearchException { - var friendlyMsg = ex.message as String var status = RestStatus.INTERNAL_SERVER_ERROR when (ex) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/util/IndexUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/util/IndexUtils.kt index 934fde0e1..92ab7cfc1 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/util/IndexUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/util/IndexUtils.kt @@ -6,7 +6,6 @@ package org.opensearch.indexmanagement.util import org.apache.logging.log4j.LogManager -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.IndicesAdminClient @@ -16,6 +15,7 @@ import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.common.hash.MurmurHash3 import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.action.ActionListener import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.indexmanagement.IndexManagementIndices @@ -53,7 +53,7 @@ class IndexUtils { fun getSchemaVersion(mapping: String): Long { val xcp = XContentType.JSON.xContent().createParser( NamedXContentRegistry.EMPTY, - LoggingDeprecationHandler.INSTANCE, mapping + LoggingDeprecationHandler.INSTANCE, mapping, ) while (!xcp.isClosed) { @@ -96,7 +96,7 @@ class IndexUtils { fun checkAndUpdateConfigIndexMapping( clusterState: ClusterState, client: IndicesAdminClient, - actionListener: ActionListener + actionListener: ActionListener, ) { checkAndUpdateIndexMapping( IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, @@ -104,14 +104,14 @@ class IndexUtils { IndexManagementIndices.indexManagementMappings, clusterState, client, - actionListener + actionListener, ) } fun checkAndUpdateHistoryIndexMapping( clusterState: ClusterState, client: IndicesAdminClient, - actionListener: ActionListener + actionListener: ActionListener, ) { checkAndUpdateAliasMapping( IndexManagementIndices.HISTORY_WRITE_INDEX_ALIAS, @@ -119,7 +119,7 @@ class IndexUtils { IndexManagementIndices.indexStateManagementHistoryMappings, clusterState, client, - actionListener + actionListener, ) } @@ -131,7 +131,7 @@ class IndexUtils { mapping: String, clusterState: ClusterState, client: IndicesAdminClient, - actionListener: ActionListener + actionListener: ActionListener, ) { if (clusterState.metadata.indices.containsKey(index)) { if (shouldUpdateIndex(clusterState.metadata.indices[index], schemaVersion)) { @@ -154,7 +154,7 @@ class IndexUtils { mapping: String, clusterState: ClusterState, client: IndicesAdminClient, - actionListener: ActionListener + actionListener: ActionListener, ) { val result = clusterState.metadata.indicesLookup[alias] if (result == null || result.type != IndexAbstraction.Type.ALIAS) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/util/RestHandlerUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/util/RestHandlerUtils.kt index 934b3d3fb..fefb48c1f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/util/RestHandlerUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/util/RestHandlerUtils.kt @@ -4,6 +4,7 @@ */ @file:Suppress("TopLevelPropertyNaming", "MatchingDeclarationName") + package org.opensearch.indexmanagement.util import org.opensearch.indexmanagement.common.model.rest.DEFAULT_PAGINATION_FROM diff --git a/src/main/kotlin/org/opensearch/indexmanagement/util/ScheduledJobUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/util/ScheduledJobUtils.kt index 6880dd9c7..b4250bb9c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/util/ScheduledJobUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/util/ScheduledJobUtils.kt @@ -7,24 +7,24 @@ package org.opensearch.indexmanagement.util import org.opensearch.ExceptionsHelper import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener -import org.opensearch.core.action.ActionResponse import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.client.Client -import org.opensearch.core.common.bytes.BytesReference import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.core.xcontent.XContentParser import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse +import org.opensearch.core.common.bytes.BytesReference +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.XContentParser import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.rollup.action.get.GetRollupsResponse import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.transform.action.get.GetTransformsResponse import org.opensearch.indexmanagement.transform.model.Transform -import org.opensearch.core.rest.RestStatus import org.opensearch.search.builder.SearchSourceBuilder fun getJobs( @@ -32,7 +32,7 @@ fun getJobs( searchSourceBuilder: SearchSourceBuilder, listener: ActionListener, scheduledJobType: String, - contentParser: (b: BytesReference) -> XContentParser = ::contentParser + contentParser: (b: BytesReference) -> XContentParser = ::contentParser, ) { val searchRequest = SearchRequest(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX).source(searchSourceBuilder) client.search( @@ -54,15 +54,15 @@ fun getJobs( listener.onFailure( OpenSearchStatusException( "Failed to parse $scheduledJobType", - RestStatus.INTERNAL_SERVER_ERROR, ExceptionsHelper.unwrapCause(e) - ) + RestStatus.INTERNAL_SERVER_ERROR, ExceptionsHelper.unwrapCause(e), + ), ) } } } override fun onFailure(e: Exception) = listener.onFailure(e) - } + }, ) } @@ -71,7 +71,7 @@ private fun populateResponse( jobType: String, jobs: List, status: RestStatus, - totalJobs: Int + totalJobs: Int, ): ActionResponse { return when (jobType) { Rollup.ROLLUP_TYPE -> GetRollupsResponse(jobs as List, totalJobs, status) @@ -95,6 +95,6 @@ private fun getParser(jobType: String): (XContentParser, String, Long, Long) -> private fun contentParser(bytesReference: BytesReference): XContentParser { return XContentHelper.createParser( NamedXContentRegistry.EMPTY, - LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON + LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON, ) } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/util/SecurityUtils.kt b/src/main/kotlin/org/opensearch/indexmanagement/util/SecurityUtils.kt index b087a4a7a..d9733c9c2 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/util/SecurityUtils.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/util/SecurityUtils.kt @@ -6,14 +6,14 @@ package org.opensearch.indexmanagement.util import org.opensearch.OpenSearchStatusException -import org.opensearch.core.action.ActionListener import org.opensearch.common.util.concurrent.ThreadContext import org.opensearch.commons.ConfigConstants import org.opensearch.commons.authuser.User +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus import org.opensearch.index.query.BoolQueryBuilder import org.opensearch.index.query.ExistsQueryBuilder import org.opensearch.index.query.TermsQueryBuilder -import org.opensearch.core.rest.RestStatus @Suppress("ReturnCount", "UtilityClassWithPublicConstructor") class SecurityUtils { @@ -44,12 +44,12 @@ class SecurityUtils { throw IndexManagementException.wrap( OpenSearchStatusException( "Filter by user backend roles in IndexManagement is not supported with security disabled", - RestStatus.FORBIDDEN - ) + RestStatus.FORBIDDEN, + ), ) } else if (user.backendRoles.isEmpty()) { throw IndexManagementException.wrap( - OpenSearchStatusException("User doesn't have backend roles configured. Contact administrator", RestStatus.FORBIDDEN) + OpenSearchStatusException("User doesn't have backend roles configured. Contact administrator", RestStatus.FORBIDDEN), ) } } @@ -66,16 +66,16 @@ class SecurityUtils { IndexManagementException.wrap( OpenSearchStatusException( "Filter by user backend roles in IndexManagement is not supported with security disabled", - RestStatus.FORBIDDEN - ) - ) + RestStatus.FORBIDDEN, + ), + ), ) return false } else if (user.backendRoles.isEmpty()) { actionListener.onFailure( IndexManagementException.wrap( - OpenSearchStatusException("User doesn't have backend roles configured. Contact administrator", RestStatus.FORBIDDEN) - ) + OpenSearchStatusException("User doesn't have backend roles configured. Contact administrator", RestStatus.FORBIDDEN), + ), ) return false } @@ -93,13 +93,13 @@ class SecurityUtils { filterEnabled: Boolean = false, resourceName: String, resourceId: String, - actionListener: ActionListener + actionListener: ActionListener, ): Boolean { if (!userHasPermissionForResource(requestedUser, resourceUser, filterEnabled)) { actionListener.onFailure( IndexManagementException.wrap( - OpenSearchStatusException("Do not have permission for $resourceName [$resourceId]", RestStatus.FORBIDDEN) - ) + OpenSearchStatusException("Do not have permission for $resourceName [$resourceId]", RestStatus.FORBIDDEN), + ), ) return false } @@ -115,11 +115,11 @@ class SecurityUtils { resourceUser: User?, filterEnabled: Boolean = false, resourceName: String, - resourceId: String + resourceId: String, ) { if (!userHasPermissionForResource(requestedUser, resourceUser, filterEnabled)) { throw IndexManagementException.wrap( - OpenSearchStatusException("Do not have permission for $resourceName [$resourceId]", RestStatus.FORBIDDEN) + OpenSearchStatusException("Do not have permission for $resourceName [$resourceId]", RestStatus.FORBIDDEN), ) } } @@ -131,7 +131,7 @@ class SecurityUtils { fun userHasPermissionForResource( requestedUser: User?, resourceUser: User?, - filterEnabled: Boolean = false + filterEnabled: Boolean = false, ): Boolean { // Will not filter if filter is not enabled or stored user is null or requested user is null or if the user is admin if (!filterEnabled || resourceUser == null || requestedUser == null || requestedUser.roles.contains(ADMIN_ROLE)) { @@ -153,11 +153,11 @@ class SecurityUtils { } val filterQuery = BoolQueryBuilder().should( - TermsQueryBuilder("$filterPathPrefix.backend_roles.keyword", user.backendRoles) + TermsQueryBuilder("$filterPathPrefix.backend_roles.keyword", user.backendRoles), ).should( BoolQueryBuilder().mustNot( - ExistsQueryBuilder(filterPathPrefix) - ) + ExistsQueryBuilder(filterPathPrefix), + ), ) queryBuilder.filter(filterQuery) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/AccessRoles.kt b/src/test/kotlin/org/opensearch/indexmanagement/AccessRoles.kt index 19682e3ac..56ca4e55e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/AccessRoles.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/AccessRoles.kt @@ -36,6 +36,7 @@ const val GET_POLICY = GetPolicyAction.NAME const val EXPLAIN_INDEX = ExplainAction.NAME const val MANAGED_INDEX = ManagedIndexAction.NAME const val DELETE_POLICY = DeletePolicyAction.NAME + // Rollup const val ROLLUP_ALL = "cluster:admin/opendistro/rollup/*" const val INDEX_ROLLUP = IndexRollupAction.NAME @@ -43,6 +44,7 @@ const val GET_ROLLUP = GetRollupAction.NAME const val EXPLAIN_ROLLUP = ExplainRollupAction.NAME const val UPDATE_ROLLUP = UpdateRollupMappingAction.NAME const val DELETE_ROLLUP = DeleteRollupAction.NAME + // Transform const val TRANSFORM_ACTION = IndexTransformAction.NAME const val GET_TRANSFORM = GetTransformAction.NAME @@ -51,8 +53,10 @@ const val START_TRANSFORM = StartTransformAction.NAME const val DELETE_TRANSFORM = DeleteTransformsAction.NAME const val GET_TRANSFORMS = GetTransformsAction.NAME const val STOP_TRANSFORM = StopTransformAction.NAME + // In order to execute transform, user need to have health privilege const val HEALTH = "cluster:monitor/health" + // Index const val GET_INDEX_MAPPING = "indices:admin/mappings/get" const val PUT_INDEX_MAPPING = "indices:admin/mapping/put" @@ -60,6 +64,7 @@ const val SEARCH_INDEX = "indices:data/read/search" const val CREATE_INDEX = "indices:admin/create" const val WRITE_INDEX = "indices:data/write/index" const val BULK_WRITE_INDEX = "indices:data/write/bulk*" + // Long-running operation notification (lron) const val INDEX_LRON_CONFIG = IndexLRONConfigAction.NAME const val GET_LRON_CONFIG = GetLRONConfigAction.NAME diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt index 603a24e8d..1816f6644 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt @@ -8,8 +8,9 @@ package org.opensearch.indexmanagement import org.apache.http.entity.ContentType import org.apache.http.entity.StringEntity import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.IndexManagementIndices.Companion.HISTORY_INDEX_BASE import org.opensearch.indexmanagement.IndexManagementIndices.Companion.HISTORY_WRITE_INDEX_ALIAS import org.opensearch.indexmanagement.IndexManagementIndices.Companion.indexManagementMappings @@ -32,7 +33,6 @@ import org.opensearch.indexmanagement.opensearchapi.string import org.opensearch.indexmanagement.refreshanalyzer.RestRefreshSearchAnalyzerAction import org.opensearch.indexmanagement.rollup.randomRollup import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import java.util.Locale @@ -41,22 +41,22 @@ class IndexManagementIndicesIT : IndexStateManagementRestTestCase() { private val testIndexName = javaClass.simpleName.lowercase(Locale.ROOT) /* - * If this test fails it means you changed the config mappings - * This test is to ensure you did not forget to increase the schema_version in the mappings _meta object - * The schema_version is used at runtime to check if the mappings need to be updated for the index - * Once you are sure you increased the schema_version or know it is not needed you can update the cached mappings with the new values - * */ + * If this test fails it means you changed the config mappings + * This test is to ensure you did not forget to increase the schema_version in the mappings _meta object + * The schema_version is used at runtime to check if the mappings need to be updated for the index + * Once you are sure you increased the schema_version or know it is not needed you can update the cached mappings with the new values + * */ fun `test config mappings schema version number`() { val cachedMappings = javaClass.classLoader.getResource("mappings/cached-opendistro-ism-config.json")!!.readText() assertEquals("I see you updated the config mappings. Did you also update the schema_version?", cachedMappings, indexManagementMappings) } /* - * If this test fails it means you changed the history mappings - * This test is to ensure you did not forget to increase the schema_version in the mappings _meta object - * The schema_version is used at runtime to check if the mappings need to be updated for the index - * Once you are sure you increased the schema_version or know it is not needed you can update the cached mappings with the new values - * */ + * If this test fails it means you changed the history mappings + * This test is to ensure you did not forget to increase the schema_version in the mappings _meta object + * The schema_version is used at runtime to check if the mappings need to be updated for the index + * Once you are sure you increased the schema_version or know it is not needed you can update the cached mappings with the new values + * */ fun `test history mappings schema version number`() { val cachedMappings = javaClass.classLoader.getResource("mappings/cached-opendistro-ism-history.json")!!.readText() assertEquals("I see you updated the history mappings. Did you also update the schema_version?", cachedMappings, indexStateManagementHistoryMappings) @@ -134,7 +134,7 @@ class IndexManagementIndicesIT : IndexStateManagementRestTestCase() { val entity = StringEntity(mapping, ContentType.APPLICATION_JSON) client().makeRequest( RestRequest.Method.PUT.toString(), - "/$INDEX_MANAGEMENT_INDEX/_mapping", emptyMap(), entity + "/$INDEX_MANAGEMENT_INDEX/_mapping", emptyMap(), entity, ) verifyIndexSchemaVersion(INDEX_MANAGEMENT_INDEX, 0) @@ -143,7 +143,7 @@ class IndexManagementIndicesIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(newPolicy.id, null, emptyList(), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity(), ) verifyIndexSchemaVersion(INDEX_MANAGEMENT_INDEX, configSchemaVersion) @@ -165,38 +165,38 @@ class IndexManagementIndicesIT : IndexStateManagementRestTestCase() { val addPolicyResponse = client().makeRequest( RestRequest.Method.POST.toString(), "${RestAddPolicyAction.LEGACY_ADD_POLICY_BASE_URI}/$indexName", - StringEntity("{ \"policy_id\": \"$policyId\" }", ContentType.APPLICATION_JSON) + StringEntity("{ \"policy_id\": \"$policyId\" }", ContentType.APPLICATION_JSON), ) assertEquals("Unexpected RestStatus", RestStatus.OK, addPolicyResponse.restStatus()) val changePolicyResponse = client().makeRequest( RestRequest.Method.POST.toString(), "${RestAddPolicyAction.LEGACY_ADD_POLICY_BASE_URI}/$indexName", - StringEntity("{ \"policy_id\": \"$policyId\" }", ContentType.APPLICATION_JSON) + StringEntity("{ \"policy_id\": \"$policyId\" }", ContentType.APPLICATION_JSON), ) assertEquals("Unexpected RestStatus", RestStatus.OK, changePolicyResponse.restStatus()) val retryFailedResponse = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.LEGACY_RETRY_BASE_URI}/$indexName" + "${RestRetryFailedManagedIndexAction.LEGACY_RETRY_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, retryFailedResponse.restStatus()) val explainResponse = client().makeRequest( RestRequest.Method.GET.toString(), - "${RestExplainAction.LEGACY_EXPLAIN_BASE_URI}/$indexName" + "${RestExplainAction.LEGACY_EXPLAIN_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, explainResponse.restStatus()) val removePolicyResponse = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRemovePolicyAction.LEGACY_REMOVE_POLICY_BASE_URI}/$indexName" + "${RestRemovePolicyAction.LEGACY_REMOVE_POLICY_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, removePolicyResponse.restStatus()) val deletePolicyResponse = client().makeRequest( RestRequest.Method.DELETE.toString(), - "${IndexManagementPlugin.LEGACY_POLICY_BASE_URI}/$policyId" + "${IndexManagementPlugin.LEGACY_POLICY_BASE_URI}/$policyId", ) assertEquals("Unexpected RestStatus", RestStatus.OK, deletePolicyResponse.restStatus()) @@ -219,8 +219,8 @@ class IndexManagementIndicesIT : IndexStateManagementRestTestCase() { "PUT", "${IndexManagementPlugin.LEGACY_ROLLUP_JOBS_BASE_URI}/${rollup.id}", emptyMap(), StringEntity( rollupJsonString, - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) assertEquals("Create rollup failed", RestStatus.CREATED, createRollupResponse.restStatus()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt index 3d55c6b31..1d1aeb6fd 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt @@ -16,17 +16,17 @@ import org.opensearch.client.Request import org.opensearch.client.RequestOptions import org.opensearch.client.Response import org.opensearch.client.ResponseException -import org.opensearch.core.common.Strings import org.opensearch.client.RestClient import org.opensearch.client.WarningsHandler import org.opensearch.common.io.PathUtils import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.common.Strings +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.DeprecationHandler +import org.opensearch.core.xcontent.MediaType import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN -import org.opensearch.core.rest.RestStatus -import org.opensearch.core.xcontent.MediaType import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule @@ -34,8 +34,8 @@ import java.io.IOException import java.nio.file.Files import java.time.Duration import java.time.Instant -import java.util.Date import java.util.* +import java.util.Date import javax.management.MBeanServerInvocationHandler import javax.management.ObjectName import javax.management.remote.JMXConnectorFactory @@ -53,7 +53,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { fun setAutoCreateIndex() { client().makeRequest( "PUT", "_cluster/settings", - StringEntity("""{"persistent":{"action.auto_create_index":"-.opendistro-*,*"}}""", ContentType.APPLICATION_JSON) + StringEntity("""{"persistent":{"action.auto_create_index":"-.opendistro-*,*"}}""", ContentType.APPLICATION_JSON), ) } @@ -84,8 +84,8 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) } @@ -224,8 +224,8 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { StringEntity( "{\"doc\":{\"rollup\":{\"schedule\":{\"interval\":{\"start_time\":" + "\"$startTimeMillis\"}}}}}", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -253,8 +253,8 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { StringEntity( "{\"doc\":{\"transform\":{\"schedule\":{\"interval\":{\"start_time\":" + "\"$startTimeMillis\"}}}}}", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -265,6 +265,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { val isMultiNode = System.getProperty("cluster.number_of_nodes", "1").toInt() > 1 val isBWCTest = System.getProperty("tests.plugin_bwc_version", "0") != "0" protected val defaultKeepIndexSet = setOf(".opendistro_security") + /** * We override preserveIndicesUponCompletion to true and use this function to clean up indices * Meant to be used in @After or @AfterClass of your feature test suite @@ -290,7 +291,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { val xContentType = MediaType.fromMediaType(response.entity.contentType.value) xContentType.xContent().createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - response.entity.content + response.entity.content, ).use { parser -> for (index in parser.list()) { val jsonObject: Map<*, *> = index as java.util.HashMap<*, *> @@ -359,7 +360,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { val xContentType = MediaType.fromMediaType(response.entity.contentType.value) xContentType.xContent().createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - response.entity.content + response.entity.content, ).use { parser -> for (index in parser.list()) { val jsonObject: Map<*, *> = index as java.util.HashMap<*, *> @@ -384,13 +385,13 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { } /* - * We need to be able to dump the jacoco coverage before the cluster shuts down. - * The new internal testing framework removed some gradle tasks we were listening to, - * to choose a good time to do it. This will dump the executionData to file after each test. - * TODO: This is also currently just overwriting integTest.exec with the updated execData without - * resetting after writing each time. This can be improved to either write an exec file per test - * or by letting jacoco append to the file. - * */ + * We need to be able to dump the jacoco coverage before the cluster shuts down. + * The new internal testing framework removed some gradle tasks we were listening to, + * to choose a good time to do it. This will dump the executionData to file after each test. + * TODO: This is also currently just overwriting integTest.exec with the updated execData without + * resetting after writing each time. This can be improved to either write an exec file per test + * or by letting jacoco append to the file. + * */ @JvmStatic @AfterClass fun dumpCoverage() { @@ -403,7 +404,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { connector.mBeanServerConnection, ObjectName("org.jacoco:type=Runtime"), IProxy::class.java, - false + false, ) proxy.getExecutionData(false)?.let { val path = PathUtils.get("$jacocoBuildPath/integTest.exec") diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementSettingsTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementSettingsTests.kt index 2bf14f914..7988ee2e2 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementSettingsTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementSettingsTests.kt @@ -56,9 +56,9 @@ class IndexManagementSettingsTests : OpenSearchTestCase() { LegacyOpenDistroRollupSettings.ROLLUP_INDEX, LegacyOpenDistroRollupSettings.ROLLUP_ENABLED, LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_ENABLED, - LegacyOpenDistroRollupSettings.ROLLUP_DASHBOARDS - ) - ) + LegacyOpenDistroRollupSettings.ROLLUP_DASHBOARDS, + ), + ), ) } @@ -95,16 +95,16 @@ class IndexManagementSettingsTests : OpenSearchTestCase() { RollupSettings.ROLLUP_SEARCH_ENABLED, RollupSettings.ROLLUP_SEARCH_ALL_JOBS, RollupSettings.ROLLUP_DASHBOARDS, - SnapshotManagementSettings.FILTER_BY_BACKEND_ROLES - ) - ) + SnapshotManagementSettings.FILTER_BY_BACKEND_ROLES, + ), + ), ) } fun testLegacyOpenDistroSettingsFallback() { assertEquals( ManagedIndexSettings.INDEX_STATE_MANAGEMENT_ENABLED.get(Settings.EMPTY), - LegacyOpenDistroManagedIndexSettings.INDEX_STATE_MANAGEMENT_ENABLED.get(Settings.EMPTY) + LegacyOpenDistroManagedIndexSettings.INDEX_STATE_MANAGEMENT_ENABLED.get(Settings.EMPTY), ) } @@ -127,7 +127,7 @@ class IndexManagementSettingsTests : OpenSearchTestCase() { assertEquals(ManagedIndexSettings.ROLLOVER_SKIP.get(settings), false) assertSettingDeprecationsAndWarnings( - arrayOf(LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP) + arrayOf(LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP), ) } @@ -207,8 +207,8 @@ class IndexManagementSettingsTests : OpenSearchTestCase() { LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_COUNT, LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_BACKOFF_MILLIS, LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_BACKOFF_COUNT, - LegacyOpenDistroRollupSettings.ROLLUP_DASHBOARDS - ) + LegacyOpenDistroRollupSettings.ROLLUP_DASHBOARDS, + ), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt index 00bbd543f..e09c337af 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt @@ -15,6 +15,7 @@ import org.junit.After import org.junit.Before import org.opensearch.client.RestClient import org.opensearch.commons.rest.SecureRestClientBuilder +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Terms import org.opensearch.indexmanagement.indexstatemanagement.action.RollupAction @@ -33,7 +34,6 @@ import org.opensearch.indexmanagement.rollup.model.metric.Max import org.opensearch.indexmanagement.rollup.model.metric.Min import org.opensearch.indexmanagement.rollup.model.metric.Sum import org.opensearch.indexmanagement.rollup.model.metric.ValueCount -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant import java.time.temporal.ChronoUnit @@ -76,7 +76,7 @@ class IndexStateManagementSecurityBehaviorIT : SecurityRestTestCase() { BULK_WRITE_INDEX, GET_INDEX_MAPPING, SEARCH_INDEX, - PUT_INDEX_MAPPING + PUT_INDEX_MAPPING, ) // In this test suite case john is a "super-user" which has all relevant privileges createUser(superIsmUser, password, listOf(HELPDESK)) @@ -117,7 +117,7 @@ class IndexStateManagementSecurityBehaviorIT : SecurityRestTestCase() { val actionConfig = RollupAction(rollup, 0) val states = listOf( - State("rollup", listOf(actionConfig), listOf()) + State("rollup", listOf(actionConfig), listOf()), ) val policy = createPolicyWithRollupStep(policyID, states, indexName) @@ -240,8 +240,8 @@ class IndexStateManagementSecurityBehaviorIT : SecurityRestTestCase() { defaultState = states[0].name, states = states, ismTemplate = listOf( - ISMTemplate(listOf("$indexName*"), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS)) - ) + ISMTemplate(listOf("$indexName*"), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS)), + ), ) return policy } @@ -254,22 +254,22 @@ class IndexStateManagementSecurityBehaviorIT : SecurityRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), RollupMetrics( sourceField = "total_amount", targetField = "total_amount", - metrics = listOf(Max(), Min()) - ) - ) + metrics = listOf(Max(), Min()), + ), + ), ) } @@ -287,7 +287,7 @@ class IndexStateManagementSecurityBehaviorIT : SecurityRestTestCase() { waitFor { assertEquals( AttemptCreateRollupJobStep.getSuccessMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -303,7 +303,7 @@ class IndexStateManagementSecurityBehaviorIT : SecurityRestTestCase() { waitFor { assertEquals( WaitForRollupCompletionStep.getJobCompletionMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/MocksTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/MocksTestCase.kt index 43f1c075d..d5cf4f836 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/MocksTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/MocksTestCase.kt @@ -11,14 +11,14 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import org.junit.Before import org.mockito.Mockito -import org.opensearch.core.action.ActionListener -import org.opensearch.core.action.ActionResponse import org.opensearch.action.index.IndexResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.ClusterAdminClient import org.opensearch.common.settings.Settings import org.opensearch.common.util.concurrent.ThreadContext +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse import org.opensearch.indexmanagement.snapshotmanagement.mockIndexResponse import org.opensearch.test.OpenSearchTestCase import org.opensearch.threadpool.ThreadPool @@ -51,52 +51,61 @@ abstract class MocksTestCase : OpenSearchTestCase() { fun mockCreateSnapshotCall( response: ActionResponse? = null, - exception: Exception? = null + exception: Exception? = null, ) { assertTrue( "Must provide either a response or an exception.", - (response != null).xor(exception != null) + (response != null).xor(exception != null), ) whenever(client.admin()).thenReturn(adminClient) whenever(adminClient.cluster()).thenReturn(clusterAdminClient) doAnswer { val listener = it.getArgument>(1) - if (response != null) listener.onResponse(response) - else listener.onFailure(exception) + if (response != null) { + listener.onResponse(response) + } else { + listener.onFailure(exception) + } }.whenever(clusterAdminClient).createSnapshot(any(), any()) } fun mockDeleteSnapshotCall( response: ActionResponse? = null, - exception: Exception? = null + exception: Exception? = null, ) { assertTrue( "Must provide either a response or an exception.", - (response != null).xor(exception != null) + (response != null).xor(exception != null), ) whenever(client.admin()).thenReturn(adminClient) whenever(adminClient.cluster()).thenReturn(clusterAdminClient) doAnswer { val listener = it.getArgument>(1) - if (response != null) listener.onResponse(response) - else listener.onFailure(exception) + if (response != null) { + listener.onResponse(response) + } else { + listener.onFailure(exception) + } }.whenever(clusterAdminClient).deleteSnapshot(any(), any()) } fun mockGetSnapshotsCall( response: ActionResponse? = null, - exception: Exception? = null + exception: Exception? = null, ) { assertTrue( "Must provide either a response or an exception.", - (response != null).xor(exception != null) + (response != null).xor(exception != null), ) whenever(client.admin()).thenReturn(adminClient) whenever(adminClient.cluster()).thenReturn(clusterAdminClient) doAnswer { val listener = it.getArgument>(1) - if (response != null) listener.onResponse(response) - else listener.onFailure(exception) + if (response != null) { + listener.onResponse(response) + } else { + listener.onFailure(exception) + } }.whenever(clusterAdminClient).getSnapshots(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt index 9f898ff12..ddaff665c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt @@ -17,13 +17,13 @@ import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest import org.opensearch.client.ResponseException import org.opensearch.client.RestClient import org.opensearch.commons.rest.SecureRestClientBuilder +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.action.AliasAction import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.model.State import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification import org.opensearch.indexmanagement.indexstatemanagement.transport.action.addpolicy.AddPolicyAction -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant @@ -39,12 +39,13 @@ class PolicySecurityBehaviorIT : SecurityRestTestCase() { private val permittedIndicesPrefix = "permitted-index" private val permittedIndicesPattern = "permitted-index*" + @Before fun setupUsersAndRoles() { // updateClusterSetting(ManagedIndexSettings.JITTER.key, "0.0", false) val custerPermissions = listOf( - AddPolicyAction.NAME + AddPolicyAction.NAME, ) val indexPermissions = listOf( @@ -54,7 +55,7 @@ class PolicySecurityBehaviorIT : SecurityRestTestCase() { BULK_WRITE_INDEX, GET_INDEX_MAPPING, SEARCH_INDEX, - PUT_INDEX_MAPPING + PUT_INDEX_MAPPING, ) createUser(ismUser, password, listOf(HELPDESK)) createRole(HELPDESK_ROLE, custerPermissions, indexPermissions, listOf(permittedIndicesPattern)) @@ -76,7 +77,6 @@ class PolicySecurityBehaviorIT : SecurityRestTestCase() { } fun `test add policy`() { - val notPermittedIndexPrefix = OpenSearchTestCase.randomAlphaOfLength(10).lowercase(Locale.getDefault()) val policyId = OpenSearchTestCase.randomAlphaOfLength(10) @@ -101,7 +101,7 @@ class PolicySecurityBehaviorIT : SecurityRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = "alias", - states = states + states = states, ) createPolicy(policy, policy.id, true, client()) // Call AddPolicyAction as user diff --git a/src/test/kotlin/org/opensearch/indexmanagement/RollupSecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/RollupSecurityBehaviorIT.kt index fa444d40c..9dc4b5e54 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/RollupSecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/RollupSecurityBehaviorIT.kt @@ -15,6 +15,7 @@ import org.junit.After import org.junit.Before import org.opensearch.client.RestClient import org.opensearch.commons.rest.SecureRestClientBuilder +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.rollup.model.Rollup @@ -27,7 +28,6 @@ import org.opensearch.indexmanagement.rollup.model.metric.Sum import org.opensearch.indexmanagement.rollup.model.metric.ValueCount import org.opensearch.indexmanagement.rollup.randomRollup import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant import java.time.temporal.ChronoUnit @@ -53,7 +53,7 @@ class RollupSecurityBehaviorIT : SecurityRestTestCase() { GET_ROLLUP, EXPLAIN_ROLLUP, UPDATE_ROLLUP, - DELETE_ROLLUP + DELETE_ROLLUP, ) @@ -64,7 +64,7 @@ class RollupSecurityBehaviorIT : SecurityRestTestCase() { BULK_WRITE_INDEX, GET_INDEX_MAPPING, SEARCH_INDEX, - PUT_INDEX_MAPPING + PUT_INDEX_MAPPING, ) // In this test suite case john is a "super-user" which has all relevant privileges createUser(superRollupUser, password, listOf(HELPDESK)) @@ -232,9 +232,9 @@ class RollupSecurityBehaviorIT : SecurityRestTestCase() { RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) - ) - ) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), + ), + ), ) private fun createTestUserWithRole(clusterPermissions: List, indexPermissions: List) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/SecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/SecurityBehaviorIT.kt index c12b8b798..a04122c38 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/SecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/SecurityBehaviorIT.kt @@ -15,8 +15,8 @@ import org.junit.After import org.junit.Before import org.opensearch.client.RestClient import org.opensearch.commons.rest.SecureRestClientBuilder -import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.core.rest.RestStatus +import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.test.junit.annotations.TestLogging @TestLogging("level:DEBUG", reason = "Debug for tests.") @@ -34,7 +34,7 @@ class SecurityBehaviorIT : SecurityRestTestCase() { WRITE_POLICY, GET_POLICY, GET_POLICIES, - EXPLAIN_INDEX + EXPLAIN_INDEX, ) val indexPermissions = listOf( @@ -44,7 +44,7 @@ class SecurityBehaviorIT : SecurityRestTestCase() { BULK_WRITE_INDEX, GET_INDEX_MAPPING, SEARCH_INDEX, - PUT_INDEX_MAPPING + PUT_INDEX_MAPPING, ) // In this test suite case john is a "super-user" which has all relevant privileges createUser(john, password, listOf(HELPDESK)) @@ -74,7 +74,7 @@ class SecurityBehaviorIT : SecurityRestTestCase() { EXPLAIN_INDEX, GET_POLICY, WRITE_POLICY, - GET_POLICIES + GET_POLICIES, ) val indexPermissions = listOf( @@ -82,7 +82,7 @@ class SecurityBehaviorIT : SecurityRestTestCase() { CREATE_INDEX, GET_INDEX_MAPPING, SEARCH_INDEX, - PUT_INDEX_MAPPING + PUT_INDEX_MAPPING, ) // Jane is phone operator; Phone operators can search availability indexes createUserWithCustomRole( @@ -92,7 +92,7 @@ class SecurityBehaviorIT : SecurityRestTestCase() { phoneOperatorClusterPermissions, indexPermissions, listOf(PHONE_OPERATOR), - listOf(AVAILABILITY_INDEX_PATTERN) + listOf(AVAILABILITY_INDEX_PATTERN), ) val jillClient = diff --git a/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt index b38b7e112..af56b400e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt @@ -19,9 +19,10 @@ import org.opensearch.client.Request import org.opensearch.client.Response import org.opensearch.client.ResponseException import org.opensearch.client.RestClient -import org.opensearch.core.common.Strings import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.common.Strings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy @@ -39,7 +40,6 @@ import org.opensearch.indexmanagement.transform.TransformRestTestCase import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.transform.toJsonString import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import java.util.Locale @@ -51,7 +51,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { rollup: Rollup, rollupId: String, refresh: Boolean, - client: RestClient + client: RestClient, ) = super.createRollup(rollup, rollupId, refresh, client) fun getRollupMetadataExt( @@ -83,7 +83,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { policyString: String, policyId: String, refresh: Boolean = true, - client: RestClient + client: RestClient, ) = super.createPolicyJson(policyString, policyId, refresh, client) fun updateManagedIndexConfigStartTimeExt(update: ManagedIndexConfig, desiredStartTimeMillis: Long? = null, retryOnConflict: Int = 0) = super.updateManagedIndexConfigStartTime(update, desiredStartTimeMillis, retryOnConflict) @@ -119,7 +119,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { fun getTransformExt( transformId: String, header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), - userClient: RestClient? = null + userClient: RestClient? = null, ) = super.getTransform(transformId, header, userClient) fun getTransformMetadataExt(metadataId: String) = super.getTransformMetadata(metadataId) @@ -136,14 +136,14 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { """.trimIndent() val res = client().makeRequest( "PUT", "_cluster/settings", emptyMap(), - StringEntity(request, ContentType.APPLICATION_JSON) + StringEntity(request, ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, res.restStatus()) } protected fun createRollup( rollup: Rollup, - client: RestClient + client: RestClient, ): Rollup { return RollupRestTestCaseSecurityExtension.createRollupExt(rollup, rollup.id, true, client) } @@ -151,9 +151,8 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { protected fun createRollupAndCheckStatus( rollup: Rollup, expectedStatus: RestStatus, - client: RestClient + client: RestClient, ): Response { - val request = Request("PUT", "${IndexManagementPlugin.ROLLUP_JOBS_BASE_URI}/${rollup.id}?refresh=true") request.setJsonEntity(rollup.toJsonString()) return executeRequest(request, expectedStatus, client) @@ -217,7 +216,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { policyString: String, policyId: String, refresh: Boolean = true, - client: RestClient + client: RestClient, ): Response { return IndexStateManagementRestTestCaseExt.createPolicyJsonExt(policyString, policyId, refresh, client) } @@ -278,11 +277,11 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { userClient: RestClient, user: String, expectedNumberOfPolicies: Int?, - expectedStatus: RestStatus = RestStatus.OK + expectedStatus: RestStatus = RestStatus.OK, ): Response? { val response = executeRequest(request = Request(RestRequest.Method.GET.name, IndexManagementPlugin.POLICY_BASE_URI), expectedStatus, userClient) assertEquals( - "User $user not able to see all policies", expectedNumberOfPolicies, response.asMap()["total_policies"] + "User $user not able to see all policies", expectedNumberOfPolicies, response.asMap()["total_policies"], ) return response } @@ -317,7 +316,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { protected fun createTransformAndCheckStatus( transform: Transform, expectedStatus: RestStatus, - client: RestClient + client: RestClient, ): Response { val request = Request(RestRequest.Method.PUT.name, "${IndexManagementPlugin.TRANSFORM_BASE_URI}/${transform.id}?refresh=true") request.setJsonEntity(transform.toJsonString()) @@ -327,7 +326,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { protected fun createPolicyAndCheckStatus( policy: Policy, expectedStatus: RestStatus, - client: RestClient + client: RestClient, ): Response { val request = Request("PUT", "${IndexManagementPlugin.POLICY_BASE_URI}/${policy.id}?refresh=true") request.setJsonEntity(policy.toJsonString()) @@ -337,7 +336,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { protected fun getTransform( transformId: String, header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), - client: RestClient + client: RestClient, ) = TransformRestTestCaseExt.getTransformExt(transformId, header, client) protected fun getTransformMetadata(metadataId: String) = TransformRestTestCaseExt.getTransformMetadataExt(metadataId) @@ -370,7 +369,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { protected fun executeRequest( request: Request, expectedRestStatus: RestStatus? = null, - client: RestClient + client: RestClient, ): Response { val response = try { client.performRequest(request) @@ -405,7 +404,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { clusterPermissions: List = emptyList(), indexPermissions: List = emptyList(), backendRoles: List = emptyList(), - indexPatterns: List = emptyList() + indexPatterns: List = emptyList(), ) { createUser(user, password, backendRoles) createRole(role, clusterPermissions, indexPermissions, indexPatterns) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt b/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt index 44064ea16..1712edcff 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt @@ -72,7 +72,7 @@ fun RestClient.makeRequest( params: Map = emptyMap(), entity: HttpEntity? = null, vararg headers: Header, - strictDeprecationMode: Boolean = false + strictDeprecationMode: Boolean = false, ): Response { val request = Request(method, endpoint) val options = RequestOptions.DEFAULT.toBuilder() @@ -97,7 +97,7 @@ fun RestClient.makeRequest( endpoint: String, entity: HttpEntity? = null, vararg headers: Header, - strictDeprecationMode: Boolean = false + strictDeprecationMode: Boolean = false, ): Response { val request = Request(method, endpoint) val options = RequestOptions.DEFAULT.toBuilder() @@ -112,7 +112,7 @@ fun RestClient.makeRequest( fun waitFor( timeout: Instant = Instant.ofEpochSecond(20), - block: () -> T + block: () -> T, ): T { var to = timeout if (isMultiNode) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/TransformSecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/TransformSecurityBehaviorIT.kt index 77b97efa0..6ca38067c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/TransformSecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/TransformSecurityBehaviorIT.kt @@ -15,13 +15,13 @@ import org.junit.After import org.junit.Before import org.opensearch.client.RestClient import org.opensearch.commons.rest.SecureRestClientBuilder +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.common.model.dimension.Terms import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.transform.randomTransform import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant import java.time.temporal.ChronoUnit @@ -51,7 +51,7 @@ class TransformSecurityBehaviorIT : SecurityRestTestCase() { START_TRANSFORM, DELETE_TRANSFORM, HEALTH, - GET_TRANSFORMS + GET_TRANSFORMS, ) val indexPermissions = listOf( @@ -61,7 +61,7 @@ class TransformSecurityBehaviorIT : SecurityRestTestCase() { BULK_WRITE_INDEX, GET_INDEX_MAPPING, SEARCH_INDEX, - PUT_INDEX_MAPPING + PUT_INDEX_MAPPING, ) // In this test suite case john is a "super-user" which has all relevant privileges createUser(superTransformUser, password, listOf(HELPDESK)) @@ -272,8 +272,8 @@ class TransformSecurityBehaviorIT : SecurityRestTestCase() { roles = emptyList(), pageSize = 100, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") - ) + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), + ), ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/bwc/ISMBackwardsCompatibilityIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/bwc/ISMBackwardsCompatibilityIT.kt index d2e5fbedc..687d3f227 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/bwc/ISMBackwardsCompatibilityIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/bwc/ISMBackwardsCompatibilityIT.kt @@ -22,7 +22,8 @@ class ISMBackwardsCompatibilityIT : IndexStateManagementRestTestCase() { private enum class ClusterType { OLD, MIXED, - UPGRADED; + UPGRADED, + ; companion object { fun parse(value: String): ClusterType { @@ -174,12 +175,12 @@ class ISMBackwardsCompatibilityIT : IndexStateManagementRestTestCase() { val info = getExplainManagedIndexMetaData(index).info as Map assertEquals( "Index rollover before it met the condition.", - AttemptRolloverStep.getPendingMessage(index), info["message"] + AttemptRolloverStep.getPendingMessage(index), info["message"], ) val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", - setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map @@ -202,7 +203,7 @@ class ISMBackwardsCompatibilityIT : IndexStateManagementRestTestCase() { val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", - setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map diff --git a/src/test/kotlin/org/opensearch/indexmanagement/bwc/IndexManagementBackwardsCompatibilityIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/bwc/IndexManagementBackwardsCompatibilityIT.kt index 733d52674..5fd0d5aac 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/bwc/IndexManagementBackwardsCompatibilityIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/bwc/IndexManagementBackwardsCompatibilityIT.kt @@ -9,6 +9,7 @@ import org.apache.http.entity.ContentType.APPLICATION_JSON import org.apache.http.entity.StringEntity import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.core.rest.RestStatus import org.opensearch.index.query.QueryBuilders import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_POLICY_BASE_URI @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.opensearchapi.string import org.opensearch.indexmanagement.util.NO_ID -import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.waitFor import org.opensearch.search.builder.SearchSourceBuilder @@ -83,7 +83,8 @@ class IndexManagementBackwardsCompatibilityIT : IndexManagementRestTestCase() { private enum class ClusterType { OLD, MIXED, - UPGRADED; + UPGRADED, + ; companion object { fun parse(value: String): ClusterType { @@ -123,14 +124,14 @@ class IndexManagementBackwardsCompatibilityIT : IndexManagementRestTestCase() { method = "PUT", endpoint = "$LEGACY_POLICY_BASE_URI/$POLICY_NAME?refresh=true", params = emptyMap(), - entity = StringEntity(policyString, APPLICATION_JSON) + entity = StringEntity(policyString, APPLICATION_JSON), ) val addResponse = client().makeRequest( method = "POST", endpoint = "$LEGACY_ISM_BASE_URI/add/$INDEX_NAME", params = emptyMap(), - entity = StringEntity(policyNameString, APPLICATION_JSON) + entity = StringEntity(policyNameString, APPLICATION_JSON), ) assertEquals("Create policy failed", RestStatus.CREATED, createResponse.restStatus()) @@ -150,7 +151,7 @@ class IndexManagementBackwardsCompatibilityIT : IndexManagementRestTestCase() { "GET", "$uri/$POLICY_NAME", emptyMap(), - StringEntity(search, APPLICATION_JSON) + StringEntity(search, APPLICATION_JSON), ) assertEquals("Get policy failed", RestStatus.OK, getResponse.restStatus()) } @@ -161,7 +162,7 @@ class IndexManagementBackwardsCompatibilityIT : IndexManagementRestTestCase() { val getResponse = client().makeRequest( method = "GET", endpoint = "$uri/explain/$INDEX_NAME", - params = emptyMap() + params = emptyMap(), ) assertEquals("Explain Index failed", RestStatus.OK, getResponse.restStatus()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigSecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigSecurityBehaviorIT.kt index bed2e0b9f..8e63e19dd 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigSecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/LRONConfigSecurityBehaviorIT.kt @@ -10,12 +10,12 @@ import org.junit.Before import org.opensearch.client.Request import org.opensearch.client.RestClient import org.opensearch.commons.rest.SecureRestClientBuilder +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.DELETE_LRON_CONFIG import org.opensearch.indexmanagement.GET_LRON_CONFIG import org.opensearch.indexmanagement.INDEX_LRON_CONFIG import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.SecurityRestTestCase -import org.opensearch.core.rest.RestStatus @Suppress("UNCHECKED_CAST") class LRONConfigSecurityBehaviorIT : SecurityRestTestCase() { @@ -34,7 +34,7 @@ class LRONConfigSecurityBehaviorIT : SecurityRestTestCase() { val helpdeskClusterPermissions = listOf( INDEX_LRON_CONFIG, GET_LRON_CONFIG, - DELETE_LRON_CONFIG + DELETE_LRON_CONFIG, ) // In this test suite case john is a "super-user" which has all relevant privileges @@ -42,14 +42,14 @@ class LRONConfigSecurityBehaviorIT : SecurityRestTestCase() { createAndAssignRole(HELPDESK_ROLE, helpdeskClusterPermissions, superUser) superUserClient = SecureRestClientBuilder(clusterHosts.toTypedArray(), isHttps(), superUser, password).setSocketTimeout( - 60000 + 60000, ).setConnectionRequestTimeout(180000) .build() createUser(name = testUser, pwd = password) testUserClient = SecureRestClientBuilder(clusterHosts.toTypedArray(), isHttps(), testUser, password).setSocketTimeout( - 60000 + 60000, ).setConnectionRequestTimeout(180000) .build() } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/SerializationTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/SerializationTests.kt index d8c2c6979..f5d4df756 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/SerializationTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/SerializationTests.kt @@ -9,8 +9,8 @@ import org.junit.Assert import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.indexmanagement.controlcenter.notification.action.delete.DeleteLRONConfigRequest import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigRequest -import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse +import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig import org.opensearch.indexmanagement.opensearchapi.convertToMap import org.opensearch.indexmanagement.snapshotmanagement.getRandomString import org.opensearch.test.OpenSearchTestCase @@ -25,7 +25,7 @@ class SerializationTests : OpenSearchTestCase() { Assert.assertEquals( buildMessage("lronConfig"), lronConfig, - LRONConfig(out.bytes().streamInput()) + LRONConfig(out.bytes().streamInput()), ) } @@ -36,7 +36,7 @@ class SerializationTests : OpenSearchTestCase() { Assert.assertEquals( buildMessage("deleteLronConfigRequest"), deleteLRONConfigRequest.docId, - DeleteLRONConfigRequest(out.bytes().streamInput()).docId + DeleteLRONConfigRequest(out.bytes().streamInput()).docId, ) } @@ -47,7 +47,7 @@ class SerializationTests : OpenSearchTestCase() { Assert.assertEquals( buildMessage("getLronConfigRequest"), getLRONConfigRequest.docId, - GetLRONConfigRequest(out.bytes().streamInput()).docId + GetLRONConfigRequest(out.bytes().streamInput()).docId, ) } @@ -58,7 +58,7 @@ class SerializationTests : OpenSearchTestCase() { Assert.assertEquals( buildMessage("lronConfigResponse"), lronConfigResponse.convertToMap(), - LRONConfigResponse(out.bytes().streamInput()).convertToMap() + LRONConfigResponse(out.bytes().streamInput()).convertToMap(), ) } @@ -69,12 +69,12 @@ class SerializationTests : OpenSearchTestCase() { Assert.assertEquals( buildMessage("getLRONConfigResponse"), getLRONConfigResponse.convertToMap(), - GetLRONConfigResponse(out.bytes().streamInput()).convertToMap() + GetLRONConfigResponse(out.bytes().streamInput()).convertToMap(), ) } private fun buildMessage( - itemType: String + itemType: String, ): String { return "$itemType serialization test failed. " } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/TestHelpers.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/TestHelpers.kt index b1ca9a2fb..621357d25 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/TestHelpers.kt @@ -9,26 +9,27 @@ import org.opensearch.client.RestClient import org.opensearch.common.UUIDs import org.opensearch.common.xcontent.XContentFactory import org.opensearch.commons.authuser.User +import org.opensearch.core.tasks.TaskId import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.IndexManagementPlugin +import org.opensearch.indexmanagement.common.model.notification.Channel +import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse import org.opensearch.indexmanagement.controlcenter.notification.model.LRONCondition import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig import org.opensearch.indexmanagement.controlcenter.notification.util.getDocID import org.opensearch.indexmanagement.controlcenter.notification.util.getPriority import org.opensearch.indexmanagement.controlcenter.notification.util.supportedActions -import org.opensearch.indexmanagement.common.model.notification.Channel -import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse import org.opensearch.indexmanagement.indexstatemanagement.randomChannel import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.opensearchapi.string import org.opensearch.indexmanagement.randomUser -import org.opensearch.core.tasks.TaskId import org.opensearch.test.OpenSearchTestCase.randomBoolean import org.opensearch.test.OpenSearchTestCase.randomLong import org.opensearch.test.rest.OpenSearchRestTestCase /* need to be initialized before used */ var nodeIdsInRestIT: Set = emptySet() + @Suppress("UNCHECKED_CAST") fun initNodeIdsInRestIT(client: RestClient) { if (nodeIdsInRestIT.isNotEmpty()) { @@ -45,7 +46,7 @@ fun randomLRONConfig( taskId: TaskId? = randomTaskId(), actionName: String? = randomActionName(), channels: List? = List(OpenSearchRestTestCase.randomIntBetween(1, 10)) { randomChannel() }, - user: User? = randomUser() + user: User? = randomUser(), ): LRONConfig { val priority = getPriority(taskId, actionName) return LRONConfig( @@ -54,20 +55,20 @@ fun randomLRONConfig( actionName = actionName, channels = channels, user = user, - priority = priority + priority = priority, ) } fun randomLRONCondition( success: Boolean = randomBoolean(), - failure: Boolean = randomBoolean() + failure: Boolean = randomBoolean(), ): LRONCondition { return LRONCondition(success, failure) } fun randomTaskId( nodeId: String = UUIDs.randomBase64UUID(), - id: Long = randomLong() + id: Long = randomLong(), ): TaskId { return TaskId(nodeId, id) } @@ -77,26 +78,26 @@ fun randomActionName(): String { } fun randomLRONConfigResponse( - lronConfig: LRONConfig = randomLRONConfig() + lronConfig: LRONConfig = randomLRONConfig(), ): LRONConfigResponse { val id = getDocID(lronConfig.taskId, lronConfig.actionName) return LRONConfigResponse( id = id, - lronConfig = lronConfig + lronConfig = lronConfig, ) } fun randomGetLRONConfigResponse( - size: Int = 10 + size: Int = 10, ): GetLRONConfigResponse { return GetLRONConfigResponse( lronConfigResponses = List(size) { randomLRONConfigResponse() }, - size + size, ) } fun LRONConfig.toJsonString(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): String = this.toXContent( - XContentFactory.jsonBuilder(), params + XContentFactory.jsonBuilder(), params, ).string() fun getResourceURI(taskId: TaskId?, actionName: String?): String { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/XContentTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/XContentTests.kt index 5cd779ada..417e3803e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/XContentTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/XContentTests.kt @@ -11,19 +11,19 @@ import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.tasks.TaskId import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentParser +import org.opensearch.indexmanagement.common.model.notification.Channel +import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse import org.opensearch.indexmanagement.controlcenter.notification.model.LRONCondition import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig import org.opensearch.indexmanagement.controlcenter.notification.util.PRIORITY_TASK_ID import org.opensearch.indexmanagement.controlcenter.notification.util.getDocID -import org.opensearch.indexmanagement.common.model.notification.Channel -import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.opensearchapi.string import org.opensearch.indexmanagement.randomUser -import org.opensearch.core.tasks.TaskId import org.opensearch.test.OpenSearchTestCase class XContentTests : OpenSearchTestCase() { @@ -31,7 +31,7 @@ class XContentTests : OpenSearchTestCase() { Assert.assertEquals( buildMessage("lronConfig", XContentType.JSON), sampleLRONConfig, - parsedItem(sampleLRONConfig, XContentType.JSON, LRONConfig.Companion::parse) + parsedItem(sampleLRONConfig, XContentType.JSON, LRONConfig.Companion::parse), ) val xContentType = XContentType.values().random() @@ -39,7 +39,7 @@ class XContentTests : OpenSearchTestCase() { Assert.assertEquals( buildMessage("lronConfig", xContentType), lronConfig, - parsedItem(lronConfig, xContentType, LRONConfig.Companion::parse) + parsedItem(lronConfig, xContentType, LRONConfig.Companion::parse), ) } @@ -59,7 +59,7 @@ class XContentTests : OpenSearchTestCase() { val lronConfig = XContentType.JSON.xContent().createParser( xContentRegistry(), LoggingDeprecationHandler.INSTANCE, - jsonString + jsonString, ).parseWithType(parse = LRONConfig.Companion::parse) assertEquals("action name should be null", null, lronConfig.actionName) assertEquals("should be true by default", true, lronConfig.lronCondition.success) @@ -78,7 +78,7 @@ class XContentTests : OpenSearchTestCase() { XContentType.JSON.xContent().createParser( xContentRegistry(), LoggingDeprecationHandler.INSTANCE, - jsonString + jsonString, ).parseWithType(parse = LRONConfig.Companion::parse) Assert.fail("expect to throw error when parsing lronConfig") } catch (e: IllegalArgumentException) { @@ -102,7 +102,7 @@ class XContentTests : OpenSearchTestCase() { XContentType.JSON.xContent().createParser( xContentRegistry(), LoggingDeprecationHandler.INSTANCE, - jsonString + jsonString, ).parseWithType(parse = LRONConfig.Companion::parse) Assert.fail("expect to throw error when parsing lronConfig") } catch (e: IllegalArgumentException) { @@ -120,7 +120,7 @@ class XContentTests : OpenSearchTestCase() { fun `test getLRONConfigResponse`() { val response = GetLRONConfigResponse( listOf(sampleLRONConfigResponse, sampleLRONConfigResponse), - totalNumber = 2 + totalNumber = 2, ) val responseString = response.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).string() val expectedJSON = """ @@ -138,7 +138,7 @@ class XContentTests : OpenSearchTestCase() { private fun buildMessage( itemType: String, - xContentType: XContentType + xContentType: XContentType, ): String { return "$itemType toXContent test failed. xContentType: ${xContentType.subtype()}. " } @@ -146,19 +146,19 @@ class XContentTests : OpenSearchTestCase() { private fun parsedItem( item: T, xContentType: XContentType, - parseWithTypeParser: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T + parseWithTypeParser: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T, ): T { val bytesReference = toShuffledXContent( item, xContentType.xContent().mediaType(), ToXContent.EMPTY_PARAMS, - randomBoolean() + randomBoolean(), ) val xcp = XContentHelper.createParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytesReference, - xContentType.xContent().mediaType() + xContentType.xContent().mediaType(), ) return xcp.parseWithType(parse = parseWithTypeParser) } @@ -177,11 +177,11 @@ class XContentTests : OpenSearchTestCase() { actionName = "indices:admin/resize", channels = listOf(Channel("channel123"), Channel("channel456")), user = randomUser(), - priority = PRIORITY_TASK_ID + priority = PRIORITY_TASK_ID, ) sampleLRONConfigResponse = LRONConfigResponse( id = getDocID(sampleLRONConfig.taskId, sampleLRONConfig.actionName), - lronConfig = sampleLRONConfig + lronConfig = sampleLRONConfig, ) sampleExpectedJson = """ { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilterTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilterTests.kt index 8a1a13f9d..f94fd7ac2 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilterTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/IndexOperationActionFilterTests.kt @@ -8,8 +8,6 @@ package org.opensearch.indexmanagement.controlcenter.notification.filter import org.junit.Assert import org.junit.Before import org.mockito.Mockito -import org.opensearch.core.action.ActionListener -import org.opensearch.core.action.ActionResponse import org.opensearch.action.admin.indices.forcemerge.ForceMergeAction import org.opensearch.action.admin.indices.open.OpenIndexAction import org.opensearch.action.admin.indices.shrink.ResizeAction @@ -18,11 +16,13 @@ import org.opensearch.client.Client import org.opensearch.cluster.OpenSearchAllocationTestCase import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.service.ClusterService +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse +import org.opensearch.core.tasks.TaskId import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.index.reindex.ReindexAction import org.opensearch.index.reindex.ReindexRequest import org.opensearch.tasks.Task -import org.opensearch.core.tasks.TaskId import org.opensearch.threadpool.ThreadPool class IndexOperationActionFilterTests : OpenSearchAllocationTestCase() { @@ -49,7 +49,7 @@ class IndexOperationActionFilterTests : OpenSearchAllocationTestCase() { val activeShardsObserver = ActiveShardsObserver(clusterService, client.threadPool()) filter = IndexOperationActionFilter( - this.client, clusterService, activeShardsObserver, indexNameExpressionResolver + this.client, clusterService, activeShardsObserver, indexNameExpressionResolver, ) } @@ -64,7 +64,7 @@ class IndexOperationActionFilterTests : OpenSearchAllocationTestCase() { task, ReindexAction.NAME, ReindexRequest(), - listener + listener, ) Assert.assertNotSame(listener, newListener) @@ -80,7 +80,7 @@ class IndexOperationActionFilterTests : OpenSearchAllocationTestCase() { task, "test", ReindexRequest(), - listener + listener, ) Assert.assertSame(listener, newListener) @@ -94,7 +94,7 @@ class IndexOperationActionFilterTests : OpenSearchAllocationTestCase() { task, ReindexAction.NAME, ReindexRequest(), - listener + listener, ) Assert.assertSame(listener, newListener) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt index 073d294b6..83ab81bb4 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt @@ -17,13 +17,13 @@ import org.opensearch.client.Response import org.opensearch.client.ResponseException import org.opensearch.client.RestClient import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.index.reindex.ReindexAction import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementRestTestCase import org.opensearch.indexmanagement.controlcenter.notification.util.supportedActions import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.waitFor -import org.opensearch.core.rest.RestStatus import java.net.InetAddress import java.net.InetSocketAddress import java.time.Instant @@ -46,7 +46,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { logger.info(msg) val res = client.makeRequest( "POST", "$notificationIndex/_doc?refresh=true", - StringEntity("""{"msg": "${msg.replace(System.lineSeparator(), " ")}"}""", ContentType.APPLICATION_JSON) + StringEntity("""{"msg": "${msg.replace(System.lineSeparator(), " ")}"}""", ContentType.APPLICATION_JSON), ) logger.info(res.restStatus()) @@ -92,8 +92,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) supportedActions.forEach { action -> @@ -112,8 +112,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) } } @@ -123,7 +123,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { insertSampleData("source-index", 10) val response = client.makeRequest( - "POST", "source-index/_forcemerge" + "POST", "source-index/_forcemerge", ) Assert.assertTrue(response.restStatus() == RestStatus.OK) @@ -135,7 +135,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:merge") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -155,8 +155,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) Assert.assertTrue(response.restStatus() == RestStatus.OK) @@ -168,7 +168,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:Split") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -180,7 +180,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { closeIndex("source-index") val response = client.makeRequest( - "POST", "source-index/_open" + "POST", "source-index/_open", ) Assert.assertTrue(response.restStatus() == RestStatus.OK) @@ -192,7 +192,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:Open") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -210,7 +210,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:reindex") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -237,8 +237,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) val response = client.makeRequest( @@ -254,8 +254,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) Assert.assertTrue(response.restStatus() == RestStatus.OK) @@ -278,8 +278,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) val id = policyResponse.asMap()["_id"] as String logger.info("policy id {}", id) @@ -291,7 +291,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:Reindex") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) // runtime policy been removed @@ -327,8 +327,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) waitFor(Instant.ofEpochSecond(60)) { @@ -338,7 +338,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:Reindex") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -355,7 +355,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:Close") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -369,7 +369,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { client.makeRequest("DELETE", "_plugins/_im/lron/LRON:${OpenIndexAction.NAME.replace("/", "%2F")}") val response = client.makeRequest( - "POST", "source-index/_open" + "POST", "source-index/_open", ) Assert.assertTrue(response.restStatus() == RestStatus.OK) @@ -382,7 +382,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:Open") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -396,7 +396,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { client.makeRequest("DELETE", IndexManagementPlugin.CONTROL_CENTER_INDEX) val response = client.makeRequest( - "POST", "source-index/_open" + "POST", "source-index/_open", ) Assert.assertTrue(response.restStatus() == RestStatus.OK) @@ -409,7 +409,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:Open") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } @@ -442,8 +442,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) waitFor(Instant.ofEpochSecond(60)) { @@ -453,7 +453,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { ( client.makeRequest("GET", "$notificationIndex/_search?q=msg:reindex") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) try { @@ -482,8 +482,8 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) return response } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerTests.kt index 29797757c..74d7d309e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerTests.kt @@ -8,13 +8,13 @@ package org.opensearch.indexmanagement.controlcenter.notification.filter import org.junit.Assert import org.junit.Before import org.mockito.Mockito.mock -import org.opensearch.core.action.ActionListener import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.support.ActiveShardsObserver import org.opensearch.client.Client import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.service.ClusterService +import org.opensearch.core.action.ActionListener +import org.opensearch.core.action.ActionResponse import org.opensearch.indexmanagement.controlcenter.notification.action.get.GetLRONConfigResponse import org.opensearch.indexmanagement.controlcenter.notification.model.LRONCondition import org.opensearch.indexmanagement.controlcenter.notification.randomLRONConfig @@ -50,7 +50,7 @@ class NotificationActionListenerTests : OpenSearchTestCase() { task, activeShardsObserver, request, - indexNameExpressionResolver + indexNameExpressionResolver, ) } @@ -58,7 +58,7 @@ class NotificationActionListenerTests : OpenSearchTestCase() { val lronConfig = randomLRONConfig(lronCondition = LRONCondition(false, false)) val lronConfigResponse = randomLRONConfigResponse(lronConfig = lronConfig) val responses = GetLRONConfigResponse( - lronConfigResponses = listOf(lronConfigResponse), 1 + lronConfigResponses = listOf(lronConfigResponse), 1, ) Assert.assertTrue(listener.getNotificationPolices(responses, OperationResult.COMPLETE).isEmpty()) @@ -70,12 +70,12 @@ class NotificationActionListenerTests : OpenSearchTestCase() { val lronConfigDefault = randomLRONConfig( lronCondition = LRONCondition(true, true), taskId = null, - actionName = lronConfigWithTaskId.actionName + actionName = lronConfigWithTaskId.actionName, ) val lronConfigResponseWithTaskId = randomLRONConfigResponse(lronConfig = lronConfigWithTaskId) val lronConfigResponseDefault = randomLRONConfigResponse(lronConfig = lronConfigDefault) val responses = GetLRONConfigResponse( - lronConfigResponses = listOf(lronConfigResponseWithTaskId, lronConfigResponseDefault), 2 + lronConfigResponses = listOf(lronConfigResponseWithTaskId, lronConfigResponseDefault), 2, ) Assert.assertEquals(2, listener.getNotificationPolices(responses, OperationResult.COMPLETE).size) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ForceMergeIndexRespParserTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ForceMergeIndexRespParserTests.kt index 89b61d16a..f475c6564 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ForceMergeIndexRespParserTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ForceMergeIndexRespParserTests.kt @@ -9,12 +9,12 @@ import org.junit.Assert import org.opensearch.OpenSearchException import org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest import org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse -import org.opensearch.core.action.support.DefaultShardOperationFailedException import org.opensearch.action.support.broadcast.BroadcastResponse import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.action.support.DefaultShardOperationFailedException +import org.opensearch.core.index.Index import org.opensearch.core.xcontent.DeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry -import org.opensearch.core.index.Index import org.opensearch.indexmanagement.controlcenter.notification.filter.OperationResult import org.opensearch.indexmanagement.snapshotmanagement.toJsonString @@ -23,7 +23,7 @@ class ForceMergeIndexRespParserTests : BaseRespParserTests() { fun `test build message for completion`() { val xContentParser = XContentType.JSON.xContent().createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.IGNORE_DEPRECATIONS, - "{\"_shards\":{\"total\":10,\"successful\":10,\"failed\":0}}" + "{\"_shards\":{\"total\":10,\"successful\":10,\"failed\":0}}", ) val response = ForceMergeResponse.fromXContent(xContentParser) @@ -35,14 +35,14 @@ class ForceMergeIndexRespParserTests : BaseRespParserTests() { Assert.assertEquals(title, "Force merge operation on [test-cluster/test-index-1] has completed") Assert.assertEquals( msg, - "The force merge operation on [test-cluster/test-index-1] has been completed." + "The force merge operation on [test-cluster/test-index-1] has been completed.", ) } fun `test build message for completion with multiple indexes`() { val xContentParser = XContentType.JSON.xContent().createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.IGNORE_DEPRECATIONS, - "{\"_shards\":{\"total\":10,\"successful\":10,\"failed\":0}}" + "{\"_shards\":{\"total\":10,\"successful\":10,\"failed\":0}}", ) val response = ForceMergeResponse.fromXContent(xContentParser) @@ -54,7 +54,7 @@ class ForceMergeIndexRespParserTests : BaseRespParserTests() { Assert.assertEquals(title, "Force merge operation on 2 indexes from [test-cluster] has completed") Assert.assertEquals( msg, - "[test-index-1,test-index-2] from [test-cluster] have been merged." + "[test-index-1,test-index-2] from [test-cluster] have been merged.", ) } @@ -63,12 +63,12 @@ class ForceMergeIndexRespParserTests : BaseRespParserTests() { ex.index = Index("test-index-1", "uuid-1") val resp = BroadcastResponse( 2, 1, 1, - arrayListOf(DefaultShardOperationFailedException(ex)) + arrayListOf(DefaultShardOperationFailedException(ex)), ) val xContentParser = XContentType.JSON.xContent().createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.IGNORE_DEPRECATIONS, - resp.toJsonString() + resp.toJsonString(), ) val response = ForceMergeResponse.fromXContent(xContentParser) @@ -80,7 +80,7 @@ class ForceMergeIndexRespParserTests : BaseRespParserTests() { Assert.assertEquals(ret.title, "Force merge operation on [test-cluster/test-index-1] has failed") Assert.assertEquals( ret.message, - "index [test-index-1] shard [-1] OpenSearchException[OpenSearch exception [type=exception, reason=shard is not available]]" + "index [test-index-1] shard [-1] OpenSearchException[OpenSearch exception [type=exception, reason=shard is not available]]", ) } } @@ -96,7 +96,7 @@ class ForceMergeIndexRespParserTests : BaseRespParserTests() { Assert.assertEquals(ret.title, "Force merge operation on [test-cluster/test-index-1] has failed") Assert.assertEquals( ret.message, - "index [test-index-1] index not exists." + "index [test-index-1] index not exists.", ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParserTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParserTests.kt index ddaed9112..f0e6a54e1 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParserTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ReindexRespParserTests.kt @@ -11,13 +11,13 @@ import org.opensearch.OpenSearchException import org.opensearch.action.bulk.BulkItemResponse import org.opensearch.common.unit.TimeValue import org.opensearch.core.index.Index +import org.opensearch.core.tasks.TaskId import org.opensearch.index.reindex.BulkByScrollResponse import org.opensearch.index.reindex.BulkByScrollTask import org.opensearch.index.reindex.ReindexAction import org.opensearch.index.reindex.ReindexRequest import org.opensearch.indexmanagement.controlcenter.notification.filter.OperationResult import org.opensearch.tasks.Task -import org.opensearch.core.tasks.TaskId import java.lang.Exception import java.util.concurrent.TimeUnit @@ -52,9 +52,9 @@ class ReindexRespParserTests : BaseRespParserTests() { TimeValue(0, TimeUnit.SECONDS), 0.0f, "", - TimeValue(0, TimeUnit.SECONDS) + TimeValue(0, TimeUnit.SECONDS), ), - listOf(), listOf(), false + listOf(), listOf(), false, ) val parser = ReindexRespParser(task, request, clusterService) @@ -64,7 +64,7 @@ class ReindexRespParserTests : BaseRespParserTests() { "The reindex operation from [test-cluster/source] to [test-cluster/dest] has been completed.\n" + "\n" + "*Summary (number of documents)* \n" + - "Total: 100, Created: 100, Updated: 0, Deleted: 0, Conflicts: 0" + "Total: 100, Created: 100, Updated: 0, Deleted: 0, Conflicts: 0", ) val title = parser.buildNotificationTitle(OperationResult.COMPLETE) @@ -88,9 +88,9 @@ class ReindexRespParserTests : BaseRespParserTests() { TimeValue(0, TimeUnit.SECONDS), 0.0f, "user cancelled", - TimeValue(0, TimeUnit.SECONDS) + TimeValue(0, TimeUnit.SECONDS), ), - listOf(), listOf(), false + listOf(), listOf(), false, ) val parser = ReindexRespParser(task, request, clusterService) @@ -100,7 +100,7 @@ class ReindexRespParserTests : BaseRespParserTests() { "The reindex operation from [test-cluster/source] to [test-cluster/dest] has been cancelled by user's request\n" + "\n" + "*Summary (number of documents)* \n" + - "Total: 100, Created: 20, Updated: 0, Deleted: 0, Conflicts: 0" + "Total: 100, Created: 20, Updated: 0, Deleted: 0, Conflicts: 0", ) val title = parser.buildNotificationTitle(OperationResult.CANCELLED) @@ -125,10 +125,10 @@ class ReindexRespParserTests : BaseRespParserTests() { 0.0f, "", TimeValue( - 0, TimeUnit.SECONDS - ) + 0, TimeUnit.SECONDS, + ), ), - listOf(BulkItemResponse.Failure("dest", "id-1", Exception("version conflicts"))), listOf(), false + listOf(BulkItemResponse.Failure("dest", "id-1", Exception("version conflicts"))), listOf(), false, ) val parser = ReindexRespParser(task, request, clusterService) @@ -142,7 +142,7 @@ class ReindexRespParserTests : BaseRespParserTests() { "To see full errors, use `GET /_tasks/mJzoy8SBuTW12rbV8jSg:1`\n" + "\n" + "*Summary (number of documents)* \n" + - "Total: 100, Created: 99, Updated: 0, Deleted: 0, Conflicts: 1" + "Total: 100, Created: 99, Updated: 0, Deleted: 0, Conflicts: 1", ) val title = parser.buildNotificationTitle(OperationResult.FAILED) @@ -159,7 +159,7 @@ class ReindexRespParserTests : BaseRespParserTests() { Assert.assertEquals(ret.title, "Reindex operation on [test-cluster/source] has failed") Assert.assertEquals( ret.message, - "The reindex operation from [test-cluster/source] to [test-cluster/dest] has failed. index doest not exists" + "The reindex operation from [test-cluster/source] to [test-cluster/dest] has failed. index doest not exists", ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParserTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParserTests.kt index 4456c695d..5856f4ee4 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParserTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/parser/ResizeIndexRespParserTests.kt @@ -75,7 +75,7 @@ class ResizeIndexRespParserTests : BaseRespParserTests() { Mockito.eq(ActiveShardCount.DEFAULT), eq(TimeValue.timeValueMinutes(50)), any(), - any() + any(), ) } fun `test source index not exist exception`() { @@ -117,7 +117,7 @@ class ResizeIndexRespParserTests : BaseRespParserTests() { "You must allocate a copy of every shard of the source index to the same node before split. To allocate it to same node, try use PUT /source_index/_settings\n" + "{\n" + "\"index.routing.allocation.require._name\":\"your_node_name\"\n" + - "}" + "}", ) Assert.assertEquals(ret.title, "Split operation on [test-cluster/source_index] has failed") } @@ -132,7 +132,7 @@ class ResizeIndexRespParserTests : BaseRespParserTests() { parser.parseAndSendNotification(response) { ret -> Assert.assertEquals( ret.message, - "The shrink operation from [test-cluster/source] to [test-cluster/target] has taken more than 4h to complete. To see the latest status, use `GET /target/_recovery`" + "The shrink operation from [test-cluster/source] to [test-cluster/target] has taken more than 4h to complete. To see the latest status, use `GET /target/_recovery`", ) Assert.assertEquals(ret.title, "Shrink operation on [test-cluster/source] has timed out") } @@ -163,7 +163,7 @@ class ResizeIndexRespParserTests : BaseRespParserTests() { val msg = parser.buildNotificationMessage(response, ResourceAlreadyExistsException(Index("target-index", "uuid"))) Assert.assertEquals( msg, - "The target index [test-cluster/target-index] already exists." + "The target index [test-cluster/target-index] already exists.", ) val title = parser.buildNotificationTitle(OperationResult.FAILED) @@ -179,7 +179,7 @@ class ResizeIndexRespParserTests : BaseRespParserTests() { val msg = parser.buildNotificationMessage(response, isTimeout = true) Assert.assertEquals( msg, - "The split operation from [test-cluster/source] to [test-cluster/target] has taken more than 1h to complete. To see the latest status, use `GET /target/_recovery`" + "The split operation from [test-cluster/source] to [test-cluster/target] has taken more than 1h to complete. To see the latest status, use `GET /target/_recovery`", ) val title = parser.buildNotificationTitle(OperationResult.TIMEOUT) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt index 7b5012541..731d61ac7 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt @@ -13,13 +13,13 @@ import org.junit.AfterClass import org.junit.Before import org.opensearch.client.Response import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementRestTestCase import org.opensearch.indexmanagement.controlcenter.notification.initNodeIdsInRestIT import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig import org.opensearch.indexmanagement.controlcenter.notification.toJsonString import org.opensearch.indexmanagement.makeRequest -import org.opensearch.core.rest.RestStatus abstract class LRONConfigRestTestCase : IndexManagementRestTestCase() { @Before @@ -35,7 +35,7 @@ abstract class LRONConfigRestTestCase : IndexManagementRestTestCase() { "POST", "${IndexManagementPlugin.CONTROL_CENTER_INDEX}/_delete_by_query", mapOf("refresh" to "true"), - StringEntity("""{"query": {"match_all": {}}}""", ContentType.APPLICATION_JSON) + StringEntity("""{"query": {"match_all": {}}}""", ContentType.APPLICATION_JSON), ) } catch (e: ResponseException) { logger.info(e.response.asMap()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigActionIT.kt index e603ea886..32f82330f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestDeleteLRONConfigActionIT.kt @@ -7,13 +7,13 @@ package org.opensearch.indexmanagement.controlcenter.notification.resthandler import org.junit.Assert import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.controlcenter.notification.getResourceURI import org.opensearch.indexmanagement.controlcenter.notification.nodeIdsInRestIT import org.opensearch.indexmanagement.controlcenter.notification.randomLRONConfig import org.opensearch.indexmanagement.controlcenter.notification.randomTaskId import org.opensearch.indexmanagement.controlcenter.notification.util.getDocID import org.opensearch.indexmanagement.makeRequest -import org.opensearch.core.rest.RestStatus @Suppress("UNCHECKED_CAST") class RestDeleteLRONConfigActionIT : LRONConfigRestTestCase() { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigActionIT.kt index c2193a7b9..7b7444d9a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestGetLRONConfigActionIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.controlcenter.notification.resthandler import org.junit.Assert import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.controlcenter.notification.getResourceURI import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig @@ -16,7 +17,6 @@ import org.opensearch.indexmanagement.controlcenter.notification.randomTaskId import org.opensearch.indexmanagement.controlcenter.notification.util.getDocID import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.opensearchapi.convertToMap -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase @Suppress("UNCHECKED_CAST") @@ -34,7 +34,7 @@ class RestGetLRONConfigActionIT : LRONConfigRestTestCase() { Assert.assertEquals( "not same LRONConfig", lronConfigMap.filterKeys { it != LRONConfig.USER_FIELD && it != LRONConfig.PRIORITY_FIELD }, - responseBody["lron_config"] as Map + responseBody["lron_config"] as Map, ) } @@ -71,7 +71,7 @@ class RestGetLRONConfigActionIT : LRONConfigRestTestCase() { assertEquals( "different lronConfigResponse", lronConfigResponse[LRONConfig.LRON_CONFIG_FIELD], - resLRONConfigResponse!![LRONConfig.LRON_CONFIG_FIELD] + resLRONConfigResponse!![LRONConfig.LRON_CONFIG_FIELD], ) } } @@ -82,7 +82,7 @@ class RestGetLRONConfigActionIT : LRONConfigRestTestCase() { client().makeRequest( "GET", getResourceURI(lronConfig.taskId, lronConfig.actionName), - mapOf("size" to "10") + mapOf("size" to "10"), ) Assert.fail("Expected 400 BAD_REQUEST") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt index 00ecd594a..471216c47 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.runBlocking import org.junit.Assert import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.controlcenter.notification.getResourceURI import org.opensearch.indexmanagement.controlcenter.notification.model.LRONConfig @@ -24,7 +25,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.randomChannel import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.opensearchapi.convertToMap import org.opensearch.indexmanagement.util.DRY_RUN -import org.opensearch.core.rest.RestStatus import java.util.concurrent.Executors @Suppress("UNCHECKED_CAST") @@ -40,7 +40,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { Assert.assertEquals( "not same LRONConfig", lronConfigMap.filterKeys { it != LRONConfig.USER_FIELD && it != LRONConfig.PRIORITY_FIELD }, - responseBody["lron_config"] as Map + responseBody["lron_config"] as Map, ) } @@ -51,7 +51,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { "POST", getResourceURI(lronConfig.taskId, lronConfig.actionName), emptyMap(), - lronConfig.toHttpEntity() + lronConfig.toHttpEntity(), ) fail("Expected 405 METHOD_NOT_ALLOWED") } catch (e: ResponseException) { @@ -80,14 +80,14 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { actionName = lronConfig.actionName, channels = List(10) { randomChannel() }, user = null, - priority = null + priority = null, ) val response = client().makeRequest( "PUT", getResourceURI(lronConfig.taskId, lronConfig.actionName), emptyMap(), - newLRONConfig.toHttpEntity() + newLRONConfig.toHttpEntity(), ) assertEquals("update LRONConfig failed", RestStatus.OK, response.restStatus()) @@ -98,7 +98,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { Assert.assertEquals( "not same LRONConfig", newLRONConfigMap.filterKeys { it != LRONConfig.USER_FIELD && it != LRONConfig.PRIORITY_FIELD }, - responseBody["lron_config"] as Map + responseBody["lron_config"] as Map, ) } @@ -108,7 +108,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { "PUT", getResourceURI(lronConfig.taskId, lronConfig.actionName), emptyMap(), - lronConfig.toHttpEntity() + lronConfig.toHttpEntity(), ) assertEquals("autocreate LRONConfig failed", RestStatus.OK, response.restStatus()) val responseBody = response.asMap() @@ -116,7 +116,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { Assert.assertEquals( "not same LRONConfig", lronConfigMap.filterKeys { it != LRONConfig.USER_FIELD && it != LRONConfig.PRIORITY_FIELD }, - responseBody["lron_config"] as Map + responseBody["lron_config"] as Map, ) } @@ -127,7 +127,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { "PUT", IndexManagementPlugin.LRON_BASE_URI, emptyMap(), - lronConfig.toHttpEntity() + lronConfig.toHttpEntity(), ) fail("Expected 405 METHOD_NOT_ALLOWED") } catch (e: ResponseException) { @@ -142,13 +142,13 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { "POST", IndexManagementPlugin.LRON_BASE_URI, mapOf(DRY_RUN to "true"), - lronConfig.toHttpEntity() + lronConfig.toHttpEntity(), ) client().makeRequest( "PUT", getResourceURI(lronConfig.taskId, lronConfig.actionName), mapOf(DRY_RUN to "true"), - lronConfig.toHttpEntity() + lronConfig.toHttpEntity(), ) try { client().makeRequest("GET", getResourceURI(lronConfig.taskId, lronConfig.actionName)) @@ -168,7 +168,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { response = client().makeRequest( "PUT", getResourceURI(lronConfig.taskId, lronConfig.actionName), - lronConfig.toHttpEntity() + lronConfig.toHttpEntity(), ) assertEquals("Create LRONConfig failed", RestStatus.OK, response.restStatus()) } @@ -184,7 +184,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { val expected = createParser( XContentType.JSON.xContent(), javaClass.classLoader.getResource("mappings/opensearch-control-center.json")!! - .readText() + .readText(), ) val expectedMap = expected.map() diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtilsTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtilsTests.kt index 527cf2401..b89837591 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtilsTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/util/LRONUtilsTests.kt @@ -6,10 +6,10 @@ package org.opensearch.indexmanagement.controlcenter.notification.util import org.junit.Assert +import org.opensearch.core.tasks.TaskId import org.opensearch.index.reindex.ReindexAction import org.opensearch.indexmanagement.controlcenter.notification.randomActionName import org.opensearch.indexmanagement.controlcenter.notification.randomTaskId -import org.opensearch.core.tasks.TaskId import org.opensearch.test.OpenSearchTestCase import kotlin.IllegalArgumentException diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProviderTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProviderTests.kt index 757eff33f..e2aa0b3ef 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProviderTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexMetadataProviderTests.kt @@ -42,8 +42,8 @@ class IndexMetadataProviderTests : OpenSearchTestCase() { "Should not manage index management config index", indexEvaluator.isUnManageableIndex( IndexManagementPlugin - .INDEX_MANAGEMENT_INDEX - ) + .INDEX_MANAGEMENT_INDEX, + ), ) assertTrue("Should not manage kibana index", indexEvaluator.isUnManageableIndex(".kibana_1242142_user")) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementIntegTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementIntegTestCase.kt index 054831be1..7aa4ecb51 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementIntegTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementIntegTestCase.kt @@ -11,23 +11,24 @@ import org.junit.After import org.junit.Before import org.opensearch.OpenSearchParseException import org.opensearch.action.ActionRequest -import org.opensearch.core.action.ActionResponse import org.opensearch.action.admin.cluster.reroute.ClusterRerouteRequest import org.opensearch.action.search.SearchResponse import org.opensearch.client.Request import org.opensearch.client.Response import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand -import org.opensearch.core.common.Strings import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.DeprecationHandler import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.core.xcontent.XContentParser -import org.opensearch.core.xcontent.XContentParserUtils import org.opensearch.common.xcontent.XContentType import org.opensearch.common.xcontent.json.JsonXContent +import org.opensearch.core.action.ActionResponse +import org.opensearch.core.common.Strings +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.DeprecationHandler +import org.opensearch.core.xcontent.NamedXContentRegistry +import org.opensearch.core.xcontent.XContentParser +import org.opensearch.core.xcontent.XContentParserUtils import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementRestTestCase.Companion.wipeAllIndices import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig @@ -49,7 +50,6 @@ import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule import org.opensearch.plugins.ActionPlugin import org.opensearch.plugins.Plugin import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchIntegTestCase import org.opensearch.test.rest.OpenSearchRestTestCase.entityAsMap import java.io.IOException @@ -85,7 +85,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { actionMetaData = null, stepMetaData = null, policyRetryInfo = PolicyRetryInfoMetaData(false, 0), - info = mapOf("message" to "Happy moving") + info = mapOf("message" to "Happy moving"), ) override fun nodePlugins(): Collection> { @@ -97,9 +97,9 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { return listOf( ActionPlugin.ActionHandler( UpdateManagedIndexMetaDataAction.INSTANCE, - TransportUpdateManagedIndexMetaDataAction::class.java + TransportUpdateManagedIndexMetaDataAction::class.java, ), - ActionPlugin.ActionHandler(ExplainAction.INSTANCE, TransportExplainAction::class.java) + ActionPlugin.ActionHandler(ExplainAction.INSTANCE, TransportExplainAction::class.java), ) } } @@ -120,7 +120,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { fun createPolicy( policy: Policy, policyId: String = randomAlphaOfLength(10), - refresh: Boolean = true + refresh: Boolean = true, ): Policy { val response = createPolicyJson(policy.toJsonString(), policyId, refresh) @@ -128,28 +128,28 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { .createParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - response.entity.content + response.entity.content, ).map() val createdId = policyJson["_id"] as String assertEquals("policy ids are not the same", policyId, createdId) return policy.copy( id = createdId, seqNo = (policyJson["_seq_no"] as Int).toLong(), - primaryTerm = (policyJson["_primary_term"] as Int).toLong() + primaryTerm = (policyJson["_primary_term"] as Int).toLong(), ) } protected fun createPolicyJson( policyString: String, policyId: String, - refresh: Boolean = true + refresh: Boolean = true, ): Response { val response = getRestClient() .makeRequest( "PUT", "${IndexManagementPlugin.POLICY_BASE_URI}/$policyId?refresh=$refresh", emptyMap(), - StringEntity(policyString, ContentType.APPLICATION_JSON) + StringEntity(policyString, ContentType.APPLICATION_JSON), ) assertEquals("Unable to create a new policy", RestStatus.CREATED, response.restStatus()) return response @@ -159,7 +159,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { protected fun addPolicyToIndex( index: String, - policyID: String + policyID: String, ) { val body = """ { @@ -192,7 +192,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { """.trimIndent() val response = getRestClient().makeRequest( "POST", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_search", emptyMap(), - StringEntity(request, ContentType.APPLICATION_JSON) + StringEntity(request, ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val searchResponse = @@ -214,8 +214,8 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { StringEntity( "{\"doc\":{\"managed_index\":{\"schedule\":{\"interval\":{\"start_time\":" + "\"$startTimeMillis\"}}}}}", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -228,8 +228,8 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { "POST", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_update/${update.id}", StringEntity( "{\"doc\":{\"managed_index\": $policyJsonString }}", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -238,8 +238,8 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { "POST", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_update/${update.id}", StringEntity( "{\"doc\":{\"managed_index\": {\"policy_seq_no\": \"0\", \"policy_primary_term\": \"1\"} }}", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -260,7 +260,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { return XContentHelper.convertToMap( XContentType.JSON.xContent(), `is`, - true + true, ) } } @@ -272,7 +272,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { val response = getRestClient().makeRequest( RestRequest.Method.GET.toString(), - "${RestExplainAction.EXPLAIN_BASE_URI}/$indexName" + "${RestExplainAction.EXPLAIN_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) @@ -281,13 +281,16 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { XContentParserUtils.ensureExpectedToken( XContentParser.Token.START_OBJECT, xcp.nextToken(), - xcp + xcp, ) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { xcp.currentName() xcp.nextToken() - if (xcp.currentName() == TOTAL_MANAGED_INDICES) xcp.intValue() - else metadata = ManagedIndexMetaData.parse(xcp) + if (xcp.currentName() == TOTAL_MANAGED_INDICES) { + xcp.intValue() + } else { + metadata = ManagedIndexMetaData.parse(xcp) + } } return metadata } @@ -315,7 +318,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - response.entity.content + response.entity.content, ) .use { parser -> parser.list() } } catch (e: IOException) { @@ -350,7 +353,7 @@ abstract class IndexStateManagementIntegTestCase : OpenSearchIntegTestCase() { """.trimIndent() val res = getRestClient().makeRequest( "PUT", "_cluster/settings", emptyMap(), - StringEntity(request, ContentType.APPLICATION_JSON) + StringEntity(request, ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, res.restStatus()) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt index ab8e772a2..ac53cfbf3 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt @@ -23,13 +23,14 @@ import org.opensearch.cluster.ClusterModule import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.common.settings.Settings import org.opensearch.common.unit.TimeValue -import org.opensearch.core.xcontent.DeprecationHandler import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType +import org.opensearch.common.xcontent.json.JsonXContent.jsonXContent +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.DeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.common.xcontent.XContentType -import org.opensearch.common.xcontent.json.JsonXContent.jsonXContent import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin @@ -38,7 +39,13 @@ import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_STAT import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ISM_BASE_URI import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.POLICY_BASE_URI import org.opensearch.indexmanagement.IndexManagementRestTestCase +import org.opensearch.indexmanagement.indexstatemanagement.model.ChangePolicy +import org.opensearch.indexmanagement.indexstatemanagement.model.ExplainFilter +import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate +import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig +import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.model.Policy.Companion.POLICY_TYPE +import org.opensearch.indexmanagement.indexstatemanagement.model.StateFilter import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestExplainAction import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.util.FAILED_INDICES @@ -50,6 +57,7 @@ import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.rollup.model.RollupMetadata +import org.opensearch.indexmanagement.rollup.randomTermQuery import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.PolicyRetryInfoMetaData @@ -65,14 +73,6 @@ import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule import org.opensearch.rest.RestRequest import org.opensearch.search.SearchModule -import org.opensearch.core.rest.RestStatus -import org.opensearch.indexmanagement.indexstatemanagement.model.ChangePolicy -import org.opensearch.indexmanagement.indexstatemanagement.model.ExplainFilter -import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate -import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig -import org.opensearch.indexmanagement.indexstatemanagement.model.Policy -import org.opensearch.indexmanagement.indexstatemanagement.model.StateFilter -import org.opensearch.indexmanagement.rollup.randomTermQuery import org.opensearch.test.OpenSearchTestCase import java.io.IOException import java.time.Duration @@ -107,7 +107,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() policy: Policy, policyId: String = OpenSearchTestCase.randomAlphaOfLength(10), refresh: Boolean = true, - userClient: RestClient? = null + userClient: RestClient? = null, ): Policy { val response = createPolicyJson(policy.toJsonString(), policyId, refresh, userClient) @@ -115,14 +115,14 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() .createParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - response.entity.content + response.entity.content, ).map() val createdId = policyJson["_id"] as String assertEquals("policy ids are not the same", policyId, createdId) return policy.copy( id = createdId, seqNo = (policyJson["_seq_no"] as Int).toLong(), - primaryTerm = (policyJson["_primary_term"] as Int).toLong() + primaryTerm = (policyJson["_primary_term"] as Int).toLong(), ) } @@ -130,7 +130,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() policyString: String, policyId: String, refresh: Boolean = true, - userClient: RestClient? = null + userClient: RestClient? = null, ): Response { val client = userClient ?: client() val response = client @@ -138,7 +138,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() "PUT", "$POLICY_BASE_URI/$policyId?refresh=$refresh", emptyMap(), - StringEntity(policyString, APPLICATION_JSON) + StringEntity(policyString, APPLICATION_JSON), ) assertEquals("Unable to create a new policy", RestStatus.CREATED, response.restStatus()) return response @@ -152,7 +152,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun getPolicy( policyId: String, - header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ): Policy { val response = client().makeRequest("GET", "$POLICY_BASE_URI/$policyId", null, header) assertEquals("Unable to get policy $policyId", RestStatus.OK, response.restStatus()) @@ -217,7 +217,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun createDataStream( dataStream: String, - template: StringEntity? = null + template: StringEntity? = null, ) { val dataStreamTemplate = template ?: StringEntity( """ @@ -226,12 +226,12 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() "index_patterns": ["$dataStream"] } """.trimIndent(), - APPLICATION_JSON + APPLICATION_JSON, ) val res = client().makeRequest( "PUT", "/_index_template/transform-data-stream-template", - dataStreamTemplate + dataStreamTemplate, ) assertEquals("Unexpected RestStatus", RestStatus.OK, res.restStatus()) val response = client().makeRequest("PUT", "/_data_stream/$dataStream") @@ -247,16 +247,20 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() searchRouting: Int = randomInt(), indexRouting: Int = randomInt(), filter: String = randomTermQuery().toString(), - isHidden: Boolean = randomBoolean() + isHidden: Boolean = randomBoolean(), ) { val isWriteIndexField = if (isWriteIndex) "\",\"is_write_index\": \"$isWriteIndex" else "" - val params = if (action == "add" && routing != null) """ + val params = if (action == "add" && routing != null) { + """ ,"routing": $routing, "search_routing": $searchRouting, "index_routing": $indexRouting, "filter": $filter, "is_hidden": $isHidden - """.trimIndent() else "" + """.trimIndent() + } else { + "" + } val body = """ { "actions": [ @@ -281,7 +285,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun addPolicyToIndex( index: String, - policyID: String + policyID: String, ) { val body = """ { @@ -312,7 +316,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() """.trimIndent() val res = client().makeRequest( "PUT", "_cluster/settings", emptyMap(), - StringEntity(request, APPLICATION_JSON) + StringEntity(request, APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, res.restStatus()) } @@ -328,7 +332,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun updateIndexSetting( index: String, key: String, - value: String + value: String, ) { val body = """ { @@ -337,14 +341,14 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() """.trimIndent() val res = client().makeRequest( "PUT", "$index/_settings", emptyMap(), - StringEntity(body, APPLICATION_JSON) + StringEntity(body, APPLICATION_JSON), ) assertEquals("Update index setting failed", RestStatus.OK, res.restStatus()) } protected fun getIndexSetting(index: String) { val res = client().makeRequest( - "GET", "$index/_settings", emptyMap() + "GET", "$index/_settings", emptyMap(), ) assertEquals("Update index setting failed", RestStatus.OK, res.restStatus()) } @@ -362,7 +366,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() """.trimIndent() val response = client().makeRequest( "POST", "$INDEX_MANAGEMENT_INDEX/_search", emptyMap(), - StringEntity(request, APPLICATION_JSON) + StringEntity(request, APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val searchResponse = SearchResponse.fromXContent(createParser(jsonXContent, response.entity.content)) @@ -402,7 +406,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() """.trimIndent() val response = client().makeRequest( "POST", "${IndexManagementIndices.HISTORY_ALL}/_search", emptyMap(), - StringEntity(request, APPLICATION_JSON) + StringEntity(request, APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) return SearchResponse.fromXContent(createParser(jsonXContent, response.entity.content)) @@ -434,7 +438,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() client().makeRequest( "GET", "_cluster/allocation/explain", - StringEntity("{ \"index\": \"$INDEX_MANAGEMENT_INDEX\" }", APPLICATION_JSON) + StringEntity("{ \"index\": \"$INDEX_MANAGEMENT_INDEX\" }", APPLICATION_JSON), ) fail("Expected 400 Bad Request when there are no unassigned shards to explain") } catch (e: ResponseException) { @@ -452,8 +456,8 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() StringEntity( "{\"doc\":{\"managed_index\":{\"schedule\":{\"interval\":{\"start_time\":" + "\"$startTimeMillis\"}}}}}", - APPLICATION_JSON - ) + APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -464,8 +468,8 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.id}", StringEntity( "{\"doc\":{\"managed_index\":{\"policy_seq_no\":\"${update.policySeqNo}\"}}}", - APPLICATION_JSON - ) + APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } @@ -634,7 +638,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() .makeRequest( "GET", "_cat/nodes?format=json", - emptyMap() + emptyMap(), ) assertEquals("Unable to get nodes", RestStatus.OK, response.restStatus()) try { @@ -711,21 +715,21 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() val response = client().performRequest( Request( "POST", - "/$alias/_rollover" - ) + "/$alias/_rollover", + ), ) assertEquals(response.statusLine.statusCode, RestStatus.OK.status) } protected fun createRepository( - repository: String + repository: String, ) { val response = client() .makeRequest( "PUT", "_snapshot/$repository", emptyMap(), - StringEntity("{\"type\":\"fs\", \"settings\": {\"location\": \"$repository\"}}", APPLICATION_JSON) + StringEntity("{\"type\":\"fs\", \"settings\": {\"location\": \"$repository\"}}", APPLICATION_JSON), ) assertEquals("Unable to create a new repository", RestStatus.OK, response.restStatus()) } @@ -735,7 +739,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() .makeRequest( "GET", "_cat/shards/$target?format=json", - emptyMap() + emptyMap(), ) assertEquals("Unable to get allocation info", RestStatus.OK, response.restStatus()) try { @@ -752,7 +756,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() .makeRequest( "GET", "_cat/$endpoint", - emptyMap() + emptyMap(), ) assertEquals("Unable to get cat info", RestStatus.OK, response.restStatus()) try { @@ -781,7 +785,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() .makeRequest( "GET", "_cat/snapshots/$repository?format=json", - emptyMap() + emptyMap(), ) assertEquals("Unable to get a snapshot", RestStatus.OK, response.restStatus()) try { @@ -795,7 +799,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun getRollup( rollupId: String, - header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ): Rollup { val response = client().makeRequest("GET", "${IndexManagementPlugin.ROLLUP_JOBS_BASE_URI}/$rollupId", null, header) assertEquals("Unable to get rollup $rollupId", RestStatus.OK, response.restStatus()) @@ -823,7 +827,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun getRollupMetadata( metadataId: String, - header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ): RollupMetadata { val response = client().makeRequest("GET", "$INDEX_MANAGEMENT_INDEX/_doc/$metadataId", null, header) assertEquals("Unable to get rollup metadata $metadataId", RestStatus.OK, response.restStatus()) @@ -852,7 +856,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun getTransform( transformId: String, - header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ): Transform { val response = client().makeRequest("GET", "${IndexManagementPlugin.TRANSFORM_BASE_URI}/$transformId", null, header) assertEquals("Unable to get transform $transformId", RestStatus.OK, response.restStatus()) @@ -880,7 +884,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun getTransformMetadata( metadataId: String, - header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ): TransformMetadata { val response = client().makeRequest("GET", "$INDEX_MANAGEMENT_INDEX/_doc/$metadataId", null, header) assertEquals("Unable to get transform metadata $metadataId", RestStatus.OK, response.restStatus()) @@ -915,13 +919,13 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() @Suppress("UNCHECKED_CAST") protected fun assertSnapshotExists( repository: String, - snapshot: String + snapshot: String, ) = require(getSnapshotsList(repository).any { element -> (element as Map)["id"]!!.startsWith(snapshot) }) { "No snapshot found with id: $snapshot" } @Suppress("UNCHECKED_CAST") protected fun assertSnapshotFinishedWithSuccess( repository: String, - snapshot: String + snapshot: String, ) = require(getSnapshotsList(repository).any { element -> (element as Map)["id"]!!.startsWith(snapshot) && "SUCCESS" == element["status"] }) { "Snapshot didn't finish with success." } /** @@ -980,7 +984,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() protected fun assertPredicatesOnMetaData( indexPredicates: List Boolean>>>>, response: Map, - strict: Boolean = true + strict: Boolean = true, ) { indexPredicates.forEach { (index, predicates) -> assertTrue("The index: $index was not found in the response: $response", response.containsKey(index)) @@ -1037,7 +1041,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() @Suppress("UNCHECKED_CAST") protected fun assertPredicatesOnISMTemplatesMap( templatePredicates: List Boolean>>>>, // response map name: predicate - response: Map + response: Map, ) { val templates = response["ism_templates"] as ArrayList> @@ -1078,8 +1082,8 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() " }, \n" + " \"order\": $order\n" + "}", - APPLICATION_JSON - ) + APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } @@ -1092,8 +1096,8 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() " \"index_patterns\": [\"$indexPatterns\"],\n" + " \"order\": $order\n" + "}", - APPLICATION_JSON - ) + APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } @@ -1115,8 +1119,8 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() " }\n" + " }\n" + "}", - APPLICATION_JSON - ) + APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } @@ -1137,7 +1141,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - response.entity.content + response.entity.content, ) .use { parser -> parser.list() } } catch (e: IOException) { @@ -1149,8 +1153,8 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() return NamedXContentRegistry( listOf( ClusterModule.getNamedXWriteables(), - SearchModule(Settings.EMPTY, emptyList()).namedXContents - ).flatten() + SearchModule(Settings.EMPTY, emptyList()).namedXContents, + ).flatten(), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt index d911f6d4c..fa19739a6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt @@ -6,8 +6,8 @@ package org.opensearch.indexmanagement.indexstatemanagement import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.XContentParser import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.xcontent.XContentParser import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.test.OpenSearchTestCase @@ -16,7 +16,6 @@ import kotlin.test.assertFailsWith class ManagedIndexConfigTests : OpenSearchTestCase() { fun `test managed index config parsing`() { - val missingIndexUuid = """{"managed_index":{"name":"edpNNwdVXG","enabled":false,"index":"DcdVHfmQUI","schedule":{"interval":{"start_time":1560402722674,"period":5,"unit":"Minutes"}},"last_updated_time":1560402722676,"enabled_time":null,"policy_id":"KumaJGCWPi","policy_seq_no":5,"policy_primary_term":17,"policy":{"name":"KumaJGCWPi","last_updated_time":1560402722676,"schema_version":348392,"error_notification":null,"default_state":"EpbLVqVhtL","states":[{"name":"EpbLVqVhtL","action":[],"transitions":[]},{"name":"IIJxQdcenu","action":[],"transitions":[]},{"name":"zSXlbLUBqG","action":[],"transitions":[]},{"name":"nYRPBojBiy","action":[],"transitions":[]}]},"change_policy":{"policy_id":"BtrDpcCBeT","state":"obxAkRuhvq"}}}""" val missingIndex = """{"managed_index":{"name":"edpNNwdVXG","enabled":false,"index_uuid":"SdcNvtdyAZYyrVkFMoQr","schedule":{"interval":{"start_time":1560402722674,"period":5,"unit":"Minutes"}},"last_updated_time":1560402722676,"enabled_time":null,"policy_id":"KumaJGCWPi","policy_seq_no":5,"policy_primary_term":17,"policy":{"name":"KumaJGCWPi","last_updated_time":1560402722676,"schema_version":348392,"error_notification":null,"default_state":"EpbLVqVhtL","states":[{"name":"EpbLVqVhtL","action":[],"transitions":[]},{"name":"IIJxQdcenu","action":[],"transitions":[]},{"name":"zSXlbLUBqG","action":[],"transitions":[]},{"name":"nYRPBojBiy","action":[],"transitions":[]}]},"change_policy":{"policy_id":"BtrDpcCBeT","state":"obxAkRuhvq"}}}""" val missingName = """{"managed_index":{"enabled":false,"index":"DcdVHfmQUI","index_uuid":"SdcNvtdyAZYyrVkFMoQr","schedule":{"interval":{"start_time":1560402722674,"period":5,"unit":"Minutes"}},"last_updated_time":1560402722676,"enabled_time":null,"policy_id":"KumaJGCWPi","policy_seq_no":5,"policy_primary_term":17,"policy":{"name":"KumaJGCWPi","last_updated_time":1560402722676,"schema_version":348392,"error_notification":null,"default_state":"EpbLVqVhtL","states":[{"name":"EpbLVqVhtL","action":[],"transitions":[]},{"name":"IIJxQdcenu","action":[],"transitions":[]},{"name":"zSXlbLUBqG","action":[],"transitions":[]},{"name":"nYRPBojBiy","action":[],"transitions":[]}]},"change_policy":{"policy_id":"BtrDpcCBeT","state":"obxAkRuhvq"}}}""" diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataRegressionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataRegressionIT.kt index b9594c474..5167cb17b 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataRegressionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataRegressionIT.kt @@ -60,7 +60,7 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -74,15 +74,15 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { metadataToClusterState = metadataToClusterState.copy( index = indexName, indexUuid = indexMetadata.indexUUID, - policyID = policyID + policyID = policyID, ) val request = UpdateManagedIndexMetaDataRequest( indicesToAddManagedIndexMetaDataTo = listOf( - Pair(Index(metadataToClusterState.index, metadataToClusterState.indexUuid), metadataToClusterState) - ) + Pair(Index(metadataToClusterState.index, metadataToClusterState.indexUuid), metadataToClusterState), + ), ) val response: AcknowledgedResponse = client().execute( - UpdateManagedIndexMetaDataAction.INSTANCE, request + UpdateManagedIndexMetaDataAction.INSTANCE, request, ).get() logger.info(response.isAcknowledged) indexMetadata = getIndexMetadata(indexName)!! @@ -93,14 +93,14 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { waitFor(Instant.ofEpochSecond(60)) { assertEquals( METADATA_MOVING_WARNING, - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } waitFor(Instant.ofEpochSecond(120)) { assertEquals( "Happy moving", - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) assertEquals(null, getIndexMetadata(indexName)!!.getCustomData("managed_index_metadata")) } @@ -116,7 +116,7 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { assertEquals( "Index did not set number_of_replicas to ${actionConfig.numOfReplicas}", actionConfig.numOfReplicas, - getNumberOfReplicasSetting(indexName) + getNumberOfReplicasSetting(indexName), ) } } @@ -143,7 +143,7 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -160,15 +160,15 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { metadataToClusterState = metadataToClusterState.copy( index = indexName, indexUuid = indexMetadata.indexUUID, - policyID = policyID + policyID = policyID, ) val request = UpdateManagedIndexMetaDataRequest( indicesToAddManagedIndexMetaDataTo = listOf( - Pair(Index(metadataToClusterState.index, metadataToClusterState.indexUuid), metadataToClusterState) - ) + Pair(Index(metadataToClusterState.index, metadataToClusterState.indexUuid), metadataToClusterState), + ), ) val response: AcknowledgedResponse = client().execute( - UpdateManagedIndexMetaDataAction.INSTANCE, request + UpdateManagedIndexMetaDataAction.INSTANCE, request, ).get() logger.info(response.isAcknowledged) @@ -178,14 +178,14 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { waitFor { assertEquals( METADATA_MOVING_WARNING, - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } waitFor(Instant.ofEpochSecond(120)) { assertEquals( "Happy moving", - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) assertEquals(null, getIndexMetadata(indexName)!!.getCustomData("managed_index_metadata")) } @@ -198,7 +198,7 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { assertEquals( "Index did not set number_of_replicas to ${actionConfig.numOfReplicas}", actionConfig.numOfReplicas, - getNumberOfReplicasSetting(indexName) + getNumberOfReplicasSetting(indexName), ) } } @@ -215,7 +215,7 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -229,12 +229,12 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { metadataToClusterState = metadataToClusterState.copy( index = indexName, indexUuid = "randomindexuuid", - policyID = policyID + policyID = policyID, ) val request = UpdateManagedIndexMetaDataRequest( indicesToAddManagedIndexMetaDataTo = listOf( - Pair(Index(indexName, indexMetadata.indexUUID), metadataToClusterState) - ) + Pair(Index(indexName, indexMetadata.indexUUID), metadataToClusterState), + ), ) client().execute(UpdateManagedIndexMetaDataAction.INSTANCE, request).get() logger.info("check if metadata is saved in cluster state: ${getIndexMetadata(indexName)!!.getCustomData("managed_index_metadata")}") @@ -242,7 +242,7 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { waitFor { assertEquals( METADATA_CORRUPT_WARNING, - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -279,7 +279,7 @@ class MetadataRegressionIT : IndexStateManagementIntegTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt index 1505dae40..940ab1192 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt @@ -14,7 +14,6 @@ import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -22,6 +21,7 @@ import org.opensearch.client.ClusterAdminClient import org.opensearch.cluster.ClusterState import org.opensearch.cluster.metadata.Metadata import org.opensearch.cluster.service.ClusterService +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.test.OpenSearchTestCase import kotlin.test.assertFailsWith @@ -49,9 +49,9 @@ class MetadataServiceTests : OpenSearchTestCase() { getAdminClient( getClusterAdminClient( updateSettingResponse = null, - updateSettingException = ex - ) - ) + updateSettingException = ex, + ), + ), ) val skipFlag = SkipExecution(client) val metadataService = MetadataService(client, clusterService, skipFlag, imIndices) @@ -69,9 +69,9 @@ class MetadataServiceTests : OpenSearchTestCase() { getAdminClient( getClusterAdminClient( updateSettingResponse = null, - updateSettingException = ex - ) - ) + updateSettingException = ex, + ), + ), ) val skipFlag = SkipExecution(client) @@ -97,18 +97,21 @@ class MetadataServiceTests : OpenSearchTestCase() { private fun getClusterAdminClient( updateSettingResponse: ClusterUpdateSettingsResponse?, - updateSettingException: Exception? + updateSettingException: Exception?, ): ClusterAdminClient { assertTrue( "Must provide either a getMappingsResponse or getMappingsException", - (updateSettingResponse != null).xor(updateSettingException != null) + (updateSettingResponse != null).xor(updateSettingException != null), ) return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (updateSettingResponse != null) listener.onResponse(updateSettingResponse) - else listener.onFailure(updateSettingException) + if (updateSettingResponse != null) { + listener.onResponse(updateSettingResponse) + } else { + listener.onFailure(updateSettingException) + } }.whenever(this.mock).updateSettings(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/TestHelpers.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/TestHelpers.kt index 29aebc443..539ee0c0f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/TestHelpers.kt @@ -7,12 +7,13 @@ package org.opensearch.indexmanagement.indexstatemanagement import org.opensearch.action.admin.indices.alias.Alias import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest -import org.opensearch.core.common.unit.ByteSizeValue import org.opensearch.common.unit.TimeValue -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.core.common.unit.ByteSizeValue +import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.RandomCreateIndexGenerator.randomAlias import org.opensearch.index.seqno.SequenceNumbers +import org.opensearch.indexmanagement.common.model.notification.Channel import org.opensearch.indexmanagement.indexstatemanagement.action.AliasAction import org.opensearch.indexmanagement.indexstatemanagement.action.AllocationAction import org.opensearch.indexmanagement.indexstatemanagement.action.CloseAction @@ -28,6 +29,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.RolloverAction import org.opensearch.indexmanagement.indexstatemanagement.action.RollupAction import org.opensearch.indexmanagement.indexstatemanagement.action.ShrinkAction import org.opensearch.indexmanagement.indexstatemanagement.action.SnapshotAction +import org.opensearch.indexmanagement.indexstatemanagement.action.TransformAction import org.opensearch.indexmanagement.indexstatemanagement.model.ChangePolicy import org.opensearch.indexmanagement.indexstatemanagement.model.Conditions import org.opensearch.indexmanagement.indexstatemanagement.model.ErrorNotification @@ -40,8 +42,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.model.StateFilter import org.opensearch.indexmanagement.indexstatemanagement.model.Transition import org.opensearch.indexmanagement.indexstatemanagement.model.coordinator.ClusterStateManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.coordinator.SweptManagedIndexConfig -import org.opensearch.indexmanagement.common.model.notification.Channel -import org.opensearch.indexmanagement.indexstatemanagement.action.TransformAction import org.opensearch.indexmanagement.indexstatemanagement.model.destination.Chime import org.opensearch.indexmanagement.indexstatemanagement.model.destination.CustomWebhook import org.opensearch.indexmanagement.indexstatemanagement.model.destination.Destination @@ -75,25 +75,25 @@ fun randomPolicy( lastUpdatedTime: Instant = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification: ErrorNotification? = randomErrorNotification(), states: List = List(OpenSearchRestTestCase.randomIntBetween(1, 10)) { randomState() }, - ismTemplate: List? = null + ismTemplate: List? = null, ): Policy { return Policy( id = id, schemaVersion = schemaVersion, lastUpdatedTime = lastUpdatedTime, - errorNotification = errorNotification, defaultState = states[0].name, states = states, description = description, ismTemplate = ismTemplate + errorNotification = errorNotification, defaultState = states[0].name, states = states, description = description, ismTemplate = ismTemplate, ) } fun randomState( name: String = OpenSearchRestTestCase.randomAlphaOfLength(10), actions: List = listOf(), - transitions: List = listOf() + transitions: List = listOf(), ): State { return State(name = name, actions = actions, transitions = transitions) } fun randomTransition( stateName: String = OpenSearchRestTestCase.randomAlphaOfLength(10), - conditions: Conditions? = randomConditions() + conditions: Conditions? = randomConditions(), ): Transition { return Transition(stateName = stateName, conditions = conditions) } @@ -106,9 +106,8 @@ fun randomTransition( */ fun randomConditions( condition: Pair? = - OpenSearchRestTestCase.randomFrom(listOf(randomIndexAge(), randomDocCount(), randomSize(), randomRolloverAge(), null)) + OpenSearchRestTestCase.randomFrom(listOf(randomIndexAge(), randomDocCount(), randomSize(), randomRolloverAge(), null)), ): Conditions? { - if (condition == null) return null val type = condition.first @@ -135,14 +134,14 @@ fun randomRolloverActionConfig( minSize: ByteSizeValue = randomByteSizeValue(), minDocs: Long = OpenSearchRestTestCase.randomLongBetween(1, 1000), minAge: TimeValue = randomTimeValueObject(), - minPrimaryShardSize: ByteSizeValue = randomByteSizeValue() + minPrimaryShardSize: ByteSizeValue = randomByteSizeValue(), ): RolloverAction { return RolloverAction( minSize = minSize, minDocs = minDocs, minAge = minAge, minPrimaryShardSize = minPrimaryShardSize, - index = 0 + index = 0, ) } @@ -154,7 +153,7 @@ fun randomShrinkAction( targetIndexTemplate: Script? = if (randomBoolean()) randomTemplateScript(randomAlphaOfLength(10)) else null, aliases: List? = if (randomBoolean()) randomList(10) { randomAlias() } else null, switchAliases: Boolean = randomBoolean(), - forceUnsafe: Boolean? = if (randomBoolean()) randomBoolean() else null + forceUnsafe: Boolean? = if (randomBoolean()) randomBoolean() else null, ): ShrinkAction { if (numNewShards == null && maxShardSize == null && percentageOfSourceShards == null) { when (randomInt(2)) { @@ -183,7 +182,7 @@ fun randomIndexPriorityActionConfig(indexPriority: Int = OpenSearchRestTestCase. } fun randomForceMergeActionConfig( - maxNumSegments: Int = OpenSearchRestTestCase.randomIntBetween(1, 50) + maxNumSegments: Int = OpenSearchRestTestCase.randomIntBetween(1, 50), ): ForceMergeAction { return ForceMergeAction(maxNumSegments = maxNumSegments, index = 0) } @@ -191,7 +190,7 @@ fun randomForceMergeActionConfig( fun randomNotificationActionConfig( destination: Destination = randomDestination(), messageTemplate: Script = randomTemplateScript("random message"), - index: Int = 0 + index: Int = 0, ): NotificationAction { return NotificationAction(destination, null, messageTemplate, index) } @@ -239,7 +238,7 @@ fun randomDestination(type: DestinationType = randomDestinationType()): Destinat type = type, chime = if (type == DestinationType.CHIME) randomChime() else null, slack = if (type == DestinationType.SLACK) randomSlack() else null, - customWebhook = if (type == DestinationType.CUSTOM_WEBHOOK) randomCustomWebhook() else null + customWebhook = if (type == DestinationType.CUSTOM_WEBHOOK) randomCustomWebhook() else null, ) } @@ -266,7 +265,7 @@ fun randomCustomWebhook(): CustomWebhook { queryParams = emptyMap(), headerParams = emptyMap(), username = null, - password = null + password = null, ) } @@ -274,7 +273,7 @@ fun randomTemplateScript( source: String = OpenSearchRestTestCase.randomAlphaOfLength(10), params: Map = emptyMap(), scriptType: ScriptType = ScriptType.INLINE, - lang: String = Script.DEFAULT_TEMPLATE_LANG + lang: String = Script.DEFAULT_TEMPLATE_LANG, ): Script = Script(scriptType, lang, source, params) fun randomSnapshotActionConfig(repository: String = "repo", snapshot: String = "sp"): SnapshotAction { @@ -300,8 +299,9 @@ fun randomTimeValueObject(): TimeValue = TimeValue.parseTimeValue(OpenSearchRest fun randomByteSizeValue(): ByteSizeValue = ByteSizeValue.parseBytesSizeValue( OpenSearchRestTestCase.randomIntBetween(1, 1000).toString() + OpenSearchRestTestCase.randomFrom(listOf("b", "kb", "mb", "gb")), - "" + "", ) + /** * End - Conditions helper functions */ @@ -310,7 +310,7 @@ fun randomExplainFilter( policyID: String? = if (OpenSearchRestTestCase.randomBoolean()) OpenSearchRestTestCase.randomAlphaOfLength(10) else null, state: String? = if (OpenSearchRestTestCase.randomBoolean()) OpenSearchRestTestCase.randomAlphaOfLength(10) else null, actionType: String? = if (OpenSearchRestTestCase.randomBoolean()) OpenSearchRestTestCase.randomAlphaOfLength(10) else null, - failed: Boolean? = if (OpenSearchRestTestCase.randomBoolean()) OpenSearchRestTestCase.randomBoolean() else null + failed: Boolean? = if (OpenSearchRestTestCase.randomBoolean()) OpenSearchRestTestCase.randomBoolean() else null, ): ExplainFilter { return ExplainFilter(policyID, state, actionType, failed) } @@ -319,7 +319,7 @@ fun randomChangePolicy( policyID: String = OpenSearchRestTestCase.randomAlphaOfLength(10), state: String? = if (OpenSearchRestTestCase.randomBoolean()) OpenSearchRestTestCase.randomAlphaOfLength(10) else null, include: List = emptyList(), - isSafe: Boolean = false + isSafe: Boolean = false, ): ChangePolicy { return ChangePolicy(policyID, state, include, isSafe) } @@ -339,7 +339,7 @@ fun randomManagedIndexConfig( policyID: String = OpenSearchRestTestCase.randomAlphaOfLength(10), policy: Policy? = randomPolicy(), changePolicy: ChangePolicy? = randomChangePolicy(), - jitter: Double? = 0.0 + jitter: Double? = 0.0, ): ManagedIndexConfig { return ManagedIndexConfig( jobName = name, @@ -354,7 +354,7 @@ fun randomManagedIndexConfig( policyPrimaryTerm = policy?.primaryTerm, policy = policy?.copy(seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM), changePolicy = changePolicy, - jobJitter = jitter + jobJitter = jitter, ) } @@ -363,14 +363,14 @@ fun randomClusterStateManagedIndexConfig( uuid: String = OpenSearchRestTestCase.randomAlphaOfLength(20), policyID: String = OpenSearchRestTestCase.randomAlphaOfLength(10), seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM + primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, ): ClusterStateManagedIndexConfig { return ClusterStateManagedIndexConfig( index = index, uuid = uuid, policyID = policyID, seqNo = seqNo, - primaryTerm = primaryTerm + primaryTerm = primaryTerm, ) } @@ -381,7 +381,7 @@ fun randomSweptManagedIndexConfig( seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, changePolicy: ChangePolicy? = null, - policy: Policy? = null + policy: Policy? = null, ): SweptManagedIndexConfig { return SweptManagedIndexConfig( index = index, @@ -390,19 +390,19 @@ fun randomSweptManagedIndexConfig( seqNo = seqNo, primaryTerm = primaryTerm, policy = policy, - changePolicy = changePolicy + changePolicy = changePolicy, ) } fun randomISMTemplate( indexPatterns: List = listOf(OpenSearchRestTestCase.randomAlphaOfLength(10) + "*"), priority: Int = OpenSearchRestTestCase.randomIntBetween(0, 100), - lastUpdatedTime: Instant = Instant.now().truncatedTo(ChronoUnit.MILLIS) + lastUpdatedTime: Instant = Instant.now().truncatedTo(ChronoUnit.MILLIS), ): ISMTemplate { return ISMTemplate( indexPatterns = indexPatterns, priority = priority, - lastUpdatedTime = lastUpdatedTime + lastUpdatedTime = lastUpdatedTime, ) } @@ -538,7 +538,7 @@ fun Channel.toJsonString(): String { @Suppress("RethrowCaughtException") fun wait( timeout: Instant = Instant.ofEpochSecond(10), - block: () -> T + block: () -> T, ) { val startTime = Instant.now().toEpochMilli() do { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionRetryIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionRetryIT.kt index f6970b754..5ab29b82e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionRetryIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionRetryIT.kt @@ -53,9 +53,9 @@ class ActionRetryIT : IndexStateManagementRestTestCase() { assertEquals( ActionMetaData( "rollover", managedIndexMetaData.actionMetaData?.startTime, 0, false, 1, - managedIndexMetaData.actionMetaData?.lastRetryTime, null + managedIndexMetaData.actionMetaData?.lastRetryTime, null, ), - managedIndexMetaData.actionMetaData + managedIndexMetaData.actionMetaData, ) assertEquals(expectedInfoString, managedIndexMetaData.info.toString()) @@ -69,9 +69,9 @@ class ActionRetryIT : IndexStateManagementRestTestCase() { assertEquals( ActionMetaData( "rollover", managedIndexMetaData.actionMetaData?.startTime, 0, false, 2, - managedIndexMetaData.actionMetaData?.lastRetryTime, null + managedIndexMetaData.actionMetaData?.lastRetryTime, null, ), - managedIndexMetaData.actionMetaData + managedIndexMetaData.actionMetaData, ) assertEquals(expectedInfoString, managedIndexMetaData.info.toString()) @@ -85,9 +85,9 @@ class ActionRetryIT : IndexStateManagementRestTestCase() { assertEquals( ActionMetaData( "rollover", managedIndexMetaData.actionMetaData?.startTime, 0, true, 2, - managedIndexMetaData.actionMetaData?.lastRetryTime, null + managedIndexMetaData.actionMetaData?.lastRetryTime, null, ), - managedIndexMetaData.actionMetaData + managedIndexMetaData.actionMetaData, ) assertEquals(expectedInfoString, managedIndexMetaData.info.toString()) @@ -149,20 +149,20 @@ class ActionRetryIT : IndexStateManagementRestTestCase() { ActionMetaData.ACTION to fun(actionMetaDataMap: Any?): Boolean = assertActionEquals( ActionMetaData("rollover", Instant.now().toEpochMilli(), 0, false, 1, null, null), - actionMetaDataMap + actionMetaDataMap, ), StepMetaData.STEP to fun(stepMetaDataMap: Any?): Boolean = assertStepEquals( StepMetaData("attempt_rollover", Instant.now().toEpochMilli(), Step.StepStatus.FAILED), - stepMetaDataMap + stepMetaDataMap, ), PolicyRetryInfoMetaData.RETRY_INFO to fun(retryInfoMetaDataMap: Any?): Boolean = assertRetryInfoEquals(PolicyRetryInfoMetaData(false, 0), retryInfoMetaDataMap), ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString(), - ManagedIndexMetaData.ENABLED to true::equals - ) + ManagedIndexMetaData.ENABLED to true::equals, + ), ), - getExplainMap(indexName) + getExplainMap(indexName), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionTimeoutIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionTimeoutIT.kt index 551132009..e4cfd8392 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionTimeoutIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ActionTimeoutIT.kt @@ -43,7 +43,7 @@ class ActionTimeoutIT : IndexStateManagementRestTestCase() { assertEquals( "Should be attempting to rollover", getExplainManagedIndexMetaData(indexName).info?.get("message"), - AttemptRolloverStep.getPendingMessage(indexName) + AttemptRolloverStep.getPendingMessage(indexName), ) } @@ -57,14 +57,14 @@ class ActionTimeoutIT : IndexStateManagementRestTestCase() { assertActionEquals( ActionMetaData( name = RolloverAction.name, startTime = Instant.now().toEpochMilli(), index = 0, - failed = true, consumedRetries = 0, lastRetryTime = null, actionProperties = null + failed = true, consumedRetries = 0, lastRetryTime = null, actionProperties = null, ), - actionMetaDataMap - ) - ) + actionMetaDataMap, + ), + ), ), getExplainMap(indexName), - strict = false + strict = false, ) } } @@ -98,7 +98,7 @@ class ActionTimeoutIT : IndexStateManagementRestTestCase() { assertPredicatesOnMetaData( listOf(indexName to listOf(ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedOpenInfoString == info.toString())), getExplainMap(indexName), - strict = false + strict = false, ) } @@ -112,7 +112,7 @@ class ActionTimeoutIT : IndexStateManagementRestTestCase() { assertEquals( "Should be attempting to rollover", getExplainManagedIndexMetaData(indexName).info?.get("message"), - AttemptRolloverStep.getPendingMessage(indexName) + AttemptRolloverStep.getPendingMessage(indexName), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasActionIT.kt index 0ce641fbd..c0865d395 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AliasActionIT.kt @@ -34,7 +34,7 @@ class AliasActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -77,7 +77,7 @@ class AliasActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -120,7 +120,7 @@ class AliasActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID, aliasName) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationActionIT.kt index 63b00200a..e0ec7456d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/AllocationActionIT.kt @@ -24,7 +24,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = AllocationAction(require = mapOf("box_type" to "hot"), exclude = emptyMap(), include = emptyMap(), index = 0) val states = listOf( - State("Allocate", listOf(actionConfig), listOf()) + State("Allocate", listOf(actionConfig), listOf()), ) val policy = Policy( id = policyID, @@ -33,7 +33,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -67,7 +67,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { availableNodes.remove(getIndexShardNodes(indexName)[0]) val actionConfig = AllocationAction(require = mapOf("_name" to availableNodes.first()), exclude = emptyMap(), include = emptyMap(), index = 0) val states = listOf( - State("Allocate", listOf(actionConfig), listOf()) + State("Allocate", listOf(actionConfig), listOf()), ) val policy = Policy( id = policyID, @@ -76,7 +76,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) addPolicyToIndex(policyID, indexName) @@ -113,7 +113,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { val excludedNode = getIndexShardNodes(indexName)[0].toString() val actionConfig = AllocationAction(require = emptyMap(), exclude = mapOf("_name" to excludedNode), include = emptyMap(), index = 0) val states = listOf( - State("Allocate", listOf(actionConfig), listOf()) + State("Allocate", listOf(actionConfig), listOf()), ) val policy = Policy( id = policyID, @@ -122,7 +122,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) addPolicyToIndex(policyID, indexName) @@ -160,7 +160,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { availableNodes.remove(getIndexShardNodes(indexName)[0]) val actionConfig = AllocationAction(require = emptyMap(), exclude = emptyMap(), include = mapOf("_name" to availableNodes.first()), index = 0) val states = listOf( - State("Allocate", listOf(actionConfig), listOf()) + State("Allocate", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -170,7 +170,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) addPolicyToIndex(policyID, indexName) @@ -201,7 +201,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_illegal_key" val actionConfig = AllocationAction(require = mapOf("..//" to "value"), exclude = emptyMap(), include = emptyMap(), index = 0) val states = listOf( - State("Allocate", listOf(actionConfig), listOf()) + State("Allocate", listOf(actionConfig), listOf()), ) val policy = Policy( id = policyID, @@ -210,7 +210,7 @@ class AllocationActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID, null, "0") diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseActionIT.kt index 1a2760cce..e2fd5f528 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/CloseActionIT.kt @@ -23,7 +23,7 @@ class CloseActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = CloseAction(0) val states = listOf( - State("CloseState", listOf(actionConfig), listOf()) + State("CloseState", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -33,7 +33,7 @@ class CloseActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -58,7 +58,7 @@ class CloseActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_2" val actionConfig = CloseAction(0) val states = listOf( - State("CloseState", listOf(actionConfig), listOf()) + State("CloseState", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -68,7 +68,7 @@ class CloseActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -104,7 +104,7 @@ class CloseActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteActionIT.kt index 163e862e2..7540498dd 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteActionIT.kt @@ -22,7 +22,7 @@ class DeleteActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = DeleteAction(0) val states = listOf( - State("DeleteState", listOf(actionConfig), listOf()) + State("DeleteState", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -32,7 +32,7 @@ class DeleteActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionIT.kt index 67567be71..d97ac6ae5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ForceMergeActionIT.kt @@ -36,7 +36,7 @@ class ForceMergeActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -64,7 +64,7 @@ class ForceMergeActionIT : IndexStateManagementRestTestCase() { assertEquals( "maxNumSegments not set in ActionProperties", forceMergeActionConfig.maxNumSegments, - getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.maxNumSegments + getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.maxNumSegments, ) } @@ -92,7 +92,7 @@ class ForceMergeActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPolicyActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPolicyActionIT.kt index c42fa88fe..1c3fd9123 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPolicyActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPolicyActionIT.kt @@ -40,13 +40,13 @@ class IndexPolicyActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) client().makeRequest( "PUT", "${IndexManagementPlugin.POLICY_BASE_URI}/init-index", emptyMap(), - StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON) + StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON), ) updateClusterSetting(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.key + "zone.values", "a, b") @@ -56,7 +56,7 @@ class IndexPolicyActionIT : IndexStateManagementRestTestCase() { "PUT", "${IndexManagementPlugin.POLICY_BASE_URI}/$policyID", emptyMap(), - StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON) + StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON), ) actionConfig = ReplicaCountAction(4, 0) @@ -68,16 +68,16 @@ class IndexPolicyActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) Assert.assertThrows( - ResponseException::class.java + ResponseException::class.java, ) { client().makeRequest( "PUT", "${IndexManagementPlugin.POLICY_BASE_URI}/$policyID", emptyMap(), - StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON) + StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON), ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionIT.kt index c77b5e8ad..91e50e175 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPriorityActionIT.kt @@ -29,7 +29,7 @@ class IndexPriorityActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexStateManagementHistoryIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexStateManagementHistoryIT.kt index a592d2c18..c7c040db7 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexStateManagementHistoryIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexStateManagementHistoryIT.kt @@ -14,10 +14,10 @@ import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotificati import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.step.readonly.SetReadOnlyStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StateMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.PolicyRetryInfoMetaData +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StateMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.indexmanagement.waitFor import java.time.Instant @@ -32,7 +32,7 @@ class IndexStateManagementHistoryIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = ReadOnlyAction(0) val states = listOf( - State("ReadOnlyState", listOf(actionConfig), listOf()) + State("ReadOnlyState", listOf(actionConfig), listOf()), ) val policy = Policy( id = policyID, @@ -41,7 +41,7 @@ class IndexStateManagementHistoryIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -76,7 +76,7 @@ class IndexStateManagementHistoryIT : IndexStateManagementRestTestCase() { actionMetaData = ActionMetaData(ReadOnlyAction.name, actualHistory.actionMetaData!!.startTime, 0, false, 0, 0, null), stepMetaData = StepMetaData("set_read_only", actualHistory.stepMetaData!!.startTime, Step.StepStatus.COMPLETED), policyRetryInfo = PolicyRetryInfoMetaData(false, 0), - info = mapOf("message" to SetReadOnlyStep.getSuccessMessage(indexName)) + info = mapOf("message" to SetReadOnlyStep.getSuccessMessage(indexName)), ) assertEquals(expectedHistory, actualHistory) @@ -88,7 +88,7 @@ class IndexStateManagementHistoryIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_2" val actionConfig = ReadOnlyAction(0) val states = listOf( - State("ReadOnlyState", listOf(actionConfig), listOf()) + State("ReadOnlyState", listOf(actionConfig), listOf()), ) val policy = Policy( id = policyID, @@ -97,7 +97,7 @@ class IndexStateManagementHistoryIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -137,7 +137,7 @@ class IndexStateManagementHistoryIT : IndexStateManagementRestTestCase() { actionMetaData = ActionMetaData(ReadOnlyAction.name, actualHistory.actionMetaData!!.startTime, 0, false, 0, 0, null), stepMetaData = StepMetaData("set_read_only", actualHistory.stepMetaData!!.startTime, Step.StepStatus.COMPLETED), policyRetryInfo = PolicyRetryInfoMetaData(false, 0), - info = mapOf("message" to SetReadOnlyStep.getSuccessMessage(indexName)) + info = mapOf("message" to SetReadOnlyStep.getSuccessMessage(indexName)), ) assertEquals(expectedHistory, actualHistory) @@ -168,7 +168,7 @@ class IndexStateManagementHistoryIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt index 6790d2ed6..7f3634f1f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt @@ -45,8 +45,8 @@ class NotificationActionIT : IndexStateManagementRestTestCase() { queryParams = emptyMap(), headerParams = mapOf("Content-Type" to "application/json"), username = if (securityEnabled()) "admin" else null, - password = if (securityEnabled()) "admin" else null - ) + password = if (securityEnabled()) "admin" else null, + ), ) val messageTemplate = Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, "{ \"testing\": 5 }", emptyMap()) val actionConfig = NotificationAction(destination = destination, channel = null, messageTemplate = messageTemplate, index = 0) @@ -58,7 +58,7 @@ class NotificationActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -78,7 +78,7 @@ class NotificationActionIT : IndexStateManagementRestTestCase() { ( client().makeRequest("GET", "$notificationIndex/_search") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) // Speed up to second execution where it will trigger the first execution of the action which @@ -92,7 +92,7 @@ class NotificationActionIT : IndexStateManagementRestTestCase() { ( client().makeRequest("GET", "$notificationIndex/_search") .asMap() as Map>> - )["hits"]!!["total"]!!["value"] + )["hits"]!!["total"]!!["value"], ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenActionIT.kt index d253806ba..32058e46d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/OpenActionIT.kt @@ -22,7 +22,7 @@ class OpenActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = OpenAction(0) val states = listOf( - State("OpenState", listOf(actionConfig), listOf()) + State("OpenState", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -32,7 +32,7 @@ class OpenActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -59,7 +59,7 @@ class OpenActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_2" val actionConfig = OpenAction(0) val states = listOf( - State("OpenState", listOf(actionConfig), listOf()) + State("OpenState", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -69,7 +69,7 @@ class OpenActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyActionIT.kt index 8ecf52aeb..66fc79d86 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadOnlyActionIT.kt @@ -22,7 +22,7 @@ class ReadOnlyActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = ReadOnlyAction(0) val states = listOf( - State("ReadOnlyState", listOf(actionConfig), listOf()) + State("ReadOnlyState", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -32,7 +32,7 @@ class ReadOnlyActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteActionIT.kt index e52786314..db3b59544 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReadWriteActionIT.kt @@ -24,7 +24,7 @@ class ReadWriteActionIT : IndexStateManagementRestTestCase() { val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = ReadWriteAction(0) val states = listOf( - State("ReadWriteState", listOf(actionConfig), listOf()) + State("ReadWriteState", listOf(actionConfig), listOf()), ) val policy = Policy( @@ -34,7 +34,7 @@ class ReadWriteActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -42,7 +42,7 @@ class ReadWriteActionIT : IndexStateManagementRestTestCase() { // Set index to read-only updateIndexSettings( indexName, - Settings.builder().put("index.blocks.write", true) + Settings.builder().put("index.blocks.write", true), ) assertEquals("true", getIndexBlocksWriteSetting(indexName)) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionIT.kt index f88a094b8..4dece6f88 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionIT.kt @@ -30,7 +30,7 @@ class ReplicaCountActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt index c5569dd9c..a48510298 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt @@ -10,9 +10,11 @@ import org.apache.http.entity.StringEntity import org.junit.Assert import org.opensearch.cluster.metadata.DataStream import org.opensearch.common.settings.Settings +import org.opensearch.common.unit.TimeValue import org.opensearch.core.common.unit.ByteSizeUnit import org.opensearch.core.common.unit.ByteSizeValue -import org.opensearch.common.unit.TimeValue +import org.opensearch.core.rest.RestStatus +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate import org.opensearch.indexmanagement.indexstatemanagement.model.Policy @@ -26,8 +28,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionRetry import org.opensearch.indexmanagement.waitFor import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus -import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.test.OpenSearchTestCase import java.time.Instant import java.time.temporal.ChronoUnit @@ -51,7 +51,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -91,8 +91,8 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { " \"$aliasName\": {\"is_write_index\": true}\n" + " }\n" + "}", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) val policyID = "${testIndexName}_bwc" @@ -105,7 +105,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -142,7 +142,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -161,12 +161,12 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val info = getExplainManagedIndexMetaData(firstIndex).info as Map assertEquals( "Index rollover before it met the condition.", - AttemptRolloverStep.getPendingMessage(firstIndex), info["message"] + AttemptRolloverStep.getPendingMessage(firstIndex), info["message"], ) val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min size and min doc count conditions", - setOf(RolloverAction.MIN_SIZE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_SIZE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minSize = conditions[RolloverAction.MIN_SIZE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map @@ -186,7 +186,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min size and min doc count conditions", - setOf(RolloverAction.MIN_SIZE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_SIZE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minSize = conditions[RolloverAction.MIN_SIZE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map @@ -214,7 +214,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -225,7 +225,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { alias = aliasName, replicas = "0", shards = "20", - settings = Settings.builder().put("store.stats_refresh_interval", "1s").build() + settings = Settings.builder().put("store.stats_refresh_interval", "1s").build(), ) val managedIndexConfig = getExistingManagedIndexConfig(firstIndex) @@ -258,12 +258,12 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val info = getExplainManagedIndexMetaData(firstIndex).info as Map assertEquals( "Index rollover before it met the condition.", - AttemptRolloverStep.getPendingMessage(firstIndex), info["message"] + AttemptRolloverStep.getPendingMessage(firstIndex), info["message"], ) val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min primary shard size condition", - setOf(RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD), conditions.keys + setOf(RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD), conditions.keys, ) val minPrimarySize = conditions[RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD] as Map assertEquals("Did not have min size condition", "100kb", minPrimarySize["condition"]) @@ -300,7 +300,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min primary shard size conditions", - setOf(RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD), conditions.keys + setOf(RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD), conditions.keys, ) val minPrimaryShardSize = conditions[RolloverAction.MIN_PRIMARY_SHARD_SIZE_FIELD] as Map assertEquals("Did not have min primary shard size condition", "100kb", minPrimaryShardSize["condition"]) @@ -324,7 +324,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -343,12 +343,12 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val info = getExplainManagedIndexMetaData(firstIndex).info as Map assertEquals( "Index rollover before it met the condition.", - AttemptRolloverStep.getPendingMessage(firstIndex), info["message"] + AttemptRolloverStep.getPendingMessage(firstIndex), info["message"], ) val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", - setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map @@ -368,7 +368,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", - setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map @@ -398,7 +398,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(index1, policyID) @@ -420,7 +420,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val info = getExplainManagedIndexMetaData(index1).info as Map assertEquals( "Index rollover not stopped by pre-check.", - AttemptRolloverStep.getFailedPreCheckMessage(index1), info["message"] + AttemptRolloverStep.getFailedPreCheckMessage(index1), info["message"], ) } @@ -428,7 +428,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$index1" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$index1", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) @@ -437,7 +437,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val info = getExplainManagedIndexMetaData(index1).info as Map assertEquals( "Index rollover not skip.", - AttemptRolloverStep.getSkipRolloverMessage(index1), info["message"] + AttemptRolloverStep.getSkipRolloverMessage(index1), info["message"], ) } } @@ -457,7 +457,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { errorNotification = randomErrorNotification(), defaultState = states[0].name, states = states, - ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))) + ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))), ) createPolicy(policy, policyID) @@ -466,7 +466,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { client().makeRequest( "PUT", "/_index_template/rollover-data-stream-template", - StringEntity("{ \"index_patterns\": [ \"$dataStreamName\" ], \"data_stream\": { } }", ContentType.APPLICATION_JSON) + StringEntity("{ \"index_patterns\": [ \"$dataStreamName\" ], \"data_stream\": { } }", ContentType.APPLICATION_JSON), ) client().makeRequest("PUT", "/_data_stream/$dataStreamName") @@ -483,7 +483,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { assertEquals( "Data stream did not rollover.", AttemptRolloverStep.getSuccessDataStreamRolloverMessage(dataStreamName, firstIndexName), - info["message"] + info["message"], ) assertNull("Should not have conditions if none specified", info["conditions"]) } @@ -516,7 +516,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { errorNotification = randomErrorNotification(), defaultState = states[0].name, states = states, - ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))) + ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))), ) createPolicy(policy, policyID) @@ -525,7 +525,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { client().makeRequest( "PUT", "/_index_template/rollover-data-stream-template", - StringEntity("{ \"index_patterns\": [ \"$dataStreamName\" ], \"data_stream\": { } }", ContentType.APPLICATION_JSON) + StringEntity("{ \"index_patterns\": [ \"$dataStreamName\" ], \"data_stream\": { } }", ContentType.APPLICATION_JSON), ) client().makeRequest("PUT", "/_data_stream/$dataStreamName") @@ -543,14 +543,14 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { assertEquals( "Index rollover before it met the condition.", AttemptRolloverStep.getPendingMessage(firstIndexName), - info["message"] + info["message"], ) val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), - conditions.keys + conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map @@ -571,14 +571,14 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { assertEquals( "Data stream did not rollover", AttemptRolloverStep.getSuccessDataStreamRolloverMessage(dataStreamName, firstIndexName), - info["message"] + info["message"], ) val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), - conditions.keys + conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map @@ -610,7 +610,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -652,7 +652,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -665,7 +665,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { filter = """ { "term": { "user.id": "kimchy" } } """.trimIndent(), - isHidden = false + isHidden = false, ) changeAlias(firstIndex, "test_alias2", "add") changeAlias(firstIndex, "test_alias3", "add") @@ -682,12 +682,12 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val info = getExplainManagedIndexMetaData(firstIndex).info as Map assertEquals( "Index rollover before it met the condition.", - AttemptRolloverStep.getPendingMessage(firstIndex), info["message"] + AttemptRolloverStep.getPendingMessage(firstIndex), info["message"], ) val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", - setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map @@ -709,7 +709,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val conditions = info["conditions"] as Map assertEquals( "Did not have exclusively min age and min doc count conditions", - setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys + setOf(RolloverAction.MIN_INDEX_AGE_FIELD, RolloverAction.MIN_DOC_COUNT_FIELD), conditions.keys, ) val minAge = conditions[RolloverAction.MIN_INDEX_AGE_FIELD] as Map val minDocCount = conditions[RolloverAction.MIN_DOC_COUNT_FIELD] as Map @@ -749,7 +749,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -782,8 +782,8 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { " }\n" + " }\n" + "}", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupActionIT.kt index 422f72877..b1fc33090 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RollupActionIT.kt @@ -46,22 +46,22 @@ class RollupActionIT : IndexStateManagementRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ) val actionConfig = RollupAction(rollup, 0) val states = listOf( - State("rollup", listOf(actionConfig), listOf()) + State("rollup", listOf(actionConfig), listOf()), ) val sourceIndexMappingString = "\"properties\": {\"tpep_pickup_datetime\": { \"type\": \"date\" }, \"RatecodeID\": { \"type\": " + "\"keyword\" }, \"PULocationID\": { \"type\": \"keyword\" }, \"passenger_count\": { \"type\": \"integer\" }, \"total_amount\": " + @@ -73,7 +73,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID, mapping = sourceIndexMappingString) @@ -92,20 +92,20 @@ class RollupActionIT : IndexStateManagementRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), ), RollupMetrics( sourceField = "total_amount", targetField = "total_amount", - metrics = listOf(Max(), Min()) - ) - ) + metrics = listOf(Max(), Min()), + ), + ), ) // Create an ISM policy to rollup backing indices of a data stream. @@ -119,7 +119,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { errorNotification = randomErrorNotification(), defaultState = states[0].name, states = states, - ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))) + ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))), ) createPolicy(policy, policyID) @@ -136,8 +136,8 @@ class RollupActionIT : IndexStateManagementRestTestCase() { "\"index_patterns\": [ \"$dataStreamName\" ], " + "\"data_stream\": { \"timestamp_field\": { \"name\": \"tpep_pickup_datetime\" } }, " + "\"template\": { \"mappings\": { $sourceIndexMappingString } } }", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) client().makeRequest("PUT", "/_data_stream/$dataStreamName") @@ -156,20 +156,20 @@ class RollupActionIT : IndexStateManagementRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), ), RollupMetrics( sourceField = "total_amount", targetField = "total_amount", - metrics = listOf(Max(), Min()) - ) - ) + metrics = listOf(Max(), Min()), + ), + ), ) // Create an ISM policy to rollup backing indices of a data stream. @@ -183,7 +183,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { errorNotification = randomErrorNotification(), defaultState = states[0].name, states = states, - ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))) + ismTemplate = listOf(ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS))), ) createPolicy(policy, policyID) @@ -200,8 +200,8 @@ class RollupActionIT : IndexStateManagementRestTestCase() { "\"index_patterns\": [ \"$dataStreamName\" ], " + "\"data_stream\": { \"timestamp_field\": { \"name\": \"tpep_pickup_datetime\" } }, " + "\"template\": { \"mappings\": { $sourceIndexMappingString } } }", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) client().makeRequest("PUT", "/_data_stream/$dataStreamName") @@ -221,23 +221,23 @@ class RollupActionIT : IndexStateManagementRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) - ) - ) + ValueCount(), Average(), + ), + ), + ), ) val rollup = ismRollup.toRollup(indexName) val rollupId = rollup.id val actionConfig = RollupAction(ismRollup, 0) val states = listOf( - State("rollup", listOf(actionConfig), listOf()) + State("rollup", listOf(actionConfig), listOf()), ) val sourceIndexMappingString = "\"properties\": {\"tpep_pickup_datetime\": { \"type\": \"date\" }, \"RatecodeID\": { \"type\": " + "\"keyword\" }, \"passenger_count\": { \"type\": \"integer\" }, \"total_amount\": " + @@ -249,7 +249,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID, mapping = sourceIndexMappingString) @@ -265,7 +265,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateRollupJobStep.getSuccessMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -275,7 +275,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForRollupCompletionStep.getJobFailedMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } @@ -290,22 +290,22 @@ class RollupActionIT : IndexStateManagementRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) - ) - ) + ValueCount(), Average(), + ), + ), + ), ) val rollupId = rollup.toRollup(indexName).id val actionConfig = RollupAction(rollup, 0) val states = listOf( - State("rollup", listOf(actionConfig), listOf()) + State("rollup", listOf(actionConfig), listOf()), ) val sourceIndexMappingString = "\"properties\": {\"tpep_pickup_datetime\": { \"type\": \"date\" }, \"RatecodeID\": { \"type\": " + "\"keyword\" }, \"passenger_count\": { \"type\": \"integer\" }, \"total_amount\": " + @@ -317,7 +317,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID, mapping = sourceIndexMappingString) @@ -333,7 +333,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateRollupJobStep.getFailedMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } @@ -348,17 +348,17 @@ class RollupActionIT : IndexStateManagementRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) - ) - ) + ValueCount(), Average(), + ), + ), + ), ) val rollup = ismRollup.toRollup(indexName) val rollupId = rollup.id @@ -383,7 +383,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateRollupJobStep.getSuccessMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -392,7 +392,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForRollupCompletionStep.getJobProcessingMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -402,7 +402,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForRollupCompletionStep.getJobFailedMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } @@ -421,7 +421,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateRollupJobStep.getSuccessMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -437,7 +437,7 @@ class RollupActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForRollupCompletionStep.getJobCompletionMessage(rollupId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkActionIT.kt index 83b5267e8..ea37bf4be 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ShrinkActionIT.kt @@ -60,7 +60,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { """.trimIndent() val res = client().makeRequest( "PUT", "_cluster/settings", emptyMap(), - StringEntity(request, ContentType.APPLICATION_JSON) + StringEntity(request, ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, res.restStatus()) } @@ -80,7 +80,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -104,7 +104,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { targetIndexTemplate = targetIndexTemplate, aliases = aliases, forceUnsafe = true, - index = 0 + index = 0, ) 1 -> ShrinkAction( @@ -114,7 +114,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { targetIndexTemplate = targetIndexTemplate, aliases = aliases, forceUnsafe = true, - index = 0 + index = 0, ) 2 -> ShrinkAction( @@ -124,7 +124,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { targetIndexTemplate = targetIndexTemplate, aliases = aliases, forceUnsafe = true, - index = 0 + index = 0, ) else -> { @@ -154,7 +154,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { waitFor(Instant.ofEpochSecond(60)) { assertEquals( targetIndexName, - getExplainManagedIndexMetaData(indexName).actionMetaData!!.actionProperties!!.shrinkActionProperties!!.targetIndexName + getExplainManagedIndexMetaData(indexName).actionMetaData!!.actionProperties!!.shrinkActionProperties!!.targetIndexName, ) assertEquals("true", getIndexBlocksWriteSetting(indexName)) val nodeName = getExplainManagedIndexMetaData(indexName).actionMetaData!!.actionProperties!!.shrinkActionProperties!!.nodeName @@ -167,7 +167,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertEquals(nodeToShrink, settings["index.routing.allocation.require._name"]) assertEquals( AttemptMoveShardsStep.getSuccessMessage(nodeToShrink), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } val nodeToShrink = @@ -178,7 +178,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { waitFor(Instant.ofEpochSecond(60)) { assertEquals( WaitForMoveShardsStep.getSuccessMessage(nodeToShrink), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -190,7 +190,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertEquals(Step.StepStatus.COMPLETED, getExplainManagedIndexMetaData(indexName).stepMetaData?.stepStatus) assertEquals( AttemptShrinkStep.getSuccessMessage(targetIndexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -201,7 +201,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertTrue(getIndexShards(targetIndexName).size == 2) assertEquals( WaitForShrinkStep.SUCCESS_MESSAGE, - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) assertEquals("Write block setting was not reset after successful shrink", "true", getIndexBlocksWriteSetting(indexName)) val aliases = getAlias(targetIndexName, "") @@ -223,7 +223,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -233,7 +233,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { logger.info("Excluded node: $excludedNode") updateIndexSettings( indexName, - Settings.builder().put("index.routing.allocation.exclude._name", excludedNode) + Settings.builder().put("index.routing.allocation.exclude._name", excludedNode), ) assertShrinkActionRun(indexName, policyID, excludedNode) @@ -270,7 +270,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { aliases = listOf(aliasToOverride, aliasToAdd), switchAliases = true, forceUnsafe = true, - index = 0 + index = 0, ) val states = listOf(State("ShrinkState", listOf(shrinkAction), listOf())) @@ -281,18 +281,18 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID, null, "0", "3", "") changeAlias( index = indexName, alias = aliasToSwitch.name(), action = "add", filter = aliasToSwitch.filter(), isWriteIndex = aliasToSwitch.writeIndex(), isHidden = aliasToSwitch.isHidden, - routing = aliasToSwitch.indexRouting().toInt(), indexRouting = aliasToSwitch.indexRouting().toInt(), searchRouting = aliasToSwitch.searchRouting().toInt() + routing = aliasToSwitch.indexRouting().toInt(), indexRouting = aliasToSwitch.indexRouting().toInt(), searchRouting = aliasToSwitch.searchRouting().toInt(), ) changeAlias( index = indexName, alias = aliasToOverride.name(), action = "add", filter = aliasToOverride.filter(), isWriteIndex = false, isHidden = aliasToOverride.isHidden, - routing = aliasToOverride.indexRouting().toInt(), indexRouting = aliasToOverride.indexRouting().toInt(), searchRouting = aliasToOverride.searchRouting().toInt() + routing = aliasToOverride.indexRouting().toInt(), indexRouting = aliasToOverride.indexRouting().toInt(), searchRouting = aliasToOverride.searchRouting().toInt(), ) insertSampleData(indexName, 3) @@ -317,7 +317,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertEquals(nodeToShrink, settings["index.routing.allocation.require._name"]) assertEquals( AttemptMoveShardsStep.getSuccessMessage(nodeToShrink), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -328,7 +328,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { waitFor(Instant.ofEpochSecond(60)) { assertEquals( WaitForMoveShardsStep.getSuccessMessage(nodeToShrink), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } // Wait for move should finish before this. Starts AttemptShrinkStep @@ -337,7 +337,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertTrue("Target index is not created", indexExists(targetIndexName)) assertEquals( AttemptShrinkStep.getSuccessMessage(targetIndexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -389,7 +389,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { targetIndexTemplate = Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, "{{ctx.index}}$testIndexSuffix", mapOf()), aliases = null, forceUnsafe = true, - index = 0 + index = 0, ) val states = listOf(State("ShrinkState", listOf(shrinkAction), listOf())) @@ -400,7 +400,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -424,12 +424,12 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertEquals( "Did not get the no-op due to single primary shard message", AttemptMoveShardsStep.ONE_PRIMARY_SHARD_MESSAGE, - metadata.info?.get("message") + metadata.info?.get("message"), ) assertEquals( "Was not on the last step after no-op due to single primary shard", WaitForShrinkStep.name, - metadata.stepMetaData?.name + metadata.stepMetaData?.name, ) } } @@ -448,7 +448,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID, null, "1", "3", "") @@ -490,7 +490,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertEquals(nodeToShrink, settings["index.routing.allocation.require._name"]) assertEquals( AttemptMoveShardsStep.getSuccessMessage(nodeToShrink), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } var nodeToShrink = getExplainManagedIndexMetaData(indexName).actionMetaData!!.actionProperties!!.shrinkActionProperties!!.nodeName @@ -499,7 +499,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { waitFor(Instant.ofEpochSecond(60)) { assertEquals( WaitForMoveShardsStep.getSuccessMessage(nodeToShrink), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } // Create an index with the target index name so the AttemptShrinkStep fails @@ -516,7 +516,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertFalse("Did not clear index write block setting.", settings.containsKey("index.blocks.writes")) assertNull( "Did not clear shrink action properties", - getExplainManagedIndexMetaData(indexName).actionMetaData!!.actionProperties!!.shrinkActionProperties + getExplainManagedIndexMetaData(indexName).actionMetaData!!.actionProperties!!.shrinkActionProperties, ) } @@ -545,7 +545,7 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() { assertEquals(nodeToShrink, settings["index.routing.allocation.require._name"]) assertEquals( AttemptMoveShardsStep.getSuccessMessage(nodeToShrink), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionIT.kt index 555f8610e..c1f7a674e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionIT.kt @@ -28,7 +28,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { val snapshot = "snapshot" val actionConfig = SnapshotAction(repository, snapshot, 0) val states = listOf( - State("Snapshot", listOf(actionConfig), listOf()) + State("Snapshot", listOf(actionConfig), listOf()), ) createRepository(repository) @@ -40,7 +40,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -65,7 +65,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { val repository = "repository" val actionConfig = SnapshotAction(repository, "{{ctx.index}}", 0) val states = listOf( - State("Snapshot", listOf(actionConfig), listOf()) + State("Snapshot", listOf(actionConfig), listOf()), ) createRepository(repository) @@ -77,7 +77,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -102,7 +102,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { val repository = "repository" val actionConfig = SnapshotAction(repository, "{{ctx.someField}}", 0) val states = listOf( - State("Snapshot", listOf(actionConfig), listOf()) + State("Snapshot", listOf(actionConfig), listOf()), ) createRepository(repository) @@ -114,7 +114,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -140,7 +140,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { val snapshot = "snapshot_success_test" val actionConfig = SnapshotAction(repository, snapshot, 0) val states = listOf( - State("Snapshot", listOf(actionConfig), listOf()) + State("Snapshot", listOf(actionConfig), listOf()), ) createRepository(repository) @@ -152,7 +152,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -174,7 +174,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { // verify we set snapshotName in action properties waitFor { assert( - getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.snapshotName?.contains(snapshot) == true + getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.snapshotName?.contains(snapshot) == true, ) } @@ -189,7 +189,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { val snapshot = "-" val actionConfig = SnapshotAction(repository, "", 0) val states = listOf( - State("Snapshot", listOf(actionConfig), listOf()) + State("Snapshot", listOf(actionConfig), listOf()), ) createRepository(repository) @@ -201,7 +201,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -223,7 +223,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { // verify we set snapshotName in action properties waitFor { assert( - getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.snapshotName?.contains(snapshot) == true + getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.snapshotName?.contains(snapshot) == true, ) } @@ -238,7 +238,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { val snapshot = "snapshot_failed_test" val actionConfig = SnapshotAction(repository, snapshot, 0) val states = listOf( - State("Snapshot", listOf(actionConfig), listOf()) + State("Snapshot", listOf(actionConfig), listOf()), ) createRepository(repository) @@ -250,7 +250,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) @@ -291,7 +291,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { val repository = "hello-world" val actionConfig = SnapshotAction(repository, "snapshot", 0) val states = listOf( - State("Snapshot", listOf(actionConfig), listOf()) + State("Snapshot", listOf(actionConfig), listOf()), ) createRepository(repository) @@ -303,7 +303,7 @@ class SnapshotActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) createIndex(indexName, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformActionIT.kt index 386e47407..0eaa8115d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransformActionIT.kt @@ -97,14 +97,14 @@ class TransformActionIT : IndexStateManagementRestTestCase() { dataSelectionQuery = MatchAllQueryBuilder(), groups = listOf( DateHistogram(sourceField = "timestamp", fixedInterval = "1d"), - Terms(sourceField = "wrong_field", targetField = "wrong_field") + Terms(sourceField = "wrong_field", targetField = "wrong_field"), ), aggregations = AggregatorFactories.builder() .addAggregator(sumAggregation()) .addAggregator(maxAggregation()) .addAggregator(minAggregation()) .addAggregator(avgAggregation()) - .addAggregator(valueCountAggregation()) + .addAggregator(valueCountAggregation()), ) val policy = preparePolicyContainingTransform(indexName, ismTransform, policyId) createPolicy(policy, policyId) @@ -125,14 +125,14 @@ class TransformActionIT : IndexStateManagementRestTestCase() { dataSelectionQuery = MatchAllQueryBuilder(), groups = listOf( DateHistogram(sourceField = "timestamp", fixedInterval = "1d"), - Terms(sourceField = "wrong_field", targetField = "wrong_field") + Terms(sourceField = "wrong_field", targetField = "wrong_field"), ), aggregations = AggregatorFactories.builder() .addAggregator(sumAggregation()) .addAggregator(maxAggregation()) .addAggregator(minAggregation()) .addAggregator(avgAggregation()) - .addAggregator(valueCountAggregation()) + .addAggregator(valueCountAggregation()), ) val transform = ismTransform.toTransform(indexName) val policy = preparePolicyContainingTransform(indexName, ismTransform, policyId, retry = 1) @@ -146,7 +146,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateTransformJobStep.getFailedMessage(transform.id, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } @@ -173,14 +173,14 @@ class TransformActionIT : IndexStateManagementRestTestCase() { dataSelectionQuery = MatchAllQueryBuilder(), groups = listOf( DateHistogram(sourceField = "timestamp", fixedInterval = "1d"), - Terms(sourceField = "category", targetField = "category") + Terms(sourceField = "category", targetField = "category"), ), aggregations = AggregatorFactories.builder() .addAggregator(sumAggregation()) .addAggregator(maxAggregation()) .addAggregator(minAggregation()) .addAggregator(avgAggregation()) - .addAggregator(valueCountAggregation()) + .addAggregator(valueCountAggregation()), ) } @@ -188,7 +188,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { val actionConfig = TransformAction(ismTransform, 0) actionConfig.configRetry = ActionRetry(retry) val states = listOf( - State("transform", listOf(actionConfig), listOf()) + State("transform", listOf(actionConfig), listOf()), ) return Policy( id = policyId, @@ -202,9 +202,9 @@ class TransformActionIT : IndexStateManagementRestTestCase() { ISMTemplate( indexPatterns = listOf(indexName), priority = 100, - lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS) - ) - ) + lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), + ), + ), ) } @@ -212,13 +212,13 @@ class TransformActionIT : IndexStateManagementRestTestCase() { indexName: String, ismTransform: ISMTransform, policyId: String, - retry: Long = 0 + retry: Long = 0, ): Policy { val actionConfig = TransformAction(ismTransform, 0) actionConfig.configRetry = ActionRetry(retry) val states = listOf( State("transform1", listOf(actionConfig), listOf(Transition(stateName = "transform2", conditions = null))), - State("transform2", listOf(actionConfig), listOf()) + State("transform2", listOf(actionConfig), listOf()), ) return Policy( id = policyId, @@ -232,9 +232,9 @@ class TransformActionIT : IndexStateManagementRestTestCase() { ISMTemplate( indexPatterns = listOf(indexName), priority = 100, - lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS) - ) - ) + lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), + ), + ), ) } @@ -248,8 +248,8 @@ class TransformActionIT : IndexStateManagementRestTestCase() { "\"index_patterns\": [ \"$dataStreamName\" ], " + "\"data_stream\": { \"timestamp_field\": { \"name\": \"timestamp\" } }, " + "\"template\": { \"mappings\": { $SOURCE_INDEX_MAPPING } } }", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) // create data stream client().makeRequest("PUT", "/_data_stream/$dataStreamName") @@ -269,7 +269,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateTransformJobStep.getSuccessMessage(transformId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -282,7 +282,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForTransformCompletionStep.getJobCompletionMessage(transformId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } @@ -301,7 +301,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateTransformJobStep.getSuccessMessage(transformId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -312,7 +312,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForTransformCompletionStep.getJobCompletionMessage(transformId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -321,7 +321,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptTransitionStep.getSuccessMessage(indexName, "transform2"), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -330,7 +330,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateTransformJobStep.getSuccessRestartMessage(transformId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -341,7 +341,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForTransformCompletionStep.getJobCompletionMessage(transformId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } @@ -369,7 +369,7 @@ class TransformActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptCreateTransformJobStep.getFailedMessage(transformId, indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionActionIT.kt index 05fb85954..28be24af9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/TransitionActionIT.kt @@ -28,7 +28,7 @@ class TransitionActionIT : IndexStateManagementRestTestCase() { val secondStateName = "second" val states = listOf( State("first", listOf(), listOf(Transition(secondStateName, Conditions(docCount = 5L)))), - State(secondStateName, listOf(), listOf()) + State(secondStateName, listOf(), listOf()), ) val policy = Policy( @@ -38,7 +38,7 @@ class TransitionActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -73,7 +73,7 @@ class TransitionActionIT : IndexStateManagementRestTestCase() { val secondStateName = "second" val states = listOf( State("first", listOf(), listOf(Transition(secondStateName, Conditions(rolloverAge = TimeValue.timeValueSeconds(30))))), - State(secondStateName, listOf(), listOf()) + State(secondStateName, listOf(), listOf()), ) val policy = Policy( @@ -83,7 +83,7 @@ class TransitionActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -110,7 +110,7 @@ class TransitionActionIT : IndexStateManagementRestTestCase() { val secondStateName = "second" val states = listOf( State("first", listOf(), listOf(Transition(secondStateName, Conditions(rolloverAge = TimeValue.timeValueMillis(1))))), - State(secondStateName, listOf(), listOf()) + State(secondStateName, listOf(), listOf()), ) val policy = Policy( @@ -120,7 +120,7 @@ class TransitionActionIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt index f42b55a56..db03193f8 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorIT.kt @@ -77,7 +77,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { assertPredicatesOnMetaData( listOf(index to listOf(ManagedIndexMetaData.POLICY_ID to policy.id::equals)), getExplainMap(index), - false + false, ) } @@ -94,11 +94,11 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { policyID == null, explainResponseOpenSearchPolicyIdSetting to fun(policyID: Any?): Boolean = policyID == null, - ManagedIndexMetaData.ENABLED to fun(enabled: Any?): Boolean = enabled == null - ) + ManagedIndexMetaData.ENABLED to fun(enabled: Any?): Boolean = enabled == null, + ), ), getExplainMap(index), - true + true, ) } } @@ -118,7 +118,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { assertPredicatesOnMetaData( listOf(index to listOf(ManagedIndexMetaData.POLICY_ID to policy.id::equals)), getExplainMap(index), - false + false, ) } @@ -148,7 +148,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -189,11 +189,11 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { indexName to listOf( ManagedIndexMetaData.INDEX to indexName::equals, ManagedIndexMetaData.POLICY_ID to policyID::equals, - ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString() - ) + ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString(), + ), ), getExplainMap(indexName), - false + false, ) } @@ -212,7 +212,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptRolloverStep.getSuccessMessage(indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } @@ -228,9 +228,9 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { State( name = "ForceMergeState", actions = listOf(forceMergeActionConfig), - transitions = listOf(Transition(stateName = "DeleteState", conditions = null)) + transitions = listOf(Transition(stateName = "DeleteState", conditions = null)), ), - State(name = "DeleteState", actions = listOf(deleteActionConfig), transitions = listOf()) + State(name = "DeleteState", actions = listOf(deleteActionConfig), transitions = listOf()), ) val policy = Policy( @@ -240,7 +240,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -252,7 +252,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { waitFor { assertTrue( "Segment count for [$indexName] was less than expected", - validateSegmentCount(indexName, min = 2) + validateSegmentCount(indexName, min = 2), ) } @@ -279,7 +279,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { assertEquals( "maxNumSegments not set in ActionProperties", forceMergeActionConfig.maxNumSegments, - getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.maxNumSegments + getExplainManagedIndexMetaData(indexName).actionMetaData?.actionProperties?.maxNumSegments, ) } @@ -293,7 +293,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForForceMergeStep.getSuccessMessage(indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -303,7 +303,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { // Validate segments were merged assertTrue( "Segment count for [$indexName] after force merge is incorrect", - validateSegmentCount(indexName, min = 1, max = 1) + validateSegmentCount(indexName, min = 1, max = 1), ) // Fifth execution: Attempt transition, which is safe to disable on, so job should be disabled @@ -313,7 +313,7 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( WaitForForceMergeStep.getSuccessMessage(indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } @@ -334,11 +334,11 @@ class ManagedIndexCoordinatorIT : IndexStateManagementRestTestCase() { indexName to listOf( ManagedIndexMetaData.INDEX to indexName::equals, ManagedIndexMetaData.POLICY_ID to policyID::equals, - ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString() - ) + ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString(), + ), ), getExplainMap(indexName), - false + false, ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorTests.kt index bce83125e..0c243e9ad 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/ManagedIndexCoordinatorTests.kt @@ -20,8 +20,8 @@ import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexCoordinator import org.opensearch.indexmanagement.indexstatemanagement.MetadataService -import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.migration.ISMTemplateService +import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.search.SearchModule import org.opensearch.test.ClusterServiceUtils import org.opensearch.test.OpenSearchTestCase @@ -78,7 +78,7 @@ class ManagedIndexCoordinatorTests : OpenSearchAllocationTestCase() { indexMetadataProvider = IndexMetadataProvider(settings, client, clusterService, mutableMapOf()) coordinator = ManagedIndexCoordinator( settings, client, clusterService, threadPool, indexManagementIndices, metadataService, - templateService, indexMetadataProvider, NamedXContentRegistry(SearchModule(Settings.EMPTY, emptyList()).namedXContents) + templateService, indexMetadataProvider, NamedXContentRegistry(SearchModule(Settings.EMPTY, emptyList()).namedXContents), ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt index 654a4fe5a..616785557 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt @@ -7,9 +7,9 @@ package org.opensearch.indexmanagement.indexstatemanagement.extension import org.junit.After import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser import org.opensearch.indexmanagement.opensearchapi.convertToMap import org.opensearch.indexmanagement.opensearchapi.string diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt index 64b80ad31..b3a6fb1ee 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt @@ -81,7 +81,7 @@ class SampleCustomActionParser : ActionParser() { return currentMetadata.copy( stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), transitionTo = null, - info = null + info = null, ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServicesIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServicesIT.kt index b082352fe..cc489a66e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServicesIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/migration/MigrationServicesIT.kt @@ -46,10 +46,10 @@ class MigrationServicesIT : IndexStateManagementRestTestCase() { listOf( indexName to listOf( ManagedIndexSettings.POLICY_ID.key to policyID2::equals, - LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID2::equals - ) + LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID2::equals, + ), ), - getExplainMap(indexName), false + getExplainMap(indexName), false, ) } } @@ -106,10 +106,10 @@ class MigrationServicesIT : IndexStateManagementRestTestCase() { listOf( indexName to listOf( ManagedIndexSettings.POLICY_ID.key to policyID1::equals, - LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID1::equals - ) + LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID1::equals, + ), ), - getExplainMap(indexName), false + getExplainMap(indexName), false, ) } } @@ -122,10 +122,10 @@ class MigrationServicesIT : IndexStateManagementRestTestCase() { listOf( indexName to listOf( ManagedIndexSettings.POLICY_ID.key to policyID2::equals, - LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID2::equals - ) + LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID2::equals, + ), ), - getExplainMap(indexName), false + getExplainMap(indexName), false, ) } } @@ -162,10 +162,10 @@ class MigrationServicesIT : IndexStateManagementRestTestCase() { listOf( indexName to listOf( ManagedIndexSettings.POLICY_ID.key to policyID1::equals, - LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID1::equals - ) + LegacyOpenDistroManagedIndexSettings.POLICY_ID.key to policyID1::equals, + ), ), - getExplainMap(indexName), false + getExplainMap(indexName), false, ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionPropertiesTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionPropertiesTests.kt index da7a55c88..f128bce28 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionPropertiesTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionPropertiesTests.kt @@ -17,7 +17,7 @@ class ActionPropertiesTests : OpenSearchTestCase() { // This is to catch any commits/PRs that add to ActionProperties but forget to add to history mappings val expected = createParser( XContentType.JSON.xContent(), - javaClass.classLoader.getResource("mappings/opendistro-ism-history.json")!!.readText() + javaClass.classLoader.getResource("mappings/opendistro-ism-history.json")!!.readText(), ) val expectedMap = expected.map() as Map>>>>>>> val actionProperties = ActionProperties.Properties.values().map { it.key } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionTests.kt index 070388cd9..ac1a6e84e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionTests.kt @@ -6,21 +6,21 @@ package org.opensearch.indexmanagement.indexstatemanagement.model import org.opensearch.cluster.routing.allocation.DiskThresholdSettings -import org.opensearch.core.common.io.stream.InputStreamStreamInput -import org.opensearch.core.common.io.stream.OutputStreamStreamOutput import org.opensearch.common.settings.ClusterSettings import org.opensearch.common.settings.Settings -import org.opensearch.core.common.unit.ByteSizeValue import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.common.io.stream.InputStreamStreamInput +import org.opensearch.core.common.io.stream.OutputStreamStreamOutput +import org.opensearch.core.common.unit.ByteSizeValue import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser import org.opensearch.indexmanagement.indexstatemanagement.action.DeleteAction import org.opensearch.indexmanagement.indexstatemanagement.action.NotificationAction import org.opensearch.indexmanagement.indexstatemanagement.randomAllocationActionConfig -import org.opensearch.indexmanagement.indexstatemanagement.randomChannel import org.opensearch.indexmanagement.indexstatemanagement.randomByteSizeValue +import org.opensearch.indexmanagement.indexstatemanagement.randomChannel import org.opensearch.indexmanagement.indexstatemanagement.randomCloseActionConfig import org.opensearch.indexmanagement.indexstatemanagement.randomDeleteActionConfig import org.opensearch.indexmanagement.indexstatemanagement.randomDestination @@ -141,8 +141,8 @@ class ActionTests : OpenSearchTestCase() { ( require = mapOf("box_type" to "hot"), include = mapOf(randomAlphaOfLengthBetween(1, 10) to randomAlphaOfLengthBetween(1, 10)), - exclude = mapOf(randomAlphaOfLengthBetween(1, 10) to randomAlphaOfLengthBetween(1, 10)) - ) + exclude = mapOf(randomAlphaOfLengthBetween(1, 10) to randomAlphaOfLengthBetween(1, 10)), + ), ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ConditionsTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ConditionsTests.kt index b3c0e6ebc..83a5bc49c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ConditionsTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ConditionsTests.kt @@ -16,7 +16,7 @@ class ConditionsTests : OpenSearchTestCase() { fun `test supplying more than one transition condition fails`() { assertFailsWith( IllegalArgumentException::class, - "Expected IllegalArgumentException for supplying multiple transition conditions" + "Expected IllegalArgumentException for supplying multiple transition conditions", ) { Conditions(indexAge = randomTimeValueObject(), size = randomByteSizeValue()) } @@ -25,7 +25,7 @@ class ConditionsTests : OpenSearchTestCase() { fun `test doc count condition of zero fails`() { assertFailsWith( IllegalArgumentException::class, - "Expected IllegalArgumentException for doc count condition less than 1" + "Expected IllegalArgumentException for doc count condition less than 1", ) { Conditions(docCount = 0) } @@ -34,7 +34,7 @@ class ConditionsTests : OpenSearchTestCase() { fun `test size condition of zero fails`() { assertFailsWith( IllegalArgumentException::class, - "Expected IllegalArgumentException for size condition less than 1" + "Expected IllegalArgumentException for size condition less than 1", ) { Conditions(size = ByteSizeValue.parseBytesSizeValue("0", "size_test")) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexMetaDataTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexMetaDataTests.kt index dc1810219..dace7203a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexMetaDataTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexMetaDataTests.kt @@ -36,7 +36,7 @@ class ManagedIndexMetaDataTests : OpenSearchTestCase() { actionMetaData = null, stepMetaData = null, policyRetryInfo = PolicyRetryInfoMetaData(false, 0), - info = mapOf("message" to "Successfully initialized policy: close_policy") + info = mapOf("message" to "Successfully initialized policy: close_policy"), ) roundTripManagedIndexMetaData(expectedManagedIndexMetaData) @@ -57,7 +57,7 @@ class ManagedIndexMetaDataTests : OpenSearchTestCase() { actionMetaData = ActionMetaData("close", 4321, 0, false, 0, 0, null), stepMetaData = null, policyRetryInfo = PolicyRetryInfoMetaData(false, 0), - info = mapOf("message" to "Successfully closed index") + info = mapOf("message" to "Successfully closed index"), ) roundTripManagedIndexMetaData(expectedManagedIndexMetaData) @@ -78,7 +78,7 @@ class ManagedIndexMetaDataTests : OpenSearchTestCase() { actionMetaData = ActionMetaData("close", 4321, 0, false, 0, 0, ActionProperties(3)), stepMetaData = null, policyRetryInfo = PolicyRetryInfoMetaData(false, 0), - info = mapOf("message" to "Successfully closed index") + info = mapOf("message" to "Successfully closed index"), ) roundTripManagedIndexMetaData(expectedManagedIndexMetaData) @@ -99,7 +99,7 @@ class ManagedIndexMetaDataTests : OpenSearchTestCase() { actionMetaData = ActionMetaData("rollover", 4321, 0, false, 0, 0, null), stepMetaData = StepMetaData("attempt_rollover", 6789, Step.StepStatus.FAILED), policyRetryInfo = PolicyRetryInfoMetaData(false, 0), - info = mapOf("message" to "There is no valid rollover_alias=null set on movies") + info = mapOf("message" to "There is no valid rollover_alias=null set on movies"), ) roundTripManagedIndexMetaData(expectedManagedIndexMetaData) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/XContentTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/XContentTests.kt index fda797fac..1d14a005e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/XContentTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/XContentTests.kt @@ -6,11 +6,11 @@ package org.opensearch.indexmanagement.indexstatemanagement.model import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.XContentParser import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.xcontent.XContentParser +import org.opensearch.indexmanagement.common.model.notification.Channel import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser import org.opensearch.indexmanagement.indexstatemanagement.action.RollupAction -import org.opensearch.indexmanagement.common.model.notification.Channel import org.opensearch.indexmanagement.indexstatemanagement.model.destination.DestinationType import org.opensearch.indexmanagement.indexstatemanagement.nonNullRandomConditions import org.opensearch.indexmanagement.indexstatemanagement.randomAliasAction @@ -142,21 +142,21 @@ class XContentTests : OpenSearchTestCase() { val chimeParsedNotificationAction = ISMActionsParser.instance.parse(parser(chimeNotificationActionString), 0) assertEquals( "Round tripping chime NotificationAction doesn't work", - chimeNotificationAction.convertToMap(), chimeParsedNotificationAction.convertToMap() + chimeNotificationAction.convertToMap(), chimeParsedNotificationAction.convertToMap(), ) val slackNotificationActionString = slackNotificationAction.toJsonString() val slackParsedNotificationAction = ISMActionsParser.instance.parse(parser(slackNotificationActionString), 0) assertEquals( "Round tripping slack NotificationAction doesn't work", - slackNotificationAction.convertToMap(), slackParsedNotificationAction.convertToMap() + slackNotificationAction.convertToMap(), slackParsedNotificationAction.convertToMap(), ) val customNotificationActionString = customNotificationAction.toJsonString() val customParsedNotificationAction = ISMActionsParser.instance.parse(parser(customNotificationActionString), 0) assertEquals( "Round tripping custom webhook NotificationAction doesn't work", - customNotificationAction.convertToMap(), customParsedNotificationAction.convertToMap() + customNotificationAction.convertToMap(), customParsedNotificationAction.convertToMap(), ) } @@ -167,7 +167,7 @@ class XContentTests : OpenSearchTestCase() { val parsedSnapshotAction = ISMActionsParser.instance.parse(parser(snapshotActionString), 0) assertEquals( "Round tripping SnapshotAction doesn't work", - snapshotAction.convertToMap(), parsedSnapshotAction.convertToMap() + snapshotAction.convertToMap(), parsedSnapshotAction.convertToMap(), ) } @@ -175,7 +175,7 @@ class XContentTests : OpenSearchTestCase() { val allocationAction = randomAllocationActionConfig( require = mapOf("box_type" to "hot"), include = mapOf(randomAlphaOfLengthBetween(1, 10) to randomAlphaOfLengthBetween(1, 10)), - exclude = mapOf(randomAlphaOfLengthBetween(1, 10) to randomAlphaOfLengthBetween(1, 10)) + exclude = mapOf(randomAlphaOfLengthBetween(1, 10) to randomAlphaOfLengthBetween(1, 10)), ) val allocationActionString = allocationAction.toJsonString() @@ -252,7 +252,7 @@ class XContentTests : OpenSearchTestCase() { actionMetaData = null, stepMetaData = null, policyRetryInfo = null, - info = null + info = null, ) val metadataString = metadata.toJsonString() val parsedMetaData = ManagedIndexMetaData.parse(parser(metadataString)) @@ -297,7 +297,7 @@ class XContentTests : OpenSearchTestCase() { val aliasAction = randomAliasAction(true) val aliasActionString = aliasAction.toJsonString() ISMActionsParser.instance.parse(parser(aliasActionString), 0) - } + }, ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/ISMTemplateRestAPIIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/ISMTemplateRestAPIIT.kt index 4fad90ebb..17d5c3c56 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/ISMTemplateRestAPIIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/ISMTemplateRestAPIIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.action.ReadOnlyAction import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate @@ -18,7 +19,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN import org.opensearch.indexmanagement.randomInstant import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.waitFor -import org.opensearch.core.rest.RestStatus import java.time.Instant import java.time.temporal.ChronoUnit import java.util.Locale @@ -91,7 +91,7 @@ class ISMTemplateRestAPIIT : IndexStateManagementRestTestCase() { val action = ReadOnlyAction(0) val states = listOf( - State("ReadOnlyState", listOf(action), listOf()) + State("ReadOnlyState", listOf(action), listOf()), ) val policy = Policy( id = policyID, @@ -101,7 +101,7 @@ class ISMTemplateRestAPIIT : IndexStateManagementRestTestCase() { errorNotification = randomErrorNotification(), defaultState = states[0].name, states = states, - ismTemplate = listOf(ismTemp) + ismTemplate = listOf(ismTemp), ) createPolicy(policy, policyID) @@ -121,11 +121,11 @@ class ISMTemplateRestAPIIT : IndexStateManagementRestTestCase() { indexName1 to listOf( explainResponseOpendistroPolicyIdSetting to fun(policyID: Any?): Boolean = policyID == null, explainResponseOpenSearchPolicyIdSetting to fun(policyID: Any?): Boolean = policyID == null, - ManagedIndexMetaData.ENABLED to fun(enabled: Any?): Boolean = enabled == null - ) + ManagedIndexMetaData.ENABLED to fun(enabled: Any?): Boolean = enabled == null, + ), ), getExplainMap(indexName1), - true + true, ) assertNull(getManagedIndexConfig(indexName1)) @@ -135,11 +135,11 @@ class ISMTemplateRestAPIIT : IndexStateManagementRestTestCase() { indexName1 to listOf( explainResponseOpendistroPolicyIdSetting to fun(policyID: Any?): Boolean = policyID == null, explainResponseOpenSearchPolicyIdSetting to fun(policyID: Any?): Boolean = policyID == null, - ManagedIndexMetaData.ENABLED to fun(enabled: Any?): Boolean = enabled == null - ) + ManagedIndexMetaData.ENABLED to fun(enabled: Any?): Boolean = enabled == null, + ), ), getExplainMap(indexName1), - true + true, ) assertNull(getManagedIndexConfig(indexName3)) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt index d72db8da7..c23b0c48a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt @@ -11,6 +11,7 @@ import org.opensearch.action.search.SearchResponse import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType import org.opensearch.common.xcontent.json.JsonXContent.jsonXContent +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.POLICY_BASE_URI import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser @@ -27,7 +28,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import org.opensearch.test.junit.annotations.TestLogging @@ -120,12 +120,12 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { // update the policy to have read_only action which is not allowed val updatedPolicy = policy.copy( defaultState = "some_state", - states = listOf(randomState(name = "some_state", actions = listOf(randomReadOnlyActionConfig()))) + states = listOf(randomState(name = "some_state", actions = listOf(randomReadOnlyActionConfig()))), ) client().makeRequest( "PUT", "$POLICY_BASE_URI/${updatedPolicy.id}?refresh=true&if_seq_no=${updatedPolicy.seqNo}&if_primary_term=${updatedPolicy.primaryTerm}", - emptyMap(), updatedPolicy.toHttpEntity() + emptyMap(), updatedPolicy.toHttpEntity(), ) fail("Expected 403 Method FORBIDDEN response") } catch (e: ResponseException) { @@ -154,7 +154,7 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { val mappingsMap = parserMap[INDEX_MANAGEMENT_INDEX]!!["mappings"] as Map val expected = createParser( XContentType.JSON.xContent(), - javaClass.classLoader.getResource("mappings/opendistro-ism-config.json").readText() + javaClass.classLoader.getResource("mappings/opendistro-ism-config.json").readText(), ) val expectedMap = expected.map() @@ -169,7 +169,7 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { client().makeRequest( "PUT", "$POLICY_BASE_URI/${policy.id}?refresh=true&if_seq_no=10251989&if_primary_term=2342", - emptyMap(), policy.toHttpEntity() + emptyMap(), policy.toHttpEntity(), ) fail("expected 409 ResponseException") } catch (e: ResponseException) { @@ -183,7 +183,7 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { val updateResponse = client().makeRequest( "PUT", "$POLICY_BASE_URI/${policy.id}?refresh=true&if_seq_no=${policy.seqNo}&if_primary_term=${policy.primaryTerm}", - emptyMap(), policy.toHttpEntity() + emptyMap(), policy.toHttpEntity(), ) assertEquals("Update policy failed", RestStatus.OK, updateResponse.restStatus()) @@ -267,7 +267,7 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { """.trimIndent() val response = client().makeRequest( "POST", "$INDEX_MANAGEMENT_INDEX/_search", emptyMap(), - StringEntity(request, APPLICATION_JSON) + StringEntity(request, APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val searchResponse = SearchResponse.fromXContent(createParser(jsonXContent, response.entity.content)) @@ -278,7 +278,7 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { val actualResponse = client().makeRequest(RestRequest.Method.GET.toString(), POLICY_BASE_URI).asMap() val expectedResponse = mapOf( "policies" to emptyList(), - "total_policies" to 0 + "total_policies" to 0, ) assertEquals(expectedResponse, actualResponse) } @@ -308,12 +308,12 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { mapOf( "name" to it.name, "transitions" to it.transitions, - "actions" to it.actions + "actions" to it.actions, ) - } - ) - ) - ) + }, + ), + ), + ), ) assertEquals(expectedMessage.toString(), actualMessage.toString()) @@ -346,12 +346,12 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { mapOf( "name" to it.name, "transitions" to it.transitions, - "actions" to it.actions + "actions" to it.actions, ) - } - ) - ) - ) + }, + ), + ), + ), ) assertEquals(expectedMessage.toString(), actualMessage.toString()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyActionIT.kt index 52ec82300..902ef4933 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyActionIT.kt @@ -11,6 +11,7 @@ import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.util.FAILED_INDICES @@ -20,7 +21,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.UPDATED_INDICES import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.waitFor import org.opensearch.rest.RestRequest.Method.POST -import org.opensearch.core.rest.RestStatus class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { @@ -34,12 +34,12 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices") + mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices"), ), "type" to "illegal_argument_exception", - "reason" to "Missing indices" + "reason" to "Missing indices", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -54,7 +54,7 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), "${RestAddPolicyAction.ADD_POLICY_BASE_URI}/$index", - StringEntity("{ \"policy_id\": \"${policy.id}\" }", APPLICATION_JSON) + StringEntity("{ \"policy_id\": \"${policy.id}\" }", APPLICATION_JSON), ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -65,9 +65,9 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to index, "index_uuid" to getUuid(index), - "reason" to "This index is closed" - ) - ) + "reason" to "This index is closed", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -81,7 +81,7 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), "${RestAddPolicyAction.ADD_POLICY_BASE_URI}/$index", - StringEntity("{ \"policy_id\": \"${policy.id}\" }", APPLICATION_JSON) + StringEntity("{ \"policy_id\": \"${policy.id}\" }", APPLICATION_JSON), ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -92,9 +92,9 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to index, "index_uuid" to getUuid(index), - "reason" to "This index already has a policy, use the update policy API to update index policies" - ) - ) + "reason" to "This index already has a policy, use the update policy API to update index policies", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -113,7 +113,7 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), "${RestAddPolicyAction.ADD_POLICY_BASE_URI}/$indexOne,$indexTwo", - StringEntity("{ \"policy_id\": \"${newPolicy.id}\" }", APPLICATION_JSON) + StringEntity("{ \"policy_id\": \"${newPolicy.id}\" }", APPLICATION_JSON), ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -124,14 +124,14 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexOne, "index_uuid" to getUuid(indexOne), - "reason" to "This index is closed" + "reason" to "This index is closed", ), mapOf( "index_name" to indexTwo, "index_uuid" to getUuid(indexTwo), - "reason" to "This index already has a policy, use the update policy API to update index policies" - ) - ) + "reason" to "This index already has a policy, use the update policy API to update index policies", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -153,7 +153,7 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), "${RestAddPolicyAction.ADD_POLICY_BASE_URI}/$indexPattern*", - StringEntity("{ \"policy_id\": \"${newPolicy.id}\" }", APPLICATION_JSON) + StringEntity("{ \"policy_id\": \"${newPolicy.id}\" }", APPLICATION_JSON), ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -164,14 +164,14 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexOne, "index_uuid" to getUuid(indexOne), - "reason" to "This index is closed" + "reason" to "This index is closed", ), mapOf( "index_name" to indexTwo, "index_uuid" to getUuid(indexTwo), - "reason" to "This index already has a policy, use the update policy API to update index policies" - ) - ) + "reason" to "This index already has a policy, use the update policy API to update index policies", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -198,7 +198,7 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), "${RestAddPolicyAction.ADD_POLICY_BASE_URI}/.*", - StringEntity("{ \"policy_id\": \"${policy.id}\" }", APPLICATION_JSON) + StringEntity("{ \"policy_id\": \"${policy.id}\" }", APPLICATION_JSON), ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -210,24 +210,24 @@ class RestAddPolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexOne, "index_uuid" to getUuidWithOutStrictChecking(indexOne), - "reason" to "Matches restricted index pattern defined in the cluster setting" + "reason" to "Matches restricted index pattern defined in the cluster setting", ), mapOf( "index_name" to indexTwo, "index_uuid" to getUuidWithOutStrictChecking(indexTwo), - "reason" to "Matches restricted index pattern defined in the cluster setting" + "reason" to "Matches restricted index pattern defined in the cluster setting", ), mapOf( "index_name" to indexThree, "index_uuid" to getUuidWithOutStrictChecking(indexThree), - "reason" to "Matches restricted index pattern defined in the cluster setting" + "reason" to "Matches restricted index pattern defined in the cluster setting", ), mapOf( "index_name" to IndexManagementPlugin.INDEX_MANAGEMENT_INDEX, "index_uuid" to getUuidWithOutStrictChecking(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX), - "reason" to "Matches restricted index pattern defined in the cluster setting" - ) - ) + "reason" to "Matches restricted index pattern defined in the cluster setting", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt index 17f96cda6..c7cafb343 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.junit.Before import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.action.DeleteAction @@ -33,7 +34,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedInde import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StateMetaData import org.opensearch.indexmanagement.waitFor import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import java.time.Instant import java.util.Locale @@ -59,12 +59,12 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "illegal_argument_exception", "reason" to "Missing index") + mapOf("type" to "illegal_argument_exception", "reason" to "Missing index"), ), "type" to "illegal_argument_exception", - "reason" to "Missing index" + "reason" to "Missing index", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -77,7 +77,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { createPolicy(policy, policy.id) client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/other_index", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/other_index", emptyMap(), changePolicy.toHttpEntity(), ) fail("Expected a failure.") } catch (e: ResponseException) { @@ -92,7 +92,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy("some_id", null, emptyList(), false) client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/other_index", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/other_index", emptyMap(), changePolicy.toHttpEntity(), ) fail("Expected a failure.") } catch (e: ResponseException) { @@ -107,17 +107,17 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { "index" to ".opendistro-ism-config", "resource.type" to "index_expression", "resource.id" to ".opendistro-ism-config", - "reason" to "no such index [.opendistro-ism-config]" - ) + "reason" to "no such index [.opendistro-ism-config]", + ), ), "type" to "index_not_found_exception", "index_uuid" to "_na_", "index" to ".opendistro-ism-config", "resource.type" to "index_expression", "resource.id" to ".opendistro-ism-config", - "reason" to "no such index [.opendistro-ism-config]" + "reason" to "no such index [.opendistro-ism-config]", ), - "status" to 404 + "status" to 404, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -129,7 +129,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(policy.id, null, emptyList(), false) client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/this_does_not_exist", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/this_does_not_exist", emptyMap(), changePolicy.toHttpEntity(), ) fail("Expected a failure.") } catch (e: ResponseException) { @@ -144,17 +144,17 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { "index" to "this_does_not_exist", "resource.type" to "index_or_alias", "resource.id" to "this_does_not_exist", - "reason" to "no such index [this_does_not_exist]" - ) + "reason" to "no such index [this_does_not_exist]", + ), ), "type" to "index_not_found_exception", "index_uuid" to "_na_", "index" to "this_does_not_exist", "resource.type" to "index_or_alias", "resource.id" to "this_does_not_exist", - "reason" to "no such index [this_does_not_exist]" + "reason" to "no such index [this_does_not_exist]", ), - "status" to 404 + "status" to 404, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -166,7 +166,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(policy.id, null, emptyList(), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/movies", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/movies", emptyMap(), changePolicy.toHttpEntity(), ) val expectedResponse = mapOf( FAILURES to true, @@ -174,10 +174,10 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to "movies", "index_uuid" to getUuid("movies"), - "reason" to INDEX_NOT_MANAGED - ) + "reason" to INDEX_NOT_MANAGED, + ), ), - UPDATED_INDICES to 0 + UPDATED_INDICES to 0, ) assertAffectedIndicesResponseIsEqual(expectedResponse, response.asMap()) } @@ -196,7 +196,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(newPolicy.id, null, emptyList(), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity(), ) assertAffectedIndicesResponseIsEqual(mapOf(FAILURES to false, FAILED_INDICES to emptyList(), UPDATED_INDICES to 1), response.asMap()) @@ -237,7 +237,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(newPolicy.id, null, emptyList(), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index,movi*", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index,movi*", emptyMap(), changePolicy.toHttpEntity(), ) val expectedResponse = mapOf( FAILURES to true, @@ -245,20 +245,20 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to "movies", "index_uuid" to getUuid("movies"), - "reason" to INDEX_NOT_MANAGED + "reason" to INDEX_NOT_MANAGED, ), mapOf( "index_name" to "movies_1", "index_uuid" to getUuid("movies_1"), - "reason" to INDEX_NOT_MANAGED + "reason" to INDEX_NOT_MANAGED, ), mapOf( "index_name" to "movies_2", "index_uuid" to getUuid("movies_2"), - "reason" to INDEX_NOT_MANAGED - ) + "reason" to INDEX_NOT_MANAGED, + ), ), - UPDATED_INDICES to 1 + UPDATED_INDICES to 1, ) assertAffectedIndicesResponseIsEqual(expectedResponse, response.asMap()) @@ -281,7 +281,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val stateWithDeleteAction = randomState(actions = listOf(DeleteAction(index = 0))) val updatedStateWithReadOnlyAction = stateWithReadOnlyAction.copy( actions = listOf(stateWithReadOnlyAction.actions.first(), OpenAction(index = 1)), - transitions = listOf(Transition(stateWithDeleteAction.name, null)) + transitions = listOf(Transition(stateWithDeleteAction.name, null)), ) val newPolicy = createPolicy(randomPolicy(states = listOf(updatedStateWithReadOnlyAction, stateWithDeleteAction)), "new_policy", true) val indexName = "${testIndexName}_mouse" @@ -290,7 +290,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { // Set index to read-write updateIndexSettings( index, - Settings.builder().put("index.blocks.write", false) + Settings.builder().put("index.blocks.write", false), ) val managedIndexConfig = getExistingManagedIndexConfig(index) @@ -324,22 +324,22 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { ManagedIndexMetaData.INDEX_UUID to executedManagedIndexConfig.indexUuid::equals, ManagedIndexMetaData.POLICY_ID to executedManagedIndexConfig.policyID::equals, StateMetaData.STATE to fun(stateMetaDataMap: Any?): Boolean = - assertStateEquals(StateMetaData(policy.defaultState, Instant.now().toEpochMilli()), stateMetaDataMap) - ) + assertStateEquals(StateMetaData(policy.defaultState, Instant.now().toEpochMilli()), stateMetaDataMap), + ), ), - explainResponseMap, false + explainResponseMap, false, ) } val changePolicy = ChangePolicy(newPolicy.id, null, emptyList(), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity(), ) val expectedResponse = mapOf( FAILURES to false, FAILED_INDICES to emptyList(), - UPDATED_INDICES to 1 + UPDATED_INDICES to 1, ) assertAffectedIndicesResponseIsEqual(expectedResponse, response.asMap()) @@ -374,13 +374,13 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { assertActionEquals( ActionMetaData( name = ReadOnlyAction.name, startTime = Instant.now().toEpochMilli(), index = 0, - failed = false, consumedRetries = 0, lastRetryTime = null, actionProperties = null + failed = false, consumedRetries = 0, lastRetryTime = null, actionProperties = null, ), - actionMetaDataMap - ) - ) + actionMetaDataMap, + ), + ), ), - getExplainMap(index), false + getExplainMap(index), false, ) } @@ -413,13 +413,13 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { assertActionEquals( ActionMetaData( name = TransitionsAction.name, startTime = Instant.now().toEpochMilli(), index = 0, - failed = false, consumedRetries = 0, lastRetryTime = null, actionProperties = null + failed = false, consumedRetries = 0, lastRetryTime = null, actionProperties = null, ), - actionMetaDataMap - ) - ) + actionMetaDataMap, + ), + ), ), - getExplainMap(index), false + getExplainMap(index), false, ) } } @@ -471,12 +471,12 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(newPolicy.id, null, listOf(StateFilter(state = firstState.name)), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$firstIndex,$secondIndex", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$firstIndex,$secondIndex", emptyMap(), changePolicy.toHttpEntity(), ) val expectedResponse = mapOf( FAILURES to false, FAILED_INDICES to emptyList(), - UPDATED_INDICES to 1 + UPDATED_INDICES to 1, ) // TODO flaky part, log for more info val responseMap = response.asMap() @@ -510,7 +510,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(newPolicy.id, "some_other_state", emptyList(), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity(), ) assertAffectedIndicesResponseIsEqual(mapOf(FAILURES to false, FAILED_INDICES to emptyList(), UPDATED_INDICES to 1), response.asMap()) @@ -541,10 +541,10 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { ManagedIndexMetaData.INDEX_UUID to updatedManagedIndexConfig.indexUuid::equals, ManagedIndexMetaData.POLICY_ID to newPolicy.id::equals, StateMetaData.STATE to fun(stateMetaDataMap: Any?): Boolean = - assertStateEquals(StateMetaData("some_other_state", Instant.now().toEpochMilli()), stateMetaDataMap) - ) + assertStateEquals(StateMetaData("some_other_state", Instant.now().toEpochMilli()), stateMetaDataMap), + ), ), - getExplainMap(index), false + getExplainMap(index), false, ) } } @@ -577,25 +577,25 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { assertEquals(RolloverAction.name, getExplainManagedIndexMetaData(indexName).actionMetaData?.name) assertEquals( AttemptRolloverStep.getPendingMessage(indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } val newStateWithReadOnlyAction = randomState( name = stateWithReadOnlyAction.name, - actions = listOf(RolloverAction(index = 0, minDocs = 5, minAge = null, minSize = null, minPrimaryShardSize = null)) + actions = listOf(RolloverAction(index = 0, minDocs = 5, minAge = null, minSize = null, minPrimaryShardSize = null)), ) val newRandomPolicy = randomPolicy(states = listOf(newStateWithReadOnlyAction)) val newPolicy = createPolicy(newRandomPolicy) val changePolicy = ChangePolicy(newPolicy.id, null, emptyList(), false) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$index", emptyMap(), changePolicy.toHttpEntity(), ) val expectedResponse = mapOf( FAILURES to false, FAILED_INDICES to emptyList(), - UPDATED_INDICES to 1 + UPDATED_INDICES to 1, ) assertAffectedIndicesResponseIsEqual(expectedResponse, response.asMap()) @@ -619,7 +619,7 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals( AttemptRolloverStep.getSuccessMessage(indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainActionIT.kt index c0842adbf..4bf4d2b14 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainActionIT.kt @@ -6,18 +6,14 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase -import org.opensearch.indexmanagement.indexstatemanagement.model.ChangePolicy -import org.opensearch.indexmanagement.makeRequest -import org.opensearch.indexmanagement.opensearchapi.toMap -import org.opensearch.indexmanagement.waitFor -import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.action.AllocationAction import org.opensearch.indexmanagement.indexstatemanagement.action.DeleteAction import org.opensearch.indexmanagement.indexstatemanagement.action.OpenAction import org.opensearch.indexmanagement.indexstatemanagement.action.ReadOnlyAction +import org.opensearch.indexmanagement.indexstatemanagement.model.ChangePolicy import org.opensearch.indexmanagement.indexstatemanagement.model.ExplainFilter import org.opensearch.indexmanagement.indexstatemanagement.model.Transition import org.opensearch.indexmanagement.indexstatemanagement.randomPolicy @@ -25,6 +21,8 @@ import org.opensearch.indexmanagement.indexstatemanagement.randomState import org.opensearch.indexmanagement.indexstatemanagement.util.SHOW_POLICY_QUERY_PARAM import org.opensearch.indexmanagement.indexstatemanagement.util.TOTAL_MANAGED_INDICES import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT_TYPE_AND_USER +import org.opensearch.indexmanagement.makeRequest +import org.opensearch.indexmanagement.opensearchapi.toMap import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionRetry @@ -32,6 +30,8 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedInde import org.opensearch.indexmanagement.spi.indexstatemanagement.model.PolicyRetryInfoMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StateMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData +import org.opensearch.indexmanagement.waitFor +import org.opensearch.rest.RestRequest import java.time.Instant import java.util.Locale @@ -47,8 +47,8 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { indexName to mapOf( explainResponseOpendistroPolicyIdSetting to null, explainResponseOpenSearchPolicyIdSetting to null, - ManagedIndexMetaData.ENABLED to null - ) + ManagedIndexMetaData.ENABLED to null, + ), ) assertResponseMap(expected, getExplainMap(indexName)) } @@ -57,7 +57,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { val indexName = "${testIndexName}_movies" createIndex(indexName, null) val expected = mapOf( - "total_managed_indices" to 0 + "total_managed_indices" to 0, ) assertResponseMap(expected, getExplainMap(null)) } @@ -78,13 +78,13 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName1, "index_uuid" to getUuid(indexName1), "policy_id" to policy.id, - ManagedIndexMetaData.ENABLED to true + ManagedIndexMetaData.ENABLED to true, ), indexName2 to mapOf( explainResponseOpendistroPolicyIdSetting to null, explainResponseOpenSearchPolicyIdSetting to null, - ManagedIndexMetaData.ENABLED to null - ) + ManagedIndexMetaData.ENABLED to null, + ), ) waitFor { assertResponseMap(expected, getExplainMap("$indexName1,$indexName2")) @@ -106,9 +106,9 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName1, "index_uuid" to getUuid(indexName1), "policy_id" to policy.id, - "enabled" to true + "enabled" to true, ), - "total_managed_indices" to 1 + "total_managed_indices" to 1, ) waitFor { assertResponseMap(expected, getExplainMap(null)) @@ -131,7 +131,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName1, "index_uuid" to getUuid(indexName1), "policy_id" to policy.id, - ManagedIndexMetaData.ENABLED to true + ManagedIndexMetaData.ENABLED to true, ), indexName2 to mapOf( explainResponseOpendistroPolicyIdSetting to policy.id, @@ -139,13 +139,13 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName2, "index_uuid" to getUuid(indexName2), "policy_id" to policy.id, - ManagedIndexMetaData.ENABLED to true + ManagedIndexMetaData.ENABLED to true, ), indexName3 to mapOf( explainResponseOpendistroPolicyIdSetting to null, explainResponseOpenSearchPolicyIdSetting to null, - ManagedIndexMetaData.ENABLED to null - ) + ManagedIndexMetaData.ENABLED to null, + ), ) waitFor { assertResponseMap(expected, getExplainMap("$indexName1*")) @@ -174,7 +174,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName1, "index_uuid" to getUuid(indexName1), "policy_id" to policy.id, - "enabled" to true + "enabled" to true, ) val indexName2Map = indexName2 to mapOf( explainResponseOpendistroPolicyIdSetting to policy.id, @@ -182,7 +182,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName2, "index_uuid" to getUuid(indexName2), "policy_id" to policy.id, - "enabled" to true + "enabled" to true, ) val indexName4Map = indexName4 to mapOf( explainResponseOpendistroPolicyIdSetting to policy.id, @@ -190,7 +190,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName4, "index_uuid" to getUuid(indexName4), "policy_id" to policy.id, - "enabled" to true + "enabled" to true, ) val indexName5Map = indexName5 to mapOf( explainResponseOpendistroPolicyIdSetting to policy.id, @@ -198,7 +198,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to indexName5, "index_uuid" to getUuid(indexName5), "policy_id" to policy.id, - "enabled" to true + "enabled" to true, ) val datastreamMap = ".ds-$dataStreamName-000001" to mapOf( explainResponseOpendistroPolicyIdSetting to policy.id, @@ -206,7 +206,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { "index" to ".ds-$dataStreamName-000001", "index_uuid" to getUuid(".ds-$dataStreamName-000001"), "policy_id" to policy.id, - "enabled" to true + "enabled" to true, ) waitFor { @@ -215,7 +215,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { indexName2Map, indexName4Map, indexName5Map, - "total_managed_indices" to 4 + "total_managed_indices" to 4, ) // These should match all non datastream managed indices assertResponseMap(expected, getExplainMap(indexName = null, queryParams = "queryString=$testIndexName*")) @@ -230,7 +230,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { indexName4Map, indexName5Map, datastreamMap, - "total_managed_indices" to 5 + "total_managed_indices" to 5, ) // These should match all managed indices including datastreams assertResponseMap(expected, getExplainMap(indexName = null, queryParams = "queryString=*$testIndexName-*")) @@ -241,7 +241,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { waitFor { val expected = mapOf( datastreamMap, - "total_managed_indices" to 1 + "total_managed_indices" to 1, ) // These should match all datastream managed indices (and system/hidden indices) assertResponseMap(expected, getExplainMap(indexName = null, queryParams = "queryString=.*")) @@ -251,7 +251,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { waitFor { val expected = mapOf( indexName4Map, - "total_managed_indices" to 1 + "total_managed_indices" to 1, ) // These should match all just the single index, and validates that it does not match the 15-02-2022 index // i.e. if it was still matching on tokens then ["2022", "02", "15"] would match both which we don't want @@ -286,15 +286,15 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { StateMetaData.STATE to fun(stateMetaDataMap: Any?): Boolean = assertStateEquals( StateMetaData(policy.defaultState, Instant.now().toEpochMilli()), - stateMetaDataMap + stateMetaDataMap, ), PolicyRetryInfoMetaData.RETRY_INFO to fun(retryInfoMetaDataMap: Any?): Boolean = assertRetryInfoEquals(PolicyRetryInfoMetaData(false, 0), retryInfoMetaDataMap), ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString(), - ManagedIndexMetaData.ENABLED to true::equals - ) + ManagedIndexMetaData.ENABLED to true::equals, + ), ), - getExplainMap(indexName) + getExplainMap(indexName), ) } } @@ -307,11 +307,11 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { val changePolicy = ChangePolicy(newPolicy.id, null, emptyList(), false) client().makeRequest( RestRequest.Method.POST.toString(), - "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$indexName", emptyMap(), changePolicy.toHttpEntity() + "${RestChangePolicyAction.CHANGE_POLICY_BASE_URI}/$indexName", emptyMap(), changePolicy.toHttpEntity(), ) val deletePolicyResponse = client().makeRequest( RestRequest.Method.DELETE.toString(), - "${IndexManagementPlugin.LEGACY_POLICY_BASE_URI}/${changePolicy.policyID}" + "${IndexManagementPlugin.LEGACY_POLICY_BASE_URI}/${changePolicy.policyID}", ) assertEquals("Unexpected RestStatus", RestStatus.OK, deletePolicyResponse.restStatus()) @@ -335,10 +335,10 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { assertRetryInfoEquals(PolicyRetryInfoMetaData(true, 0), retryInfoMetaDataMap), ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString(), ManagedIndexMetaData.INDEX_CREATION_DATE to fun(indexCreationDate: Any?): Boolean = (indexCreationDate as Long) > 1L, - ManagedIndexMetaData.ENABLED to true::equals - ) + ManagedIndexMetaData.ENABLED to true::equals, + ), ), - explainMap + explainMap, ) } } @@ -377,7 +377,7 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { val stateWithDeleteAction = randomState(actions = listOf(DeleteAction(index = 0))) val updatedStateWithReadOnlyAction = stateWithReadOnlyAction.copy( actions = listOf(stateWithReadOnlyAction.actions.first(), OpenAction(index = 1)), - transitions = listOf(Transition(stateWithDeleteAction.name, null)) + transitions = listOf(Transition(stateWithDeleteAction.name, null)), ) val policy2 = createPolicy(randomPolicy(states = listOf(stateWithDeleteAction, updatedStateWithReadOnlyAction))) @@ -411,18 +411,18 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { ManagedIndexMetaData.INDEX_CREATION_DATE to fun(indexCreationDate: Any?): Boolean = (indexCreationDate as Long) > 1L, StateMetaData.STATE to fun(stateMetaDataMap: Any?): Boolean = assertStateEquals( StateMetaData(policy1.defaultState, Instant.now().toEpochMilli()), - stateMetaDataMap + stateMetaDataMap, ), ActionMetaData.ACTION to fun(actionMetaDataMap: Any?): Boolean = assertActionEquals( ActionMetaData( name = "read_only", startTime = Instant.now().toEpochMilli(), failed = false, - index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null + index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null, ), - actionMetaDataMap + actionMetaDataMap, ), PolicyRetryInfoMetaData.RETRY_INFO to fun(retryInfoMetaDataMap: Any?): Boolean = assertRetryInfoEquals(PolicyRetryInfoMetaData(false, 0), retryInfoMetaDataMap), - ManagedIndexMetaData.ENABLED to true::equals + ManagedIndexMetaData.ENABLED to true::equals, ) val index2Predicates = indexName2 to listOf( @@ -436,18 +436,18 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { ManagedIndexMetaData.INDEX_CREATION_DATE to fun(indexCreationDate: Any?): Boolean = (indexCreationDate as Long) > 1L, StateMetaData.STATE to fun(stateMetaDataMap: Any?): Boolean = assertStateEquals( StateMetaData(policy2.defaultState, Instant.now().toEpochMilli()), - stateMetaDataMap + stateMetaDataMap, ), ActionMetaData.ACTION to fun(actionMetaDataMap: Any?): Boolean = assertActionEquals( ActionMetaData( name = "delete", startTime = Instant.now().toEpochMilli(), failed = false, - index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null + index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null, ), - actionMetaDataMap + actionMetaDataMap, ), PolicyRetryInfoMetaData.RETRY_INFO to fun(retryInfoMetaDataMap: Any?): Boolean = assertRetryInfoEquals(PolicyRetryInfoMetaData(false, 0), retryInfoMetaDataMap), - ManagedIndexMetaData.ENABLED to true::equals + ManagedIndexMetaData.ENABLED to true::equals, ) // check metadata for result from filtering on the first policy and its state @@ -455,19 +455,19 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { val filterPolicy = ExplainFilter( policyID = policy1.id, state = policy1.states[0].name, - failed = false + failed = false, ) val resp = client().makeRequest( RestRequest.Method.POST.toString(), - RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), filterPolicy.toHttpEntity() + RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), filterPolicy.toHttpEntity(), ) assertEquals("Unexpected RestStatus", RestStatus.OK, resp.restStatus()) assertPredicatesOnMetaData( listOf(index1Predicates), - resp.asMap(), false + resp.asMap(), false, ) } @@ -480,21 +480,21 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { waitFor { val filterPolicy = ExplainFilter( actionType = "delete", - failed = false + failed = false, ) val resp = client().makeRequest( RestRequest.Method.POST.toString(), - RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), filterPolicy.toHttpEntity() + RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), filterPolicy.toHttpEntity(), ) assertEquals("Unexpected RestStatus", RestStatus.OK, resp.restStatus()) assertPredicatesOnMetaData( listOf( - index2Predicates + index2Predicates, ), - resp.asMap(), false + resp.asMap(), false, ) } @@ -515,12 +515,12 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { val states = listOf( randomState().copy( transitions = listOf(), - actions = listOf(config) - ) + actions = listOf(config), + ), ) val invalidPolicy = randomPolicy().copy( states = states, - defaultState = states[0].name + defaultState = states[0].name, ) // for successful index @@ -545,12 +545,12 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { updateManagedIndexConfigStartTime(managedIndexConfig1) waitFor { val explainFilter = ExplainFilter( - failed = true + failed = true, ) val resp = client().makeRequest( RestRequest.Method.POST.toString(), - RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), explainFilter.toHttpEntity() + RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), explainFilter.toHttpEntity(), ) assertEquals("Unexpected RestStatus", RestStatus.OK, resp.restStatus()) @@ -566,24 +566,24 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { ManagedIndexMetaData.INDEX_CREATION_DATE to fun(indexCreationDate: Any?): Boolean = (indexCreationDate as Long) > 1L, StepMetaData.STEP to fun(stepMetaDataMap: Any?): Boolean = assertStepEquals( StepMetaData("attempt_allocation", Instant.now().toEpochMilli(), Step.StepStatus.FAILED), - stepMetaDataMap + stepMetaDataMap, ), - ManagedIndexMetaData.ENABLED to true::equals - ) + ManagedIndexMetaData.ENABLED to true::equals, + ), ), - resp.asMap(), false + resp.asMap(), false, ) } updateManagedIndexConfigStartTime(managedIndexConfig2) waitFor { val explainFilter = ExplainFilter( - failed = false + failed = false, ) val resp = client().makeRequest( RestRequest.Method.POST.toString(), - RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), explainFilter.toHttpEntity() + RestExplainAction.EXPLAIN_BASE_URI, emptyMap(), explainFilter.toHttpEntity(), ) assertEquals("Unexpected RestStatus", RestStatus.OK, resp.restStatus()) @@ -599,12 +599,12 @@ class RestExplainActionIT : IndexStateManagementRestTestCase() { ManagedIndexMetaData.INDEX_CREATION_DATE to fun(indexCreationDate: Any?): Boolean = (indexCreationDate as Long) > 1L, StepMetaData.STEP to fun(stepMetaDataMap: Any?): Boolean = assertStepEquals( StepMetaData("set_read_only", Instant.now().toEpochMilli(), Step.StepStatus.STARTING), - stepMetaDataMap + stepMetaDataMap, ), - ManagedIndexMetaData.ENABLED to true::equals - ) + ManagedIndexMetaData.ENABLED to true::equals, + ), ), - resp.asMap(), false + resp.asMap(), false, ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyActionIT.kt index 4449049e3..83c8ac272 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyActionIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.opensearch.client.ResponseException import org.opensearch.cluster.metadata.IndexMetadata +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.util.FAILED_INDICES @@ -15,7 +16,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.UPDATED_INDICES import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.waitFor import org.opensearch.rest.RestRequest.Method.POST -import org.opensearch.core.rest.RestStatus class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { @@ -29,12 +29,12 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices") + mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices"), ), "type" to "illegal_argument_exception", - "reason" to "Missing indices" + "reason" to "Missing indices", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -48,7 +48,7 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), - "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$index" + "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$index", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -59,9 +59,9 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to index, "index_uuid" to getUuid(index), - "reason" to "This index is closed" - ) - ) + "reason" to "This index is closed", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -74,7 +74,7 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), - "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$index" + "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$index", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -85,9 +85,9 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to index, "index_uuid" to getUuid(index), - "reason" to "This index does not have a policy to remove" - ) - ) + "reason" to "This index does not have a policy to remove", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -104,7 +104,7 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), - "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$indexOne,$indexTwo" + "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$indexOne,$indexTwo", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -115,14 +115,14 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexOne, "index_uuid" to getUuid(indexOne), - "reason" to "This index is closed" + "reason" to "This index is closed", ), mapOf( "index_name" to indexTwo, "index_uuid" to getUuid(indexTwo), - "reason" to "This index does not have a policy to remove" - ) - ) + "reason" to "This index does not have a policy to remove", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -142,7 +142,7 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), - "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$indexPattern*" + "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$indexPattern*", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -153,14 +153,14 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexOne, "index_uuid" to getUuid(indexOne), - "reason" to "This index is closed" + "reason" to "This index is closed", ), mapOf( "index_name" to indexTwo, "index_uuid" to getUuid(indexTwo), - "reason" to "This index does not have a policy to remove" - ) - ) + "reason" to "This index does not have a policy to remove", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) @@ -188,14 +188,14 @@ class RestRemovePolicyActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( POST.toString(), - "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$indexPattern" + "${RestRemovePolicyAction.REMOVE_POLICY_BASE_URI}/$indexPattern", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() val expectedMessage = mapOf( UPDATED_INDICES to 4, FAILURES to false, - FAILED_INDICES to emptyList() + FAILED_INDICES to emptyList(), ) assertAffectedIndicesResponseIsEqual(expectedMessage, actualMessage) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt index 4425e5ffd..76ace7123 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt @@ -6,11 +6,13 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.action.AllocationAction import org.opensearch.indexmanagement.indexstatemanagement.randomForceMergeActionConfig import org.opensearch.indexmanagement.indexstatemanagement.randomPolicy import org.opensearch.indexmanagement.indexstatemanagement.randomState +import org.opensearch.indexmanagement.indexstatemanagement.step.forcemerge.AttemptSetReadOnlyStep import org.opensearch.indexmanagement.indexstatemanagement.util.FAILED_INDICES import org.opensearch.indexmanagement.indexstatemanagement.util.FAILURES import org.opensearch.indexmanagement.indexstatemanagement.util.UPDATED_INDICES @@ -21,8 +23,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionRetry import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.waitFor import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus -import org.opensearch.indexmanagement.indexstatemanagement.step.forcemerge.AttemptSetReadOnlyStep import java.time.Instant import java.util.Locale @@ -40,12 +40,12 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices") + mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices"), ), "type" to "illegal_argument_exception", - "reason" to "Missing indices" + "reason" to "Missing indices", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -64,7 +64,7 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName,$indexName1" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName,$indexName1", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -75,14 +75,14 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexName, "index_uuid" to getUuid(indexName), - "reason" to "This index is not being managed." + "reason" to "This index is not being managed.", ), mapOf( "index_name" to indexName1, "index_uuid" to getUuid(indexName1), - "reason" to "This index has no metadata information" - ) - ) + "reason" to "This index has no metadata information", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedErrorMessage, actualMessage) } @@ -100,7 +100,7 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName*" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName*", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) @@ -112,19 +112,19 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexName, "index_uuid" to getUuid(indexName), - "reason" to "This index is not being managed." + "reason" to "This index is not being managed.", ), mapOf( "index_name" to indexName1, "index_uuid" to getUuid(indexName1), - "reason" to "This index is not being managed." + "reason" to "This index is not being managed.", ), mapOf( "index_name" to indexName2, "index_uuid" to getUuid(indexName2), - "reason" to "This index has no metadata information" - ) - ) + "reason" to "This index has no metadata information", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedErrorMessage, actualMessage) } @@ -134,7 +134,7 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { createIndex(indexName, null) val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -145,9 +145,9 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexName, "index_uuid" to getUuid(indexName), - "reason" to "This index is not being managed." - ) - ) + "reason" to "This index is not being managed.", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedErrorMessage, actualMessage) } @@ -159,7 +159,7 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -170,9 +170,9 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexName, "index_uuid" to getUuid(indexName), - "reason" to "This index has no metadata information" - ) - ) + "reason" to "This index has no metadata information", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedErrorMessage, actualMessage) } @@ -189,7 +189,7 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { waitFor { val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() @@ -200,9 +200,9 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { mapOf( "index_name" to indexName, "index_uuid" to getUuid(indexName), - "reason" to "This index is not in failed state." - ) - ) + "reason" to "This index is not in failed state.", + ), + ), ) assertAffectedIndicesResponseIsEqual(expectedErrorMessage, actualMessage) } @@ -215,12 +215,12 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { val states = listOf( randomState().copy( transitions = listOf(), - actions = listOf(config) - ) + actions = listOf(config), + ), ) val invalidPolicy = randomPolicy().copy( states = states, - defaultState = states[0].name + defaultState = states[0].name, ) createPolicy(invalidPolicy, invalidPolicy.id) createIndex(indexName, invalidPolicy.id) @@ -239,14 +239,14 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { waitFor { val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val actualMessage = response.asMap() val expectedErrorMessage = mapOf( UPDATED_INDICES to 1, FAILURES to false, - FAILED_INDICES to emptyList>() + FAILED_INDICES to emptyList>(), ) assertAffectedIndicesResponseIsEqual(expectedErrorMessage, actualMessage) } @@ -280,13 +280,13 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { ActionMetaData.ACTION to fun(actionMetaDataMap: Any?): Boolean = assertActionEquals( ActionMetaData( name = "force_merge", startTime = Instant.now().toEpochMilli(), failed = false, - index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null + index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null, ), - actionMetaDataMap - ) - ) + actionMetaDataMap, + ), + ), ), - explainMap, false + explainMap, false, ) } @@ -308,27 +308,27 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { return assertActionEquals( ActionMetaData( name = "force_merge", startTime = Instant.now().toEpochMilli(), failed = true, - index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null + index = 0, consumedRetries = 0, lastRetryTime = null, actionProperties = null, ), - actionMetaDataMap + actionMetaDataMap, ) - } - ) + }, + ), ), - getExplainMap(indexName), false + getExplainMap(indexName), false, ) } // retry val response = client().makeRequest( RestRequest.Method.POST.toString(), - "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName" + "${RestRetryFailedManagedIndexAction.RETRY_BASE_URI}/$indexName", ) assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) val expectedErrorMessage = mapOf( UPDATED_INDICES to 1, FAILURES to false, - FAILED_INDICES to emptyList>() + FAILED_INDICES to emptyList>(), ) assertAffectedIndicesResponseIsEqual(expectedErrorMessage, response.asMap()) // verify actionStartTime was reset to null @@ -339,10 +339,10 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { @Suppress("UNCHECKED_CAST") actionMetaDataMap as Map return actionMetaDataMap[ManagedIndexMetaData.START_TIME] as Long? == null - } - ) + }, + ), ), - getExplainMap(indexName), false + getExplainMap(indexName), false, ) // should execute and set the startTime again @@ -356,14 +356,14 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { @Suppress("UNCHECKED_CAST") actionMetaDataMap as Map return actionMetaDataMap[ManagedIndexMetaData.START_TIME] as Long > firstStartTime - } - ) + }, + ), ), - getExplainMap(indexName), false + getExplainMap(indexName), false, ) assertEquals( AttemptSetReadOnlyStep.getSuccessMessage(indexName), - getExplainManagedIndexMetaData(indexName).info?.get("message") + getExplainManagedIndexMetaData(indexName).info?.get("message"), ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/runner/ManagedIndexRunnerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/runner/ManagedIndexRunnerIT.kt index 38d013232..e364af491 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/runner/ManagedIndexRunnerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/runner/ManagedIndexRunnerIT.kt @@ -43,7 +43,7 @@ class ManagedIndexRunnerIT : IndexStateManagementRestTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) createPolicy(policy, policyID) @@ -69,11 +69,11 @@ class ManagedIndexRunnerIT : IndexStateManagementRestTestCase() { indexName to listOf( PolicyRetryInfoMetaData.RETRY_INFO to fun(retryInfoMetaDataMap: Any?): Boolean = assertRetryInfoEquals(PolicyRetryInfoMetaData(true, 0), retryInfoMetaDataMap), - ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString() - ) + ManagedIndexMetaData.INFO to fun(info: Any?): Boolean = expectedInfoString == info.toString(), + ), ), getExplainMap(indexName), - strict = false + strict = false, ) } } @@ -88,7 +88,7 @@ class ManagedIndexRunnerIT : IndexStateManagementRestTestCase() { assertEquals( "Created managed index did not default to ${ManagedIndexSettings.DEFAULT_JOB_INTERVAL} minutes", - ManagedIndexSettings.DEFAULT_JOB_INTERVAL, (managedIndexConfig.jobSchedule as IntervalSchedule).interval + ManagedIndexSettings.DEFAULT_JOB_INTERVAL, (managedIndexConfig.jobSchedule as IntervalSchedule).interval, ) // init policy @@ -118,7 +118,7 @@ class ManagedIndexRunnerIT : IndexStateManagementRestTestCase() { assertEquals( "New managed index did not have updated job schedule interval", - newJobInterval, (newManagedIndexConfig.jobSchedule as IntervalSchedule).interval + newJobInterval, (newManagedIndexConfig.jobSchedule as IntervalSchedule).interval, ) // init new policy @@ -135,11 +135,11 @@ class ManagedIndexRunnerIT : IndexStateManagementRestTestCase() { val firstState = randomState( name = "first_state", actions = listOf(randomReadOnlyActionConfig()), - transitions = listOf(randomTransition(stateName = "second_state", conditions = null)) + transitions = listOf(randomTransition(stateName = "second_state", conditions = null)), ) val secondState = randomState( name = "second_state", actions = listOf(randomReadWriteActionConfig()), - transitions = listOf(randomTransition(stateName = "first_state", conditions = null)) + transitions = listOf(randomTransition(stateName = "first_state", conditions = null)), ) val randomPolicy = randomPolicy(id = "allow_policy", states = listOf(firstState, secondState)) @@ -187,7 +187,7 @@ class ManagedIndexRunnerIT : IndexStateManagementRestTestCase() { val managedIndexConfig = getExistingManagedIndexConfig(indexName) assertEquals( - "Created managed index did not default to 0.0", 0.0, managedIndexConfig.jitter + "Created managed index did not default to 0.0", 0.0, managedIndexConfig.jitter, ) waitFor { @@ -207,7 +207,7 @@ class ManagedIndexRunnerIT : IndexStateManagementRestTestCase() { val newManagedIndexConfig = getExistingManagedIndexConfig(newIndexName) assertEquals( - "New managed index did not have updated jitter", newJitter, newManagedIndexConfig.jitter + "New managed index did not have updated jitter", newJitter, newManagedIndexConfig.jitter, ) waitFor { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt index 68af07ac0..657284e61 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt @@ -11,13 +11,13 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.close.CloseIndexResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.step.close.AttemptCloseStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -128,8 +128,11 @@ class AttemptCloseStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (closeIndexResponse != null) listener.onResponse(closeIndexResponse) - else listener.onFailure(exception) + if (closeIndexResponse != null) { + listener.onResponse(closeIndexResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).close(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateRollupJobStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateRollupJobStepTests.kt index f41eca7c3..33b97fb7a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateRollupJobStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateRollupJobStepTests.kt @@ -20,7 +20,7 @@ class AttemptCreateRollupJobStepTests : OpenSearchTestCase() { private val rollupId: String = rollupAction.ismRollup.toRollup(indexName).id private val metadata = ManagedIndexMetaData( indexName, "indexUuid", "policy_id", null, null, null, null, null, null, null, - ActionMetaData(AttemptCreateRollupJobStep.name, 1, 0, false, 0, null, ActionProperties(rollupId = rollupId)), null, null, null + ActionMetaData(AttemptCreateRollupJobStep.name, 1, 0, false, 0, null, ActionProperties(rollupId = rollupId)), null, null, null, ) private val step = AttemptCreateRollupJobStep(rollupAction) @@ -31,7 +31,7 @@ class AttemptCreateRollupJobStepTests : OpenSearchTestCase() { assertEquals( "Error message is not expected", AttemptCreateRollupJobStep.getFailedMessage(rollupId, indexName), - updatedManagedIndexMetaData.info?.get("message") + updatedManagedIndexMetaData.info?.get("message"), ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateTransformJobStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateTransformJobStepTests.kt index 02945979e..14fc920a5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateTransformJobStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCreateTransformJobStepTests.kt @@ -32,11 +32,11 @@ class AttemptCreateTransformJobStepTests : OpenSearchTestCase() { null, ActionMetaData( AttemptCreateTransformJobStep.name, 1, 0, false, 0, null, - ActionProperties(transformActionProperties = TransformActionProperties(transformId)) + ActionProperties(transformActionProperties = TransformActionProperties(transformId)), ), null, null, - null + null, ) private val step = AttemptCreateTransformJobStep(transformAction) @@ -46,16 +46,16 @@ class AttemptCreateTransformJobStepTests : OpenSearchTestCase() { assertEquals( "Step status is not FAILED", Step.StepStatus.FAILED, - updatedManagedIndexMedaData.stepMetaData?.stepStatus + updatedManagedIndexMedaData.stepMetaData?.stepStatus, ) assertEquals( "Error message is not expected", AttemptCreateTransformJobStep.getFailedMessage(transformId, indexName), - updatedManagedIndexMedaData.info?.get("message") + updatedManagedIndexMedaData.info?.get("message"), ) assertNull( "TransformId in action properties is not cleaned up", - updatedManagedIndexMedaData.actionMetaData?.actionProperties?.transformActionProperties?.transformId + updatedManagedIndexMedaData.actionMetaData?.actionProperties?.transformActionProperties?.transformId, ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt index 4748e2107..7574d89fa 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt @@ -11,13 +11,13 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.mockito.Mockito.doAnswer -import org.opensearch.core.action.ActionListener import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.step.delete.AttemptDeleteStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -98,8 +98,11 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (acknowledgedResponse != null) listener.onResponse(acknowledgedResponse) - else listener.onFailure(exception) + if (acknowledgedResponse != null) { + listener.onResponse(acknowledgedResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).delete(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt index c7996be55..c421e3be6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt @@ -11,13 +11,13 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.open.OpenIndexResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.step.open.AttemptOpenStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -84,8 +84,11 @@ class AttemptOpenStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (openIndexResponse != null) listener.onResponse(openIndexResponse) - else listener.onFailure(exception) + if (openIndexResponse != null) { + listener.onResponse(openIndexResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).open(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt index 5c4beea89..056030162 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt @@ -12,7 +12,6 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.rollover.RolloverResponse import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient @@ -20,9 +19,13 @@ import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.ClusterState import org.opensearch.cluster.metadata.IndexMetadata +import org.opensearch.cluster.metadata.Metadata import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener +import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.indexstatemanagement.action.RolloverAction +import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.AttemptRolloverStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -30,9 +33,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService import org.opensearch.test.OpenSearchTestCase -import org.opensearch.cluster.metadata.Metadata -import org.opensearch.index.IndexNotFoundException -import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings class AttemptRolloverStepTests : OpenSearchTestCase() { @@ -78,7 +78,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { null, null, null, null, null, null, null, null, null, - null, null, rolledOverIndexName = newIndexName + null, null, rolledOverIndexName = newIndexName, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) @@ -102,7 +102,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { null, null, null, null, null, null, null, null, null, - null, null, rolledOverIndexName = newIndexName + null, null, rolledOverIndexName = newIndexName, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) @@ -126,7 +126,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { null, null, null, null, null, null, null, null, null, - null, null, rolledOverIndexName = newIndexName + null, null, rolledOverIndexName = newIndexName, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) @@ -150,7 +150,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { null, null, null, null, null, null, null, null, null, - null, null, rolledOverIndexName = null + null, null, rolledOverIndexName = null, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) @@ -171,23 +171,29 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ): IndicesAdminClient { assertTrue( "Must provide one and only one response or exception", - (rolloverResponse != null).xor(rolloverException != null) + (rolloverResponse != null).xor(rolloverException != null), ) assertTrue( "Must provide one and only one response or exception", - (aliasResponse != null).xor(aliasException != null) + (aliasResponse != null).xor(aliasException != null), ) return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (rolloverResponse != null) listener.onResponse(rolloverResponse) - else listener.onFailure(rolloverException) + if (rolloverResponse != null) { + listener.onResponse(rolloverResponse) + } else { + listener.onFailure(rolloverException) + } }.whenever(this.mock).rolloverIndex(any(), any()) doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (aliasResponse != null) listener.onResponse(aliasResponse) - else listener.onFailure(aliasException) + if (aliasResponse != null) { + listener.onResponse(aliasResponse) + } else { + listener.onFailure(aliasException) + } }.whenever(this.mock).aliases(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt index 4a4e33ae9..4397b685f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt @@ -11,13 +11,13 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.opensearch.core.action.ActionListener import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.action.IndexPriorityAction import org.opensearch.indexmanagement.indexstatemanagement.step.indexpriority.AttemptSetIndexPriorityStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -105,8 +105,11 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (acknowledgedResponse != null) listener.onResponse(acknowledgedResponse) - else listener.onFailure(exception) + if (acknowledgedResponse != null) { + listener.onResponse(acknowledgedResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).updateSettings(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt index 9256c5a83..093500a54 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt @@ -11,13 +11,13 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.mockito.Mockito.doAnswer -import org.opensearch.core.action.ActionListener import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.action.ReplicaCountAction import org.opensearch.indexmanagement.indexstatemanagement.step.replicacount.AttemptReplicaCountStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -88,8 +88,11 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (replicaResponse != null) listener.onResponse(replicaResponse) - else listener.onFailure(exception) + if (replicaResponse != null) { + listener.onResponse(replicaResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).updateSettings(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt index 646f64964..27a17032c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt @@ -13,7 +13,6 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -21,6 +20,8 @@ import org.opensearch.client.ClusterAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.ClusterSettings import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.randomSnapshotActionConfig import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.SNAPSHOT_DENY_LIST import org.opensearch.indexmanagement.indexstatemanagement.step.snapshot.AttemptSnapshotStep @@ -31,7 +32,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedInde import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.ingest.TestTemplateService.MockTemplateScript import org.opensearch.jobscheduler.spi.utils.LockService -import org.opensearch.core.rest.RestStatus import org.opensearch.script.ScriptService import org.opensearch.script.TemplateScript import org.opensearch.snapshots.ConcurrentSnapshotExecutionException @@ -144,8 +144,11 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (createSnapshotRequest != null) listener.onResponse(createSnapshotRequest) - else listener.onFailure(exception) + if (createSnapshotRequest != null) { + listener.onResponse(createSnapshotRequest) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).createSnapshot(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt index 158cc8d18..135f09faa 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt @@ -12,7 +12,6 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.rollover.RolloverInfo import org.opensearch.action.admin.indices.stats.CommonStats import org.opensearch.action.admin.indices.stats.IndicesStatsResponse @@ -25,6 +24,8 @@ import org.opensearch.cluster.metadata.Metadata import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.ClusterSettings import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener +import org.opensearch.core.rest.RestStatus import org.opensearch.index.shard.DocsStats import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider import org.opensearch.indexmanagement.indexstatemanagement.action.TransitionsAction @@ -37,7 +38,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedInde import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.jobscheduler.spi.utils.LockService -import org.opensearch.core.rest.RestStatus import org.opensearch.script.ScriptService import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException @@ -47,6 +47,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { private val indexName: String = "test" private val indexUUID: String = "indexUuid" + @Suppress("UNCHECKED_CAST") private val indexMetadata: IndexMetadata = mock { on { rolloverInfos } doReturn mapOf() @@ -148,8 +149,11 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (statsResponse != null) listener.onResponse(statsResponse) - else listener.onFailure(exception) + if (statsResponse != null) { + listener.onResponse(statsResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).stats(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt index f46d142b3..cbfafc407 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt @@ -11,13 +11,13 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.opensearch.core.action.ActionListener import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.step.readonly.SetReadOnlyStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -84,8 +84,11 @@ class SetReadOnlyStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (setReadOnlyResponse != null) listener.onResponse(setReadOnlyResponse) - else listener.onFailure(exception) + if (setReadOnlyResponse != null) { + listener.onResponse(setReadOnlyResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).updateSettings(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt index f42f92c82..2750a758a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt @@ -11,13 +11,13 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.opensearch.core.action.ActionListener import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.step.readwrite.SetReadWriteStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -84,8 +84,11 @@ class SetReadWriteStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (setReadWriteResponse != null) listener.onResponse(setReadWriteResponse) - else listener.onFailure(exception) + if (setReadWriteResponse != null) { + listener.onResponse(setReadWriteResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).updateSettings(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt index b769d42e2..f89b01107 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt @@ -34,11 +34,11 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { indexName, "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData (WaitForRollupCompletionStep.name, 1, 0, false, 0, null, ActionProperties(rollupId = rollupId)), - null, null, null + null, null, null, ) private val rollupMetadata = RollupMetadata( rollupID = rollupId, lastUpdatedTime = Instant.now(), status = RollupMetadata.Status.FINISHED, - stats = RollupStats(1, 1, 1, 1, 1) + stats = RollupStats(1, 1, 1, 1, 1), ) private val client: Client = mock() private val step = WaitForRollupCompletionStep() @@ -59,7 +59,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing failure message", WaitForRollupCompletionStep.getMissingRollupJobMessage(indexName), - updatedManagedIndexMetaData.info?.get("message") + updatedManagedIndexMetaData.info?.get("message"), ) } @@ -72,7 +72,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing failure message", WaitForRollupCompletionStep.getJobFailedMessage(rollupId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertEquals("Missing rollup failed action property", true, updateManagedIndexMetaData.actionMetaData?.actionProperties?.hasRollupFailed) } @@ -86,7 +86,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing failure message", WaitForRollupCompletionStep.getJobFailedMessage(rollupId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertEquals("Missing rollup failed action property", true, updateManagedIndexMetaData.actionMetaData?.actionProperties?.hasRollupFailed) assertEquals("Mismatch in cause", WaitForRollupCompletionStep.JOB_STOPPED_MESSAGE, updateManagedIndexMetaData.info?.get("cause")) @@ -101,7 +101,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing processing message", WaitForRollupCompletionStep.getJobProcessingMessage(rollupId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertNull("rollup failed property is not null", updateManagedIndexMetaData.actionMetaData?.actionProperties?.hasRollupFailed) } @@ -115,7 +115,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing processing message", WaitForRollupCompletionStep.getJobProcessingMessage(rollupId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertNull("rollup failed property is not null", updateManagedIndexMetaData.actionMetaData?.actionProperties?.hasRollupFailed) } @@ -129,7 +129,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing processing message", WaitForRollupCompletionStep.getJobCompletionMessage(rollupId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertNull("rollup failed property is not null", updateManagedIndexMetaData.actionMetaData?.actionProperties?.hasRollupFailed) } @@ -143,7 +143,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing processing message", WaitForRollupCompletionStep.getJobProcessingMessage(rollupId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertNull("rollup failed property is not null", updateManagedIndexMetaData.actionMetaData?.actionProperties?.hasRollupFailed) } @@ -156,7 +156,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { assertEquals( "Mismatch in message", WaitForRollupCompletionStep.getFailedMessage(rollupId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updateManagedIndexMetaData.stepMetaData?.stepStatus) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForShrinkStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForShrinkStepTests.kt index dbad3098b..ec1b94607 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForShrinkStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForShrinkStepTests.kt @@ -182,8 +182,11 @@ class WaitForShrinkStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (response != null) listener.onResponse(response) - else listener.onFailure(exception) + if (response != null) { + listener.onResponse(response) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).aliases(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt index b30084392..416512c7a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt @@ -11,7 +11,6 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse import org.opensearch.client.AdminClient @@ -20,6 +19,7 @@ import org.opensearch.client.ClusterAdminClient import org.opensearch.cluster.SnapshotsInProgress import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.action.SnapshotAction import org.opensearch.indexmanagement.indexstatemanagement.step.snapshot.WaitForSnapshotStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -194,8 +194,11 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (snapshotsStatusResponse != null) listener.onResponse(snapshotsStatusResponse) - else listener.onFailure(exception) + if (snapshotsStatusResponse != null) { + listener.onResponse(snapshotsStatusResponse) + } else { + listener.onFailure(exception) + } }.whenever(this.mock).snapshotsStatus(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt index d536c7449..45ee4e3d6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt @@ -12,14 +12,14 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.indexstatemanagement.step.transform.AttemptCreateTransformJobStep import org.opensearch.indexmanagement.indexstatemanagement.step.transform.WaitForTransformCompletionStep -import org.opensearch.indexmanagement.transform.model.TransformMetadata -import org.opensearch.indexmanagement.transform.model.TransformStats import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.TransformActionProperties +import org.opensearch.indexmanagement.transform.model.TransformMetadata +import org.opensearch.indexmanagement.transform.model.TransformStats import org.opensearch.indexmanagement.util.NO_ID import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService @@ -46,18 +46,18 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { null, ActionMetaData( AttemptCreateTransformJobStep.name, 1, 0, false, 0, null, - ActionProperties(transformActionProperties = TransformActionProperties(transformId)) + ActionProperties(transformActionProperties = TransformActionProperties(transformId)), ), null, null, - null + null, ) private val transformMetadata = TransformMetadata( id = NO_ID, transformId = transformId, lastUpdatedAt = Instant.now(), status = TransformMetadata.Status.FINISHED, - stats = TransformStats(1, 1, 1, 1, 1) + stats = TransformStats(1, 1, 1, 1, 1), ) private val client: Client = mock() private val step = WaitForTransformCompletionStep() @@ -78,7 +78,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing failure message", WaitForTransformCompletionStep.getMissingTransformJobMessage(indexName), - updatedManagedIndexMetaData.info?.get("message") + updatedManagedIndexMetaData.info?.get("message"), ) } @@ -91,7 +91,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing failure message", WaitForTransformCompletionStep.getJobFailedMessage(transformId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) } @@ -104,7 +104,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing failure message", WaitForTransformCompletionStep.getJobFailedMessage(transformId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertEquals("Mismatch in cause", WaitForTransformCompletionStep.JOB_STOPPED_MESSAGE, updateManagedIndexMetaData.info?.get("cause")) } @@ -117,12 +117,12 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { assertEquals( "Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, - updateManagedIndexMetaData.stepMetaData?.stepStatus + updateManagedIndexMetaData.stepMetaData?.stepStatus, ) assertEquals( "Missing processing message", WaitForTransformCompletionStep.getJobProcessingMessage(transformId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) } @@ -135,7 +135,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing processing message", WaitForTransformCompletionStep.getJobProcessingMessage(transformId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) } @@ -148,7 +148,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { assertEquals( "Missing processing message", WaitForTransformCompletionStep.getJobCompletionMessage(transformId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) } @@ -160,7 +160,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { assertEquals( "Mismatch in message", WaitForTransformCompletionStep.getFailedMessage(transformId, indexName), - updateManagedIndexMetaData.info?.get("message") + updateManagedIndexMetaData.info?.get("message"), ) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updateManagedIndexMetaData.stepMetaData?.stepStatus) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequestTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequestTests.kt index 61d9d81e2..1495ff046 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequestTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainRequestTests.kt @@ -6,8 +6,8 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.explain import org.opensearch.common.io.stream.BytesStreamOutput -import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.common.unit.TimeValue +import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.indexmanagement.common.model.rest.SearchParams import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE import org.opensearch.test.OpenSearchTestCase diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponseTests.kt index bbab164f3..be32991ba 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/explain/ExplainResponseTests.kt @@ -32,7 +32,7 @@ class ExplainResponseTests : OpenSearchTestCase() { actionMetaData = null, stepMetaData = null, policyRetryInfo = null, - info = null + info = null, ) val validationResult = ValidationResult("test", Validate.ValidationStatus.FAILED) val validationResults = listOf(validationResult) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponseTests.kt index 939774f07..c11b5c573 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPoliciesResponseTests.kt @@ -6,11 +6,11 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.getpolicy import org.opensearch.common.io.stream.BytesStreamOutput -import org.opensearch.core.common.io.stream.StreamInput -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.json.JsonXContent +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser import org.opensearch.indexmanagement.indexstatemanagement.extension.SampleCustomActionParser import org.opensearch.indexmanagement.indexstatemanagement.model.Policy @@ -54,7 +54,7 @@ class GetPoliciesResponseTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val res = GetPoliciesResponse(listOf(policy), 1) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt index b84b9150c..6776c4b99 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt @@ -6,11 +6,11 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.getpolicy import org.opensearch.common.io.stream.BytesStreamOutput -import org.opensearch.core.common.io.stream.StreamInput -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.json.JsonXContent +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser import org.opensearch.indexmanagement.indexstatemanagement.action.IndexPriorityAction import org.opensearch.indexmanagement.indexstatemanagement.extension.SampleCustomActionParser @@ -39,7 +39,7 @@ class GetPolicyResponseTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val res = GetPolicyResponse(id, version, seqNo, primaryTerm, policy) @@ -73,7 +73,7 @@ class GetPolicyResponseTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val res = GetPolicyResponse(id, version, seqNo, primaryTerm, policy) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt index 3cc77a0ad..7a74b06ad 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt @@ -34,7 +34,7 @@ class IndexPolicyRequestTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val seqNo: Long = 123 val primaryTerm: Long = 456 @@ -63,7 +63,7 @@ class IndexPolicyRequestTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val seqNo: Long = 123 val primaryTerm: Long = 456 @@ -92,7 +92,7 @@ class IndexPolicyRequestTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val seqNo: Long = 123 val primaryTerm: Long = 456 @@ -124,7 +124,7 @@ class IndexPolicyRequestTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val seqNo: Long = 123 val primaryTerm: Long = 456 diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt index 7e68b0a0c..6b3610f0e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt @@ -6,11 +6,12 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.indexpolicy import org.opensearch.common.io.stream.BytesStreamOutput -import org.opensearch.core.common.io.stream.StreamInput -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.json.JsonXContent +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.rest.RestStatus +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser import org.opensearch.indexmanagement.indexstatemanagement.action.IndexPriorityAction import org.opensearch.indexmanagement.indexstatemanagement.extension.SampleCustomActionParser @@ -19,7 +20,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.model.State import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification import org.opensearch.indexmanagement.opensearchapi.convertToMap import org.opensearch.indexmanagement.opensearchapi.string -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import java.time.Instant import java.time.temporal.ChronoUnit @@ -41,7 +41,7 @@ class IndexPolicyResponseTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val status = RestStatus.CREATED @@ -78,7 +78,7 @@ class IndexPolicyResponseTests : OpenSearchTestCase() { lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, - states = states + states = states, ) val status = RestStatus.CREATED diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequestTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequestTests.kt index 6cf699be6..cf27c76e9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequestTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/retryfailedmanagedindex/RetryFailedManagedIndexRequestTests.kt @@ -6,8 +6,8 @@ package org.opensearch.indexmanagement.indexstatemanagement.transport.action.retryfailedmanagedindex import org.opensearch.common.io.stream.BytesStreamOutput -import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.common.unit.TimeValue +import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE import org.opensearch.test.OpenSearchTestCase diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt index 3dd7b20ec..8d80a439d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt @@ -5,15 +5,15 @@ package org.opensearch.indexmanagement.indexstatemanagement.util -import org.opensearch.core.common.bytes.BytesReference -import org.opensearch.core.common.unit.ByteSizeValue import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentHelper -import org.opensearch.core.xcontent.XContentParser import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.destination.message.LegacyBaseMessage import org.opensearch.commons.destination.message.LegacyCustomWebhookMessage +import org.opensearch.core.common.bytes.BytesReference +import org.opensearch.core.common.unit.ByteSizeValue +import org.opensearch.core.xcontent.XContentParser import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.indexstatemanagement.action.RolloverAction import org.opensearch.indexmanagement.indexstatemanagement.model.Conditions @@ -64,7 +64,7 @@ class ManagedIndexUtilsTests : OpenSearchTestCase() { val policyID = randomAlphaOfLength(10) val sweptManagedIndexConfig = SweptManagedIndexConfig( index = index, uuid = uuid, policyID = policyID, - primaryTerm = 1, seqNo = 1, changePolicy = randomChangePolicy(policyID = policyID), policy = null + primaryTerm = 1, seqNo = 1, changePolicy = randomChangePolicy(policyID = policyID), policy = null, ) val updateRequest = updateManagedIndexRequest(sweptManagedIndexConfig) @@ -76,7 +76,7 @@ class ManagedIndexUtilsTests : OpenSearchTestCase() { logger.info("source is $source") assertEquals( "Incorrect policy_id added to change_policy", sweptManagedIndexConfig.policyID, - ((source["managed_index"] as Map)["change_policy"] as Map)["policy_id"] + ((source["managed_index"] as Map)["change_policy"] as Map)["policy_id"], ) } @@ -87,25 +87,25 @@ class ManagedIndexUtilsTests : OpenSearchTestCase() { val clusterConfigToUpdate = randomClusterStateManagedIndexConfig(policyID = "update_me") val sweptConfigToBeUpdated = randomSweptManagedIndexConfig( index = clusterConfigToUpdate.index, - uuid = clusterConfigToUpdate.uuid, policyID = "to_something_new", seqNo = 5, primaryTerm = 17 + uuid = clusterConfigToUpdate.uuid, policyID = "to_something_new", seqNo = 5, primaryTerm = 17, ) val clusterConfigBeingUpdated = randomClusterStateManagedIndexConfig(policyID = "updating") val sweptConfigBeingUpdated = randomSweptManagedIndexConfig( index = clusterConfigBeingUpdated.index, uuid = clusterConfigBeingUpdated.uuid, policyID = "to_something_new", seqNo = 5, primaryTerm = 17, - changePolicy = randomChangePolicy("updating") + changePolicy = randomChangePolicy("updating"), ) val clusterConfig = randomClusterStateManagedIndexConfig(policyID = "do_nothing") val sweptConfig = randomSweptManagedIndexConfig( index = clusterConfig.index, - uuid = clusterConfig.uuid, policyID = clusterConfig.policyID, seqNo = 5, primaryTerm = 17 + uuid = clusterConfig.uuid, policyID = clusterConfig.policyID, seqNo = 5, primaryTerm = 17, ) val managedIndicesToDelete = getManagedIndicesToDelete( listOf(clusterConfig.uuid, clusterConfigToUpdate.uuid, clusterConfigBeingUpdated.uuid, clusterConfigToCreate.uuid), - listOf(sweptConfig.uuid, sweptConfigToDelete.uuid, sweptConfigToBeUpdated.uuid, sweptConfigBeingUpdated.uuid) + listOf(sweptConfig.uuid, sweptConfigToDelete.uuid, sweptConfigToBeUpdated.uuid, sweptConfigBeingUpdated.uuid), ) val requests = managedIndicesToDelete.map { deleteManagedIndexRequest(it) } @@ -128,108 +128,108 @@ class ManagedIndexUtilsTests : OpenSearchTestCase() { assertTrue( "No conditions should always pass", noConditionsConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "No conditions should always pass", noConditionsConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(100), numDocs = 5, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(100), numDocs = 5, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)), ) assertTrue( "No conditions should always pass", noConditionsConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(6000), numDocs = 5, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(6000), numDocs = 5, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)), ) val minSizeConfig = RolloverAction(minSize = ByteSizeValue(5), minDocs = null, minAge = null, minPrimaryShardSize = null, index = 0) assertFalse( "Less bytes should not pass", minSizeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Equal bytes should pass", minSizeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)), ) assertTrue( "More bytes should pass", minSizeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(10), primaryShardSize = ByteSizeValue(10)) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(10), primaryShardSize = ByteSizeValue(10)), ) val minPrimarySizeConfig = RolloverAction(minSize = null, minDocs = null, minAge = null, minPrimaryShardSize = ByteSizeValue(5), index = 0) assertFalse( "Less primary bytes should not pass", minPrimarySizeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Equal primary bytes should pass", minPrimarySizeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(5), primaryShardSize = ByteSizeValue(5)), ) assertTrue( "More primary bytes should pass", minPrimarySizeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(10), primaryShardSize = ByteSizeValue(10)) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue(10), primaryShardSize = ByteSizeValue(10)), ) val minDocsConfig = RolloverAction(minSize = null, minDocs = 5, minAge = null, minPrimaryShardSize = null, index = 0) assertFalse( "Less docs should not pass", minDocsConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Equal docs should pass", minDocsConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 5, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 5, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "More docs should pass", minDocsConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 10, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 10, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) val minAgeConfig = RolloverAction(minSize = null, minDocs = null, minAge = TimeValue.timeValueSeconds(5), minPrimaryShardSize = null, index = 0) assertFalse( "Index age that is too young should not pass", minAgeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(1000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Index age that is older should pass", minAgeConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(10000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(10000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) val multiConfig = RolloverAction(minSize = ByteSizeValue(1), minDocs = 1, minAge = TimeValue.timeValueSeconds(5), minPrimaryShardSize = ByteSizeValue(1), index = 0) assertFalse( "No conditions met should not pass", multiConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Multi condition, age should pass", multiConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(10000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(10000), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Multi condition, docs should pass", multiConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 2, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 2, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Multi condition, size should pass", multiConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue(2), primaryShardSize = ByteSizeValue.ZERO) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue(2), primaryShardSize = ByteSizeValue.ZERO), ) assertTrue( "Multi condition, primary size should pass", multiConfig - .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue(2)) + .evaluateConditions(indexAgeTimeValue = TimeValue.timeValueMillis(0), numDocs = 0, indexSize = ByteSizeValue.ZERO, primaryShardSize = ByteSizeValue(2)), ) } @@ -238,54 +238,54 @@ class ManagedIndexUtilsTests : OpenSearchTestCase() { assertTrue( "No conditions should pass", emptyTransition - .evaluateConditions(indexCreationDate = Instant.now(), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null) + .evaluateConditions(indexCreationDate = Instant.now(), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null), ) val timeTransition = Transition( stateName = "some_state", - conditions = Conditions(indexAge = TimeValue.timeValueSeconds(5)) + conditions = Conditions(indexAge = TimeValue.timeValueSeconds(5)), ) assertFalse( "Index age that is too young should not pass", timeTransition - .evaluateConditions(indexCreationDate = Instant.now(), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null) + .evaluateConditions(indexCreationDate = Instant.now(), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null), ) assertTrue( "Index age that is older should pass", timeTransition - .evaluateConditions(indexCreationDate = Instant.now().minusSeconds(10), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null) + .evaluateConditions(indexCreationDate = Instant.now().minusSeconds(10), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null), ) assertFalse( "Index age that is -1L should not pass", timeTransition - .evaluateConditions(indexCreationDate = Instant.ofEpochMilli(-1L), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null) + .evaluateConditions(indexCreationDate = Instant.ofEpochMilli(-1L), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null), ) val rolloverTimeTransition = Transition( stateName = "some_state", - conditions = Conditions(rolloverAge = TimeValue.timeValueSeconds(5)) + conditions = Conditions(rolloverAge = TimeValue.timeValueSeconds(5)), ) assertFalse( "Rollover age that is too young should not pass", rolloverTimeTransition - .evaluateConditions(indexCreationDate = Instant.now(), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = Instant.now()) + .evaluateConditions(indexCreationDate = Instant.now(), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = Instant.now()), ) assertTrue( "Rollover age that is older should pass", rolloverTimeTransition - .evaluateConditions(indexCreationDate = Instant.now().minusSeconds(10), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = Instant.now().minusSeconds(10)) + .evaluateConditions(indexCreationDate = Instant.now().minusSeconds(10), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = Instant.now().minusSeconds(10)), ) assertFalse( "Rollover age that is null should not pass", rolloverTimeTransition - .evaluateConditions(indexCreationDate = Instant.ofEpochMilli(-1L), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null) + .evaluateConditions(indexCreationDate = Instant.ofEpochMilli(-1L), numDocs = null, indexSize = null, transitionStartTime = Instant.now(), rolloverDate = null), ) } private fun contentParser(bytesReference: BytesReference): XContentParser { return XContentHelper.createParser( xContentRegistry(), LoggingDeprecationHandler.INSTANCE, - bytesReference, XContentType.JSON + bytesReference, XContentType.JSON, ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtilsTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtilsTests.kt index 9eef04b65..6b19e0e7b 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtilsTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/util/StepUtilsTests.kt @@ -33,7 +33,7 @@ class StepUtilsTests : OpenSearchTestCase() { randomNonNegativeLong(), randomInstant().toEpochMilli(), randomInstant().toEpochMilli(), - mapOf() + mapOf(), ) val lockModel = getShrinkLockModel(shrinkActionProperties) assertEquals("Incorrect lock model job index name", INDEX_MANAGEMENT_INDEX, lockModel.jobIndexName) @@ -55,7 +55,7 @@ class StepUtilsTests : OpenSearchTestCase() { randomNonNegativeLong(), randomInstant().toEpochMilli(), randomInstant().toEpochMilli(), - mapOf() + mapOf(), ) val lockModel = LockModel( randomAlphaOfLength(10), @@ -64,7 +64,7 @@ class StepUtilsTests : OpenSearchTestCase() { randomInstant().toEpochMilli(), false, randomNonNegativeLong(), - randomNonNegativeLong() + randomNonNegativeLong(), ) val updatedProperties = getUpdatedShrinkActionProperties(shrinkActionProperties, lockModel) @@ -81,7 +81,7 @@ class StepUtilsTests : OpenSearchTestCase() { fun `test get action start time`() { val metadata = ManagedIndexMetaData( "indexName", "indexUuid", "policy_id", null, null, null, null, null, null, null, - ActionMetaData("name", randomInstant().toEpochMilli(), 0, false, 0, null, null), null, null, null + ActionMetaData("name", randomInstant().toEpochMilli(), 0, false, 0, null, null), null, null, null, ) assertEquals("Action start time was not extracted correctly", metadata.actionMetaData?.startTime, getActionStartTime(metadata).toEpochMilli()) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerActionIT.kt index 3ecbe9cd1..c601c4186 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerActionIT.kt @@ -202,7 +202,7 @@ class RefreshSearchAnalyzerActionIT : IndexManagementRestTestCase() { fun refreshAnalyzer(indexName: String) { val request = Request( "POST", - "$REFRESH_SEARCH_ANALYZER_BASE_URI/$indexName" + "$REFRESH_SEARCH_ANALYZER_BASE_URI/$indexName", ) client().performRequest(request) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerActionIT.kt index f523b7c6c..4abaffad0 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerActionIT.kt @@ -8,11 +8,11 @@ package org.opensearch.indexmanagement.refreshanalyzer import org.junit.AfterClass import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementRestTestCase import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.refreshanalyzer.RestRefreshSearchAnalyzerAction.Companion.REFRESH_SEARCH_ANALYZER_BASE_URI import org.opensearch.rest.RestRequest.Method.POST -import org.opensearch.core.rest.RestStatus class RestRefreshSearchAnalyzerActionIT : IndexManagementRestTestCase() { @@ -33,12 +33,12 @@ class RestRefreshSearchAnalyzerActionIT : IndexManagementRestTestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices") + mapOf("type" to "illegal_argument_exception", "reason" to "Missing indices"), ), "type" to "illegal_argument_exception", - "reason" to "Missing indices" + "reason" to "Missing indices", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperServiceTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperServiceTests.kt index fdaa225aa..76f42726d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperServiceTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMapperServiceTests.kt @@ -13,7 +13,6 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.mockito.ArgumentMatchers.anyBoolean -import org.opensearch.core.action.ActionListener import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -22,6 +21,7 @@ import org.opensearch.cluster.metadata.IndexNameExpressionResolver import org.opensearch.cluster.metadata.MappingMetadata import org.opensearch.cluster.service.ClusterService import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.rollup.model.RollupJobValidationResult import org.opensearch.test.OpenSearchTestCase import java.time.Instant @@ -33,28 +33,28 @@ class RollupMapperServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomDateHistogram().copy( - sourceField = "order_date" - ) + sourceField = "order_date", + ), ) val metrics = listOf( randomRollupMetrics().copy( - sourceField = "total_quantity" - ) + sourceField = "total_quantity", + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), dimensions = dimensions, - metrics = metrics + metrics = metrics, ) val client = getClient( getAdminClient( getIndicesAdminClient( getMappingsResponse = getMappingResponse(sourceIndex), - getMappingsException = null - ) - ) + getMappingsException = null, + ), + ), ) val clusterService = getClusterService() @@ -72,28 +72,28 @@ class RollupMapperServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomDateHistogram().copy( - sourceField = "order_date" - ) + sourceField = "order_date", + ), ) val metrics = listOf( randomRollupMetrics().copy( - sourceField = "total_quantity" - ) + sourceField = "total_quantity", + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), dimensions = dimensions, - metrics = metrics + metrics = metrics, ) val client = getClient( getAdminClient( getIndicesAdminClient( getMappingsResponse = getMappingResponse(sourceIndex), - getMappingsException = null - ) - ) + getMappingsException = null, + ), + ), ) val clusterService = getClusterService() val indexNameExpressionResolver = getIndexNameExpressionResolver(listOf(sourceIndex)) @@ -110,28 +110,28 @@ class RollupMapperServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomDateHistogram().copy( - sourceField = "order_date" - ) + sourceField = "order_date", + ), ) val metrics = listOf( randomRollupMetrics().copy( - sourceField = "total_quantity" - ) + sourceField = "total_quantity", + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), dimensions = dimensions, - metrics = metrics + metrics = metrics, ) val client = getClient( getAdminClient( getIndicesAdminClient( getMappingsResponse = getMappingResponse(sourceIndex, true), - getMappingsException = null - ) - ) + getMappingsException = null, + ), + ), ) val clusterService = getClusterService() val indexNameExpressionResolver = getIndexNameExpressionResolver(listOf(sourceIndex)) @@ -148,28 +148,28 @@ class RollupMapperServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomDateHistogram().copy( - sourceField = "category.keyword" - ) + sourceField = "category.keyword", + ), ) val metrics = listOf( randomRollupMetrics().copy( - sourceField = "total_quantity" - ) + sourceField = "total_quantity", + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), dimensions = dimensions, - metrics = metrics + metrics = metrics, ) val client = getClient( getAdminClient( getIndicesAdminClient( getMappingsResponse = getMappingResponse(sourceIndex), - getMappingsException = null - ) - ) + getMappingsException = null, + ), + ), ) val clusterService = getClusterService() @@ -187,28 +187,28 @@ class RollupMapperServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomDateHistogram().copy( - sourceField = "order_date" - ) + sourceField = "order_date", + ), ) val metrics = listOf( randomRollupMetrics().copy( - sourceField = "products.quantity" - ) + sourceField = "products.quantity", + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), dimensions = dimensions, - metrics = metrics + metrics = metrics, ) val client = getClient( getAdminClient( getIndicesAdminClient( getMappingsResponse = getMappingResponse(sourceIndex), - getMappingsException = null - ) - ) + getMappingsException = null, + ), + ), ) val clusterService = getClusterService() @@ -226,23 +226,23 @@ class RollupMapperServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomDateHistogram().copy( - sourceField = "nonexistent_field" - ) + sourceField = "nonexistent_field", + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), dimensions = dimensions, - metrics = emptyList() + metrics = emptyList(), ) val client = getClient( getAdminClient( getIndicesAdminClient( getMappingsResponse = getMappingResponse(sourceIndex), - getMappingsException = null - ) - ) + getMappingsException = null, + ), + ), ) val clusterService = getClusterService() @@ -267,18 +267,21 @@ class RollupMapperServiceTests : OpenSearchTestCase() { private fun getIndicesAdminClient( getMappingsResponse: GetMappingsResponse?, - getMappingsException: Exception? + getMappingsException: Exception?, ): IndicesAdminClient { assertTrue( "Must provide either a getMappingsResponse or getMappingsException", - (getMappingsResponse != null).xor(getMappingsException != null) + (getMappingsResponse != null).xor(getMappingsException != null), ) return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (getMappingsResponse != null) listener.onResponse(getMappingsResponse) - else listener.onFailure(getMappingsException) + if (getMappingsResponse != null) { + listener.onResponse(getMappingsResponse) + } else { + listener.onFailure(getMappingsException) + } }.whenever(this.mock).getMappings(any(), any()) } } @@ -295,7 +298,7 @@ class RollupMapperServiceTests : OpenSearchTestCase() { } else { val mappingSourceMap = createParser( XContentType.JSON.xContent(), - javaClass.classLoader.getResource("mappings/kibana-sample-data.json").readText() + javaClass.classLoader.getResource("mappings/kibana-sample-data.json").readText(), ).map() val mappingMetadata = MappingMetadata("_doc", mappingSourceMap) // it seems it still expects a type, i.e. _doc now mapOf(indexName to mappingMetadata) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataServiceTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataServiceTests.kt index b181a9f4b..557346437 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataServiceTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupMetadataServiceTests.kt @@ -12,15 +12,15 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before -import org.opensearch.core.action.ActionListener import org.opensearch.action.DocWriteResponse import org.opensearch.action.get.GetResponse import org.opensearch.action.index.IndexResponse import org.opensearch.action.search.SearchResponse import org.opensearch.client.Client -import org.opensearch.core.common.bytes.BytesReference import org.opensearch.common.document.DocumentField +import org.opensearch.core.action.ActionListener import org.opensearch.core.common.bytes.BytesArray +import org.opensearch.core.common.bytes.BytesReference import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.common.model.dimension.DateHistogram @@ -53,15 +53,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1m", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-10-02T05:01:15Z" @@ -69,7 +69,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -91,15 +91,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1h", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-10-02T05:35:15Z" @@ -107,7 +107,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -129,15 +129,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1h", - timezone = ZoneId.of("America/Los_Angeles") - ) + timezone = ZoneId.of("America/Los_Angeles"), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-03-08T01:35:15-08:00" @@ -145,7 +145,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -168,15 +168,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "day", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-10-02T05:35:15Z" @@ -184,7 +184,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -206,15 +206,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1d", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-02-28T08:40:15Z" @@ -222,7 +222,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -244,15 +244,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1w", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-03-22T08:40:15Z" // March 22, 2020, Sunday @@ -260,7 +260,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -284,15 +284,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1M", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2019-12-24T08:40:15Z" @@ -300,7 +300,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -322,15 +322,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1q", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-04-24T08:40:15Z" @@ -338,7 +338,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -360,15 +360,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1y", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-04-24T08:40:15Z" @@ -376,7 +376,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -398,15 +398,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1h", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-04-24T08:40:15-07:00" // UTC-07:00 for America/Los_Angeles @@ -414,7 +414,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -436,15 +436,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomCalendarDateHistogram().copy( calendarInterval = "1h", - timezone = ZoneId.of("America/Los_Angeles") - ) + timezone = ZoneId.of("America/Los_Angeles"), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-04-24T08:40:15Z" @@ -452,7 +452,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -474,15 +474,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomFixedDateHistogram().copy( fixedInterval = "3h", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-04-24T22:40:15Z" @@ -490,7 +490,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -512,15 +512,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomFixedDateHistogram().copy( fixedInterval = "3h", - timezone = ZoneId.of("America/Los_Angeles") - ) + timezone = ZoneId.of("America/Los_Angeles"), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-03-08T00:40:15-08:00" @@ -528,7 +528,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -552,15 +552,15 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val dimensions = listOf( randomFixedDateHistogram().copy( fixedInterval = "30d", - timezone = ZoneId.of(DateHistogram.UTC) - ) + timezone = ZoneId.of(DateHistogram.UTC), + ), ) val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), metadataID = null, continuous = true, - dimensions = dimensions + dimensions = dimensions, ) val firstDocTimestamp = "2020-02-01T22:40:15Z" @@ -568,7 +568,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = getIndexResponse(), - indexException = null + indexException = null, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -591,7 +591,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), - metadataID = randomAlphaOfLength(10) + metadataID = randomAlphaOfLength(10), ) val getException = Exception("Test failure") @@ -615,7 +615,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { val rollup = randomRollup().copy( enabled = true, jobEnabledTime = Instant.now(), - metadataID = null + metadataID = null, ) val indexException = Exception("Test failure") @@ -624,7 +624,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse = getSearchResponseForTimestamp(rollup, firstDocTimestamp), searchException = null, indexResponse = null, - indexException = indexException + indexException = indexException, ) val metadataService = RollupMetadataService(client, xContentRegistry) @@ -647,7 +647,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { // Truncating to seconds since not doing so causes milliseconds mismatch when comparing results lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.SECONDS), status = RollupMetadata.Status.INIT, - stats = RollupStats(0, 0, 0, 0, 0) + stats = RollupStats(0, 0, 0, 0, 0), ) val getResponse: GetResponse = mock() @@ -691,7 +691,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { runBlocking { val getExistingMetadataResult = metadataService.getExistingMetadata( randomRollup() - .copy(id = randomAlphaOfLength(10), metadataID = randomAlphaOfLength(10)) + .copy(id = randomAlphaOfLength(10), metadataID = randomAlphaOfLength(10)), ) require(getExistingMetadataResult is MetadataResult.NoMetadata) { "Getting existing metadata returned unexpected results" @@ -715,7 +715,7 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { runBlocking { val getExistingMetadataResult = metadataService.getExistingMetadata( randomRollup() - .copy(id = randomAlphaOfLength(10), metadataID = randomAlphaOfLength(10)) + .copy(id = randomAlphaOfLength(10), metadataID = randomAlphaOfLength(10)), ) require(getExistingMetadataResult is MetadataResult.Failure) { "Getting existing metadata returned unexpected results" @@ -761,21 +761,27 @@ class RollupMetadataServiceTests : OpenSearchTestCase() { searchResponse: SearchResponse?, searchException: Exception?, indexResponse: IndexResponse?, - indexException: Exception? + indexException: Exception?, ): Client { assertTrue("Must provide either a searchResponse or searchException", (searchResponse != null).xor(searchException != null)) assertTrue("Must provide either an indexResponse or indexException", (indexResponse != null).xor(indexException != null)) return mock { doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (searchResponse != null) listener.onResponse(searchResponse) - else listener.onFailure(searchException) + if (searchResponse != null) { + listener.onResponse(searchResponse) + } else { + listener.onFailure(searchException) + } }.whenever(this.mock).search(any(), any()) doAnswer { invocationOnMock -> val listener = invocationOnMock.getArgument>(1) - if (indexResponse != null) listener.onResponse(indexResponse) - else listener.onFailure(indexException) + if (indexResponse != null) { + listener.onResponse(indexResponse) + } else { + listener.onFailure(indexException) + } }.whenever(this.mock).index(any(), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupRestTestCase.kt index 8ca6a32c3..c818d293e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/RollupRestTestCase.kt @@ -18,11 +18,12 @@ import org.opensearch.client.Response import org.opensearch.client.RestClient import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType +import org.opensearch.common.xcontent.json.JsonXContent +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentParser.Token import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.common.xcontent.XContentType -import org.opensearch.common.xcontent.json.JsonXContent import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI @@ -36,7 +37,6 @@ import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.waitFor -import org.opensearch.core.rest.RestStatus import java.time.Instant abstract class RollupRestTestCase : IndexManagementRestTestCase() { @@ -91,7 +91,7 @@ abstract class RollupRestTestCase : IndexManagementRestTestCase() { rollup: Rollup, rollupId: String, refresh: Boolean = true, - client: RestClient? = null + client: RestClient? = null, ): Rollup { val response = createRollupJson(rollup.toJsonString(), rollupId, refresh, client) @@ -103,7 +103,7 @@ abstract class RollupRestTestCase : IndexManagementRestTestCase() { return rollup.copy( id = createdId, seqNo = (rollupJson["_seq_no"] as Int).toLong(), - primaryTerm = (rollupJson["_primary_term"] as Int).toLong() + primaryTerm = (rollupJson["_primary_term"] as Int).toLong(), ) } @@ -111,7 +111,7 @@ abstract class RollupRestTestCase : IndexManagementRestTestCase() { rollupString: String, rollupId: String, refresh: Boolean = true, - userClient: RestClient? = null + userClient: RestClient? = null, ): Response { val client = userClient ?: client() val response = client @@ -119,7 +119,7 @@ abstract class RollupRestTestCase : IndexManagementRestTestCase() { "PUT", "$ROLLUP_JOBS_BASE_URI/$rollupId?refresh=$refresh", emptyMap(), - StringEntity(rollupString, APPLICATION_JSON) + StringEntity(rollupString, APPLICATION_JSON), ) assertEquals("Unable to create a new rollup", RestStatus.CREATED, response.restStatus()) return response @@ -167,7 +167,7 @@ abstract class RollupRestTestCase : IndexManagementRestTestCase() { """.trimIndent() val response = client().makeRequest( "POST", "${rollup.sourceIndex}/_doc?refresh=true", - emptyMap(), StringEntity(request, APPLICATION_JSON) + emptyMap(), StringEntity(request, APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.CREATED, response.restStatus()) } @@ -258,7 +258,7 @@ abstract class RollupRestTestCase : IndexManagementRestTestCase() { """.trimIndent() val res = client().makeRequest( "PUT", "_cluster/settings", emptyMap(), - StringEntity(request, APPLICATION_JSON) + StringEntity(request, APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, res.restStatus()) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/TestHelpers.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/TestHelpers.kt index 8d650714c..11b7c4f72 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/TestHelpers.kt @@ -5,8 +5,8 @@ package org.opensearch.indexmanagement.rollup -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.core.xcontent.ToXContent import org.opensearch.index.query.TermQueryBuilder import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Dimension @@ -57,7 +57,7 @@ fun randomHistogram(): Histogram = OpenSearchRestTestCase.randomAlphaOfLength(10 Histogram( sourceField = it, targetField = it, - interval = OpenSearchRestTestCase.randomDoubleBetween(0.0, Double.MAX_VALUE, false) // start, end, lowerInclusive + interval = OpenSearchRestTestCase.randomDoubleBetween(0.0, Double.MAX_VALUE, false), // start, end, lowerInclusive ) } @@ -114,7 +114,7 @@ fun randomRollup(): Rollup { continuous = OpenSearchRestTestCase.randomBoolean(), dimensions = randomRollupDimensions(), metrics = OpenSearchRestTestCase.randomList(20, ::randomRollupMetrics).distinctBy { it.targetField }, - user = randomUser() + user = randomUser(), ) } @@ -124,7 +124,7 @@ fun randomRollupStats(): RollupStats { documentsProcessed = OpenSearchRestTestCase.randomNonNegativeLong(), rollupsIndexed = OpenSearchRestTestCase.randomNonNegativeLong(), indexTimeInMillis = OpenSearchRestTestCase.randomNonNegativeLong(), - searchTimeInMillis = OpenSearchRestTestCase.randomNonNegativeLong() + searchTimeInMillis = OpenSearchRestTestCase.randomNonNegativeLong(), ) } @@ -137,7 +137,7 @@ fun randomContinuousMetadata(): ContinuousMetadata { val two = randomInstant() return ContinuousMetadata( nextWindowEndTime = if (one.isAfter(two)) one else two, - nextWindowStartTime = if (one.isAfter(two)) two else one + nextWindowStartTime = if (one.isAfter(two)) two else one, ) } @@ -161,7 +161,7 @@ fun randomRollupMetadata(): RollupMetadata { continuous = randomContinuousMetadata(), status = status, failureReason = if (status == RollupMetadata.Status.FAILED) OpenSearchRestTestCase.randomAlphaOfLength(10) else null, - stats = randomRollupStats() + stats = randomRollupStats(), ) } @@ -176,7 +176,7 @@ fun randomISMRollup(): ISMRollup { targetIndex = OpenSearchRestTestCase.randomAlphaOfLength(10).lowercase(Locale.ROOT), pageSize = OpenSearchRestTestCase.randomIntBetween(1, 10000), dimensions = randomRollupDimensions(), - metrics = OpenSearchRestTestCase.randomList(20, ::randomRollupMetrics).distinctBy { it.targetField } + metrics = OpenSearchRestTestCase.randomList(20, ::randomRollupMetrics).distinctBy { it.targetField }, ) } @@ -189,7 +189,7 @@ fun randomISMFieldCapabilities(): ISMFieldCapabilities { indices = OpenSearchRestTestCase.generateRandomStringArray(10, 10, true, true), nonSearchableIndices = OpenSearchRestTestCase.generateRandomStringArray(10, 10, true, true), nonAggregatableIndices = OpenSearchRestTestCase.generateRandomStringArray(10, 10, true, true), - meta = mapOf(OpenSearchRestTestCase.randomAlphaOfLength(10) to setOf(OpenSearchRestTestCase.randomAlphaOfLength(10))) + meta = mapOf(OpenSearchRestTestCase.randomAlphaOfLength(10) to setOf(OpenSearchRestTestCase.randomAlphaOfLength(10))), ) } @@ -199,7 +199,7 @@ fun randomISMIndexFieldCapabilities(): ISMIndexFieldCapabilities { type = OpenSearchRestTestCase.randomAlphaOfLength(10), isSearchable = OpenSearchRestTestCase.randomBoolean(), isAggregatable = OpenSearchRestTestCase.randomBoolean(), - meta = mapOf(OpenSearchRestTestCase.randomAlphaOfLength(10) to OpenSearchRestTestCase.randomAlphaOfLength(10)) + meta = mapOf(OpenSearchRestTestCase.randomAlphaOfLength(10) to OpenSearchRestTestCase.randomAlphaOfLength(10)), ) } @@ -207,7 +207,7 @@ fun randomISMFieldCapabilitiesIndexResponse(): ISMFieldCapabilitiesIndexResponse return ISMFieldCapabilitiesIndexResponse( indexName = OpenSearchRestTestCase.randomAlphaOfLength(10), responseMap = mapOf(OpenSearchRestTestCase.randomAlphaOfLength(10) to randomISMIndexFieldCapabilities()), - canMatch = OpenSearchRestTestCase.randomBoolean() + canMatch = OpenSearchRestTestCase.randomBoolean(), ) } @@ -215,7 +215,7 @@ fun randomISMFieldCaps(): ISMFieldCapabilitiesResponse { return ISMFieldCapabilitiesResponse( indices = OpenSearchRestTestCase.generateRandomStringArray(10, 10, false), responseMap = mapOf(OpenSearchRestTestCase.randomAlphaOfLength(10) to mapOf(OpenSearchRestTestCase.randomAlphaOfLength(10) to randomISMFieldCapabilities())), - indexResponses = OpenSearchRestTestCase.randomList(4, ::randomISMFieldCapabilitiesIndexResponse) + indexResponses = OpenSearchRestTestCase.randomList(4, ::randomISMFieldCapabilitiesIndexResponse), ) } @@ -224,7 +224,9 @@ fun randomDimension(): Dimension { return OpenSearchRestTestCase.randomSubsetOf(1, dimensions).first() } -fun randomTermQuery(): TermQueryBuilder { return TermQueryBuilder(OpenSearchRestTestCase.randomAlphaOfLength(5), OpenSearchRestTestCase.randomAlphaOfLength(5)) } +fun randomTermQuery(): TermQueryBuilder { + return TermQueryBuilder(OpenSearchRestTestCase.randomAlphaOfLength(5), OpenSearchRestTestCase.randomAlphaOfLength(5)) +} fun DateHistogram.toJsonString(): String = this.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).string() diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/RequestTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/RequestTests.kt index 6389e6f91..90e5c37b5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/RequestTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/RequestTests.kt @@ -101,7 +101,7 @@ class RequestTests : OpenSearchTestCase() { val rollup = randomRollup().copy(seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM) val req = IndexRollupRequest( rollup = rollup, - refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE + refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE, ).index(INDEX_MANAGEMENT_INDEX) val out = BytesStreamOutput().apply { req.writeTo(this) } @@ -118,7 +118,7 @@ class RequestTests : OpenSearchTestCase() { val rollup = randomRollup().copy(seqNo = 1L, primaryTerm = 2L) val req = IndexRollupRequest( rollup = rollup, - refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE + refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE, ).index(INDEX_MANAGEMENT_INDEX) val out = BytesStreamOutput().apply { req.writeTo(this) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/ResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/ResponseTests.kt index 19508dd28..bb5d84526 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/ResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/action/ResponseTests.kt @@ -7,13 +7,13 @@ package org.opensearch.indexmanagement.rollup.action import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.rollup.action.explain.ExplainRollupResponse import org.opensearch.indexmanagement.rollup.action.get.GetRollupResponse import org.opensearch.indexmanagement.rollup.action.get.GetRollupsResponse import org.opensearch.indexmanagement.rollup.action.index.IndexRollupResponse import org.opensearch.indexmanagement.rollup.randomExplainRollup import org.opensearch.indexmanagement.rollup.randomRollup -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase class ResponseTests : OpenSearchTestCase() { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilterIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilterIT.kt index 37055be2a..7b5a073a4 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilterIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/actionfilter/FieldCapsFilterIT.kt @@ -7,10 +7,10 @@ package org.opensearch.indexmanagement.rollup.actionfilter import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.rollup.RollupRestTestCase import org.opensearch.indexmanagement.rollup.settings.RollupSettings -import org.opensearch.core.rest.RestStatus // TODO: Add assertions on fields @Suppress("UNCHECKED_CAST") diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt index baafa8c63..305fdfa2d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt @@ -9,6 +9,7 @@ import org.apache.http.entity.ContentType import org.apache.http.entity.StringEntity import org.junit.Assert import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Terms import org.opensearch.indexmanagement.makeRequest @@ -23,7 +24,6 @@ import org.opensearch.indexmanagement.rollup.model.metric.Sum import org.opensearch.indexmanagement.rollup.model.metric.ValueCount import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import java.time.Instant import java.time.temporal.ChronoUnit @@ -50,18 +50,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -102,7 +102,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Terms query @@ -132,7 +132,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Range query @@ -162,7 +162,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Bool query @@ -195,7 +195,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Boost query @@ -227,7 +227,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Const score query @@ -258,7 +258,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Dis max query @@ -292,7 +292,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Match phrase query @@ -322,7 +322,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) // Unsupported query @@ -350,7 +350,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Wrong error message", "The match query is currently not supported in rollups", - (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"] + (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"], ) assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus()) } @@ -382,7 +382,7 @@ class RollupInterceptorIT : RollupRestTestCase() { "Wrong error message", "Could not find a rollup job that can answer this query because [missing field RateCodeID, missing field timestamp, " + "missing sum aggregation on total_amount]", - (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"] + (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"], ) assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus()) } @@ -446,7 +446,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Wrong error message", "Rollup search must have size explicitly set to 0, but found 3", - (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"] + (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"], ) assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus()) } @@ -460,7 +460,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Wrong error message", "Rollup search must have size explicitly set to 0, but found -1", - (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"] + (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"], ) assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus()) } @@ -486,18 +486,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -541,23 +541,23 @@ class RollupInterceptorIT : RollupRestTestCase() { val rollupAggBucket = rollupAggBuckets[idx] assertEquals( "The sum aggregation had a different value raw[$rawAggBucket] rollup[$rollupAggBucket]", - rawAggBucket["sum"]!!["value"], rollupAggBucket["sum"]!!["value"] + rawAggBucket["sum"]!!["value"], rollupAggBucket["sum"]!!["value"], ) assertEquals( "The max aggregation had a different value raw[$rawAggBucket] rollup[$rollupAggBucket]", - rawAggBucket["max"]!!["value"], rollupAggBucket["max"]!!["value"] + rawAggBucket["max"]!!["value"], rollupAggBucket["max"]!!["value"], ) assertEquals( "The min aggregation had a different value raw[$rawAggBucket] rollup[$rollupAggBucket]", - rawAggBucket["min"]!!["value"], rollupAggBucket["min"]!!["value"] + rawAggBucket["min"]!!["value"], rollupAggBucket["min"]!!["value"], ) assertEquals( "The value_count aggregation had a different value raw[$rawAggBucket] rollup[$rollupAggBucket]", - rawAggBucket["value_count"]!!["value"], rollupAggBucket["value_count"]!!["value"] + rawAggBucket["value_count"]!!["value"], rollupAggBucket["value_count"]!!["value"], ) assertEquals( "The avg aggregation had a different value raw[$rawAggBucket] rollup[$rollupAggBucket]", - rawAggBucket["avg"]!!["value"], rollupAggBucket["avg"]!!["value"] + rawAggBucket["avg"]!!["value"], rollupAggBucket["avg"]!!["value"], ) } } @@ -582,18 +582,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "7d"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -607,7 +607,7 @@ class RollupInterceptorIT : RollupRestTestCase() { // if the nextWindowStartTime is after 2019-01-02T00:00:00Z then all data has been rolled up assertTrue( "Rollup has not caught up yet, docs processed: ${rollupMetadata.stats.documentsProcessed}", - rollupMetadata.continuous!!.nextWindowStartTime.isAfter(Instant.parse("2019-01-02T00:00:00Z")) + rollupMetadata.continuous!!.nextWindowStartTime.isAfter(Instant.parse("2019-01-02T00:00:00Z")), ) } @@ -640,7 +640,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("min_passenger_count")["value"], - rollupAggRes.getValue("min_passenger_count")["value"] + rollupAggRes.getValue("min_passenger_count")["value"], ) } @@ -666,18 +666,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollupHourly) @@ -706,18 +706,18 @@ class RollupInterceptorIT : RollupRestTestCase() { continuous = false, dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1m"), - Terms("RatecodeID", "RatecodeID") + Terms("RatecodeID", "RatecodeID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollupMinutely) @@ -757,16 +757,16 @@ class RollupInterceptorIT : RollupRestTestCase() { // When the cluster setting to search all jobs is off, the aggregations will be the same for searching a single job as for searching both assertEquals( "Searching single rollup job and rollup target index did not return the same max results", - rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResSingle.getValue("max_passenger_count")["value"] + rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResSingle.getValue("max_passenger_count")["value"], ) assertEquals( "Searching single rollup job and rollup target index did not return the same sum results", - rawAgg1Res.getValue("sum_passenger_count")["value"], rollupAggResSingle.getValue("sum_passenger_count")["value"] + rawAgg1Res.getValue("sum_passenger_count")["value"], rollupAggResSingle.getValue("sum_passenger_count")["value"], ) val trueAggCount = rawAgg1Res.getValue("value_count_passenger_count")["value"] as Int + rawAgg2Res.getValue("value_count_passenger_count")["value"] as Int assertEquals( "Searching single rollup job and rollup target index did not return the same value count results", - rawAgg1Res.getValue("value_count_passenger_count")["value"], rollupAggResSingle.getValue("value_count_passenger_count")["value"] + rawAgg1Res.getValue("value_count_passenger_count")["value"], rollupAggResSingle.getValue("value_count_passenger_count")["value"], ) val trueAggSum = rawAgg1Res.getValue("sum_passenger_count")["value"] as Double + rawAgg2Res.getValue("sum_passenger_count")["value"] as Double @@ -779,15 +779,15 @@ class RollupInterceptorIT : RollupRestTestCase() { // With search all jobs setting on, the sum, and value_count will now be equal to the sum of the single job search results assertEquals( "Searching single rollup job and rollup target index did not return the same sum results", - rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResAll.getValue("max_passenger_count")["value"] + rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResAll.getValue("max_passenger_count")["value"], ) assertEquals( "Searching rollup target index did not return the sum for all of the rollup jobs on the index", - trueAggSum, rollupAggResAll.getValue("sum_passenger_count")["value"] + trueAggSum, rollupAggResAll.getValue("sum_passenger_count")["value"], ) assertEquals( "Searching rollup target index did not return the value count for all of the rollup jobs on the index", - trueAggCount, rollupAggResAll.getValue("value_count_passenger_count")["value"] + trueAggCount, rollupAggResAll.getValue("value_count_passenger_count")["value"], ) } @@ -816,18 +816,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollupHourly1) @@ -857,18 +857,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollupHourly2) @@ -908,16 +908,16 @@ class RollupInterceptorIT : RollupRestTestCase() { // When the cluster setting to search all jobs is off, the aggregations will be the same for searching a single job as for searching both assertEquals( "Searching single rollup job and rollup target index did not return the same max results", - rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResMulti.getValue("max_passenger_count")["value"] + rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResMulti.getValue("max_passenger_count")["value"], ) assertEquals( "Searching single rollup job and rollup target index did not return the same sum results", - rawAgg1Res.getValue("sum_passenger_count")["value"], rollupAggResMulti.getValue("sum_passenger_count")["value"] + rawAgg1Res.getValue("sum_passenger_count")["value"], rollupAggResMulti.getValue("sum_passenger_count")["value"], ) val trueAggCount = rawAgg1Res.getValue("value_count_passenger_count")["value"] as Int + rawAgg2Res.getValue("value_count_passenger_count")["value"] as Int assertEquals( "Searching single rollup job and rollup target index did not return the same value count results", - rawAgg1Res.getValue("value_count_passenger_count")["value"], rollupAggResMulti.getValue("value_count_passenger_count")["value"] + rawAgg1Res.getValue("value_count_passenger_count")["value"], rollupAggResMulti.getValue("value_count_passenger_count")["value"], ) val trueAggSum = rawAgg1Res.getValue("sum_passenger_count")["value"] as Double + rawAgg2Res.getValue("sum_passenger_count")["value"] as Double @@ -930,15 +930,15 @@ class RollupInterceptorIT : RollupRestTestCase() { // With search all jobs setting on, the sum, and value_count will now be equal to the sum of the single job search results assertEquals( "Searching single rollup job and rollup target index did not return the same sum results", - rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResAll.getValue("max_passenger_count")["value"] + rawAgg1Res.getValue("max_passenger_count")["value"], rollupAggResAll.getValue("max_passenger_count")["value"], ) assertEquals( "Searching rollup target index did not return the sum for all of the rollup jobs on the index", - trueAggSum, rollupAggResAll.getValue("sum_passenger_count")["value"] + trueAggSum, rollupAggResAll.getValue("sum_passenger_count")["value"], ) assertEquals( "Searching rollup target index did not return the value count for all of the rollup jobs on the index", - trueAggCount, rollupAggResAll.getValue("value_count_passenger_count")["value"] + trueAggCount, rollupAggResAll.getValue("value_count_passenger_count")["value"], ) } @@ -973,11 +973,11 @@ class RollupInterceptorIT : RollupRestTestCase() { sourceField = "fare_amount", targetField = "fare_amount", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "improvement_surcharge", targetField = "improvement_surcharge", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "improvement_surcharge", targetField = "improvement_surcharge", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollupJob1) @@ -1007,18 +1007,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_dropoff_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollupJob2) @@ -1053,12 +1053,12 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals(1, failures?.size) assertEquals( "Searching multiple indices where one is rollup and other is not, didn't return failure", - "illegal_argument_exception", failures?.get(0)?.get("type") ?: "Didn't find failure type in search response" + "illegal_argument_exception", failures?.get(0)?.get("type") ?: "Didn't find failure type in search response", ) assertEquals( "Searching multiple indices where one is rollup and other is not, didn't return failure", - "Not all indices have rollup job", failures?.get(0)?.get("reason") ?: "Didn't find failure reason in search response" + "Not all indices have rollup job", failures?.get(0)?.get("reason") ?: "Didn't find failure reason in search response", ) // Search 2 rollups with different mappings @@ -1067,13 +1067,13 @@ class RollupInterceptorIT : RollupRestTestCase() { "POST", "/$targetIndex1,$targetIndex2/_search", emptyMap(), - StringEntity(req, ContentType.APPLICATION_JSON) + StringEntity(req, ContentType.APPLICATION_JSON), ) } catch (e: ResponseException) { assertEquals( "Searching multiple rollup indices which weren't created by same rollup job, didn't return failure", "Could not find a rollup job that can answer this query because [missing field RatecodeID, missing field passenger_count]", - (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"] + (e.response.asMap() as Map>>)["error"]!!["caused_by"]!!["reason"], ) assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus()) } @@ -1113,10 +1113,10 @@ class RollupInterceptorIT : RollupRestTestCase() { sourceField = "earnings", targetField = "earnings", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) - ) - ) + ValueCount(), Average(), + ), + ), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -1159,7 +1159,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // Fuzzy query @@ -1189,7 +1189,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // Prefix query req = """ @@ -1218,7 +1218,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // Regex query req = """ @@ -1247,7 +1247,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // Range query req = """ @@ -1276,7 +1276,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // Query with field prefix req = """ @@ -1306,7 +1306,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // Using ALL_MATCH_PATTERN for default_field but rollup job didn't include all fields @@ -1334,8 +1334,8 @@ class RollupInterceptorIT : RollupRestTestCase() { } catch (e: ResponseException) { assertTrue( e.message?.contains( - "[missing terms grouping on earnings, missing terms grouping on event_ts, missing field test.vvv, missing field test.fff]" - ) ?: false + "[missing terms grouping on earnings, missing terms grouping on event_ts, missing field test.vvv, missing field test.fff]", + ) ?: false, ) } @@ -1364,8 +1364,8 @@ class RollupInterceptorIT : RollupRestTestCase() { } catch (e: ResponseException) { assertTrue( e.message?.contains( - "[missing terms grouping on earnings, missing terms grouping on event_ts, missing field test.vvv, missing field test.fff]" - ) ?: false + "[missing terms grouping on earnings, missing terms grouping on event_ts, missing field test.vvv, missing field test.fff]", + ) ?: false, ) } @@ -1419,8 +1419,8 @@ class RollupInterceptorIT : RollupRestTestCase() { } catch (e: ResponseException) { assertTrue( e.message?.contains( - "[missing terms grouping on earnings, missing terms grouping on event_ts, missing field test.vvv, missing field test.fff]" - ) ?: false + "[missing terms grouping on earnings, missing terms grouping on event_ts, missing field test.vvv, missing field test.fff]", + ) ?: false, ) } @@ -1437,8 +1437,8 @@ class RollupInterceptorIT : RollupRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) // req = """ @@ -1468,7 +1468,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // prefix pattern in "default_field" field @@ -1500,7 +1500,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // field with space in query: @@ -1531,7 +1531,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) // _exists_:field @@ -1562,7 +1562,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) } @@ -1588,18 +1588,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -1661,18 +1661,18 @@ class RollupInterceptorIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) + ValueCount(), Average(), + ), ), - RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())) - ) + RollupMetrics(sourceField = "total_amount", targetField = "total_amount", metrics = listOf(Max(), Min())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -1746,10 +1746,10 @@ class RollupInterceptorIT : RollupRestTestCase() { sourceField = "earnings", targetField = "earnings", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) - ) - ) + ValueCount(), Average(), + ), + ), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -1792,7 +1792,7 @@ class RollupInterceptorIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same min results", rawAggRes.getValue("earnings_total")["value"], - rollupAggRes.getValue("earnings_total")["value"] + rollupAggRes.getValue("earnings_total")["value"], ) } @@ -1830,10 +1830,10 @@ class RollupInterceptorIT : RollupRestTestCase() { sourceField = "earnings", targetField = "earnings", metrics = listOf( Sum(), Min(), Max(), - ValueCount(), Average() - ) - ) - ) + ValueCount(), Average(), + ), + ), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollupTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollupTests.kt index 0a2c15ee5..5a7f48c27 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollupTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollupTests.kt @@ -19,45 +19,45 @@ import kotlin.test.assertFailsWith class ISMRollupTests : OpenSearchTestCase() { fun `test ism rollup requires only one date histogram and it should be first dimension`() { - assertFailsWith(IllegalArgumentException:: class, "The first dimension must be a date histogram") { + assertFailsWith(IllegalArgumentException::class, "The first dimension must be a date histogram") { randomISMRollup().copy(dimensions = listOf(randomTerms(), randomDateHistogram())) } - assertFailsWith(IllegalArgumentException:: class, "Requires one date histogram in dimensions") { + assertFailsWith(IllegalArgumentException::class, "Requires one date histogram in dimensions") { randomISMRollup().copy(dimensions = listOf()) } - assertFailsWith(IllegalArgumentException:: class, "Requires one date histogram in dimensions") { + assertFailsWith(IllegalArgumentException::class, "Requires one date histogram in dimensions") { randomISMRollup().copy(dimensions = listOf(randomTerms())) } - assertFailsWith(IllegalArgumentException:: class, "Requires only one date histogram in dimensions") { + assertFailsWith(IllegalArgumentException::class, "Requires only one date histogram in dimensions") { randomISMRollup().copy(dimensions = listOf(randomDateHistogram(), randomDateHistogram())) } } fun `test ism rollup requires non empty description`() { - assertFailsWith(IllegalArgumentException:: class, "Requires non empty description") { + assertFailsWith(IllegalArgumentException::class, "Requires non empty description") { randomISMRollup().copy(description = "") } } fun `test ism rollup requires non empty target index`() { - assertFailsWith(IllegalArgumentException:: class, "Requires non empty target index") { + assertFailsWith(IllegalArgumentException::class, "Requires non empty target index") { randomISMRollup().copy(targetIndex = "") } } fun `test ism rollup requires page size to be between 1 and 10K`() { - assertFailsWith(IllegalArgumentException:: class, "Page size cannot be less than 1") { + assertFailsWith(IllegalArgumentException::class, "Page size cannot be less than 1") { randomISMRollup().copy(pageSize = -1) } - assertFailsWith(IllegalArgumentException:: class, "Page size cannot be less than 1") { + assertFailsWith(IllegalArgumentException::class, "Page size cannot be less than 1") { randomISMRollup().copy(pageSize = 0) } - assertFailsWith(IllegalArgumentException:: class, "Page size cannot be greater than 10000") { + assertFailsWith(IllegalArgumentException::class, "Page size cannot be greater than 10000") { randomISMRollup().copy(pageSize = 10001) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt index 174e52685..9c0da7861 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt @@ -90,14 +90,14 @@ class RollupTests : OpenSearchTestCase() { val newDelay: Long = 500 val continuousRollup = randomRollup().copy( delay = newDelay, - continuous = true + continuous = true, ) assertEquals(newDelay, continuousRollup.jobSchedule.delay) // Non continuous rollup schedule should have null delay val nonContinuousRollup = randomRollup().copy( jobSchedule = randomSchedule(), delay = newDelay, - continuous = false + continuous = false, ) assertNull(nonContinuousRollup.jobSchedule.delay) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/WriteableTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/WriteableTests.kt index 216b16d6f..4d36e00a6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/WriteableTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/WriteableTests.kt @@ -117,7 +117,7 @@ class WriteableTests : OpenSearchTestCase() { fun `test rollup roles field deprecation`() { val rollup = randomRollup().copy( delay = randomLongBetween(0, 60000000), - roles = listOf("I am deprecated") + roles = listOf("I am deprecated"), ) val out = BytesStreamOutput().also { rollup.writeTo(it) } val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/XContentTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/XContentTests.kt index 8e230013a..5c8ba60af 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/XContentTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/XContentTests.kt @@ -6,8 +6,8 @@ package org.opensearch.indexmanagement.rollup.model import org.opensearch.common.xcontent.LoggingDeprecationHandler -import org.opensearch.core.xcontent.XContentParser import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.xcontent.XContentParser import org.opensearch.indexmanagement.common.model.dimension.Dimension import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT_TYPE import org.opensearch.indexmanagement.opensearchapi.parseWithType diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt index 67bab487c..d03a3e8a8 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt @@ -6,10 +6,10 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException -import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI -import org.opensearch.indexmanagement.makeRequest import org.opensearch.core.rest.RestStatus +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.indexstatemanagement.wait +import org.opensearch.indexmanagement.makeRequest import org.opensearch.test.junit.annotations.TestLogging @TestLogging(value = "level:DEBUG", reason = "Debugging tests") diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt index 8674b0445..fabd774ea 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt @@ -6,13 +6,13 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.rollup.randomRollup import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant import java.time.temporal.ChronoUnit @@ -29,7 +29,7 @@ class RestExplainRollupActionIT : RollupRestAPITestCase() { jobSchedule = IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES), enabled = true, jobEnabledTime = Instant.now(), - metadataID = null + metadataID = null, ).let { createRollup(it, it.id) } createRollupSourceIndex(rollup) updateRollupStartTime(rollup) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt index e02b7eafb..ff2b2d985 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt @@ -6,11 +6,11 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.rollup.action.get.GetRollupsRequest.Companion.DEFAULT_SIZE import org.opensearch.indexmanagement.rollup.randomRollup -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging import java.util.Locale @@ -33,7 +33,7 @@ class RestGetRollupActionIT : RollupRestAPITestCase() { // roles are deprecated and will not be stored or returned roles = listOf(), // user information is hidden and not returned - user = null + user = null, ) assertEquals("Indexed and retrieved rollup differ", rollup, indexedRollup) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt index 4ae34eab6..01f6deddc 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.DateHistogram @@ -27,7 +28,6 @@ import org.opensearch.indexmanagement.rollup.randomRollupMetrics import org.opensearch.indexmanagement.util.NO_ID import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._SEQ_NO -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import org.opensearch.test.junit.annotations.TestLogging import java.util.Locale @@ -82,7 +82,7 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { val expected = createParser( XContentType.JSON.xContent(), javaClass.classLoader.getResource("mappings/opendistro-ism-config.json") - .readText() + .readText(), ) val expectedMap = expected.map() @@ -97,7 +97,7 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?refresh=true&if_seq_no=10251989&if_primary_term=2342", - emptyMap(), rollup.toHttpEntity() + emptyMap(), rollup.toHttpEntity(), ) fail("expected 409 ResponseException") } catch (e: ResponseException) { @@ -111,7 +111,7 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { val updateResponse = client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?refresh=true&if_seq_no=${rollup.seqNo}&if_primary_term=${rollup.primaryTerm}", - emptyMap(), rollup.toHttpEntity() + emptyMap(), rollup.toHttpEntity(), ) assertEquals("Update rollup failed", RestStatus.OK, updateResponse.restStatus()) @@ -130,7 +130,7 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?refresh=true&if_seq_no=${rollup.seqNo}&if_primary_term=${rollup.primaryTerm}", - emptyMap(), rollup.copy(sourceIndex = "something_different").toHttpEntity() + emptyMap(), rollup.copy(sourceIndex = "something_different").toHttpEntity(), ) fail("Expected 400 Method BAD_REQUEST response") } catch (e: ResponseException) { @@ -139,12 +139,12 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "status_exception", "reason" to "Not allowed to modify [source_index]") + mapOf("type" to "status_exception", "reason" to "Not allowed to modify [source_index]"), ), "type" to "status_exception", - "reason" to "Not allowed to modify [source_index]" + "reason" to "Not allowed to modify [source_index]", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -157,7 +157,7 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?refresh=true&if_seq_no=${rollup.seqNo}&if_primary_term=${rollup.primaryTerm}", - emptyMap(), rollup.copy(targetIndex = "something_different").toHttpEntity() + emptyMap(), rollup.copy(targetIndex = "something_different").toHttpEntity(), ) fail("Expected 400 Method BAD_REQUEST response") } catch (e: ResponseException) { @@ -166,12 +166,12 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "status_exception", "reason" to "Not allowed to modify [target_index]") + mapOf("type" to "status_exception", "reason" to "Not allowed to modify [target_index]"), ), "type" to "status_exception", - "reason" to "Not allowed to modify [target_index]" + "reason" to "Not allowed to modify [target_index]", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -184,7 +184,7 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?refresh=true&if_seq_no=${rollup.seqNo}&if_primary_term=${rollup.primaryTerm}", - emptyMap(), rollup.copy(continuous = !rollup.continuous).toHttpEntity() + emptyMap(), rollup.copy(continuous = !rollup.continuous).toHttpEntity(), ) fail("Expected 400 Method BAD_REQUEST response") } catch (e: ResponseException) { @@ -193,12 +193,12 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "status_exception", "reason" to "Not allowed to modify [continuous]") + mapOf("type" to "status_exception", "reason" to "Not allowed to modify [continuous]"), ), "type" to "status_exception", - "reason" to "Not allowed to modify [continuous]" + "reason" to "Not allowed to modify [continuous]", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -219,7 +219,7 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?refresh=true&if_seq_no=${rollup.seqNo}&if_primary_term=${rollup.primaryTerm}", - emptyMap(), rollup.copy(dimensions = newDimensions).toHttpEntity() + emptyMap(), rollup.copy(dimensions = newDimensions).toHttpEntity(), ) fail("Expected 400 Method BAD_REQUEST response") } catch (e: ResponseException) { @@ -228,12 +228,12 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "status_exception", "reason" to "Not allowed to modify [dimensions]") + mapOf("type" to "status_exception", "reason" to "Not allowed to modify [dimensions]"), ), "type" to "status_exception", - "reason" to "Not allowed to modify [dimensions]" + "reason" to "Not allowed to modify [dimensions]", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } @@ -253,14 +253,14 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { Metric.Type.SUM -> ValueCount() Metric.Type.VALUE_COUNT -> Average() } - } + }, ) } val rollup = createRollup(rollup = randomRollup().copy(metrics = metrics), rollupId = "$testName-2") client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?refresh=true&if_seq_no=${rollup.seqNo}&if_primary_term=${rollup.primaryTerm}", - emptyMap(), rollup.copy(metrics = newMetrics).toHttpEntity() + emptyMap(), rollup.copy(metrics = newMetrics).toHttpEntity(), ) fail("Expected 400 Method BAD_REQUEST response") } catch (e: ResponseException) { @@ -269,12 +269,12 @@ class RestIndexRollupActionIT : RollupRestAPITestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "status_exception", "reason" to "Not allowed to modify [metrics]") + mapOf("type" to "status_exception", "reason" to "Not allowed to modify [metrics]"), ), "type" to "status_exception", - "reason" to "Not allowed to modify [metrics]" + "reason" to "Not allowed to modify [metrics]", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt index d2442995d..e0b87a1cb 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI @@ -19,7 +20,6 @@ import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.rollup.randomRollup import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import java.time.Instant import java.time.temporal.ChronoUnit import java.util.Locale @@ -97,7 +97,7 @@ class RestStartRollupActionIT : RollupRestAPITestCase() { delay = 0, continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h")), - metrics = emptyList() + metrics = emptyList(), ).let { createRollup(it, it.id) } // This should fail because we did not create a source index @@ -159,7 +159,7 @@ class RestStartRollupActionIT : RollupRestAPITestCase() { delay = 0, continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h")), - metrics = emptyList() + metrics = emptyList(), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -224,7 +224,7 @@ class RestStartRollupActionIT : RollupRestAPITestCase() { delay = 0, continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h")), - metrics = emptyList() + metrics = emptyList(), ).let { createRollup(it, it.id) } // The updateRollupStartTime call can be missed if the job scheduler hasn't started listening to the new index yet, diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt index fb5154dbe..a49d5933c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI @@ -21,7 +22,6 @@ import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.rollup.randomRollup import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import java.time.Instant import java.time.temporal.ChronoUnit import java.util.Locale @@ -76,9 +76,9 @@ class RestStopRollupActionIT : RollupRestAPITestCase() { jobSchedule = IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES), enabled = true, jobEnabledTime = Instant.now(), - metadataID = null + metadataID = null, ), - rollupId = "$testName-3" + rollupId = "$testName-3", ) createRollupSourceIndex(rollup) updateRollupStartTime(rollup) @@ -115,7 +115,7 @@ class RestStopRollupActionIT : RollupRestAPITestCase() { jobSchedule = IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES), enabled = true, jobEnabledTime = Instant.now(), - metadataID = null + metadataID = null, ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -150,9 +150,9 @@ class RestStopRollupActionIT : RollupRestAPITestCase() { jobSchedule = IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES), enabled = true, jobEnabledTime = Instant.now(), - metadataID = null + metadataID = null, ), - rollupId = "$testName-4" + rollupId = "$testName-4", ) // Force rollup to execute which should fail as we did not create a source index @@ -213,9 +213,9 @@ class RestStopRollupActionIT : RollupRestAPITestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), - metrics = emptyList() + metrics = emptyList(), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -280,9 +280,9 @@ class RestStopRollupActionIT : RollupRestAPITestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), - metrics = emptyList() + metrics = emptyList(), ).let { createRollup(it, it.id) } // The updateRollupStartTime call can be missed if the job scheduler hasn't started listening to the new index yet, diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt index 65f18a1dd..f4b2bf8a1 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.rollup.runner import org.apache.http.entity.ContentType import org.apache.http.entity.StringEntity import org.opensearch.common.settings.Settings +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.DateHistogram @@ -30,7 +31,6 @@ import org.opensearch.indexmanagement.rollup.settings.RollupSettings.Companion.R import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import java.time.Instant import java.time.temporal.ChronoUnit import java.util.Collections.emptyMap @@ -50,7 +50,7 @@ class RollupRunnerIT : RollupRestTestCase() { jobEnabledTime = Instant.now(), sourceIndex = indexName, metadataID = null, - continuous = false + continuous = false, ) // Create source index @@ -102,8 +102,8 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h")), metrics = listOf( - RollupMetrics(sourceField = propertyName, targetField = propertyName, metrics = listOf(Average())) - ) + RollupMetrics(sourceField = propertyName, targetField = propertyName, metrics = listOf(Average())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -141,7 +141,7 @@ class RollupRunnerIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same avg results", rawAggRes.getValue(avgMetricName)["value"], - rollupAggRes.getValue(avgMetricName)["value"] + rollupAggRes.getValue(avgMetricName)["value"], ) } } @@ -158,7 +158,7 @@ class RollupRunnerIT : RollupRestTestCase() { sourceIndex = dataStreamName, targetIndex = "$dataStreamName-rollup", metadataID = null, - continuous = false + continuous = false, ) // Create the source data stream @@ -170,8 +170,8 @@ class RollupRunnerIT : RollupRestTestCase() { "\"index_patterns\": [ \"$dataStreamName\" ], " + "\"data_stream\": { }, " + "\"template\": { \"mappings\": { ${createRollupMappingString(rollup)} } } }", - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) client().makeRequest("PUT", "/_data_stream/$dataStreamName") @@ -209,7 +209,7 @@ class RollupRunnerIT : RollupRestTestCase() { sourceIndex = indexName, targetIndex = "${indexName}_target", metadataID = null, - continuous = false + continuous = false, ) // Create source index @@ -246,7 +246,7 @@ class RollupRunnerIT : RollupRestTestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${rollup.id}?if_seq_no=${rollup.seqNo}&if_primary_term=${rollup.primaryTerm}", - emptyMap(), rollup.copy(enabled = true, jobEnabledTime = Instant.now()).toHttpEntity() + emptyMap(), rollup.copy(enabled = true, jobEnabledTime = Instant.now()).toHttpEntity(), ) updateRollupStartTime(rollup) @@ -281,9 +281,9 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = true, dimensions = listOf( randomCalendarDateHistogram().copy( - calendarInterval = "1y" - ) - ) + calendarInterval = "1y", + ), + ), ) // Create source index @@ -335,7 +335,7 @@ class RollupRunnerIT : RollupRestTestCase() { jobEnabledTime = Instant.now(), sourceIndex = indexName, metadataID = null, - continuous = true + continuous = true, ) // Create rollup job @@ -384,8 +384,8 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h")), metrics = listOf( - RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())) - ) + RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())), + ), ).let { createRollup(it, it.id) } val secondRollup = Rollup( @@ -405,8 +405,8 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "100d")), metrics = listOf( - RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())) - ) + RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())), + ), ).let { createRollup(it, it.id) } val thirdRollup = Rollup( @@ -426,15 +426,15 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1s")), metrics = listOf( - RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())) - ) + RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) waitFor { assertTrue("Target rollup index was not created", indexExists(rollup.targetIndex)) } - val finishedRollup = waitFor() { + val finishedRollup = waitFor { val rollupJob = getRollup(rollupId = rollup.id) assertNotNull("Rollup job doesn't have metadata set", rollupJob.metadataID) val rollupMetadata = getRollupMetadata(rollupJob.metadataID!!) @@ -444,7 +444,7 @@ class RollupRunnerIT : RollupRestTestCase() { updateRollupStartTime(secondRollup) - val secondFinishedRollup = waitFor() { + val secondFinishedRollup = waitFor { val rollupJob = getRollup(rollupId = secondRollup.id) assertNotNull("Rollup job doesn't have metadata set", rollupJob.metadataID) val rollupMetadata = getRollupMetadata(rollupJob.metadataID!!) @@ -454,7 +454,7 @@ class RollupRunnerIT : RollupRestTestCase() { updateRollupStartTime(thirdRollup) - val thirdFinishedRollup = waitFor() { + val thirdFinishedRollup = waitFor { val rollupJob = getRollup(rollupId = thirdRollup.id) assertNotNull("Rollup job doesn't have metadata set", rollupJob.metadataID) val rollupMetadata = getRollupMetadata(rollupJob.metadataID!!) @@ -527,8 +527,8 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1s")), metrics = listOf( - RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())) - ) + RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -546,7 +546,7 @@ class RollupRunnerIT : RollupRestTestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${startedRollup.id}?if_seq_no=${startedRollup.seqNo}&if_primary_term=${startedRollup.primaryTerm}", - emptyMap(), rollup.copy(pageSize = 1000).toHttpEntity() + emptyMap(), rollup.copy(pageSize = 1000).toHttpEntity(), ) val finishedRollup = waitFor { @@ -585,7 +585,7 @@ class RollupRunnerIT : RollupRestTestCase() { delay = 0, continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1m")), - metrics = listOf(RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()))) + metrics = listOf(RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()))), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -620,7 +620,7 @@ class RollupRunnerIT : RollupRestTestCase() { delay = 0, continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1m")), - metrics = listOf(RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()))) + metrics = listOf(RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()))), ).let { createRollup(it, it.id) } updateRollupStartTime(secondRollup) @@ -652,9 +652,9 @@ class RollupRunnerIT : RollupRestTestCase() { delay = delay, dimensions = listOf( randomCalendarDateHistogram().copy( - calendarInterval = "5s" - ) - ) + calendarInterval = "5s", + ), + ), ) // Create source index @@ -666,14 +666,14 @@ class RollupRunnerIT : RollupRestTestCase() { val jobStartTime = Instant.now() val rollupNow = rollup.copy( jobSchedule = IntervalSchedule(jobStartTime, 1, ChronoUnit.MINUTES), - jobEnabledTime = jobStartTime + jobEnabledTime = jobStartTime, ) rollup = createRollup(rollup = rollupNow, rollupId = rollupNow.id) val expectedFirstExecutionTime = rollup.jobSchedule.getNextExecutionTime(null).toEpochMilli() assertTrue("The first job execution time should be equal [job start time] + [delay].", expectedFirstExecutionTime == jobStartTime.toEpochMilli() + delay) - waitFor() { + waitFor { assertTrue("Target rollup index was not created", indexExists(rollup.targetIndex)) val rollupJob = getRollup(rollupId = rollup.id) assertNotNull("Rollup job doesn't have metadata set", rollupJob.metadataID) @@ -711,8 +711,8 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = false, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h")), metrics = listOf( - RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())) - ) + RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())), + ), ).let { createRollup(it, it.id) } val now = Instant.now() @@ -774,8 +774,8 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = true, dimensions = listOf(DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h")), metrics = listOf( - RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())) - ) + RollupMetrics(sourceField = "passenger_count", targetField = "passenger_count", metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup, Instant.now().minusMillis(testDelay).minusMillis(55000).toEpochMilli()) @@ -840,15 +840,15 @@ class RollupRunnerIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1s"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) - ) - ) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), + ), + ), ).let { createRollup(it, it.id) } // First run, backing index is empty: no mappings, no rollup_index setting, no rollupjobs in _META @@ -872,7 +872,7 @@ class RollupRunnerIT : RollupRestTestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${startedRollup.id}?if_seq_no=${startedRollup.seqNo}&if_primary_term=${startedRollup.primaryTerm}", - emptyMap(), rollup.copy(enabled = true).toHttpEntity() + emptyMap(), rollup.copy(enabled = true).toHttpEntity(), ) // Second run, backing index is setup just like any other rollup index updateRollupStartTime(rollup) @@ -926,15 +926,15 @@ class RollupRunnerIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1s"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) - ) - ) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), + ), + ), ).let { createRollup(it, it.id) } // First run, backing index is empty: no mappings, no rollup_index setting, no rollupjobs in _META @@ -963,7 +963,7 @@ class RollupRunnerIT : RollupRestTestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${startedRollup.id}?if_seq_no=${startedRollup.seqNo}&if_primary_term=${startedRollup.primaryTerm}", - emptyMap(), rollup.copy(enabled = true).toHttpEntity() + emptyMap(), rollup.copy(enabled = true).toHttpEntity(), ) // Second run, backing index is setup just like any other rollup index updateRollupStartTime(rollup) @@ -1021,15 +1021,15 @@ class RollupRunnerIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1s"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) - ) - ) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), + ), + ), ).let { createRollup(it, it.id) } // First run, backing index is empty: no mappings, no rollup_index setting, no rollupjobs in _META @@ -1079,7 +1079,7 @@ class RollupRunnerIT : RollupRestTestCase() { client().makeRequest( "PUT", "$ROLLUP_JOBS_BASE_URI/${startedRollup1.id}?if_seq_no=${startedRollup1.seqNo}&if_primary_term=${startedRollup1.primaryTerm}", - emptyMap(), job1.copy(enabled = true).toHttpEntity() + emptyMap(), job1.copy(enabled = true).toHttpEntity(), ) // Second run, backing index is setup just like any other rollup index updateRollupStartTime(job1) @@ -1132,15 +1132,15 @@ class RollupRunnerIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1s"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) - ) - ) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), + ), + ), ).let { createRollup(it, it.id) } // First run, backing index is empty: no mappings, no rollup_index setting, no rollupjobs in _META @@ -1217,15 +1217,15 @@ class RollupRunnerIT : RollupRestTestCase() { dimensions = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1s"), Terms("RatecodeID", "RatecodeID"), - Terms("PULocationID", "PULocationID") + Terms("PULocationID", "PULocationID"), ), metrics = listOf( RollupMetrics( sourceField = "passenger_count", targetField = "passenger_count", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) - ) - ) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), + ), + ), ).let { createRollup(it, it.id) } // First run, backing index is empty: no mappings, no rollup_index setting, no rollupjobs in _META @@ -1262,7 +1262,7 @@ class RollupRunnerIT : RollupRestTestCase() { "itemPrice": { "type": "float" } - }""" + }""", ) indexDoc(index, "1", """{"purchaseDate": 1683149130000.6497, "itemName": "shoes", "itemPrice": 100.5}""".trimIndent()) @@ -1294,9 +1294,9 @@ class RollupRunnerIT : RollupRestTestCase() { RollupMetrics( sourceField = "itemPrice", targetField = "itemPrice", - metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()) - ) - ) + metrics = listOf(Sum(), Min(), Max(), ValueCount(), Average()), + ), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(job) @@ -1336,11 +1336,11 @@ class RollupRunnerIT : RollupRestTestCase() { continuous = false, dimensions = listOf( DateHistogram(sourceField = "message.timestamp_received", targetField = "message.timestamp_received", fixedInterval = "10m"), - Terms("message.plugin", "message.plugin") + Terms("message.plugin", "message.plugin"), ), metrics = listOf( - RollupMetrics(sourceField = propertyName, targetField = propertyName, metrics = listOf(Max())) - ) + RollupMetrics(sourceField = propertyName, targetField = propertyName, metrics = listOf(Max())), + ), ).let { createRollup(it, it.id) } updateRollupStartTime(rollup) @@ -1378,7 +1378,7 @@ class RollupRunnerIT : RollupRestTestCase() { assertEquals( "Source and rollup index did not return same max results", rawAggRes.getValue(maxMetricName)["value"], - rollupAggRes.getValue(maxMetricName)["value"] + rollupAggRes.getValue(maxMetricName)["value"], ) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/util/RollupFieldValueExpressionResolverTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/util/RollupFieldValueExpressionResolverTests.kt index 66a905573..84d2ff7b3 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/util/RollupFieldValueExpressionResolverTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/util/RollupFieldValueExpressionResolverTests.kt @@ -6,10 +6,10 @@ package org.opensearch.indexmanagement.rollup.util import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever -import com.nhaarman.mockitokotlin2.doReturn import org.junit.Before import org.mockito.ArgumentMatchers.anyString import org.opensearch.cluster.service.ClusterService diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunnerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunnerIT.kt index 85a9d98bb..ce9bd13ab 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunnerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SMRunnerIT.kt @@ -5,13 +5,13 @@ package org.opensearch.indexmanagement.snapshotmanagement +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.SM_POLICIES_URI import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.CronSchedule import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import java.time.Instant.now import java.time.temporal.ChronoUnit diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt index aa7df873c..deeee184f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt @@ -14,9 +14,10 @@ import org.junit.After import org.junit.Before import org.opensearch.client.Response import org.opensearch.client.ResponseException +import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.common.xcontent.XContentType import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX @@ -29,7 +30,6 @@ import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import java.io.InputStream import java.time.Duration import java.time.Instant @@ -73,7 +73,7 @@ abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() { "POST", "${IndexManagementPlugin.SM_POLICIES_URI}/$smPolicyName?refresh=$refresh", emptyMap(), - StringEntity(smPolicyString, APPLICATION_JSON) + StringEntity(smPolicyString, APPLICATION_JSON), ) assertEquals("Unable to create a new snapshot management policy", RestStatus.CREATED, response.restStatus()) return response @@ -142,8 +142,8 @@ abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() { "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.id}?wait_for_active_shards=$waitForActiveShards", StringEntity( "{\"doc\":{\"sm_policy\":{\"schedule\":{\"interval\":{\"start_time\":\"$startTimeMillis\"}}}}}", - APPLICATION_JSON - ) + APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -187,8 +187,8 @@ abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() { } } """.trimIndent(), - APPLICATION_JSON - ) + APPLICATION_JSON, + ), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) @@ -259,14 +259,14 @@ abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() { } protected fun createRepository( - repository: String + repository: String, ) { val response = client() .makeRequest( "PUT", "_snapshot/$repository", emptyMap(), - StringEntity("{\"type\":\"fs\", \"settings\": {\"location\": \"$repository\"}}", APPLICATION_JSON) + StringEntity("{\"type\":\"fs\", \"settings\": {\"location\": \"$repository\"}}", APPLICATION_JSON), ) assertEquals("Unable to create a new repository", RestStatus.OK, response.restStatus()) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt index 9b924c2b9..c7c366c6c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt @@ -16,14 +16,15 @@ import org.opensearch.cluster.SnapshotsInProgress import org.opensearch.common.UUIDs import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.ToXContent -import org.opensearch.common.xcontent.XContentFactory import org.opensearch.core.xcontent.XContentParser -import org.opensearch.common.xcontent.XContentType -import org.opensearch.indexmanagement.opensearchapi.string import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.indexstatemanagement.randomChannel +import org.opensearch.indexmanagement.opensearchapi.string import org.opensearch.indexmanagement.opensearchapi.toMap import org.opensearch.indexmanagement.randomCronSchedule import org.opensearch.indexmanagement.randomInstant @@ -33,7 +34,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.jobscheduler.spi.schedule.CronSchedule import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.snapshots.Snapshot import org.opensearch.snapshots.SnapshotId import org.opensearch.snapshots.SnapshotInfo @@ -65,7 +65,7 @@ fun randomSMMetadata( creation = SMMetadata.WorkflowMetadata( currentState = creationCurrentState, trigger = SMMetadata.Trigger( - time = nextCreationTime + time = nextCreationTime, ), started = if (startedCreation != null) listOf(startedCreation) else null, latestExecution = creationLatestExecution, @@ -74,7 +74,7 @@ fun randomSMMetadata( deletion = SMMetadata.WorkflowMetadata( currentState = deletionCurrentState, trigger = SMMetadata.Trigger( - time = nextDeletionTime + time = nextDeletionTime, ), started = startedDeletion, latestExecution = deletionLatestExecution, @@ -112,7 +112,7 @@ fun randomSMPolicy( jobSchedule: IntervalSchedule = IntervalSchedule(randomInstant(), 1, ChronoUnit.MINUTES), seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, - notificationConfig: NotificationConfig? = null + notificationConfig: NotificationConfig? = null, ): SMPolicy { if (dateFormat != null) { snapshotConfig["date_format"] = dateFormat @@ -159,7 +159,7 @@ fun randomPolicyDeletion( maxCount = deletionMaxCount, maxAge = deletionMaxAge, minCount = deletionMinCount, - ) + ), ) } @@ -221,7 +221,7 @@ fun mockSnapshotInfo( emptyList(), false, mapOf("sm_policy" to policyName), - remoteStoreIndexShallowCopy + remoteStoreIndexShallowCopy, ) return result } @@ -248,7 +248,7 @@ fun mockInProgressSnapshotInfo( "", mapOf("sm_policy" to "daily-snapshot"), Version.CURRENT, - remoteStoreIndexShallowCopy + remoteStoreIndexShallowCopy, ) return SnapshotInfo(entry) } @@ -264,8 +264,8 @@ fun mockSnapshotInfoList(num: Int, namePrefix: String = randomAlphaOfLength(10)) for (i in 1..num) { result.add( mockSnapshotInfo( - name = namePrefix + i - ) + name = namePrefix + i, + ), ) } return result.toList() diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ActionTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ActionTests.kt index 24a5949aa..5bdf53a9b 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ActionTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ActionTests.kt @@ -9,10 +9,10 @@ import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.DELETE_SM_POLICY_ACTION_TYPE import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.EXPLAIN_SM_POLICY_ACTION_NAME import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.EXPLAIN_SM_POLICY_ACTION_TYPE -import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICY_ACTION_NAME -import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICY_ACTION_TYPE import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICIES_ACTION_NAME import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICIES_ACTION_TYPE +import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICY_ACTION_NAME +import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.GET_SM_POLICY_ACTION_TYPE import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.INDEX_SM_POLICY_ACTION_NAME import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.INDEX_SM_POLICY_ACTION_TYPE import org.opensearch.indexmanagement.snapshotmanagement.api.transport.SMActions.START_SM_POLICY_ACTION_NAME diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ResponseTests.kt index 18987f768..37cb75b64 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/action/ResponseTests.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.action import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT_TYPE_AND_USER import org.opensearch.indexmanagement.snapshotmanagement.api.transport.explain.ExplainSMPolicyResponse import org.opensearch.indexmanagement.snapshotmanagement.api.transport.get.GetSMPoliciesResponse @@ -17,7 +18,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.randomSMMetadata import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy import org.opensearch.indexmanagement.snapshotmanagement.smDocIdToPolicyName import org.opensearch.indexmanagement.snapshotmanagement.toMap -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase class ResponseTests : OpenSearchTestCase() { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachineTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachineTests.kt index d7af63575..392aefdea 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachineTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/SMStateMachineTests.kt @@ -33,7 +33,7 @@ open class SMStateMachineTests : MocksTestCase() { mockCreateSnapshotCall(response = mockCreateSnapshotResponse()) val metadata = randomSMMetadata( - creationCurrentState = currentState + creationCurrentState = currentState, ) val job = randomSMPolicy() val stateMachineSpy = spy(SMStateMachine(client, job, metadata, settings, threadPool, indicesManager)) @@ -73,7 +73,7 @@ open class SMStateMachineTests : MocksTestCase() { creationCurrentState = currentState, creationLatestExecution = randomLatestExecution( status = SMMetadata.LatestExecution.Status.RETRYING, - ) + ), ) val job = randomSMPolicy() val stateMachineSpy = spy(SMStateMachine(client, job, metadata, settings, threadPool, indicesManager)) @@ -122,7 +122,7 @@ open class SMStateMachineTests : MocksTestCase() { deletionRetryCount = 2, deletionLatestExecution = randomLatestExecution( status = SMMetadata.LatestExecution.Status.RETRYING, - ) + ), ) val job = randomSMPolicy() @@ -146,7 +146,7 @@ open class SMStateMachineTests : MocksTestCase() { deletionRetryCount = 1, deletionLatestExecution = randomLatestExecution( status = SMMetadata.LatestExecution.Status.RETRYING, - ) + ), ) val job = randomSMPolicy() @@ -172,11 +172,11 @@ open class SMStateMachineTests : MocksTestCase() { startedDeletion = listOf(snapshotName), deletionLatestExecution = randomLatestExecution( startTime = now().minusSeconds(50), - ) + ), ) val job = randomSMPolicy( policyName = "daily-snapshot", - deletionTimeLimit = TimeValue.timeValueSeconds(5) + deletionTimeLimit = TimeValue.timeValueSeconds(5), ) val stateMachineSpy = spy(SMStateMachine(client, job, metadata, settings, threadPool, indicesManager)) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingStateTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingStateTests.kt index 7281ad22e..547d8cda9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingStateTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreatingStateTests.kt @@ -10,12 +10,12 @@ import org.opensearch.indexmanagement.MocksTestCase import org.opensearch.indexmanagement.snapshotmanagement.engine.SMStateMachine import org.opensearch.indexmanagement.snapshotmanagement.engine.states.SMResult import org.opensearch.indexmanagement.snapshotmanagement.engine.states.SMState -import org.opensearch.indexmanagement.snapshotmanagement.randomSMMetadata -import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy import org.opensearch.indexmanagement.snapshotmanagement.mockCreateSnapshotResponse import org.opensearch.indexmanagement.snapshotmanagement.mockGetSnapshotResponse import org.opensearch.indexmanagement.snapshotmanagement.mockSnapshotInfo import org.opensearch.indexmanagement.snapshotmanagement.model.SMMetadata +import org.opensearch.indexmanagement.snapshotmanagement.randomSMMetadata +import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy import java.time.Instant.now import java.time.temporal.ChronoUnit diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedStateTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedStateTests.kt index 27ef430e7..d0d46eec6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedStateTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationFinishedStateTests.kt @@ -153,7 +153,7 @@ class CreationFinishedStateTests : MocksTestCase() { ) val job = randomSMPolicy( policyName = "daily-snapshot", - creationTimeLimit = TimeValue.timeValueSeconds(5) + creationTimeLimit = TimeValue.timeValueSeconds(5), ) val context = SMStateMachine(client, job, metadata, settings, threadPool, indicesManager) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationStartStateTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationStartStateTests.kt index 1eeee7e06..81e1ccaf6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationStartStateTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/creation/CreationStartStateTests.kt @@ -17,7 +17,7 @@ class CreationStartStateTests : MocksTestCase() { fun `test start state execution`() = runBlocking { val metadata = randomSMMetadata( - creationCurrentState = SMState.CREATION_FINISHED + creationCurrentState = SMState.CREATION_FINISHED, ) val job = randomSMPolicy() val context = SMStateMachine(client, job, metadata, settings, threadPool, indicesManager) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingStateTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingStateTests.kt index f9eaa7137..e4ad2d287 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingStateTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletingStateTests.kt @@ -145,7 +145,7 @@ class DeletingStateTests : MocksTestCase() { deletionCurrentState = SMState.DELETION_CONDITION_MET, deletionLatestExecution = randomLatestExecution( startTime = now().minusSeconds(10), - ) + ), ) val job = randomSMPolicy(policyName = "daily-snapshot") val context = SMStateMachine(client, job, metadata, settings, threadPool, indicesManager) @@ -165,7 +165,7 @@ class DeletingStateTests : MocksTestCase() { startedDeletion = listOf(randomSnapshotName()), ) val job = randomSMPolicy( - deletionNull = true + deletionNull = true, ) val context = SMStateMachine(client, job, metadata, settings, threadPool, indicesManager) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetStateTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetStateTests.kt index 3b1cbc6d5..600836713 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetStateTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionConditionMetStateTests.kt @@ -51,7 +51,7 @@ class DeletionConditionMetStateTests : MocksTestCase() { startedDeletion = listOf(randomSnapshotName()), ) val job = randomSMPolicy( - deletionNull = true + deletionNull = true, ) val context = SMStateMachine(client, job, metadata, settings, threadPool, indicesManager) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionStartStateTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionStartStateTests.kt index 7e512e912..15baa3113 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionStartStateTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/engine/states/deletion/DeletionStartStateTests.kt @@ -17,7 +17,7 @@ class DeletionStartStateTests : MocksTestCase() { fun `test start state execution`() = runBlocking { val metadata = randomSMMetadata( - deletionCurrentState = SMState.DELETION_FINISHED + deletionCurrentState = SMState.DELETION_FINISHED, ) val job = randomSMPolicy() val context = SMStateMachine(client, job, metadata, settings, threadPool, indicesManager) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt index 130e8bf4b..c8e1f9d89 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt @@ -6,12 +6,12 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementRestTestCase import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy -import org.opensearch.core.rest.RestStatus class RestDeleteSnapshotManagementIT : SnapshotManagementRestTestCase() { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt index ba31ad552..3d94d3bd9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementRestTestCase import org.opensearch.indexmanagement.snapshotmanagement.api.transport.explain.ExplainSMPolicyResponse @@ -16,7 +17,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import java.time.Instant.now import java.time.temporal.ChronoUnit @@ -29,7 +29,7 @@ class RestExplainSnapshotManagementIT : SnapshotManagementRestTestCase() { jobEnabled = true, jobEnabledTime = now(), jobSchedule = IntervalSchedule(now(), 1, ChronoUnit.MINUTES), - ) + ), ) updateSMPolicyStartTime(smPolicy) waitFor(timeout = timeout) { @@ -71,7 +71,7 @@ class RestExplainSnapshotManagementIT : SnapshotManagementRestTestCase() { createSMPolicy( randomSMPolicy( jobEnabled = true, - ) + ), ) } // if this proves to be flaky, just index the metadata directly instead of executing to generate metadata @@ -99,7 +99,7 @@ class RestExplainSnapshotManagementIT : SnapshotManagementRestTestCase() { createSMPolicy( randomSMPolicy( jobEnabled = true, - ) + ), ) } // if this proves to be flaky, just index the metadata directly instead of executing to generate metadata diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt index 4565b8e44..938ccf3f4 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler import org.apache.http.HttpHeaders import org.apache.http.message.BasicHeader import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.opensearchapi.convertToMap @@ -16,7 +17,6 @@ import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companion.ENABLED_TIME_FIELD import org.opensearch.indexmanagement.snapshotmanagement.model.SMPolicy.Companion.SM_TYPE import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy -import org.opensearch.core.rest.RestStatus class RestGetSnapshotManagementIT : SnapshotManagementRestTestCase() { @@ -30,7 +30,7 @@ class RestGetSnapshotManagementIT : SnapshotManagementRestTestCase() { seqNo = indexedSMPolicy.seqNo, primaryTerm = indexedSMPolicy.primaryTerm, jobLastUpdateTime = indexedSMPolicy.jobLastUpdateTime, - jobSchedule = indexedSMPolicy.jobSchedule + jobSchedule = indexedSMPolicy.jobSchedule, ) assertEquals("Indexed and retrieved snapshot management policies differ", smPolicy, indexedSMPolicy) } @@ -62,7 +62,7 @@ class RestGetSnapshotManagementIT : SnapshotManagementRestTestCase() { val smPolicies = randomList(1, 15) { createSMPolicy(randomSMPolicy()) } val response = client().makeRequest( "GET", IndexManagementPlugin.SM_POLICIES_URI, null, - BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ) val map = response.asMap() val totalPolicies = map["total_policies"] as Int @@ -85,7 +85,7 @@ class RestGetSnapshotManagementIT : SnapshotManagementRestTestCase() { fun `test getting all snapshot management policies when config index doesn't exist`() { val response = client().makeRequest( "GET", IndexManagementPlugin.SM_POLICIES_URI, null, - BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ) val map = response.asMap() val totalPolicies = map["total_policies"] as Int diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt index d260f5868..80dbd3550 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.SM_POLICIES_URI import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT_TYPE_AND_USER @@ -20,7 +21,6 @@ import org.opensearch.indexmanagement.util.IndexUtils import org.opensearch.indexmanagement.util.NO_ID import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._SEQ_NO -import org.opensearch.core.rest.RestStatus import java.time.Instant class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { @@ -39,7 +39,7 @@ class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { // During indexing, we update these two fields so we need to override them here before the equality check smPolicy = smPolicy.copy( jobLastUpdateTime = Instant.ofEpochMilli(responseSMPolicy[SMPolicy.LAST_UPDATED_TIME_FIELD] as Long), - schemaVersion = IndexUtils.indexManagementConfigSchemaVersion + schemaVersion = IndexUtils.indexManagementConfigSchemaVersion, ) assertEquals("Created and returned snapshot management policies differ", smPolicy.toMap(XCONTENT_WITHOUT_TYPE_AND_USER), responseSMPolicy) } @@ -50,7 +50,7 @@ class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { val updateResponse = client().makeRequest( "PUT", "$SM_POLICIES_URI/${smPolicy.policyName}?refresh=true&if_seq_no=${smPolicy.seqNo}&if_primary_term=${smPolicy.primaryTerm}", - emptyMap(), smPolicy.toHttpEntity() + emptyMap(), smPolicy.toHttpEntity(), ) assertEquals("Update snapshot management policy failed", RestStatus.OK, updateResponse.restStatus()) @@ -72,7 +72,7 @@ class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { client().makeRequest( "PUT", "$SM_POLICIES_URI/${smPolicy.policyName}?refresh=true&if_seq_no=10251989&if_primary_term=2342", - emptyMap(), smPolicy.toHttpEntity() + emptyMap(), smPolicy.toHttpEntity(), ) fail("expected 409 ResponseException") } catch (e: ResponseException) { @@ -82,7 +82,7 @@ class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { client().makeRequest( "PUT", "$SM_POLICIES_URI/${smPolicy.policyName}?refresh=true", - emptyMap(), smPolicy.toHttpEntity() + emptyMap(), smPolicy.toHttpEntity(), ) fail("expected exception") } catch (e: ResponseException) { @@ -96,7 +96,7 @@ class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { client().makeRequest( "PUT", "$SM_POLICIES_URI/${smPolicy.policyName}?refresh=true&if_seq_no=10251989&if_primary_term=2342", - emptyMap(), smPolicy.toHttpEntity() + emptyMap(), smPolicy.toHttpEntity(), ) fail("expected exception") } catch (e: ResponseException) { @@ -137,7 +137,7 @@ class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { val mappingsMap = parserMap[INDEX_MANAGEMENT_INDEX]!!["mappings"] as Map val expected = createParser( XContentType.JSON.xContent(), - javaClass.classLoader.getResource("mappings/opendistro-ism-config.json").readText() + javaClass.classLoader.getResource("mappings/opendistro-ism-config.json").readText(), ) val expectedMap = expected.map() diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt index df58d309b..038d20a71 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt @@ -6,11 +6,11 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementRestTestCase import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy -import org.opensearch.core.rest.RestStatus import java.time.Instant class RestStartSnapshotManagementIT : SnapshotManagementRestTestCase() { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt index e0711beb6..d75f1c858 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt @@ -6,11 +6,11 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementRestTestCase import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy -import org.opensearch.core.rest.RestStatus import java.time.Instant class RestStopSnapshotManagementIT : SnapshotManagementRestTestCase() { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/TestHelpers.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/TestHelpers.kt index 415e44718..7e0256583 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/TestHelpers.kt @@ -7,13 +7,13 @@ package org.opensearch.indexmanagement.transform import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.common.io.stream.BytesStreamOutput -import org.opensearch.core.common.io.stream.NamedWriteableAwareStreamInput -import org.opensearch.core.common.io.stream.NamedWriteableRegistry import org.opensearch.common.settings.Settings -import org.opensearch.core.xcontent.ToXContent import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.core.common.io.stream.NamedWriteableAwareStreamInput +import org.opensearch.core.common.io.stream.NamedWriteableRegistry import org.opensearch.core.index.Index import org.opensearch.core.index.shard.ShardId +import org.opensearch.core.xcontent.ToXContent import org.opensearch.indexmanagement.common.model.dimension.Dimension import org.opensearch.indexmanagement.opensearchapi.string import org.opensearch.indexmanagement.randomInstant @@ -44,19 +44,19 @@ fun randomGroups(): List { } fun sumAggregation(): AggregationBuilder = AggregationBuilders.sum( - OpenSearchRestTestCase.randomAlphaOfLength(10) + OpenSearchRestTestCase.randomAlphaOfLength(10), ).field(OpenSearchRestTestCase.randomAlphaOfLength(10)) fun maxAggregation(): AggregationBuilder = AggregationBuilders.max( - OpenSearchRestTestCase.randomAlphaOfLength(10) + OpenSearchRestTestCase.randomAlphaOfLength(10), ).field(OpenSearchRestTestCase.randomAlphaOfLength(10)) fun minAggregation(): AggregationBuilder = AggregationBuilders.min( - OpenSearchRestTestCase.randomAlphaOfLength(10) + OpenSearchRestTestCase.randomAlphaOfLength(10), ).field(OpenSearchRestTestCase.randomAlphaOfLength(10)) fun valueCountAggregation(): AggregationBuilder = AggregationBuilders.count( - OpenSearchRestTestCase.randomAlphaOfLength(10) + OpenSearchRestTestCase.randomAlphaOfLength(10), ).field(OpenSearchRestTestCase.randomAlphaOfLength(10)) fun avgAggregation(): AggregationBuilder = AggregationBuilders.avg( - OpenSearchRestTestCase.randomAlphaOfLength(10) + OpenSearchRestTestCase.randomAlphaOfLength(10), ).field(OpenSearchRestTestCase.randomAlphaOfLength(10)) fun randomAggregationBuilder(): AggregationBuilder { @@ -93,7 +93,7 @@ fun randomTransform(): Transform { groups = randomGroups(), aggregations = randomAggregationFactories(), continuous = isContinuous, - user = randomUser() + user = randomUser(), ) } @@ -111,7 +111,7 @@ fun randomTransformMetadata(): TransformMetadata { failureReason = if (status == TransformMetadata.Status.FAILED) OpenSearchRestTestCase.randomAlphaOfLength(10) else null, stats = randomTransformStats(), shardIDToGlobalCheckpoint = if (isContinuous) randomShardIDToGlobalCheckpoint() else null, - continuousStats = if (isContinuous) randomContinuousStats() else null + continuousStats = if (isContinuous) randomContinuousStats() else null, ) } @@ -121,7 +121,7 @@ fun randomTransformStats(): TransformStats { documentsProcessed = OpenSearchRestTestCase.randomNonNegativeLong(), documentsIndexed = OpenSearchRestTestCase.randomNonNegativeLong(), indexTimeInMillis = OpenSearchRestTestCase.randomNonNegativeLong(), - searchTimeInMillis = OpenSearchRestTestCase.randomNonNegativeLong() + searchTimeInMillis = OpenSearchRestTestCase.randomNonNegativeLong(), ) } @@ -142,7 +142,7 @@ fun randomShardID(): ShardId { fun randomContinuousStats(): ContinuousTransformStats { return ContinuousTransformStats( lastTimestamp = randomInstant(), - documentsBehind = randomDocumentsBehind() + documentsBehind = randomDocumentsBehind(), ) } @@ -168,7 +168,7 @@ fun randomISMTransform(): ISMTransform { pageSize = OpenSearchRestTestCase.randomIntBetween(1, 10000), groups = randomGroups(), dataSelectionQuery = randomTermQuery(), - aggregations = randomAggregationFactories() + aggregations = randomAggregationFactories(), ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt index d407e5fec..478f8af44 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt @@ -15,10 +15,11 @@ import org.junit.AfterClass import org.opensearch.client.Response import org.opensearch.client.RestClient import org.opensearch.common.settings.Settings +import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentParser import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken -import org.opensearch.common.xcontent.XContentType import org.opensearch.index.seqno.SequenceNumbers import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI @@ -30,7 +31,6 @@ import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.util._ID import org.opensearch.indexmanagement.util._PRIMARY_TERM import org.opensearch.indexmanagement.util._SEQ_NO -import org.opensearch.core.rest.RestStatus import org.opensearch.search.SearchModule abstract class TransformRestTestCase : IndexManagementRestTestCase() { @@ -46,7 +46,7 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { transform: Transform, transformId: String = randomAlphaOfLength(10), refresh: Boolean = true, - client: RestClient? = null + client: RestClient? = null, ): Transform { if (!indexExists(transform.sourceIndex)) { createTransformSourceIndex(transform) @@ -60,7 +60,7 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { return transform.copy( id = createdId, seqNo = (transformJson["_seq_no"] as Int).toLong(), - primaryTerm = (transformJson["_primary_term"] as Int).toLong() + primaryTerm = (transformJson["_primary_term"] as Int).toLong(), ) } @@ -68,7 +68,7 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { transformString: String, transformId: String, refresh: Boolean = true, - userClient: RestClient? = null + userClient: RestClient? = null, ): Response { val client = userClient ?: client() val response = client @@ -76,7 +76,7 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { "PUT", "$TRANSFORM_BASE_URI/$transformId?refresh=$refresh", emptyMap(), - StringEntity(transformString, APPLICATION_JSON) + StringEntity(transformString, APPLICATION_JSON), ) assertEquals("Unable to create a new transform", RestStatus.CREATED, response.restStatus()) return response @@ -87,7 +87,7 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { .makeRequest( "POST", "$TRANSFORM_BASE_URI/$transformId/_stop", - emptyMap() + emptyMap(), ) assertEquals("Unable to disable transform $transformId", RestStatus.OK, response.restStatus()) } @@ -117,7 +117,7 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { protected fun getTransformMetadata(metadataId: String): TransformMetadata { val response = client().makeRequest( - "GET", "$INDEX_MANAGEMENT_INDEX/_doc/$metadataId", null, BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json") + "GET", "$INDEX_MANAGEMENT_INDEX/_doc/$metadataId", null, BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), ) assertEquals("Unable to get transform metadata $metadataId", RestStatus.OK, response.restStatus()) @@ -146,7 +146,7 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { protected fun getTransform( transformId: String, header: BasicHeader = BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), - userClient: RestClient? = null + userClient: RestClient? = null, ): Transform { val client = userClient ?: client() val response = client.makeRequest("GET", "$TRANSFORM_BASE_URI/$transformId", null, header) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRunnerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRunnerIT.kt index 3f4dfdcdb..262aec5b5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRunnerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRunnerIT.kt @@ -11,6 +11,7 @@ import org.opensearch.client.Request import org.opensearch.client.RequestOptions import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.index.query.TermQueryBuilder import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Histogram @@ -21,7 +22,6 @@ import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule import org.opensearch.rest.RestRequest -import org.opensearch.core.rest.RestStatus import org.opensearch.script.Script import org.opensearch.script.ScriptType import org.opensearch.search.aggregations.AggregationBuilders @@ -52,8 +52,8 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") - ) + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), + ), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -93,9 +93,9 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), ), - dataSelectionQuery = TermQueryBuilder("store_and_fwd_flag", "N") + dataSelectionQuery = TermQueryBuilder("store_and_fwd_flag", "N"), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -153,25 +153,25 @@ class TransformRunnerIT : TransformRestTestCase() { ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "state.sum += doc[\"total_amount\"].value; state.count += doc[\"passenger_count\"].value", - emptyMap() - ) + emptyMap(), + ), ) .combineScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "def d = new long[2]; d[0] = state.sum; d[1] = state.count; return d", - emptyMap() - ) + emptyMap(), + ), ) .reduceScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "double sum = 0; double count = 0; for (a in states) { sum += a[0]; count += a[1]; } return sum/count", - emptyMap() - ) - ) + emptyMap(), + ), + ), ) val transform = Transform( @@ -188,9 +188,9 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), ), - aggregations = aggregatorFactories + aggregations = aggregatorFactories, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -235,9 +235,9 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = storeAndForwardTerm, targetField = storeAndForwardTerm) + Terms(sourceField = storeAndForwardTerm, targetField = storeAndForwardTerm), ), - aggregations = AggregatorFactories.builder().addAggregator(AggregationBuilders.avg(fareAmount).field(fareAmount)) + aggregations = AggregatorFactories.builder().addAggregator(AggregationBuilders.avg(fareAmount).field(fareAmount)), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -281,7 +281,7 @@ class TransformRunnerIT : TransformRestTestCase() { val transformAggBucket = transformAggBuckets[idx] assertEquals( "The doc_count had a different value raw[$rawAggBucket] transform[$transformAggBucket]", - rawAggBucket["doc_count"]!!, transformAggBucket["doc_count"]!! + rawAggBucket["doc_count"]!!, transformAggBucket["doc_count"]!!, ) } } @@ -312,9 +312,9 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = pickupDateTime, targetField = pickupDateTime) + Terms(sourceField = pickupDateTime, targetField = pickupDateTime), ), - aggregations = AggregatorFactories.builder().addAggregator(AggregationBuilders.avg(fareAmount).field(fareAmount)) + aggregations = AggregatorFactories.builder().addAggregator(AggregationBuilders.avg(fareAmount).field(fareAmount)), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -403,9 +403,9 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = storeAndForward, targetField = storeAndForward) + Terms(sourceField = storeAndForward, targetField = storeAndForward), ), - aggregations = AggregatorFactories.builder().addAggregator(avgFareAmountAgg).addAggregator(maxDateAggBuilder) + aggregations = AggregatorFactories.builder().addAggregator(avgFareAmountAgg).addAggregator(maxDateAggBuilder), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -496,9 +496,9 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = pickupDateTime, targetField = pickupDateTimeTerm) + Terms(sourceField = pickupDateTime, targetField = pickupDateTimeTerm), ), - aggregations = AggregatorFactories.builder().addAggregator(avgFareAmountAgg).addAggregator(countDateAggBuilder) + aggregations = AggregatorFactories.builder().addAggregator(avgFareAmountAgg).addAggregator(countDateAggBuilder), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -606,8 +606,8 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") - ) + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), + ), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -635,25 +635,25 @@ class TransformRunnerIT : TransformRestTestCase() { ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "state.sum += doc[\"random_field\"].value; state.count += doc[\"passenger_count\"].value", - emptyMap() - ) + emptyMap(), + ), ) .combineScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "def d = new long[2]; d[0] = state.sum; d[1] = state.count; return d", - emptyMap() - ) + emptyMap(), + ), ) .reduceScript( Script( ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "double sum = 0; double count = 0; for (a in states) { sum += a[0]; count += a[1]; } return sum/count", - emptyMap() - ) - ) + emptyMap(), + ), + ), ) val transform = Transform( @@ -672,9 +672,9 @@ class TransformRunnerIT : TransformRestTestCase() { groups = listOf( Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), Histogram(sourceField = "passenger_count", targetField = "count", interval = 2.0), - DateHistogram(sourceField = "tpep_pickup_datetime", targetField = "date", fixedInterval = "1d") + DateHistogram(sourceField = "tpep_pickup_datetime", targetField = "date", fixedInterval = "1d"), ), - aggregations = aggregatorFactories + aggregations = aggregatorFactories, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -698,8 +698,8 @@ class TransformRunnerIT : TransformRestTestCase() { aggregatorFactories.addPipelineAggregator( BucketScriptPipelineAggregationBuilder( "test_pipeline_aggregation", - Script("1") - ) + Script("1"), + ), ) val transform = Transform( @@ -718,9 +718,9 @@ class TransformRunnerIT : TransformRestTestCase() { groups = listOf( Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), Histogram(sourceField = "passenger_count", targetField = "count", interval = 2.0), - DateHistogram(sourceField = "tpep_pickup_datetime", targetField = "date", fixedInterval = "1d") + DateHistogram(sourceField = "tpep_pickup_datetime", targetField = "date", fixedInterval = "1d"), ), - aggregations = aggregatorFactories + aggregations = aggregatorFactories, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) } @@ -744,8 +744,8 @@ class TransformRunnerIT : TransformRestTestCase() { } } """.trimIndent(), - ContentType.APPLICATION_JSON - ) + ContentType.APPLICATION_JSON, + ), ) client().makeRequest("PUT", "/_data_stream/$dataStreamName") @@ -770,8 +770,8 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 100, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") - ) + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), + ), ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -812,9 +812,9 @@ class TransformRunnerIT : TransformRestTestCase() { pageSize = 100, groups = listOf( Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), - Histogram(sourceField = "trip_distance", targetField = "distance", interval = 0.1) + Histogram(sourceField = "trip_distance", targetField = "distance", interval = 0.1), ), - continuous = true + continuous = true, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -880,10 +880,10 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 100, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), ), continuous = true, - aggregations = aggregatorFactories + aggregations = aggregatorFactories, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -909,7 +909,7 @@ class TransformRunnerIT : TransformRestTestCase() { var hits = waitFor { val response = client().makeRequest( "GET", "continuous-transform-target-index/_search", - StringEntity("{}", ContentType.APPLICATION_JSON) + StringEntity("{}", ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val responseHits = response.asMap().getValue("hits") as Map<*, *> @@ -960,7 +960,7 @@ class TransformRunnerIT : TransformRestTestCase() { hits = waitFor { val response = client().makeRequest( "GET", "continuous-transform-target-index/_search", - StringEntity("{}", ContentType.APPLICATION_JSON) + StringEntity("{}", ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val responseHits = response.asMap().getValue("hits") as Map<*, *> @@ -1008,10 +1008,10 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 100, groups = listOf( - Histogram(sourceField = "iterating_id", targetField = "id_group", interval = 5.0) + Histogram(sourceField = "iterating_id", targetField = "id_group", interval = 5.0), ), continuous = true, - aggregations = aggregatorFactories + aggregations = aggregatorFactories, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -1038,7 +1038,7 @@ class TransformRunnerIT : TransformRestTestCase() { var hits = waitFor { val response = client().makeRequest( "GET", "${transform.targetIndex}/_search", - StringEntity("{\"size\": 25}", ContentType.APPLICATION_JSON) + StringEntity("{\"size\": 25}", ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val responseHits = response.asMap().getValue("hits") as Map<*, *> @@ -1098,7 +1098,7 @@ class TransformRunnerIT : TransformRestTestCase() { hits = waitFor { val response = client().makeRequest( "GET", "${transform.targetIndex}/_search", - StringEntity("{\"size\": 25}", ContentType.APPLICATION_JSON) + StringEntity("{\"size\": 25}", ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val responseHits = response.asMap().getValue("hits") as Map<*, *> @@ -1138,9 +1138,9 @@ class TransformRunnerIT : TransformRestTestCase() { roles = emptyList(), pageSize = 100, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), ), - continuous = true + continuous = true, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -1225,10 +1225,10 @@ class TransformRunnerIT : TransformRestTestCase() { pageSize = 100, groups = listOf( Histogram(sourceField = "iterating_id", targetField = "id_group", interval = 5.0), - Terms(sourceField = "term_id", targetField = "id_term") + Terms(sourceField = "term_id", targetField = "id_term"), ), continuous = true, - aggregations = aggregatorFactories + aggregations = aggregatorFactories, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -1255,7 +1255,7 @@ class TransformRunnerIT : TransformRestTestCase() { var hits = waitFor { val response = client().makeRequest( "GET", "${transform.targetIndex}/_search", - StringEntity("{\"size\": 25}", ContentType.APPLICATION_JSON) + StringEntity("{\"size\": 25}", ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val responseHits = response.asMap().getValue("hits") as Map<*, *> @@ -1329,7 +1329,7 @@ class TransformRunnerIT : TransformRestTestCase() { hits = waitFor { val response = client().makeRequest( "GET", "${transform.targetIndex}/_search", - StringEntity("{\"size\": 40}", ContentType.APPLICATION_JSON) + StringEntity("{\"size\": 40}", ContentType.APPLICATION_JSON), ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) val responseHits = response.asMap().getValue("hits") as Map<*, *> @@ -1367,7 +1367,6 @@ class TransformRunnerIT : TransformRestTestCase() { } fun `test continuous transform with a lot of buckets`() { - // Create index with high cardinality fields val sourceIndex = "index_with_lots_of_buckets" @@ -1400,9 +1399,9 @@ class TransformRunnerIT : TransformRestTestCase() { pageSize = 1000, groups = listOf( Terms(sourceField = "id1.keyword", targetField = "id1"), - Terms(sourceField = "id2.keyword", targetField = "id2") + Terms(sourceField = "id2.keyword", targetField = "id2"), ), - continuous = true + continuous = true, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -1449,7 +1448,6 @@ class TransformRunnerIT : TransformRestTestCase() { } private fun createIndexAndBulkInsert(name: String, settings: Settings?, mapping: String?, aliases: String?, bulkData: String) { - if (settings != null || mapping != null || aliases != null) { createIndex(name, settings, mapping, aliases) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/action/RequestTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/action/RequestTests.kt index 61023eea5..c2ebe6c27 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/action/RequestTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/action/RequestTests.kt @@ -57,7 +57,7 @@ class RequestTests : OpenSearchTestCase() { val transform = randomTransform().copy(seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM) val req = IndexTransformRequest( transform = transform, - refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE + refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE, ).index(INDEX_MANAGEMENT_INDEX) val out = BytesStreamOutput().apply { req.writeTo(this) } @@ -73,7 +73,7 @@ class RequestTests : OpenSearchTestCase() { val transform = randomTransform().copy(seqNo = 1L, primaryTerm = 2L) val req = IndexTransformRequest( transform = transform, - refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE + refreshPolicy = WriteRequest.RefreshPolicy.IMMEDIATE, ).index(INDEX_MANAGEMENT_INDEX) val out = BytesStreamOutput().apply { req.writeTo(this) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/action/ResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/action/ResponseTests.kt index 9605495ba..98e89533f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/action/ResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/action/ResponseTests.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.transform.action import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.transform.action.explain.ExplainTransformResponse import org.opensearch.indexmanagement.transform.action.get.GetTransformResponse import org.opensearch.indexmanagement.transform.action.get.GetTransformsResponse @@ -15,7 +16,6 @@ import org.opensearch.indexmanagement.transform.action.preview.PreviewTransformR import org.opensearch.indexmanagement.transform.buildStreamInputForTransforms import org.opensearch.indexmanagement.transform.randomExplainTransform import org.opensearch.indexmanagement.transform.randomTransform -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import org.opensearch.test.OpenSearchTestCase.randomList @@ -47,7 +47,7 @@ class ResponseTests : OpenSearchTestCase() { fun `test preview transform response`() { val documents = listOf( mapOf("a" to mapOf("90.0" to 100), "b" to "id1", "c" to 100), - mapOf("a" to mapOf("90.0" to 50), "b" to "id2", "c" to 20) + mapOf("a" to mapOf("90.0" to 50), "b" to "id2", "c" to 20), ) val res = PreviewTransformResponse(documents, RestStatus.OK) val out = BytesStreamOutput().apply { res.writeTo(this) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransformTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransformTests.kt index 6129f453f..b576dc657 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransformTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/model/ISMTransformTests.kt @@ -30,15 +30,15 @@ class ISMTransformTests : OpenSearchTestCase() { } fun `test ism transform requires page size between 1 and 10K`() { - assertFailsWith(IllegalArgumentException:: class, "Page size cannot be less than 1") { + assertFailsWith(IllegalArgumentException::class, "Page size cannot be less than 1") { randomISMTransform().copy(pageSize = -1) } - assertFailsWith(IllegalArgumentException:: class, "Page size cannot be less than 1") { + assertFailsWith(IllegalArgumentException::class, "Page size cannot be less than 1") { randomISMTransform().copy(pageSize = 0) } - assertFailsWith(IllegalArgumentException:: class, "Page size cannot be greater than 10000") { + assertFailsWith(IllegalArgumentException::class, "Page size cannot be greater than 10000") { randomISMTransform().copy(pageSize = 10001) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/model/XContentTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/model/XContentTests.kt index e714d56ae..2c931d69d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/model/XContentTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/model/XContentTests.kt @@ -7,9 +7,9 @@ package org.opensearch.indexmanagement.transform.model import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.LoggingDeprecationHandler +import org.opensearch.common.xcontent.XContentType import org.opensearch.core.xcontent.NamedXContentRegistry import org.opensearch.core.xcontent.XContentParser -import org.opensearch.common.xcontent.XContentType import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT_TYPE import org.opensearch.indexmanagement.opensearchapi.parseWithType import org.opensearch.indexmanagement.transform.randomTransform @@ -24,7 +24,7 @@ class XContentTests : OpenSearchTestCase() { val transformMetadata = randomTransformMetadata() val transformMetadataString = transformMetadata.toJsonString(XCONTENT_WITHOUT_TYPE) val parsedTransformMetadata = TransformMetadata.parse( - parser(transformMetadataString), transformMetadata.id, transformMetadata.seqNo, transformMetadata.primaryTerm + parser(transformMetadataString), transformMetadata.id, transformMetadata.seqNo, transformMetadata.primaryTerm, ) assertEquals("Round tripping Transform metadata without type doesn't work", transformMetadata, parsedTransformMetadata) } @@ -34,7 +34,7 @@ class XContentTests : OpenSearchTestCase() { val transformMetadataString = transformMetadata.toJsonString() val parser = parserWithType(transformMetadataString) val parsedTransformMetadata = parser.parseWithType( - transformMetadata.id, transformMetadata.seqNo, transformMetadata.primaryTerm, TransformMetadata.Companion::parse + transformMetadata.id, transformMetadata.seqNo, transformMetadata.primaryTerm, TransformMetadata.Companion::parse, ) assertEquals("Round tripping Transform metadata with type doesn't work", transformMetadata, parsedTransformMetadata) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/ExtensionsTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/ExtensionsTests.kt index 605b49b5b..c06de08a3 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/ExtensionsTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/opensearchapi/ExtensionsTests.kt @@ -7,9 +7,9 @@ package org.opensearch.indexmanagement.transform.opensearchapi import org.junit.Assert import org.opensearch.OpenSearchException -import org.opensearch.indexmanagement.util.IndexManagementException import org.opensearch.core.rest.RestStatus import org.opensearch.core.tasks.TaskCancelledException +import org.opensearch.indexmanagement.util.IndexManagementException import org.opensearch.test.OpenSearchTestCase class ExtensionsTests : OpenSearchTestCase() { @@ -17,7 +17,7 @@ class ExtensionsTests : OpenSearchTestCase() { fun `test is transform operation timeout`() { val ex = OpenSearchException( "opensearch test exception", - TaskCancelledException("cancelled task with reason: Cancellation timeout of 100s is expired") + TaskCancelledException("cancelled task with reason: Cancellation timeout of 100s is expired"), ) val result = isTransformOperationTimedOut(ex) Assert.assertTrue(result) @@ -27,8 +27,8 @@ class ExtensionsTests : OpenSearchTestCase() { val result = isTransformOperationTimedOut( OpenSearchException( "opensearch test exception", - TaskCancelledException("some test msg") - ) + TaskCancelledException("some test msg"), + ), ) Assert.assertFalse(result) } @@ -37,7 +37,7 @@ class ExtensionsTests : OpenSearchTestCase() { Assert.assertTrue(isRetryable(IndexManagementException("502", RestStatus.BAD_GATEWAY, RuntimeException()), emptyList())) val ex = OpenSearchException( "opensearch test exception", - TaskCancelledException("cancelled task with reason: Cancellation timeout of 100s is expired") + TaskCancelledException("cancelled task with reason: Cancellation timeout of 100s is expired"), ) Assert.assertTrue(isRetryable(ex, emptyList())) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt index 93b5da251..5d033e059 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt @@ -6,12 +6,12 @@ package org.opensearch.indexmanagement.transform.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.transform.TransformRestTestCase import org.opensearch.indexmanagement.transform.randomTransform -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging @TestLogging(value = "level:DEBUG", reason = "Debugging tests") @@ -24,7 +24,7 @@ class RestDeleteTransformActionIT : TransformRestTestCase() { val deleteResponse = client().makeRequest( "DELETE", - "$TRANSFORM_BASE_URI/${transform.id}" + "$TRANSFORM_BASE_URI/${transform.id}", ) assertEquals("Delete failed", RestStatus.OK, deleteResponse.restStatus()) val itemList = deleteResponse.asMap()["items"] as ArrayList>> @@ -43,7 +43,7 @@ class RestDeleteTransformActionIT : TransformRestTestCase() { try { client().makeRequest( "DELETE", - "$TRANSFORM_BASE_URI/${transform.id}" + "$TRANSFORM_BASE_URI/${transform.id}", ) fail("Expected an Exception") } catch (e: Exception) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt index badc26d7a..7a7fbf1c2 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.transform.resthandler import org.junit.Assert import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.makeRequest @@ -15,7 +16,6 @@ import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.transform.randomTransform import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant import java.time.temporal.ChronoUnit @@ -33,7 +33,7 @@ class RestExplainTransformActionIT : TransformRestTestCase() { enabledAt = Instant.now(), metadataId = null, sourceIndex = "test_source", - targetIndex = "test_target" + targetIndex = "test_target", ).let { createTransform(it, it.id) } updateTransformStartTime(transform) @@ -107,7 +107,7 @@ class RestExplainTransformActionIT : TransformRestTestCase() { enabledAt = Instant.now(), metadataId = null, continuous = true, - pageSize = 50 + pageSize = 50, ).let { createTransform(it, it.id) } val transform2 = randomTransform().copy( id = "continuous_wildcard_2", @@ -116,7 +116,7 @@ class RestExplainTransformActionIT : TransformRestTestCase() { enabledAt = Instant.now(), metadataId = null, continuous = true, - pageSize = 50 + pageSize = 50, ).let { createTransform(it, it.id) } updateTransformStartTime(transform1) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformActionIT.kt index 63264d68c..f41bbee5a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestGetTransformActionIT.kt @@ -6,13 +6,13 @@ package org.opensearch.indexmanagement.transform.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.Dimension import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.transform.TransformRestTestCase import org.opensearch.indexmanagement.transform.action.get.GetTransformsRequest.Companion.DEFAULT_SIZE import org.opensearch.indexmanagement.transform.randomTransform -import org.opensearch.core.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import org.opensearch.test.junit.annotations.TestLogging @@ -33,7 +33,7 @@ class RestGetTransformActionIT : TransformRestTestCase() { // Roles are deprecated and will not be returned roles = listOf(), // User information is not returned as part of REST output - user = null + user = null, ) assertEquals("Indexed and retrieved transform differ", transform, indexedTransform) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformActionIT.kt index df424ac86..4fd62f6c9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestIndexTransformActionIT.kt @@ -7,13 +7,13 @@ package org.opensearch.indexmanagement.transform.resthandler import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.transform.TransformRestTestCase import org.opensearch.indexmanagement.transform.randomTransform import org.opensearch.indexmanagement.util.NO_ID -import org.opensearch.core.rest.RestStatus import org.opensearch.test.junit.annotations.TestLogging @TestLogging(value = "level:DEBUG", reason = "Debugging tests") @@ -29,7 +29,7 @@ class RestIndexTransformActionIT : TransformRestTestCase() { "PUT", "$TRANSFORM_BASE_URI/${transform.id}", emptyMap(), - transform.toHttpEntity() + transform.toHttpEntity(), ) assertEquals("Create transform failed", RestStatus.CREATED, response.restStatus()) val responseBody = response.asMap() @@ -47,7 +47,7 @@ class RestIndexTransformActionIT : TransformRestTestCase() { "PUT", TRANSFORM_BASE_URI, emptyMap(), - transform.toHttpEntity() + transform.toHttpEntity(), ) fail("Expected 400 Method BAD_REQUEST response") } catch (e: ResponseException) { @@ -63,7 +63,7 @@ class RestIndexTransformActionIT : TransformRestTestCase() { "POST", "$TRANSFORM_BASE_URI/some_transform", emptyMap(), - transform.toHttpEntity() + transform.toHttpEntity(), ) fail("Expected 405 Method Not Allowed response") } catch (e: ResponseException) { @@ -81,7 +81,7 @@ class RestIndexTransformActionIT : TransformRestTestCase() { val expected = createParser( XContentType.JSON.xContent(), javaClass.classLoader.getResource("mappings/opendistro-ism-config.json") - .readText() + .readText(), ) val expectedMap = expected.map() @@ -96,7 +96,7 @@ class RestIndexTransformActionIT : TransformRestTestCase() { "PUT", "$TRANSFORM_BASE_URI/${transform.id}?refresh=true&if_seq_no=${transform.seqNo}&if_primary_term=${transform.primaryTerm}", emptyMap(), - transform.copy(continuous = !transform.continuous, pageSize = 50).toHttpEntity() // Lower page size to make sure that doesn't throw an error first + transform.copy(continuous = !transform.continuous, pageSize = 50).toHttpEntity(), // Lower page size to make sure that doesn't throw an error first ) fail("Expected 405 Method Not Allowed response") } catch (e: ResponseException) { @@ -105,12 +105,12 @@ class RestIndexTransformActionIT : TransformRestTestCase() { val expectedErrorMessage = mapOf( "error" to mapOf( "root_cause" to listOf>( - mapOf("type" to "status_exception", "reason" to "Not allowed to modify [continuous]") + mapOf("type" to "status_exception", "reason" to "Not allowed to modify [continuous]"), ), "type" to "status_exception", - "reason" to "Not allowed to modify [continuous]" + "reason" to "Not allowed to modify [continuous]", ), - "status" to 400 + "status" to 400, ) assertEquals(expectedErrorMessage, actualMessage) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformActionIT.kt index 35272c75d..c0551985f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestPreviewTransformActionIT.kt @@ -9,6 +9,7 @@ import org.junit.AfterClass import org.junit.Before import org.opensearch.client.ResponseException import org.opensearch.common.time.DateFormatter +import org.opensearch.core.rest.RestStatus import org.opensearch.index.IndexNotFoundException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.Terms @@ -17,7 +18,6 @@ import org.opensearch.indexmanagement.transform.TransformRestTestCase import org.opensearch.indexmanagement.transform.model.Transform import org.opensearch.indexmanagement.transform.randomTransform import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.search.aggregations.AggregationBuilders import org.opensearch.search.aggregations.AggregatorFactories import java.time.Instant @@ -34,9 +34,9 @@ class RestPreviewTransformActionIT : TransformRestTestCase() { private val transform = randomTransform().copy( sourceIndex = sourceIndex, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), ), - aggregations = factories + aggregations = factories, ) @Before @@ -67,7 +67,7 @@ class RestPreviewTransformActionIT : TransformRestTestCase() { "POST", "$TRANSFORM_BASE_URI/_preview", emptyMap(), - transform.toHttpEntity() + transform.toHttpEntity(), ) val expectedKeys = setOf("revenue", "passengerCount", "flag", "transform._doc_count", "_doc_count") assertEquals("Preview transform failed", RestStatus.OK, response.restStatus()) @@ -94,16 +94,16 @@ class RestPreviewTransformActionIT : TransformRestTestCase() { roles = emptyList(), pageSize = 1, groups = listOf( - Terms(sourceField = pickupDateTime, targetField = pickupDateTime) + Terms(sourceField = pickupDateTime, targetField = pickupDateTime), ), - aggregations = AggregatorFactories.builder().addAggregator(AggregationBuilders.avg(fareAmount).field(fareAmount)) + aggregations = AggregatorFactories.builder().addAggregator(AggregationBuilders.avg(fareAmount).field(fareAmount)), ).let { createTransform(it, it.id) } val response = client().makeRequest( "POST", "$TRANSFORM_BASE_URI/_preview", emptyMap(), - transform.toHttpEntity() + transform.toHttpEntity(), ) val expectedKeys = setOf("fare_amount", "tpep_pickup_datetime", "transform._doc_count", "_doc_count") assertEquals("Preview transform failed", RestStatus.OK, response.restStatus()) @@ -120,14 +120,14 @@ class RestPreviewTransformActionIT : TransformRestTestCase() { .addAggregator(AggregationBuilders.sum("revenue").field("total_amountdzdfd")) val transform = transform.copy( groups = listOf(Terms(sourceField = "non-existent", targetField = "non-existent")), - aggregations = factories + aggregations = factories, ) try { client().makeRequest( "POST", "$TRANSFORM_BASE_URI/_preview", emptyMap(), - transform.toHttpEntity() + transform.toHttpEntity(), ) fail("expected exception") } catch (e: ResponseException) { @@ -142,7 +142,7 @@ class RestPreviewTransformActionIT : TransformRestTestCase() { "POST", "$TRANSFORM_BASE_URI/_preview", emptyMap(), - transform.toHttpEntity() + transform.toHttpEntity(), ) fail("expected exception") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformActionIT.kt index 5022a0768..51a042083 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStartTransformActionIT.kt @@ -6,6 +6,7 @@ package org.opensearch.indexmanagement.transform.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Terms @@ -15,7 +16,6 @@ import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.transform.randomTransform import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.search.aggregations.AggregatorFactories import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant @@ -92,9 +92,9 @@ class RestStartTransformActionIT : TransformRestTestCase() { pageSize = 10, groups = listOf( Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), - DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h") + DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"), ), - aggregations = AggregatorFactories.builder() + aggregations = AggregatorFactories.builder(), ).let { createTransform(it, it.id) } // This should fail because source index is deleted @@ -162,10 +162,10 @@ class RestStartTransformActionIT : TransformRestTestCase() { roles = emptyList(), pageSize = 10, groups = listOf( - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), ), aggregations = AggregatorFactories.builder(), - continuous = false + continuous = false, ).let { createTransform(it, it.id) } updateTransformStartTime(transform) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformActionIT.kt index c1de752fc..5d34c69e2 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestStopTransformActionIT.kt @@ -6,6 +6,7 @@ package org.opensearch.indexmanagement.transform.resthandler import org.opensearch.client.ResponseException +import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Terms @@ -16,7 +17,6 @@ import org.opensearch.indexmanagement.transform.model.TransformMetadata import org.opensearch.indexmanagement.transform.randomTransform import org.opensearch.indexmanagement.waitFor import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.core.rest.RestStatus import org.opensearch.search.aggregations.AggregatorFactories import org.opensearch.test.junit.annotations.TestLogging import java.time.Instant @@ -58,8 +58,8 @@ class RestStopTransformActionIT : TransformRestTestCase() { enabled = true, enabledAt = Instant.now(), metadataId = null, - continuous = false - ) + continuous = false, + ), ) updateTransformStartTime(transform) @@ -94,7 +94,7 @@ class RestStopTransformActionIT : TransformRestTestCase() { jobSchedule = IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES), enabled = true, enabledAt = Instant.now(), - metadataId = null + metadataId = null, ).let { createTransform(it, it.id) } deleteIndex(transform.sourceIndex) updateTransformStartTime(transform) @@ -142,9 +142,9 @@ class RestStopTransformActionIT : TransformRestTestCase() { pageSize = 1, groups = listOf( DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1m"), - Terms(sourceField = "store_and_fwd_flag", targetField = "flag") + Terms(sourceField = "store_and_fwd_flag", targetField = "flag"), ), - aggregations = AggregatorFactories.builder() + aggregations = AggregatorFactories.builder(), ).let { createTransform(it, it.id) } updateTransformStartTime(transform)