-
Couldn't load subscription status.
- Fork 76
Adding provision to invoke stop replication from other plugins #1391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0683700
be6f16a
9338aeb
174f2d9
15f644f
ccce153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| package org.opensearch.replication.action.stop | ||
|
|
||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.GlobalScope | ||
| import kotlinx.coroutines.launch | ||
| import org.apache.logging.log4j.LogManager | ||
| import org.opensearch.action.support.HandledTransportAction | ||
| import org.opensearch.action.ActionRequest | ||
| import org.opensearch.action.support.ActionFilters | ||
| import org.opensearch.action.support.clustermanager.AcknowledgedResponse | ||
| import org.opensearch.transport.client.Client | ||
| import org.opensearch.common.inject.Inject | ||
| import org.opensearch.cluster.metadata.IndexNameExpressionResolver | ||
| import org.opensearch.cluster.service.ClusterService | ||
| import org.opensearch.commons.replication.action.ReplicationActions.STOP_REPLICATION_ACTION_TYPE | ||
| import org.opensearch.commons.replication.action.StopIndexReplicationRequest | ||
| import org.opensearch.commons.replication.action.ReplicationActions.INTERNAL_STOP_REPLICATION_ACTION_NAME | ||
| import org.opensearch.commons.utils.recreateObject | ||
| import org.opensearch.core.action.ActionListener | ||
| import org.opensearch.replication.metadata.ReplicationMetadataManager | ||
| import org.opensearch.replication.util.coroutineContext | ||
| import org.opensearch.replication.util.stackTraceToString | ||
| import org.opensearch.replication.util.suspendExecute | ||
| import org.opensearch.tasks.Task | ||
| import org.opensearch.threadpool.ThreadPool | ||
| import org.opensearch.transport.TransportService | ||
|
|
||
| /* Internal transport action used by Index Management plugin to invoke stop replication | ||
| It transforms the request, and invokes the stop replication action (TransportStopIndexReplicationAction) on it. | ||
| */ | ||
| class TransportInternalStopIndexReplicationAction @Inject constructor ( | ||
| val name: String, | ||
| val transportService: TransportService, | ||
| val clusterService: ClusterService, | ||
| val threadPool: ThreadPool, | ||
| val client: Client, | ||
| val actionFilters: ActionFilters, | ||
| val indexNameExpressionResolver: IndexNameExpressionResolver, | ||
| val replicationMetadataManager: ReplicationMetadataManager, | ||
| ): HandledTransportAction<ActionRequest, AcknowledgedResponse> (INTERNAL_STOP_REPLICATION_ACTION_NAME, transportService, actionFilters, ::StopIndexReplicationRequest), | ||
| CoroutineScope by GlobalScope { | ||
| companion object { | ||
| private val log = LogManager.getLogger(TransportInternalStopIndexReplicationAction::class.java) | ||
| } | ||
|
|
||
| @Throws(Exception::class) | ||
| override fun doExecute(task: Task?, request: ActionRequest?, listener: ActionListener<AcknowledgedResponse>?) { | ||
| launch(Dispatchers.Unconfined + threadPool.coroutineContext()) { | ||
| val transformedRequest = if (request is StopIndexReplicationRequest) { | ||
| request | ||
| } else { | ||
| request?.let { recreateObject(it) { StopIndexReplicationRequest(it) } } | ||
| ?: throw IllegalArgumentException("Request cannot be null") | ||
| } | ||
|
|
||
| try { | ||
| val response = client.suspendExecute(STOP_REPLICATION_ACTION_TYPE, transformedRequest, true) | ||
| log.info("Stop replication successful for index[${transformedRequest.indexName}] with response: " + response.isAcknowledged) | ||
| listener?.onResponse(AcknowledgedResponse(true)) | ||
| } catch (e: Exception) { | ||
| log.error("Stop replication failed for index[${transformedRequest.indexName}] with error ${e.stackTraceToString()}") | ||
| listener?.onFailure(e) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
|
|
||
| package org.opensearch.replication.action.stop | ||
|
|
||
| import org.opensearch.commons.replication.action.ReplicationActions.STOP_REPLICATION_ACTION_NAME | ||
| import org.opensearch.commons.replication.action.StopIndexReplicationRequest | ||
| import org.opensearch.replication.ReplicationPlugin.Companion.REPLICATED_INDEX_SETTING | ||
| import org.opensearch.replication.action.index.block.IndexBlockUpdateType | ||
| import org.opensearch.replication.action.index.block.UpdateIndexBlockAction | ||
|
|
@@ -60,6 +62,15 @@ import org.opensearch.threadpool.ThreadPool | |
| import org.opensearch.transport.TransportService | ||
| import java.io.IOException | ||
|
|
||
| /* | ||
| The classes StopIndexReplicationRequest and StopIndexReplicationAction have been moved from ccr to common-utils | ||
| and are imported here through org.opensearch.commons.replication. | ||
| This helps in making these classes re-usable by other plugins like ism. | ||
| PR details: | ||
| [1] https://github.com/opensearch-project/common-utils/pull/667 | ||
| [2] https://github.com/opensearch-project/cross-cluster-replication/pull/1391 | ||
| */ | ||
|
|
||
| class TransportStopIndexReplicationAction @Inject constructor(transportService: TransportService, | ||
| clusterService: ClusterService, | ||
| threadPool: ThreadPool, | ||
|
|
@@ -68,7 +79,7 @@ class TransportStopIndexReplicationAction @Inject constructor(transportService: | |
| IndexNameExpressionResolver, | ||
| val client: Client, | ||
| val replicationMetadataManager: ReplicationMetadataManager) : | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment here explaining that the stop replication action class in moved to common utils and link this PR here? |
||
| TransportClusterManagerNodeAction<StopIndexReplicationRequest, AcknowledgedResponse> (StopIndexReplicationAction.NAME, | ||
| TransportClusterManagerNodeAction<StopIndexReplicationRequest, AcknowledgedResponse> (STOP_REPLICATION_ACTION_NAME, | ||
| transportService, clusterService, threadPool, actionFilters, ::StopIndexReplicationRequest, | ||
| indexNameExpressionResolver), CoroutineScope by GlobalScope { | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.