Skip to content

Commit

Permalink
Create separate class for remote request - seems cleaner this way
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Sep 11, 2024
1 parent 1990c25 commit 8ad91b2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void setupClusters() {
assertFalse(
client(clusterAlias).admin()
.cluster()
.prepareHealth(INDEX_NAME)
.prepareHealth(TEST_REQUEST_TIMEOUT, INDEX_NAME)
.setWaitForGreenStatus()
.setTimeout(TimeValue.timeValueSeconds(10))
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
package org.elasticsearch.action.admin.cluster.stats;

import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;

import java.io.IOException;
import java.util.Map;

/**
* A request to get cluster level stats.
* This request can be used both to request stats from single cluster or from remote cluster.
*/
public class ClusterStatsRequest extends BaseNodesRequest<ClusterStatsRequest> {
/**
Expand All @@ -41,12 +37,6 @@ public ClusterStatsRequest(boolean doRemotes, String... nodesIds) {
this.doRemotes = doRemotes;
}

public ClusterStatsRequest(StreamInput in) throws IOException {
super(in.readStringArray());
// We will never ask the remote to collect remote stats
doRemotes = false;
}

@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(id, type, action, "", parentTaskId, headers);
Expand All @@ -58,15 +48,4 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,
public boolean doRemotes() {
return doRemotes;
}

public ClusterStatsRequest subRequest() {
return new ClusterStatsRequest(false, nodesIds());
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeStringArrayNullable(nodesIds());
// We will never ask remote to collect remote stats
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.admin.cluster.stats;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

/**
* A request to get cluster level stats from the remote cluster.
* Note that it always passes doRemotes=false to {@link ClusterStatsRequest} since remote request can not ask for remote stats.
*/
public class RemoteClusterStatsRequest extends ClusterStatsRequest {

/**
* Get stats from nodes based on the nodes ids specified. If none are passed, stats
* based on all nodes will be returned.
*/
public RemoteClusterStatsRequest(String... nodesIds) {
super(false, nodesIds);
}

public RemoteClusterStatsRequest(StreamInput in) throws IOException {
super(false, in.readStringArray());
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeStringArrayNullable(nodesIds());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private ActionFuture<Map<String, RemoteClusterStatsResponse>> getStatsFromRemote
var groupListener = new RemoteClusterActionListener<>(remotes.size(), remotesFuture);

for (String clusterAlias : remotes) {
ClusterStatsRequest remoteRequest = request.subRequest();
var remoteRequest = new RemoteClusterStatsRequest(request.nodesIds());
var remoteClusterClient = remoteClusterService.getRemoteClusterClient(
clusterAlias,
remoteClientResponseExecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public TransportRemoteClusterStatsAction(
TYPE.name(),
// TODO: which executor here?
threadPool.executor(ThreadPool.Names.MANAGEMENT),
ClusterStatsRequest::new,
RemoteClusterStatsRequest::new,
(request, channel, task) -> execute(task, request, new ActionListener<>() {
@Override
public void onResponse(RemoteClusterStatsResponse response) {
Expand Down

0 comments on commit 8ad91b2

Please sign in to comment.