Skip to content

Commit 56c1ed5

Browse files
authored
Remove XPackClient from x-pack (#42729)
This commit removes the XPackClient class from x-pack. This class is a relic of the TransportClient and simply a wrapper around it. Calls are replaced with direct usage of a client. Additionally, the XPackRestHandler class has been removed as it only served to provide the XPackClient to implementing rest handlers.
1 parent 70fb3d8 commit 56c1ed5

File tree

29 files changed

+181
-368
lines changed

29 files changed

+181
-368
lines changed

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
import org.elasticsearch.xpack.core.XPackSettings;
1616
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
1717
import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus;
18-
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
1918
import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction;
20-
import org.elasticsearch.xpack.core.ccr.client.CcrClient;
19+
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
2120
import org.elasticsearch.xpack.core.monitoring.MonitoredSystem;
2221
import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;
2322
import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase;
@@ -33,6 +32,7 @@
3332
import static org.hamcrest.Matchers.notNullValue;
3433
import static org.hamcrest.Matchers.nullValue;
3534
import static org.mockito.Matchers.any;
35+
import static org.mockito.Matchers.eq;
3636
import static org.mockito.Mockito.mock;
3737
import static org.mockito.Mockito.verify;
3838
import static org.mockito.Mockito.when;
@@ -127,7 +127,7 @@ public void testDoCollect() throws Exception {
127127
whenClusterStateWithUUID(clusterUuid);
128128

129129
final MonitoringDoc.Node node = randomMonitoringNode(random());
130-
final CcrClient client = mock(CcrClient.class);
130+
final Client client = mock(Client.class);
131131
final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
132132
final List<FollowStatsAction.StatsResponse> statuses = mockStatuses();
133133

@@ -142,7 +142,7 @@ public void testDoCollect() throws Exception {
142142
final ActionFuture<CcrStatsAction.Response> future = (ActionFuture<CcrStatsAction.Response>) mock(ActionFuture.class);
143143
final CcrStatsAction.Response response = new CcrStatsAction.Response(autoFollowStats, statsResponse);
144144

145-
when(client.stats(any())).thenReturn(future);
145+
when(client.execute(eq(CcrStatsAction.INSTANCE), any(CcrStatsAction.Request.class))).thenReturn(future);
146146
when(future.actionGet(timeout)).thenReturn(response);
147147

148148
final StatsCollector collector = new StatsCollector(settings, clusterService, licenseState, client, threadContext);

x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequestBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class GetBasicStatusRequestBuilder extends ActionRequestBuilder<GetBasicStatusRequest, GetBasicStatusResponse> {
1212

13-
GetBasicStatusRequestBuilder(ElasticsearchClient client, GetBasicStatusAction action) {
14-
super(client, action, new GetBasicStatusRequest());
13+
GetBasicStatusRequestBuilder(ElasticsearchClient client) {
14+
super(client, GetBasicStatusAction.INSTANCE, new GetBasicStatusRequest());
1515
}
1616
}

x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequestBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class GetTrialStatusRequestBuilder extends ActionRequestBuilder<GetTrialStatusRequest, GetTrialStatusResponse> {
1212

13-
GetTrialStatusRequestBuilder(ElasticsearchClient client, GetTrialStatusAction action) {
14-
super(client, action, new GetTrialStatusRequest());
13+
GetTrialStatusRequestBuilder(ElasticsearchClient client) {
14+
super(client, GetTrialStatusAction.INSTANCE, new GetTrialStatusRequest());
1515
}
1616
}

x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensingClient.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public void deleteLicense(DeleteLicenseRequest request, ActionListener<Acknowled
4545
}
4646

4747
public PostStartTrialRequestBuilder preparePostStartTrial() {
48-
return new PostStartTrialRequestBuilder(client, PostStartTrialAction.INSTANCE);
48+
return new PostStartTrialRequestBuilder(client);
4949
}
5050

5151
public GetTrialStatusRequestBuilder prepareGetStartTrial() {
52-
return new GetTrialStatusRequestBuilder(client, GetTrialStatusAction.INSTANCE);
52+
return new GetTrialStatusRequestBuilder(client);
5353
}
5454

5555
public void postStartTrial(PostStartTrialRequest request, ActionListener<PostStartTrialResponse> listener) {
@@ -61,10 +61,10 @@ public void postStartBasic(PostStartBasicRequest request, ActionListener<PostSta
6161
}
6262

6363
public PostStartBasicRequestBuilder preparePostStartBasic() {
64-
return new PostStartBasicRequestBuilder(client, PostStartBasicAction.INSTANCE);
64+
return new PostStartBasicRequestBuilder(client);
6565
}
6666

6767
public GetBasicStatusRequestBuilder prepareGetStartBasic() {
68-
return new GetBasicStatusRequestBuilder(client, GetBasicStatusAction.INSTANCE);
68+
return new GetBasicStatusRequestBuilder(client);
6969
}
7070
}

x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicRequestBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class PostStartBasicRequestBuilder extends ActionRequestBuilder<PostStartBasicRequest, PostStartBasicResponse> {
1212

13-
PostStartBasicRequestBuilder(ElasticsearchClient client, PostStartBasicAction action) {
14-
super(client, action, new PostStartBasicRequest());
13+
PostStartBasicRequestBuilder(ElasticsearchClient client) {
14+
super(client, PostStartBasicAction.INSTANCE, new PostStartBasicRequest());
1515
}
1616

1717
public PostStartBasicRequestBuilder setAcknowledge(boolean acknowledge) {

x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequestBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class PostStartTrialRequestBuilder extends ActionRequestBuilder<PostStartTrialRequest, PostStartTrialResponse> {
1212

13-
PostStartTrialRequestBuilder(ElasticsearchClient client, PostStartTrialAction action) {
14-
super(client, action, new PostStartTrialRequest());
13+
PostStartTrialRequestBuilder(ElasticsearchClient client) {
14+
super(client, PostStartTrialAction.INSTANCE, new PostStartTrialRequest());
1515
}
1616

1717
public PostStartTrialRequestBuilder setAcknowledge(boolean acknowledge) {

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
package org.elasticsearch.license;
88

99
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.client.node.NodeClient;
1011
import org.elasticsearch.common.logging.DeprecationLogger;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
14+
import org.elasticsearch.rest.BaseRestHandler;
1315
import org.elasticsearch.rest.RestController;
1416
import org.elasticsearch.rest.RestRequest;
1517
import org.elasticsearch.rest.action.RestToXContentListener;
16-
import org.elasticsearch.xpack.core.XPackClient;
17-
import org.elasticsearch.xpack.core.rest.XPackRestHandler;
1818

1919
import java.io.IOException;
2020

2121
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
2222

23-
public class RestDeleteLicenseAction extends XPackRestHandler {
23+
public class RestDeleteLicenseAction extends BaseRestHandler {
2424

2525
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteLicenseAction.class));
2626

@@ -29,7 +29,7 @@ public class RestDeleteLicenseAction extends XPackRestHandler {
2929
// TODO: remove deprecated endpoint in 8.0.0
3030
controller.registerWithDeprecatedHandler(
3131
DELETE, "/_license", this,
32-
DELETE, URI_BASE + "/license", deprecationLogger);
32+
DELETE, "/_xpack/license", deprecationLogger);
3333
}
3434

3535
@Override
@@ -38,12 +38,12 @@ public String getName() {
3838
}
3939

4040
@Override
41-
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
41+
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
4242
DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest();
4343
deleteLicenseRequest.timeout(request.paramAsTime("timeout", deleteLicenseRequest.timeout()));
4444
deleteLicenseRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteLicenseRequest.masterNodeTimeout()));
4545

46-
return channel -> client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE, deleteLicenseRequest,
46+
return channel -> client.admin().cluster().execute(DeleteLicenseAction.INSTANCE, deleteLicenseRequest,
4747
new RestToXContentListener<>(channel));
4848
}
4949
}

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
package org.elasticsearch.license;
88

99
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.client.node.NodeClient;
1011
import org.elasticsearch.common.logging.DeprecationLogger;
1112
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.rest.BaseRestHandler;
1214
import org.elasticsearch.rest.RestController;
1315
import org.elasticsearch.rest.RestRequest;
1416
import org.elasticsearch.rest.action.RestToXContentListener;
15-
import org.elasticsearch.xpack.core.XPackClient;
16-
import org.elasticsearch.xpack.core.rest.XPackRestHandler;
1717

1818
import static org.elasticsearch.rest.RestRequest.Method.GET;
1919

20-
public class RestGetBasicStatus extends XPackRestHandler {
20+
public class RestGetBasicStatus extends BaseRestHandler {
2121

2222
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetBasicStatus.class));
2323

@@ -26,12 +26,12 @@ public class RestGetBasicStatus extends XPackRestHandler {
2626
// TODO: remove deprecated endpoint in 8.0.0
2727
controller.registerWithDeprecatedHandler(
2828
GET, "/_license/basic_status", this,
29-
GET, URI_BASE + "/license/basic_status", deprecationLogger);
29+
GET, "/_xpack/license/basic_status", deprecationLogger);
3030
}
3131

3232
@Override
33-
protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) {
34-
return channel -> client.licensing().prepareGetStartBasic().execute(new RestToXContentListener<>(channel));
33+
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
34+
return channel -> new GetBasicStatusRequestBuilder(client).execute(new RestToXContentListener<>(channel));
3535
}
3636

3737
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
package org.elasticsearch.license;
88

99
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.client.node.NodeClient;
1011
import org.elasticsearch.common.logging.DeprecationLogger;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.common.xcontent.ToXContent;
1314
import org.elasticsearch.common.xcontent.XContentBuilder;
1415
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
16+
import org.elasticsearch.rest.BaseRestHandler;
1517
import org.elasticsearch.rest.BytesRestResponse;
1618
import org.elasticsearch.rest.RestController;
1719
import org.elasticsearch.rest.RestRequest;
1820
import org.elasticsearch.rest.RestResponse;
1921
import org.elasticsearch.rest.action.RestBuilderListener;
20-
import org.elasticsearch.xpack.core.XPackClient;
21-
import org.elasticsearch.xpack.core.rest.XPackRestHandler;
2222

2323
import java.io.IOException;
2424
import java.util.HashMap;
@@ -28,7 +28,7 @@
2828
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
2929
import static org.elasticsearch.rest.RestStatus.OK;
3030

31-
public class RestGetLicenseAction extends XPackRestHandler {
31+
public class RestGetLicenseAction extends BaseRestHandler {
3232

3333
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetLicenseAction.class));
3434

@@ -37,7 +37,7 @@ public class RestGetLicenseAction extends XPackRestHandler {
3737
// TODO: remove deprecated endpoint in 8.0.0
3838
controller.registerWithDeprecatedHandler(
3939
GET, "/_license", this,
40-
GET, URI_BASE + "/license", deprecationLogger);
40+
GET, "/_xpack/license", deprecationLogger);
4141
}
4242

4343
@Override
@@ -52,15 +52,15 @@ public String getName() {
5252
* The licenses are sorted by latest issue_date
5353
*/
5454
@Override
55-
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
55+
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
5656
final Map<String, String> overrideParams = new HashMap<>(2);
5757
overrideParams.put(License.REST_VIEW_MODE, "true");
5858
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));
5959
final ToXContent.Params params = new ToXContent.DelegatingMapParams(overrideParams, request);
6060
GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
6161
getLicenseRequest.local(request.paramAsBoolean("local", getLicenseRequest.local()));
62-
return channel -> client.es().admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
63-
new RestBuilderListener<GetLicenseResponse>(channel) {
62+
return channel -> client.admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
63+
new RestBuilderListener<>(channel) {
6464
@Override
6565
public RestResponse buildResponse(GetLicenseResponse response, XContentBuilder builder) throws Exception {
6666
// Default to pretty printing, but allow ?pretty=false to disable

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
package org.elasticsearch.license;
88

99
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.client.node.NodeClient;
1011
import org.elasticsearch.common.logging.DeprecationLogger;
1112
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.rest.BaseRestHandler;
1214
import org.elasticsearch.rest.RestController;
1315
import org.elasticsearch.rest.RestRequest;
1416
import org.elasticsearch.rest.action.RestToXContentListener;
15-
import org.elasticsearch.xpack.core.XPackClient;
16-
import org.elasticsearch.xpack.core.rest.XPackRestHandler;
1717

1818
import static org.elasticsearch.rest.RestRequest.Method.GET;
1919

20-
public class RestGetTrialStatus extends XPackRestHandler {
20+
public class RestGetTrialStatus extends BaseRestHandler {
2121

2222
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetTrialStatus.class));
2323

@@ -26,12 +26,12 @@ public class RestGetTrialStatus extends XPackRestHandler {
2626
// TODO: remove deprecated endpoint in 8.0.0
2727
controller.registerWithDeprecatedHandler(
2828
GET, "/_license/trial_status", this,
29-
GET, URI_BASE + "/license/trial_status", deprecationLogger);
29+
GET, "/_xpack/license/trial_status", deprecationLogger);
3030
}
3131

3232
@Override
33-
protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) {
34-
return channel -> client.licensing().prepareGetStartTrial().execute(new RestToXContentListener<>(channel));
33+
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
34+
return channel -> new GetTrialStatusRequestBuilder(client).execute(new RestToXContentListener<>(channel));
3535
}
3636

3737
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
package org.elasticsearch.license;
88

99
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.client.node.NodeClient;
1011
import org.elasticsearch.common.logging.DeprecationLogger;
1112
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.rest.BaseRestHandler;
1214
import org.elasticsearch.rest.RestController;
1315
import org.elasticsearch.rest.RestRequest;
1416
import org.elasticsearch.rest.action.RestStatusToXContentListener;
15-
import org.elasticsearch.xpack.core.XPackClient;
16-
import org.elasticsearch.xpack.core.rest.XPackRestHandler;
1717

1818
import java.io.IOException;
1919

2020
import static org.elasticsearch.rest.RestRequest.Method.POST;
2121

22-
public class RestPostStartBasicLicense extends XPackRestHandler {
22+
public class RestPostStartBasicLicense extends BaseRestHandler {
2323

2424
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostStartBasicLicense.class));
2525

@@ -28,16 +28,16 @@ public class RestPostStartBasicLicense extends XPackRestHandler {
2828
// TODO: remove deprecated endpoint in 8.0.0
2929
controller.registerWithDeprecatedHandler(
3030
POST, "/_license/start_basic", this,
31-
POST, URI_BASE + "/license/start_basic", deprecationLogger);
31+
POST, "/_xpack/license/start_basic", deprecationLogger);
3232
}
3333

3434
@Override
35-
protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException {
35+
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
3636
PostStartBasicRequest startBasicRequest = new PostStartBasicRequest();
3737
startBasicRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
3838
startBasicRequest.timeout(request.paramAsTime("timeout", startBasicRequest.timeout()));
3939
startBasicRequest.masterNodeTimeout(request.paramAsTime("master_timeout", startBasicRequest.masterNodeTimeout()));
40-
return channel -> client.licensing().postStartBasic(startBasicRequest, new RestStatusToXContentListener<>(channel));
40+
return channel -> client.execute(PostStartBasicAction.INSTANCE, startBasicRequest, new RestStatusToXContentListener<>(channel));
4141
}
4242

4343
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
package org.elasticsearch.license;
88

99
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.client.node.NodeClient;
1011
import org.elasticsearch.common.logging.DeprecationLogger;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.common.xcontent.XContentBuilder;
14+
import org.elasticsearch.rest.BaseRestHandler;
1315
import org.elasticsearch.rest.BytesRestResponse;
1416
import org.elasticsearch.rest.RestController;
1517
import org.elasticsearch.rest.RestRequest;
1618
import org.elasticsearch.rest.RestResponse;
1719
import org.elasticsearch.rest.action.RestBuilderListener;
18-
import org.elasticsearch.xpack.core.XPackClient;
19-
import org.elasticsearch.xpack.core.rest.XPackRestHandler;
2020

2121
import java.io.IOException;
2222
import java.util.Map;
2323

2424
import static org.elasticsearch.rest.RestRequest.Method.POST;
2525

26-
public class RestPostStartTrialLicense extends XPackRestHandler {
26+
public class RestPostStartTrialLicense extends BaseRestHandler {
2727

2828
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostStartTrialLicense.class));
2929

@@ -32,16 +32,16 @@ public class RestPostStartTrialLicense extends XPackRestHandler {
3232
// TODO: remove deprecated endpoint in 8.0.0
3333
controller.registerWithDeprecatedHandler(
3434
POST, "/_license/start_trial", this,
35-
POST, URI_BASE + "/license/start_trial", deprecationLogger);
35+
POST, "/_xpack/license/start_trial", deprecationLogger);
3636
}
3737

3838
@Override
39-
protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException {
39+
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
4040
PostStartTrialRequest startTrialRequest = new PostStartTrialRequest();
4141
startTrialRequest.setType(request.param("type", "trial"));
4242
startTrialRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
43-
return channel -> client.licensing().postStartTrial(startTrialRequest,
44-
new RestBuilderListener<PostStartTrialResponse>(channel) {
43+
return channel -> client.execute(PostStartTrialAction.INSTANCE, startTrialRequest,
44+
new RestBuilderListener<>(channel) {
4545
@Override
4646
public RestResponse buildResponse(PostStartTrialResponse response, XContentBuilder builder) throws Exception {
4747
PostStartTrialResponse.Status status = response.getStatus();

0 commit comments

Comments
 (0)