-
Notifications
You must be signed in to change notification settings - Fork 64
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
Adding provision to invoke stop replication from other plugins #1391
Open
aggarwalShivani
wants to merge
4
commits into
opensearch-project:main
Choose a base branch
from
nokia:commonutils-migr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0683700
Adding provision to invoke stop replication from other plugins
aggarwalShivani be6f16a
Separate action handlers for stop replication for rest api and ism
aggarwalShivani 9338aeb
Updating comments for unfollow action handler
aggarwalShivani 174f2d9
Renamed unfollow action to InternalStopIndexReplication action
aggarwalShivani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/main/kotlin/org/opensearch/replication/action/stop/StopIndexReplicationAction.kt
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
src/main/kotlin/org/opensearch/replication/action/stop/StopIndexReplicationRequest.kt
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
...lin/org/opensearch/replication/action/stop/TransportInternalStopIndexReplicationAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?