Skip to content

Commit

Permalink
Rest APIs Backward Compatibility (#15)
Browse files Browse the repository at this point in the history
* Rest APIs Backward Compatibility

Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn authored May 21, 2021
1 parent d41f662 commit eee3191
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,9 +47,19 @@ class RestAddPolicyAction : BaseRestHandler() {
override fun getName(): String = "add_policy_action"

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,9 +50,19 @@ class RestChangePolicyAction : BaseRestHandler() {
private val log = LogManager.getLogger(javaClass)

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand All @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,8 +44,15 @@ import java.io.IOException
class RestDeletePolicyAction : BaseRestHandler() {

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
return listOf(
Route(DELETE, "$POLICY_BASE_URI/{policyID}")
ReplacedRoute(
DELETE, "$POLICY_BASE_URI/{policyID}",
DELETE, "$LEGACY_POLICY_BASE_URI/{policyID}"
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,10 +57,23 @@ private val log = LogManager.getLogger(RestGetPolicyAction::class.java)
class RestGetPolicyAction : BaseRestHandler() {

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,9 +72,19 @@ class RestIndexPolicyAction(
}

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,9 +43,19 @@ import java.io.IOException
class RestRemovePolicyAction : BaseRestHandler() {

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,9 +48,19 @@ class RestRetryFailedManagedIndexAction : BaseRestHandler() {
private val log = LogManager.getLogger(javaClass)

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,9 +43,19 @@ class RestRefreshSearchAnalyzerAction : BaseRestHandler() {
override fun getName(): String = "refresh_search_analyzer_action"

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
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}"
)
)
}

Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,8 +44,15 @@ import java.io.IOException
class RestDeleteRollupAction : BaseRestHandler() {

override fun routes(): List<Route> {
return emptyList()
}

override fun replacedRoutes(): List<ReplacedRoute> {
return listOf(
Route(DELETE, "$ROLLUP_JOBS_BASE_URI/{rollupID}")
ReplacedRoute(
DELETE, "$ROLLUP_JOBS_BASE_URI/{rollupID}",
DELETE, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}"
)
)
}

Expand Down
Loading

0 comments on commit eee3191

Please sign in to comment.