Skip to content

Commit 3d3b37a

Browse files
committed
Make TransportRequest an interface
In order to support a future TransportRequest variant that accepts the response type, TransportRequest needs to be an interface. This commit adds AbstractTransportRequest as a concrete implementation and makes TransportRequest a simple interface that joints together the parent interfaces from TransportMessage. Note that this was done entirely in Intellij using structural find and replace.
1 parent 7ad2369 commit 3d3b37a

File tree

103 files changed

+7985
-7763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+7985
-7763
lines changed

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/direct/GetDatabaseConfigurationAction.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.cluster.node.DiscoveryNode;
1919
import org.elasticsearch.common.io.stream.StreamInput;
2020
import org.elasticsearch.common.io.stream.StreamOutput;
21+
import org.elasticsearch.transport.AbstractTransportRequest;
2122
import org.elasticsearch.transport.TransportRequest;
2223
import org.elasticsearch.xcontent.ToXContentObject;
2324
import org.elasticsearch.xcontent.XContentBuilder;
@@ -78,10 +79,10 @@ public static class Response extends BaseNodesResponse<NodeResponse> implements
7879
private final List<DatabaseConfigurationMetadata> databases;
7980

8081
public Response(
81-
List<DatabaseConfigurationMetadata> databases,
82-
ClusterName clusterName,
83-
List<NodeResponse> nodes,
84-
List<FailedNodeException> failures
82+
List<DatabaseConfigurationMetadata> databases,
83+
ClusterName clusterName,
84+
List<NodeResponse> nodes,
85+
List<FailedNodeException> failures
8586
) {
8687
super(clusterName, nodes, failures);
8788
this.databases = List.copyOf(databases); // defensive copy
@@ -117,9 +118,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
117118
builder.field("id", database.id()); // serialize including the id -- this is get response serialization
118119
builder.field(VERSION.getPreferredName(), item.version());
119120
builder.timestampFieldsFromUnixEpochMillis(
120-
MODIFIED_DATE_MILLIS.getPreferredName(),
121-
MODIFIED_DATE.getPreferredName(),
122-
item.modifiedDate()
121+
MODIFIED_DATE_MILLIS.getPreferredName(),
122+
MODIFIED_DATE.getPreferredName(),
123+
item.modifiedDate()
123124
);
124125
builder.field(DATABASE.getPreferredName(), database);
125126
builder.endObject();
@@ -138,10 +139,10 @@ public boolean equals(Object o) {
138139
if (o == null || getClass() != o.getClass()) return false;
139140
Response response = (Response) o;
140141
return Objects.equals(databases, response.databases)
141-
&& Objects.equals(getClusterName(), response.getClusterName())
142-
&& Objects.equals(equalsHashCodeFailures(), response.equalsHashCodeFailures())
143-
&& Objects.equals(getNodes(), response.getNodes())
144-
&& Objects.equals(equalsHashCodeNodesMap(), response.equalsHashCodeNodesMap());
142+
&& Objects.equals(getClusterName(), response.getClusterName())
143+
&& Objects.equals(equalsHashCodeFailures(), response.equalsHashCodeFailures())
144+
&& Objects.equals(getNodes(), response.getNodes())
145+
&& Objects.equals(equalsHashCodeNodesMap(), response.equalsHashCodeNodesMap());
145146
}
146147

147148
/*
@@ -167,7 +168,7 @@ public boolean equals(Object o) {
167168
if (o == null || getClass() != o.getClass()) return false;
168169
EqualsHashCodeFailedNodeException other = (EqualsHashCodeFailedNodeException) o;
169170
return Objects.equals(failedNodeException.nodeId(), other.failedNodeException.nodeId())
170-
&& Objects.equals(failedNodeException.getMessage(), other.failedNodeException.getMessage());
171+
&& Objects.equals(failedNodeException.getMessage(), other.failedNodeException.getMessage());
171172
}
172173

173174
@Override
@@ -187,7 +188,7 @@ private synchronized Map<String, NodeResponse> equalsHashCodeNodesMap() {
187188
}
188189
}
189190

190-
public static class NodeRequest extends TransportRequest {
191+
public static class NodeRequest extends AbstractTransportRequest {
191192

192193
private final String[] databaseIds;
193194

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/stats/GeoIpStatsAction.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.common.io.stream.StreamOutput;
2222
import org.elasticsearch.common.io.stream.Writeable;
2323
import org.elasticsearch.core.TimeValue;
24+
import org.elasticsearch.transport.AbstractTransportRequest;
2425
import org.elasticsearch.transport.TransportRequest;
2526
import org.elasticsearch.xcontent.ToXContentObject;
2627
import org.elasticsearch.xcontent.XContentBuilder;
@@ -68,12 +69,13 @@ public boolean equals(Object obj) {
6869
}
6970
}
7071

71-
public static class NodeRequest extends TransportRequest {
72+
public static class NodeRequest extends AbstractTransportRequest {
7273
public NodeRequest(StreamInput in) throws IOException {
7374
super(in);
7475
}
7576

76-
public NodeRequest() {}
77+
public NodeRequest() {
78+
}
7779
}
7880

7981
public static class Response extends BaseNodesResponse<NodeResponse> implements Writeable, ToXContentObject {
@@ -175,17 +177,17 @@ protected NodeResponse(StreamInput in) throws IOException {
175177
databases = in.readCollectionAsImmutableSet(StreamInput::readString);
176178
filesInTemp = in.readCollectionAsImmutableSet(StreamInput::readString);
177179
configDatabases = in.getTransportVersion().onOrAfter(TransportVersions.V_8_0_0)
178-
? in.readCollectionAsImmutableSet(StreamInput::readString)
179-
: null;
180+
? in.readCollectionAsImmutableSet(StreamInput::readString)
181+
: null;
180182
}
181183

182184
protected NodeResponse(
183-
DiscoveryNode node,
184-
GeoIpDownloaderStats downloaderStats,
185-
CacheStats cacheStats,
186-
Set<String> databases,
187-
Set<String> filesInTemp,
188-
Set<String> configDatabases
185+
DiscoveryNode node,
186+
GeoIpDownloaderStats downloaderStats,
187+
CacheStats cacheStats,
188+
Set<String> databases,
189+
Set<String> filesInTemp,
190+
Set<String> configDatabases
189191
) {
190192
super(node);
191193
this.downloaderStats = downloaderStats;
@@ -237,10 +239,10 @@ public boolean equals(Object o) {
237239
if (o == null || getClass() != o.getClass()) return false;
238240
NodeResponse that = (NodeResponse) o;
239241
return downloaderStats.equals(that.downloaderStats)
240-
&& Objects.equals(cacheStats, that.cacheStats)
241-
&& databases.equals(that.databases)
242-
&& filesInTemp.equals(that.filesInTemp)
243-
&& Objects.equals(configDatabases, that.configDatabases);
242+
&& Objects.equals(cacheStats, that.cacheStats)
243+
&& databases.equals(that.databases)
244+
&& filesInTemp.equals(that.filesInTemp)
245+
&& Objects.equals(configDatabases, that.configDatabases);
244246
}
245247

246248
@Override

plugins/examples/security-authorization-engine/src/test/java/org/elasticsearch/example/CustomAuthorizationEngineTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.settings.Settings;
1818
import org.elasticsearch.index.IndexVersion;
1919
import org.elasticsearch.test.ESTestCase;
20+
import org.elasticsearch.transport.AbstractTransportRequest;
2021
import org.elasticsearch.transport.TransportRequest;
2122
import org.elasticsearch.xpack.core.security.authc.Authentication;
2223
import org.elasticsearch.xpack.core.security.authc.Authentication.RealmRef;
@@ -47,7 +48,7 @@ public void testGetAuthorizationInfo() {
4748

4849
public void testAuthorizeRunAs() {
4950
final String action = "cluster:monitor/foo";
50-
final TransportRequest request = new TransportRequest() {
51+
final TransportRequest request = new AbstractTransportRequest() {
5152
};
5253
CustomAuthorizationEngine engine = new CustomAuthorizationEngine();
5354
// unauthorized
@@ -181,7 +182,7 @@ public void testAuthorizeIndexAction() {
181182

182183
private RequestInfo getRequestInfo() {
183184
final String action = "cluster:monitor/foo";
184-
final TransportRequest request = new TransportRequest() {
185+
final TransportRequest request = new AbstractTransportRequest() {
185186
};
186187
final Authentication authentication = Authentication.newRealmAuthentication(
187188
new User("joe", "custom_superuser"),

server/src/main/java/org/elasticsearch/action/ActionRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
14+
import org.elasticsearch.transport.AbstractTransportRequest;
1415
import org.elasticsearch.transport.TransportRequest;
1516

1617
import java.io.IOException;
1718

18-
public abstract class ActionRequest extends TransportRequest {
19+
public abstract class ActionRequest extends AbstractTransportRequest {
1920

2021
public ActionRequest() {
2122
super();

server/src/main/java/org/elasticsearch/action/admin/cluster/node/capabilities/TransportNodesCapabilitiesAction.java

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.rest.RestRequest;
2626
import org.elasticsearch.tasks.Task;
2727
import org.elasticsearch.threadpool.ThreadPool;
28+
import org.elasticsearch.transport.AbstractTransportRequest;
2829
import org.elasticsearch.transport.TransportRequest;
2930
import org.elasticsearch.transport.TransportService;
3031

@@ -33,11 +34,11 @@
3334
import java.util.Set;
3435

3536
public class TransportNodesCapabilitiesAction extends TransportNodesAction<
36-
NodesCapabilitiesRequest,
37-
NodesCapabilitiesResponse,
38-
TransportNodesCapabilitiesAction.NodeCapabilitiesRequest,
39-
NodeCapability,
40-
Void> {
37+
NodesCapabilitiesRequest,
38+
NodesCapabilitiesResponse,
39+
TransportNodesCapabilitiesAction.NodeCapabilitiesRequest,
40+
NodeCapability,
41+
Void> {
4142

4243
public static final ActionType<NodesCapabilitiesResponse> TYPE = new ActionType<>("cluster:monitor/nodes/capabilities");
4344

@@ -46,30 +47,30 @@ public class TransportNodesCapabilitiesAction extends TransportNodesAction<
4647

4748
@Inject
4849
public TransportNodesCapabilitiesAction(
49-
ThreadPool threadPool,
50-
ClusterService clusterService,
51-
TransportService transportService,
52-
ActionFilters actionFilters,
53-
RestController restController,
54-
FeatureService featureService
50+
ThreadPool threadPool,
51+
ClusterService clusterService,
52+
TransportService transportService,
53+
ActionFilters actionFilters,
54+
RestController restController,
55+
FeatureService featureService
5556
) {
5657
super(
57-
TYPE.name(),
58-
clusterService,
59-
transportService,
60-
actionFilters,
61-
NodeCapabilitiesRequest::new,
62-
threadPool.executor(ThreadPool.Names.MANAGEMENT)
58+
TYPE.name(),
59+
clusterService,
60+
transportService,
61+
actionFilters,
62+
NodeCapabilitiesRequest::new,
63+
threadPool.executor(ThreadPool.Names.MANAGEMENT)
6364
);
6465
this.restController = restController;
6566
this.featureService = featureService;
6667
}
6768

6869
@Override
6970
protected NodesCapabilitiesResponse newResponse(
70-
NodesCapabilitiesRequest request,
71-
List<NodeCapability> responses,
72-
List<FailedNodeException> failures
71+
NodesCapabilitiesRequest request,
72+
List<NodeCapability> responses,
73+
List<FailedNodeException> failures
7374
) {
7475
return new NodesCapabilitiesResponse(clusterService.getClusterName(), responses, failures);
7576
}
@@ -101,16 +102,16 @@ protected NodeCapability newNodeResponse(StreamInput in, DiscoveryNode node) thr
101102
@Override
102103
protected NodeCapability nodeOperation(NodeCapabilitiesRequest request, Task task) {
103104
boolean supported = restController.checkSupported(
104-
request.method,
105-
request.path,
106-
request.parameters,
107-
request.capabilities,
108-
request.restApiVersion
105+
request.method,
106+
request.path,
107+
request.parameters,
108+
request.capabilities,
109+
request.restApiVersion
109110
);
110111
return new NodeCapability(supported, transportService.getLocalNode());
111112
}
112113

113-
public static class NodeCapabilitiesRequest extends TransportRequest {
114+
public static class NodeCapabilitiesRequest extends AbstractTransportRequest {
114115
private final RestRequest.Method method;
115116
private final String path;
116117
private final Set<String> parameters;
@@ -128,11 +129,11 @@ public NodeCapabilitiesRequest(StreamInput in) throws IOException {
128129
}
129130

130131
public NodeCapabilitiesRequest(
131-
RestRequest.Method method,
132-
String path,
133-
Set<String> parameters,
134-
Set<String> capabilities,
135-
RestApiVersion restApiVersion
132+
RestRequest.Method method,
133+
String path,
134+
Set<String> parameters,
135+
Set<String> capabilities,
136+
RestApiVersion restApiVersion
136137
) {
137138
this.method = method;
138139
this.path = path;

server/src/main/java/org/elasticsearch/action/admin/cluster/node/features/TransportNodesFeaturesAction.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,50 @@
2121
import org.elasticsearch.injection.guice.Inject;
2222
import org.elasticsearch.tasks.Task;
2323
import org.elasticsearch.threadpool.ThreadPool;
24+
import org.elasticsearch.transport.AbstractTransportRequest;
2425
import org.elasticsearch.transport.TransportRequest;
2526
import org.elasticsearch.transport.TransportService;
2627

2728
import java.io.IOException;
2829
import java.util.List;
2930

30-
@UpdateForV10(owner = UpdateForV10.Owner.CORE_INFRA) // this can be removed in v10. It may be called by v8 nodes to v9 nodes.
31+
@UpdateForV10(owner = UpdateForV10.Owner.CORE_INFRA)
32+
// this can be removed in v10. It may be called by v8 nodes to v9 nodes.
3133
public class TransportNodesFeaturesAction extends TransportNodesAction<
32-
NodesFeaturesRequest,
33-
NodesFeaturesResponse,
34-
TransportNodesFeaturesAction.NodeFeaturesRequest,
35-
NodeFeatures,
36-
Void> {
34+
NodesFeaturesRequest,
35+
NodesFeaturesResponse,
36+
TransportNodesFeaturesAction.NodeFeaturesRequest,
37+
NodeFeatures,
38+
Void> {
3739

3840
public static final ActionType<NodesFeaturesResponse> TYPE = new ActionType<>("cluster:monitor/nodes/features");
3941

4042
private final FeatureService featureService;
4143

4244
@Inject
4345
public TransportNodesFeaturesAction(
44-
ThreadPool threadPool,
45-
ClusterService clusterService,
46-
TransportService transportService,
47-
ActionFilters actionFilters,
48-
FeatureService featureService
46+
ThreadPool threadPool,
47+
ClusterService clusterService,
48+
TransportService transportService,
49+
ActionFilters actionFilters,
50+
FeatureService featureService
4951
) {
5052
super(
51-
TYPE.name(),
52-
clusterService,
53-
transportService,
54-
actionFilters,
55-
NodeFeaturesRequest::new,
56-
threadPool.executor(ThreadPool.Names.MANAGEMENT)
53+
TYPE.name(),
54+
clusterService,
55+
transportService,
56+
actionFilters,
57+
NodeFeaturesRequest::new,
58+
threadPool.executor(ThreadPool.Names.MANAGEMENT)
5759
);
5860
this.featureService = featureService;
5961
}
6062

6163
@Override
6264
protected NodesFeaturesResponse newResponse(
63-
NodesFeaturesRequest request,
64-
List<NodeFeatures> responses,
65-
List<FailedNodeException> failures
65+
NodesFeaturesRequest request,
66+
List<NodeFeatures> responses,
67+
List<FailedNodeException> failures
6668
) {
6769
return new NodesFeaturesResponse(clusterService.getClusterName(), responses, failures);
6870
}
@@ -82,11 +84,12 @@ protected NodeFeatures nodeOperation(NodeFeaturesRequest request, Task task) {
8284
return new NodeFeatures(featureService.getNodeFeatures().keySet(), transportService.getLocalNode());
8385
}
8486

85-
public static class NodeFeaturesRequest extends TransportRequest {
87+
public static class NodeFeaturesRequest extends AbstractTransportRequest {
8688
public NodeFeaturesRequest(StreamInput in) throws IOException {
8789
super(in);
8890
}
8991

90-
public NodeFeaturesRequest() {}
92+
public NodeFeaturesRequest() {
93+
}
9194
}
9295
}

0 commit comments

Comments
 (0)