Skip to content

Commit

Permalink
Refactored TransportGetRemoteIndexesAction to be more efficient.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Oct 10, 2023
1 parent 662ae92 commit a26bc5d
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,25 @@ class TransportGetRemoteIndexesAction @Inject constructor(
) {
log.info("hurneyt TransportGetRemoteIndexesAction START")
client.threadPool().threadContext.stashContext().use {
scope.launch {
val clusterIndexesList = mutableListOf<ClusterIndexes>()
val clusterIndexesList = mutableListOf<ClusterIndexes>()

var resolveIndexResponse: ResolveIndexAction.Response? = null
var resolveIndexResponse: ResolveIndexAction.Response? = null
scope.launch {
try {
resolveIndexResponse = getRemoteClusters(request.indexes)
} catch (e: Exception) {
log.error("Failed to retrieve indexes for request $request", e)
listener.onFailure(AlertingException.wrap(e))
}
}

val resolvedIndexes = resolveIndexResponse?.indices?.map { it.name } ?: emptyList()
log.info("hurneyt TransportGetRemoteIndexesAction::resolvedIndexes = {}", resolvedIndexes)

val clusterIndexesMap = CrossClusterMonitorUtils.separateClusterIndexes(resolvedIndexes, clusterService)
log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap = {}", clusterIndexesMap)
val resolvedIndexes = resolveIndexResponse?.indices?.map { it.name } ?: emptyList()
log.info("hurneyt TransportGetRemoteIndexesAction::resolvedIndexes = {}", resolvedIndexes)

clusterIndexesMap.forEach { (clusterName, indexes) ->
val clusterIndexesMap = CrossClusterMonitorUtils.separateClusterIndexes(resolvedIndexes, clusterService)
log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap = {}", clusterIndexesMap)
clusterIndexesMap.forEach { (clusterName, indexes) ->
scope.launch {
log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap clusterName = {}", clusterName)
log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap indexes = {}", indexes)
val targetClient = CrossClusterMonitorUtils.getClientForCluster(clusterName, client, clusterService)
Expand Down Expand Up @@ -126,9 +127,9 @@ class TransportGetRemoteIndexesAction @Inject constructor(
)
)
}
log.info("hurneyt TransportGetRemoteIndexesAction END")
listener.onResponse(GetRemoteIndexesResponse(clusterIndexes = clusterIndexesList))
}
log.info("hurneyt TransportGetRemoteIndexesAction END")
listener.onResponse(GetRemoteIndexesResponse(clusterIndexes = clusterIndexesList))
}
}

Expand All @@ -138,6 +139,7 @@ class TransportGetRemoteIndexesAction @Inject constructor(
ResolveIndexAction.Request.DEFAULT_INDICES_OPTIONS
)
return client.suspendUntil {
// TODO hurneyt: return aliases as well
admin().indices().resolveIndex(resolveRequest, it)
}
}
Expand Down

0 comments on commit a26bc5d

Please sign in to comment.