Skip to content

Commit

Permalink
Remove XPackClient from x-pack (#42729)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jaymode authored May 31, 2019
1 parent 70fb3d8 commit 56c1ed5
Show file tree
Hide file tree
Showing 29 changed files with 181 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus;
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction;
import org.elasticsearch.xpack.core.ccr.client.CcrClient;
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
import org.elasticsearch.xpack.core.monitoring.MonitoredSystem;
import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;
import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase;
Expand All @@ -33,6 +32,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -127,7 +127,7 @@ public void testDoCollect() throws Exception {
whenClusterStateWithUUID(clusterUuid);

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

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

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

final StatsCollector collector = new StatsCollector(settings, clusterService, licenseState, client, threadContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class GetBasicStatusRequestBuilder extends ActionRequestBuilder<GetBasicStatusRequest, GetBasicStatusResponse> {

GetBasicStatusRequestBuilder(ElasticsearchClient client, GetBasicStatusAction action) {
super(client, action, new GetBasicStatusRequest());
GetBasicStatusRequestBuilder(ElasticsearchClient client) {
super(client, GetBasicStatusAction.INSTANCE, new GetBasicStatusRequest());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class GetTrialStatusRequestBuilder extends ActionRequestBuilder<GetTrialStatusRequest, GetTrialStatusResponse> {

GetTrialStatusRequestBuilder(ElasticsearchClient client, GetTrialStatusAction action) {
super(client, action, new GetTrialStatusRequest());
GetTrialStatusRequestBuilder(ElasticsearchClient client) {
super(client, GetTrialStatusAction.INSTANCE, new GetTrialStatusRequest());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public void deleteLicense(DeleteLicenseRequest request, ActionListener<Acknowled
}

public PostStartTrialRequestBuilder preparePostStartTrial() {
return new PostStartTrialRequestBuilder(client, PostStartTrialAction.INSTANCE);
return new PostStartTrialRequestBuilder(client);
}

public GetTrialStatusRequestBuilder prepareGetStartTrial() {
return new GetTrialStatusRequestBuilder(client, GetTrialStatusAction.INSTANCE);
return new GetTrialStatusRequestBuilder(client);
}

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

public PostStartBasicRequestBuilder preparePostStartBasic() {
return new PostStartBasicRequestBuilder(client, PostStartBasicAction.INSTANCE);
return new PostStartBasicRequestBuilder(client);
}

public GetBasicStatusRequestBuilder prepareGetStartBasic() {
return new GetBasicStatusRequestBuilder(client, GetBasicStatusAction.INSTANCE);
return new GetBasicStatusRequestBuilder(client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class PostStartBasicRequestBuilder extends ActionRequestBuilder<PostStartBasicRequest, PostStartBasicResponse> {

PostStartBasicRequestBuilder(ElasticsearchClient client, PostStartBasicAction action) {
super(client, action, new PostStartBasicRequest());
PostStartBasicRequestBuilder(ElasticsearchClient client) {
super(client, PostStartBasicAction.INSTANCE, new PostStartBasicRequest());
}

public PostStartBasicRequestBuilder setAcknowledge(boolean acknowledge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class PostStartTrialRequestBuilder extends ActionRequestBuilder<PostStartTrialRequest, PostStartTrialResponse> {

PostStartTrialRequestBuilder(ElasticsearchClient client, PostStartTrialAction action) {
super(client, action, new PostStartTrialRequest());
PostStartTrialRequestBuilder(ElasticsearchClient client) {
super(client, PostStartTrialAction.INSTANCE, new PostStartTrialRequest());
}

public PostStartTrialRequestBuilder setAcknowledge(boolean acknowledge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
package org.elasticsearch.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.rest.XPackRestHandler;

import java.io.IOException;

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

public class RestDeleteLicenseAction extends XPackRestHandler {
public class RestDeleteLicenseAction extends BaseRestHandler {

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

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

@Override
Expand All @@ -38,12 +38,12 @@ public String getName() {
}

@Override
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest();
deleteLicenseRequest.timeout(request.paramAsTime("timeout", deleteLicenseRequest.timeout()));
deleteLicenseRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteLicenseRequest.masterNodeTimeout()));

return channel -> client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE, deleteLicenseRequest,
return channel -> client.admin().cluster().execute(DeleteLicenseAction.INSTANCE, deleteLicenseRequest,
new RestToXContentListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
package org.elasticsearch.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.rest.XPackRestHandler;

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

public class RestGetBasicStatus extends XPackRestHandler {
public class RestGetBasicStatus extends BaseRestHandler {

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

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
package org.elasticsearch.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;
import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.rest.XPackRestHandler;

import java.io.IOException;
import java.util.HashMap;
Expand All @@ -28,7 +28,7 @@
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
import static org.elasticsearch.rest.RestStatus.OK;

public class RestGetLicenseAction extends XPackRestHandler {
public class RestGetLicenseAction extends BaseRestHandler {

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

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

@Override
Expand All @@ -52,15 +52,15 @@ public String getName() {
* The licenses are sorted by latest issue_date
*/
@Override
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final Map<String, String> overrideParams = new HashMap<>(2);
overrideParams.put(License.REST_VIEW_MODE, "true");
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));
final ToXContent.Params params = new ToXContent.DelegatingMapParams(overrideParams, request);
GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
getLicenseRequest.local(request.paramAsBoolean("local", getLicenseRequest.local()));
return channel -> client.es().admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
new RestBuilderListener<GetLicenseResponse>(channel) {
return channel -> client.admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
new RestBuilderListener<>(channel) {
@Override
public RestResponse buildResponse(GetLicenseResponse response, XContentBuilder builder) throws Exception {
// Default to pretty printing, but allow ?pretty=false to disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
package org.elasticsearch.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.rest.XPackRestHandler;

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

public class RestGetTrialStatus extends XPackRestHandler {
public class RestGetTrialStatus extends BaseRestHandler {

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

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
package org.elasticsearch.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.rest.XPackRestHandler;

import java.io.IOException;

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

public class RestPostStartBasicLicense extends XPackRestHandler {
public class RestPostStartBasicLicense extends BaseRestHandler {

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

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
package org.elasticsearch.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;
import org.elasticsearch.xpack.core.XPackClient;
import org.elasticsearch.xpack.core.rest.XPackRestHandler;

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

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

public class RestPostStartTrialLicense extends XPackRestHandler {
public class RestPostStartTrialLicense extends BaseRestHandler {

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

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

@Override
protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException {
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
PostStartTrialRequest startTrialRequest = new PostStartTrialRequest();
startTrialRequest.setType(request.param("type", "trial"));
startTrialRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
return channel -> client.licensing().postStartTrial(startTrialRequest,
new RestBuilderListener<PostStartTrialResponse>(channel) {
return channel -> client.execute(PostStartTrialAction.INSTANCE, startTrialRequest,
new RestBuilderListener<>(channel) {
@Override
public RestResponse buildResponse(PostStartTrialResponse response, XContentBuilder builder) throws Exception {
PostStartTrialResponse.Status status = response.getStatus();
Expand Down
Loading

0 comments on commit 56c1ed5

Please sign in to comment.