/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.node.NodeClient import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.rollup.action.stop.StopRollupAction import org.opensearch.indexmanagement.rollup.action.stop.StopRollupRequest import org.opensearch.indexmanagement.util.NO_ID import org.opensearch.rest.BaseRestHandler import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.action.RestToXContentListener import java.io.IOException class RestStopRollupAction : BaseRestHandler() { override fun routes(): List { return emptyList() } override fun replacedRoutes(): List { return listOf( ReplacedRoute( POST, "$ROLLUP_JOBS_BASE_URI/{rollupID}/_stop", POST, "$LEGACY_ROLLUP_JOBS_BASE_URI/{rollupID}/_stop" ) ) } override fun getName(): String { return "opendistro_stop_rollup_action" } @Throws(IOException::class) override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer { val id = request.param("rollupID", NO_ID) if (NO_ID == id) { throw IllegalArgumentException("Missing rollup ID") } val stopRequest = StopRollupRequest(id) return RestChannelConsumer { channel -> client.execute(StopRollupAction.INSTANCE, stopRequest, RestToXContentListener(channel)) } } }