diff --git a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt index b45281f91..0a6e8bccb 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt @@ -150,14 +150,20 @@ internal class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, Act companion object { const val PLUGIN_NAME = "opendistro-im" - const val OPEN_DISTRO_BASE_URI = "/_opendistro" - const val ISM_BASE_URI = "$OPEN_DISTRO_BASE_URI/_ism" - const val ROLLUP_BASE_URI = "$OPEN_DISTRO_BASE_URI/_rollup" + const val PLUGINS_BASE_URI = "/_plugins" + const val ISM_BASE_URI = "$PLUGINS_BASE_URI/_ism" + const val ROLLUP_BASE_URI = "$PLUGINS_BASE_URI/_rollup" const val POLICY_BASE_URI = "$ISM_BASE_URI/policies" const val ROLLUP_JOBS_BASE_URI = "$ROLLUP_BASE_URI/jobs" const val INDEX_MANAGEMENT_INDEX = ".opendistro-ism-config" const val INDEX_MANAGEMENT_JOB_TYPE = "opendistro-index-management" const val INDEX_STATE_MANAGEMENT_HISTORY_TYPE = "managed_index_meta_data" + + const val OPEN_DISTRO_BASE_URI = "/_opendistro" + const val LEGACY_ISM_BASE_URI = "$OPEN_DISTRO_BASE_URI/_ism" + const val LEGACY_ROLLUP_BASE_URI = "$OPEN_DISTRO_BASE_URI/_rollup" + const val LEGACY_POLICY_BASE_URI = "$LEGACY_ISM_BASE_URI/policies" + const val LEGACY_ROLLUP_JOBS_BASE_URI = "$LEGACY_ROLLUP_BASE_URI/jobs" } override fun getJobIndex(): String = INDEX_MANAGEMENT_INDEX 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 72b9d7a76..48d320466 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestAddPolicyAction.kt @@ -32,9 +32,11 @@ import org.opensearch.indexmanagement.indexstatemanagement.transport.action.addp import org.opensearch.client.node.NodeClient import org.opensearch.common.Strings import org.opensearch.common.xcontent.XContentHelper +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.action.RestToXContentListener @@ -45,9 +47,19 @@ class RestAddPolicyAction : BaseRestHandler() { override fun getName(): String = "add_policy_action" override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(POST, ADD_POLICY_BASE_URI), - Route(POST, "$ADD_POLICY_BASE_URI/{index}") + ReplacedRoute( + POST, ADD_POLICY_BASE_URI, + POST, LEGACY_ADD_POLICY_BASE_URI + ), + ReplacedRoute( + POST, "$ADD_POLICY_BASE_URI/{index}", + POST, "$LEGACY_ADD_POLICY_BASE_URI/{index}" + ) ) } @@ -77,5 +89,6 @@ class RestAddPolicyAction : BaseRestHandler() { companion object { const val ADD_POLICY_BASE_URI = "$ISM_BASE_URI/add" + const val LEGACY_ADD_POLICY_BASE_URI = "$LEGACY_ISM_BASE_URI/add" } } 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 411c7966d..1abae1ba1 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyAction.kt @@ -35,9 +35,11 @@ import org.opensearch.client.node.NodeClient import org.opensearch.common.Strings import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.action.RestToXContentListener @@ -48,9 +50,19 @@ class RestChangePolicyAction : BaseRestHandler() { private val log = LogManager.getLogger(javaClass) override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(POST, CHANGE_POLICY_BASE_URI), - Route(POST, "$CHANGE_POLICY_BASE_URI/{index}") + ReplacedRoute( + POST, CHANGE_POLICY_BASE_URI, + POST, LEGACY_CHANGE_POLICY_BASE_URI + ), + ReplacedRoute( + POST, "$CHANGE_POLICY_BASE_URI/{index}", + POST, "$LEGACY_CHANGE_POLICY_BASE_URI/{index}" + ) ) } @@ -76,6 +88,7 @@ class RestChangePolicyAction : BaseRestHandler() { companion object { const val CHANGE_POLICY_BASE_URI = "$ISM_BASE_URI/change_policy" + const val LEGACY_CHANGE_POLICY_BASE_URI = "$LEGACY_ISM_BASE_URI/change_policy" const val INDEX_NOT_MANAGED = "This index is not being managed" const val INDEX_IN_TRANSITION = "Cannot change policy while transitioning to new state" } 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 1cba59fd3..34ab2ea90 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestDeletePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestDeletePolicyAction.kt @@ -32,8 +32,10 @@ import org.opensearch.indexmanagement.indexstatemanagement.transport.action.dele import org.opensearch.indexmanagement.util.REFRESH import org.opensearch.action.support.WriteRequest.RefreshPolicy import org.opensearch.client.node.NodeClient +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_POLICY_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.DELETE import org.opensearch.rest.action.RestStatusToXContentListener @@ -42,8 +44,15 @@ import java.io.IOException class RestDeletePolicyAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(DELETE, "$POLICY_BASE_URI/{policyID}") + ReplacedRoute( + DELETE, "$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 28d2cb7ef..465e0e415 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestExplainAction.kt @@ -39,9 +39,11 @@ import org.apache.logging.log4j.LogManager import org.opensearch.action.support.master.MasterNodeRequest import org.opensearch.client.node.NodeClient import org.opensearch.common.Strings +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.action.RestToXContentListener @@ -52,12 +54,23 @@ class RestExplainAction : BaseRestHandler() { companion object { const val EXPLAIN_BASE_URI = "$ISM_BASE_URI/explain" + const val LEGACY_EXPLAIN_BASE_URI = "$LEGACY_ISM_BASE_URI/explain" } override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(GET, EXPLAIN_BASE_URI), - Route(GET, "$EXPLAIN_BASE_URI/{index}") + ReplacedRoute( + GET, EXPLAIN_BASE_URI, + GET, LEGACY_EXPLAIN_BASE_URI + ), + ReplacedRoute( + GET, "$EXPLAIN_BASE_URI/{index}", + GET, "$LEGACY_EXPLAIN_BASE_URI/{index}" + ) ) } 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 d3792eab1..cf1ca1c9d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestGetPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestGetPolicyAction.kt @@ -39,9 +39,12 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_QUERY_ST import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_SORT_ORDER import org.apache.logging.log4j.LogManager import org.opensearch.client.node.NodeClient +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_POLICY_BASE_URI +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.RestRequest.Method.HEAD @@ -54,10 +57,23 @@ private val log = LogManager.getLogger(RestGetPolicyAction::class.java) class RestGetPolicyAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(GET, POLICY_BASE_URI), - Route(GET, "$POLICY_BASE_URI/{policyID}"), - Route(HEAD, "$POLICY_BASE_URI/{policyID}") + ReplacedRoute( + GET, POLICY_BASE_URI, + GET, LEGACY_ROLLUP_BASE_URI + ), + ReplacedRoute( + GET, "$POLICY_BASE_URI/{policyID}", + GET, "$LEGACY_POLICY_BASE_URI/{policyID}" + ), + ReplacedRoute( + HEAD, "$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 80a139436..9df737974 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt @@ -44,10 +44,12 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.common.xcontent.ToXContent import org.opensearch.index.seqno.SequenceNumbers +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_POLICY_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.PUT import org.opensearch.rest.RestResponse @@ -70,9 +72,19 @@ class RestIndexPolicyAction( } override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(PUT, POLICY_BASE_URI), - Route(PUT, "$POLICY_BASE_URI/{policyID}") + ReplacedRoute( + PUT, POLICY_BASE_URI, + PUT, LEGACY_POLICY_BASE_URI + ), + ReplacedRoute( + PUT, "$POLICY_BASE_URI/{policyID}", + PUT, "$LEGACY_POLICY_BASE_URI/{policyID}" + ) ) } 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 3a677db92..c9a63d18f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRemovePolicyAction.kt @@ -31,8 +31,10 @@ import org.opensearch.indexmanagement.indexstatemanagement.transport.action.remo import org.opensearch.indexmanagement.indexstatemanagement.transport.action.removepolicy.RemovePolicyRequest import org.opensearch.client.node.NodeClient import org.opensearch.common.Strings +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.action.RestToXContentListener @@ -41,9 +43,19 @@ import java.io.IOException class RestRemovePolicyAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(POST, REMOVE_POLICY_BASE_URI), - Route(POST, "$REMOVE_POLICY_BASE_URI/{index}") + ReplacedRoute( + POST, REMOVE_POLICY_BASE_URI, + POST, LEGACY_REMOVE_POLICY_BASE_URI + ), + ReplacedRoute( + POST, "$REMOVE_POLICY_BASE_URI/{index}", + POST, "$LEGACY_REMOVE_POLICY_BASE_URI/{index}" + ) ) } @@ -67,5 +79,6 @@ class RestRemovePolicyAction : BaseRestHandler() { companion object { const val REMOVE_POLICY_BASE_URI = "$ISM_BASE_URI/remove" + const val LEGACY_REMOVE_POLICY_BASE_URI = "$LEGACY_ISM_BASE_URI/remove" } } 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 12f2c35c5..d22c4b61d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexAction.kt @@ -34,9 +34,11 @@ import org.opensearch.action.support.master.MasterNodeRequest.DEFAULT_MASTER_NOD import org.opensearch.client.node.NodeClient import org.opensearch.common.Strings import org.opensearch.common.xcontent.XContentHelper +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.action.RestToXContentListener @@ -46,9 +48,19 @@ class RestRetryFailedManagedIndexAction : BaseRestHandler() { private val log = LogManager.getLogger(javaClass) override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(POST, RETRY_BASE_URI), - Route(POST, "$RETRY_BASE_URI/{index}") + ReplacedRoute( + POST, RETRY_BASE_URI, + POST, LEGACY_RETRY_BASE_URI + ), + ReplacedRoute( + POST, "$RETRY_BASE_URI/{index}", + POST, "$LEGACY_RETRY_BASE_URI/{index}" + ) ) } @@ -78,5 +90,6 @@ class RestRetryFailedManagedIndexAction : BaseRestHandler() { companion object { const val RETRY_BASE_URI = "$ISM_BASE_URI/retry" + const val LEGACY_RETRY_BASE_URI = "$LEGACY_ISM_BASE_URI/retry" } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt index 2055f8756..05baaa483 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.kt @@ -29,8 +29,10 @@ package org.opensearch.indexmanagement.refreshanalyzer import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.OPEN_DISTRO_BASE_URI import org.opensearch.client.node.NodeClient import org.opensearch.common.Strings +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.PLUGINS_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.action.RestToXContentListener @@ -41,9 +43,19 @@ class RestRefreshSearchAnalyzerAction : BaseRestHandler() { override fun getName(): String = "refresh_search_analyzer_action" override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(POST, REFRESH_SEARCH_ANALYZER_BASE_URI), - Route(POST, "$REFRESH_SEARCH_ANALYZER_BASE_URI/{index}") + ReplacedRoute( + POST, 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}" + ) ) } @@ -67,6 +79,7 @@ class RestRefreshSearchAnalyzerAction : BaseRestHandler() { } companion object { - const val REFRESH_SEARCH_ANALYZER_BASE_URI = "$OPEN_DISTRO_BASE_URI/_refresh_search_analyzers" + const val REFRESH_SEARCH_ANALYZER_BASE_URI = "$PLUGINS_BASE_URI/_refresh_search_analyzers" + const val LEGACY_REFRESH_SEARCH_ANALYZER_BASE_URI = "$OPEN_DISTRO_BASE_URI/_refresh_search_analyzers" } } 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 d72a26671..972d243bc 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupAction.kt @@ -32,8 +32,10 @@ import org.opensearch.indexmanagement.rollup.action.delete.DeleteRollupRequest import org.opensearch.indexmanagement.util.REFRESH import org.opensearch.action.support.WriteRequest.RefreshPolicy import org.opensearch.client.node.NodeClient +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.DELETE import org.opensearch.rest.action.RestToXContentListener @@ -42,8 +44,15 @@ import java.io.IOException class RestDeleteRollupAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(DELETE, "$ROLLUP_JOBS_BASE_URI/{rollupID}") + ReplacedRoute( + DELETE, "$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 2a25ca4f5..b54837bd0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupAction.kt @@ -31,8 +31,10 @@ import org.opensearch.indexmanagement.rollup.action.explain.ExplainRollupAction import org.opensearch.indexmanagement.rollup.action.explain.ExplainRollupRequest import org.opensearch.client.node.NodeClient import org.opensearch.common.Strings +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.action.RestToXContentListener @@ -40,7 +42,16 @@ import org.opensearch.rest.action.RestToXContentListener class RestExplainRollupAction : BaseRestHandler() { override fun routes(): List { - return listOf(Route(GET, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_explain")) + return emptyList() + } + + override fun replacedRoutes(): List { + return listOf( + ReplacedRoute( + GET, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_explain", + GET, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_explain" + ) + ) } override fun getName(): String = "opendistro_explain_rollup_action" 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 9ba89321b..497461c64 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupAction.kt @@ -37,8 +37,10 @@ import org.opensearch.indexmanagement.rollup.action.get.GetRollupsRequest.Compan import org.opensearch.indexmanagement.rollup.action.get.GetRollupsRequest.Companion.DEFAULT_SORT_DIRECTION import org.opensearch.indexmanagement.rollup.action.get.GetRollupsRequest.Companion.DEFAULT_SORT_FIELD import org.opensearch.client.node.NodeClient +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET import org.opensearch.rest.RestRequest.Method.HEAD @@ -48,10 +50,23 @@ import org.opensearch.search.fetch.subphase.FetchSourceContext class RestGetRollupAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(GET, ROLLUP_JOBS_BASE_URI), - Route(GET, "$ROLLUP_JOBS_BASE_URI/{rollupID}"), - Route(HEAD, "$ROLLUP_JOBS_BASE_URI/{rollupID}") + ReplacedRoute( + GET, ROLLUP_JOBS_BASE_URI, + GET, LEGACY_ROLLUP_JOBS_BASE_URI + ), + ReplacedRoute( + GET, "$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}" + ) ) } 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 fec9a4355..e103ac37f 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupAction.kt @@ -39,8 +39,10 @@ import org.opensearch.action.support.WriteRequest import org.opensearch.client.node.NodeClient import org.opensearch.common.xcontent.ToXContent import org.opensearch.index.seqno.SequenceNumbers +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse import org.opensearch.rest.RestChannel @@ -55,9 +57,19 @@ import java.time.Instant class RestIndexRollupAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(PUT, ROLLUP_JOBS_BASE_URI), - Route(PUT, "$ROLLUP_JOBS_BASE_URI/{rollupID}") + ReplacedRoute( + PUT, ROLLUP_JOBS_BASE_URI, + PUT, LEGACY_ROLLUP_JOBS_BASE_URI + ), + ReplacedRoute( + PUT, "$ROLLUP_JOBS_BASE_URI/{rollupID}", + PUT, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}" + ) ) } 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 15266f148..fe4026dab 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupAction.kt @@ -31,8 +31,10 @@ import org.opensearch.indexmanagement.rollup.action.start.StartRollupAction import org.opensearch.indexmanagement.rollup.action.start.StartRollupRequest import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.client.node.NodeClient +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST @@ -42,8 +44,15 @@ import java.io.IOException class RestStartRollupAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(POST, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_start") + ReplacedRoute( + POST, "$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 075affd82..fffcaebaa 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupAction.kt @@ -31,8 +31,10 @@ import org.opensearch.indexmanagement.rollup.action.stop.StopRollupAction import org.opensearch.indexmanagement.rollup.action.stop.StopRollupRequest import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.client.node.NodeClient +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST @@ -42,8 +44,15 @@ import java.io.IOException class RestStopRollupAction : BaseRestHandler() { override fun routes(): List { + return emptyList() + } + + override fun replacedRoutes(): List { return listOf( - Route(POST, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_stop") + ReplacedRoute( + POST, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_stop", + POST, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_stop" + ) ) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt index a0bb14ea4..a8e9c34a8 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt @@ -28,7 +28,17 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.UPDATED_INDICES import org.apache.http.entity.ContentType import org.apache.http.entity.StringEntity import org.opensearch.common.settings.Settings +import org.opensearch.common.xcontent.ToXContent +import org.opensearch.common.xcontent.XContentFactory +import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestAddPolicyAction +import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestExplainAction +import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestRemovePolicyAction +import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestRetryFailedManagedIndexAction +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.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import java.util.Locale @@ -147,4 +157,80 @@ class IndexManagementIndicesIT : IndexStateManagementRestTestCase() { waitFor { assertEquals(newPolicy.id, getManagedIndexConfig(index)?.changePolicy?.policyID) } } + + fun `test ISM backward compatibility with opendistro`() { + val policy = randomPolicy() + val policyId = OpenSearchTestCase.randomAlphaOfLength(10) + val createIndexResponse = + client().makeRequest("PUT", "${IndexManagementPlugin.LEGACY_POLICY_BASE_URI}/$policyId", emptyMap(), policy.toHttpEntity()) + assertEquals("Create policy failed", RestStatus.CREATED, createIndexResponse.restStatus()) + + val indexName = "bwc_index" + createIndex(indexName, null) + val addPolicyResponse = client().makeRequest( + RestRequest.Method.POST.toString(), + "${RestAddPolicyAction.LEGACY_ADD_POLICY_BASE_URI}/$indexName", + 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) + ) + assertEquals("Unexpected RestStatus", RestStatus.OK, changePolicyResponse.restStatus()) + + val retryFailedResponse = client().makeRequest( + RestRequest.Method.POST.toString(), + "${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") + assertEquals("Unexpected RestStatus", RestStatus.OK, explainResponse.restStatus()) + + val removePolicyResponse = client().makeRequest( + RestRequest.Method.POST.toString(), + "${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") + assertEquals("Unexpected RestStatus", RestStatus.OK, deletePolicyResponse.restStatus()) + } + + fun `test refresh search analyzer backward compatibility with opendistro`() { + val indexName = "bwc_index" + val settings = Settings.builder().build() + createIndex(indexName, settings) + val response = client().makeRequest(RestRequest.Method.POST.toString(), "${RestRefreshSearchAnalyzerAction.LEGACY_REFRESH_SEARCH_ANALYZER_BASE_URI}/$indexName") + assertEquals("Unexpected RestStatus", RestStatus.OK, response.restStatus()) + } + + fun `test rollup backward compatibility with opendistro`() { + val rollup = randomRollup() + val rollupJsonString = rollup.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).string() + val createRollupResponse = client().makeRequest("PUT", "${IndexManagementPlugin.LEGACY_ROLLUP_JOBS_BASE_URI}/${rollup.id}", emptyMap(), StringEntity(rollupJsonString, + ContentType.APPLICATION_JSON + )) + assertEquals("Create rollup failed", RestStatus.CREATED, createRollupResponse.restStatus()) + + val getRollupResponse = client().makeRequest("GET", "${IndexManagementPlugin.LEGACY_ROLLUP_JOBS_BASE_URI}/${rollup.id}") + assertEquals("Get rollup failed", RestStatus.OK, getRollupResponse.restStatus()) + + val explainRollupResponse = client().makeRequest("GET", "${IndexManagementPlugin.LEGACY_ROLLUP_JOBS_BASE_URI}/${rollup.id}/_explain") + assertEquals("Explain rollup failed", RestStatus.OK, explainRollupResponse.restStatus()) + + val startRollupResponse = client().makeRequest("POST", "${IndexManagementPlugin.LEGACY_ROLLUP_JOBS_BASE_URI}/${rollup.id}/_start") + assertEquals("Start rollup failed", RestStatus.OK, startRollupResponse.restStatus()) + + val stopRollupResponse = client().makeRequest("POST", "${IndexManagementPlugin.LEGACY_ROLLUP_JOBS_BASE_URI}/${rollup.id}/_stop") + assertEquals("Stop rollup failed", RestStatus.OK, stopRollupResponse.restStatus()) + + val deleteRollupResponse = client().makeRequest("DELETE", "${IndexManagementPlugin.LEGACY_ROLLUP_JOBS_BASE_URI}/${rollup.id}") + assertEquals("Delete rollup failed", RestStatus.OK, deleteRollupResponse.restStatus()) + } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt b/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt index 2763c077e..7e5977b90 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/TestHelpers.kt @@ -26,15 +26,16 @@ package org.opensearch.indexmanagement -import org.opensearch.jobscheduler.spi.schedule.CronSchedule -import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule -import org.opensearch.jobscheduler.spi.schedule.Schedule import org.apache.http.Header import org.apache.http.HttpEntity import org.opensearch.client.Request import org.opensearch.client.RequestOptions import org.opensearch.client.Response import org.opensearch.client.RestClient +import org.opensearch.client.WarningsHandler +import org.opensearch.jobscheduler.spi.schedule.CronSchedule +import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule +import org.opensearch.jobscheduler.spi.schedule.Schedule import org.opensearch.test.rest.OpenSearchRestTestCase import java.time.Instant import java.time.temporal.ChronoUnit @@ -76,10 +77,12 @@ fun RestClient.makeRequest( endpoint: String, params: Map = emptyMap(), entity: HttpEntity? = null, - vararg headers: Header + vararg headers: Header, + strictDeprecationMode: Boolean = false ): Response { val request = Request(method, endpoint) val options = RequestOptions.DEFAULT.toBuilder() + options.setWarningsHandler(if (strictDeprecationMode) WarningsHandler.STRICT else WarningsHandler.PERMISSIVE) headers.forEach { options.addHeader(it.name, it.value) } request.options = options.build() params.forEach { request.addParameter(it.key, it.value) } @@ -99,10 +102,12 @@ fun RestClient.makeRequest( method: String, endpoint: String, entity: HttpEntity? = null, - vararg headers: Header + vararg headers: Header, + strictDeprecationMode: Boolean = false ): Response { val request = Request(method, endpoint) val options = RequestOptions.DEFAULT.toBuilder() + options.setWarningsHandler(if (strictDeprecationMode) WarningsHandler.STRICT else WarningsHandler.PERMISSIVE) headers.forEach { options.addHeader(it.name, it.value) } request.options = options.build() if (entity != null) {