Skip to content

Commit

Permalink
renamed the classes to GetTermVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
rajiv-kv committed Feb 22, 2024
1 parent 1ede5f5 commit 0004fff
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 43 deletions.
4 changes: 1 addition & 3 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@
import org.opensearch.action.admin.cluster.snapshots.status.TransportSnapshotsStatusAction;
import org.opensearch.action.admin.cluster.state.ClusterStateAction;
import org.opensearch.action.admin.cluster.state.TransportClusterStateAction;
import org.opensearch.action.admin.cluster.state.term.ClusterTermVersionAction;
import org.opensearch.action.admin.cluster.state.term.TransportClusterTermVersionAction;
import org.opensearch.action.admin.cluster.stats.ClusterStatsAction;
import org.opensearch.action.admin.cluster.stats.TransportClusterStatsAction;
import org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptAction;
Expand Down Expand Up @@ -609,7 +607,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(ClusterAllocationExplainAction.INSTANCE, TransportClusterAllocationExplainAction.class);
actions.register(ClusterStatsAction.INSTANCE, TransportClusterStatsAction.class);
actions.register(ClusterStateAction.INSTANCE, TransportClusterStateAction.class);
actions.register(ClusterTermVersionAction.INSTANCE, TransportClusterTermVersionAction.class);
actions.register(org.opensearch.action.admin.cluster.state.term.GetTermVersionAction.INSTANCE, org.opensearch.action.admin.cluster.state.term.TransportGetTermVersionAction.class);
actions.register(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class);
actions.register(ClusterUpdateSettingsAction.INSTANCE, TransportClusterUpdateSettingsAction.class);
actions.register(ClusterRerouteAction.INSTANCE, TransportClusterRerouteAction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*
* @opensearch.internal
*/
public class ClusterTermVersionAction extends ActionType<ClusterTermVersionResponse> {
public class GetTermVersionAction extends ActionType<GetTermVersionResponse> {

public static final ClusterTermVersionAction INSTANCE = new ClusterTermVersionAction();
public static final GetTermVersionAction INSTANCE = new GetTermVersionAction();
public static final String NAME = "cluster:monitor/term";

private ClusterTermVersionAction() {
super(NAME, ClusterTermVersionResponse::new);
private GetTermVersionAction() {
super(NAME, GetTermVersionResponse::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
*
* @opensearch.internal
*/
public class ClusterTermVersionRequest extends ClusterManagerNodeReadRequest<ClusterTermVersionRequest> {
public class GetTermVersionRequest extends ClusterManagerNodeReadRequest<GetTermVersionRequest> {

public ClusterTermVersionRequest() {}
public GetTermVersionRequest() {}

public ClusterTermVersionRequest(StreamInput in) throws IOException {
public GetTermVersionRequest(StreamInput in) throws IOException {
super(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
*
* @opensearch.internal
*/
public class ClusterTermVersionResponse extends ActionResponse {
public class GetTermVersionResponse extends ActionResponse {

private final ClusterName clusterName;
private final String stateUUID;
private final long term;
private final long version;

public ClusterTermVersionResponse(ClusterName clusterName, String stateUUID, long term, long version) {
public GetTermVersionResponse(ClusterName clusterName, String stateUUID, long term, long version) {
this.clusterName = clusterName;
this.stateUUID = stateUUID;
this.term = term;
this.version = version;
}

public ClusterTermVersionResponse(StreamInput in) throws IOException {
public GetTermVersionResponse(StreamInput in) throws IOException {
super(in);
this.clusterName = new ClusterName(in);
this.stateUUID = in.readString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,26 @@
*
* @opensearch.internal
*/
public class TransportClusterTermVersionAction extends TransportClusterManagerNodeReadAction<
ClusterTermVersionRequest,
ClusterTermVersionResponse> {
public class TransportGetTermVersionAction extends TransportClusterManagerNodeReadAction<GetTermVersionRequest, GetTermVersionResponse> {

private final Logger logger = LogManager.getLogger(getClass());

@Inject
public TransportClusterTermVersionAction(
public TransportGetTermVersionAction(
TransportService transportService,
ClusterService clusterService,
ThreadPool threadPool,
ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver
) {
super(
ClusterTermVersionAction.NAME,
GetTermVersionAction.NAME,
false,
transportService,
clusterService,
threadPool,
actionFilters,
ClusterTermVersionRequest::new,
GetTermVersionRequest::new,
indexNameExpressionResolver
);
}
Expand All @@ -66,27 +64,27 @@ protected String executor() {
}

@Override
public ClusterTermVersionResponse read(StreamInput in) throws IOException {
return new ClusterTermVersionResponse(in);
public GetTermVersionResponse read(StreamInput in) throws IOException {
return new GetTermVersionResponse(in);
}

@Override
protected ClusterBlockException checkBlock(ClusterTermVersionRequest request, ClusterState state) {
protected ClusterBlockException checkBlock(GetTermVersionRequest request, ClusterState state) {
// cluster state term and version needs to be retrieved even on a fully blocked cluster
return null;
}

@Override
protected void clusterManagerOperation(
ClusterTermVersionRequest request,
GetTermVersionRequest request,
ClusterState state,
ActionListener<ClusterTermVersionResponse> listener
ActionListener<GetTermVersionResponse> listener
) throws Exception {
ActionListener.completeWith(listener, () -> buildResponse(request, state));
}

private ClusterTermVersionResponse buildResponse(ClusterTermVersionRequest request, ClusterState state) {
private GetTermVersionResponse buildResponse(GetTermVersionRequest request, ClusterState state) {
logger.trace("Serving cluster term version request using term {} and version {}", state.term(), state.version());
return new ClusterTermVersionResponse(state.getClusterName(), state.stateUUID(), state.term(), state.getVersion());
return new GetTermVersionResponse(state.getClusterName(), state.stateUUID(), state.term(), state.getVersion());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
import org.opensearch.Version;
import org.opensearch.action.ActionListenerResponseHandler;
import org.opensearch.action.ActionRunnable;
import org.opensearch.action.admin.cluster.state.term.ClusterTermVersionAction;
import org.opensearch.action.admin.cluster.state.term.ClusterTermVersionRequest;
import org.opensearch.action.admin.cluster.state.term.ClusterTermVersionResponse;
import org.opensearch.action.bulk.BackoffPolicy;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
Expand Down Expand Up @@ -350,11 +347,11 @@ private ActionListener<Response> getDelegateForLocalExecute(ClusterState cluster
private void execOnClusterManagerOnTermMismatch(DiscoveryNode clusterManagerNode, ClusterState clusterState) {
transportService.sendRequest(
clusterManagerNode,
ClusterTermVersionAction.NAME,
new ClusterTermVersionRequest(),
new TransportResponseHandler<ClusterTermVersionResponse>() {
org.opensearch.action.admin.cluster.state.term.GetTermVersionAction.NAME,
new org.opensearch.action.admin.cluster.state.term.GetTermVersionRequest(),
new TransportResponseHandler<org.opensearch.action.admin.cluster.state.term.GetTermVersionResponse>() {
@Override
public void handleResponse(ClusterTermVersionResponse response) {
public void handleResponse(org.opensearch.action.admin.cluster.state.term.GetTermVersionResponse response) {
boolean shouldExecuteOnClusterManger = !response.matches(clusterState);
if (shouldExecuteOnClusterManger) {
executeOnClusterManager(clusterManagerNode, clusterState);
Expand All @@ -378,8 +375,8 @@ public String executor() {
}

@Override
public ClusterTermVersionResponse read(StreamInput in) throws IOException {
return new ClusterTermVersionResponse(in);
public org.opensearch.action.admin.cluster.state.term.GetTermVersionResponse read(StreamInput in) throws IOException {
return new org.opensearch.action.admin.cluster.state.term.GetTermVersionResponse(in);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testClusterStateTransportCallsOnMaster() throws Exception {
ensureGreen();
Map<String, AtomicInteger> callCounters = Map.ofEntries(
Map.entry(ClusterStateAction.NAME, new AtomicInteger()),
Map.entry(ClusterTermVersionAction.NAME, new AtomicInteger())
Map.entry(GetTermVersionAction.NAME, new AtomicInteger())
);

addCallCountInterceptor(master, callCounters);
Expand All @@ -73,7 +73,7 @@ public void testClusterStateTransportCallsOnMaster() throws Exception {
dataNodeClient().admin().cluster().state(new ClusterStateRequest()).get();

AtomicInteger clusterStateCallsOnMaster = callCounters.get(ClusterStateAction.NAME);
AtomicInteger termCallsOnMaster = callCounters.get(ClusterTermVersionAction.NAME);
AtomicInteger termCallsOnMaster = callCounters.get(GetTermVersionAction.NAME);

assertThat(clusterStateCallsOnMaster.get(), is(0));
assertThat(termCallsOnMaster.get(), is(2));
Expand All @@ -97,7 +97,7 @@ public void testDatanodeOutOfSync() throws Exception {
ensureGreen();
Map<String, AtomicInteger> callCounters = Map.ofEntries(
Map.entry(ClusterStateAction.NAME, new AtomicInteger()),
Map.entry(ClusterTermVersionAction.NAME, new AtomicInteger())
Map.entry(GetTermVersionAction.NAME, new AtomicInteger())
);

stubClusterTermResponse(master);
Expand All @@ -107,16 +107,16 @@ public void testDatanodeOutOfSync() throws Exception {
dataNodeClient().admin().cluster().state(new ClusterStateRequest()).get();

AtomicInteger clusterStateCallsOnMaster = callCounters.get(ClusterStateAction.NAME);
AtomicInteger termCallsOnMaster = callCounters.get(ClusterTermVersionAction.NAME);
AtomicInteger termCallsOnMaster = callCounters.get(GetTermVersionAction.NAME);

assertThat(clusterStateCallsOnMaster.get(), is(2));
assertThat(termCallsOnMaster.get(), is(2));
}

private void stubClusterTermResponse(String master) {
MockTransportService primaryService = (MockTransportService) internalCluster().getInstance(TransportService.class, master);
primaryService.addRequestHandlingBehavior(ClusterTermVersionAction.NAME, (handler, request, channel, task) -> {
channel.sendResponse(new ClusterTermVersionResponse(new ClusterName("test"), "1", -1, -1));
primaryService.addRequestHandlingBehavior(GetTermVersionAction.NAME, (handler, request, channel, task) -> {
channel.sendResponse(new GetTermVersionResponse(new ClusterName("test"), "1", -1, -1));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
public class ClusterTermVersionTests extends OpenSearchSingleNodeTestCase {

public void testTransportTermResponse() throws ExecutionException, InterruptedException {
ClusterTermVersionRequest request = new ClusterTermVersionRequest();
ClusterTermVersionResponse resp = client().execute(ClusterTermVersionAction.INSTANCE, request).get();
GetTermVersionRequest request = new GetTermVersionRequest();
GetTermVersionResponse resp = client().execute(GetTermVersionAction.INSTANCE, request).get();

final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final ClusterState clusterState = clusterService.state();
Expand Down

0 comments on commit 0004fff

Please sign in to comment.