diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java index bb44fd59da5d2..2b85cd11e927f 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java @@ -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; @@ -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; @@ -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 statuses = mockStatuses(); @@ -142,7 +142,7 @@ public void testDoCollect() throws Exception { final ActionFuture future = (ActionFuture) 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); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequestBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequestBuilder.java index e56451c4a92ff..368bd4a9b735e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequestBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetBasicStatusRequestBuilder.java @@ -10,7 +10,7 @@ class GetBasicStatusRequestBuilder extends ActionRequestBuilder { - GetBasicStatusRequestBuilder(ElasticsearchClient client, GetBasicStatusAction action) { - super(client, action, new GetBasicStatusRequest()); + GetBasicStatusRequestBuilder(ElasticsearchClient client) { + super(client, GetBasicStatusAction.INSTANCE, new GetBasicStatusRequest()); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequestBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequestBuilder.java index d220b476bc578..4102e98f45d68 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequestBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetTrialStatusRequestBuilder.java @@ -10,7 +10,7 @@ class GetTrialStatusRequestBuilder extends ActionRequestBuilder { - GetTrialStatusRequestBuilder(ElasticsearchClient client, GetTrialStatusAction action) { - super(client, action, new GetTrialStatusRequest()); + GetTrialStatusRequestBuilder(ElasticsearchClient client) { + super(client, GetTrialStatusAction.INSTANCE, new GetTrialStatusRequest()); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensingClient.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensingClient.java index 80d1fb68f0e2a..4dcfa94f6e4d2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensingClient.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensingClient.java @@ -45,11 +45,11 @@ public void deleteLicense(DeleteLicenseRequest request, ActionListener listener) { @@ -61,10 +61,10 @@ public void postStartBasic(PostStartBasicRequest request, ActionListener { - PostStartBasicRequestBuilder(ElasticsearchClient client, PostStartBasicAction action) { - super(client, action, new PostStartBasicRequest()); + PostStartBasicRequestBuilder(ElasticsearchClient client) { + super(client, PostStartBasicAction.INSTANCE, new PostStartBasicRequest()); } public PostStartBasicRequestBuilder setAcknowledge(boolean acknowledge) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequestBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequestBuilder.java index 8e12c879f997d..93a6207d519d1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequestBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequestBuilder.java @@ -10,8 +10,8 @@ class PostStartTrialRequestBuilder extends ActionRequestBuilder { - PostStartTrialRequestBuilder(ElasticsearchClient client, PostStartTrialAction action) { - super(client, action, new PostStartTrialRequest()); + PostStartTrialRequestBuilder(ElasticsearchClient client) { + super(client, PostStartTrialAction.INSTANCE, new PostStartTrialRequest()); } public PostStartTrialRequestBuilder setAcknowledge(boolean acknowledge) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java index 5383726adc318..56c1898ac793f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java @@ -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)); @@ -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 @@ -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)); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java index 0195b350b050c..3e61c3978bcbc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java @@ -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)); @@ -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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java index 02809ae974cd7..4c1102208c840 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java @@ -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; @@ -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)); @@ -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 @@ -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 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(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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java index 20366328e5031..2ee79da977357 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java @@ -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)); @@ -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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java index 79e8849669c8f..77f09383b407d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java @@ -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)); @@ -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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java index a263d0d82c26a..d2ce0776305da 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java @@ -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)); @@ -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(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(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java index 986dacb687738..698ec440a6cbe 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java @@ -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.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.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; -public class RestPutLicenseAction extends XPackRestHandler { +public class RestPutLicenseAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutLicenseAction.class)); @@ -30,11 +30,11 @@ public class RestPutLicenseAction extends XPackRestHandler { // TODO: remove deprecated endpoint in 8.0.0 controller.registerWithDeprecatedHandler( POST, "/_license", this, - POST, URI_BASE + "/license", deprecationLogger); + POST, "/_xpack/license", deprecationLogger); // TODO: remove deprecated endpoint in 8.0.0 controller.registerWithDeprecatedHandler( PUT, "/_license", this, - PUT, URI_BASE + "/license", deprecationLogger); + PUT, "/_xpack/license", deprecationLogger); } @Override @@ -43,7 +43,7 @@ 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 { if (request.hasContent() == false) { throw new IllegalArgumentException("The license must be provided in the request body"); } @@ -58,8 +58,7 @@ public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPa "/_license/start_basic API to install a basic license that does not expire."); } - return channel -> client.es().admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest, - new RestToXContentListener<>(channel)); + return channel -> client.execute(PutLicenseAction.INSTANCE, putLicenseRequest, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClient.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClient.java deleted file mode 100644 index acf97b63684ae..0000000000000 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClient.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.core; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.settings.SecureString; -import org.elasticsearch.license.LicensingClient; -import org.elasticsearch.protocol.xpack.XPackInfoRequest; -import org.elasticsearch.protocol.xpack.XPackInfoResponse; -import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeIndexAction; -import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeRequest; -import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeResponse; -import org.elasticsearch.xpack.core.action.XPackInfoAction; -import org.elasticsearch.xpack.core.action.XPackInfoRequestBuilder; -import org.elasticsearch.xpack.core.ccr.client.CcrClient; -import org.elasticsearch.xpack.core.indexlifecycle.client.ILMClient; -import org.elasticsearch.xpack.core.ml.client.MachineLearningClient; -import org.elasticsearch.xpack.core.monitoring.client.MonitoringClient; -import org.elasticsearch.xpack.core.watcher.client.WatcherClient; - -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ExecutionException; - -import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER; -import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; - -public class XPackClient { - - private final Client client; - - private final CcrClient ccrClient; - private final LicensingClient licensingClient; - private final MonitoringClient monitoringClient; - private final WatcherClient watcherClient; - private final MachineLearningClient machineLearning; - private final ILMClient ilmClient; - - public XPackClient(Client client) { - this.client = Objects.requireNonNull(client, "client"); - this.ccrClient = new CcrClient(client); - this.licensingClient = new LicensingClient(client); - this.monitoringClient = new MonitoringClient(client); - this.watcherClient = new WatcherClient(client); - this.machineLearning = new MachineLearningClient(client); - this.ilmClient = new ILMClient(client); - } - - public Client es() { - return client; - } - - public CcrClient ccr() { - return ccrClient; - } - - public LicensingClient licensing() { - return licensingClient; - } - - public MonitoringClient monitoring() { - return monitoringClient; - } - - public WatcherClient watcher() { - return watcherClient; - } - - public MachineLearningClient machineLearning() { - return machineLearning; - } - - public ILMClient ilmClient() { - return ilmClient; - } - - public XPackClient withHeaders(Map headers) { - return new XPackClient(client.filterWithHeader(headers)); - } - - /** - * Returns a client that will call xpack APIs on behalf of the given user. - * - * @param username The username of the user - * @param passwd The password of the user. This char array can be cleared after calling this method. - */ - public XPackClient withAuth(String username, char[] passwd) { - return withHeaders(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue(username, new SecureString(passwd)))); - } - - public XPackInfoRequestBuilder prepareInfo() { - return new XPackInfoRequestBuilder(client); - } - - public void info(XPackInfoRequest request, ActionListener listener) { - client.execute(XPackInfoAction.INSTANCE, request, listener); - } - - /** - * Freezes or unfreeze one or more indices - */ - public void freeze(FreezeRequest request, ActionListener listener) { - client.execute(FreezeIndexAction.INSTANCE, request, listener); - } - - /** - * Freeze or unfreeze one or more indices - */ - public FreezeResponse freeze(FreezeRequest request) - throws ExecutionException, InterruptedException { - PlainActionFuture future = new PlainActionFuture<>(); - freeze(request, future); - return future.get(); - } -} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/XPackRestHandler.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/XPackRestHandler.java deleted file mode 100644 index 5ac0969624bc8..0000000000000 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/XPackRestHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.core.rest; - -import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.xpack.core.XPackClient; - -import java.io.IOException; - -public abstract class XPackRestHandler extends BaseRestHandler { - - protected static String URI_BASE = "/_xpack"; - - public XPackRestHandler(Settings settings) { - super(settings); - } - - @Override - public final RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - return doPrepareRequest(request, new XPackClient(client)); - } - - protected abstract RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException; -} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestFreezeIndexAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestFreezeIndexAction.java index 9604cdd8b3183..580acbae0dc87 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestFreezeIndexAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestFreezeIndexAction.java @@ -7,16 +7,17 @@ import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.action.TransportFreezeIndexAction; -import org.elasticsearch.xpack.core.rest.XPackRestHandler; +import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeIndexAction; -public final class RestFreezeIndexAction extends XPackRestHandler { +public final class RestFreezeIndexAction extends BaseRestHandler { public RestFreezeIndexAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(RestRequest.Method.POST, "/{index}/_freeze", this); @@ -24,7 +25,7 @@ public RestFreezeIndexAction(Settings settings, RestController controller) { } @Override - protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) { + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { boolean freeze = request.path().endsWith("/_freeze"); TransportFreezeIndexAction.FreezeRequest freezeRequest = new TransportFreezeIndexAction.FreezeRequest(Strings.splitStringByCommaToArray(request.param("index"))); @@ -36,7 +37,7 @@ protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient freezeRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards)); } freezeRequest.setFreeze(freeze); - return channel -> client.freeze(freezeRequest, new RestToXContentListener<>(channel)); + return channel -> client.execute(FreezeIndexAction.INSTANCE, freezeRequest, new RestToXContentListener<>(channel)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java index c057c04cc637d..2a41be1cb0cb1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java @@ -5,13 +5,14 @@ */ package org.elasticsearch.xpack.core.rest.action; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.protocol.xpack.XPackInfoRequest; +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 org.elasticsearch.xpack.core.action.XPackInfoRequestBuilder; import java.io.IOException; import java.util.EnumSet; @@ -19,11 +20,11 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; -public class RestXPackInfoAction extends XPackRestHandler { +public class RestXPackInfoAction extends BaseRestHandler { public RestXPackInfoAction(Settings settings, RestController controller) { super(settings); - controller.registerHandler(HEAD, URI_BASE, this); - controller.registerHandler(GET, URI_BASE, this); + controller.registerHandler(HEAD, "/_xpack", this); + controller.registerHandler(GET, "/_xpack", this); } @Override @@ -32,7 +33,7 @@ public String getName() { } @Override - public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException { + public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { // we piggyback verbosity on "human" output boolean verbose = request.paramAsBoolean("human", true); @@ -40,7 +41,7 @@ public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient cli EnumSet categories = XPackInfoRequest.Category .toSet(request.paramAsStringArray("categories", new String[] { "_all" })); return channel -> - client.prepareInfo() + new XPackInfoRequestBuilder(client) .setVerbose(verbose) .setCategories(categories) .execute(new RestToXContentListener<>(channel)); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java index 0f09f17dbb066..44b04c3548f7b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java @@ -6,29 +6,29 @@ package org.elasticsearch.xpack.core.rest.action; import org.elasticsearch.action.support.master.MasterNodeRequest; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; 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.XPackFeatureSet; import org.elasticsearch.xpack.core.action.XPackUsageRequestBuilder; import org.elasticsearch.xpack.core.action.XPackUsageResponse; -import org.elasticsearch.xpack.core.rest.XPackRestHandler; import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.OK; -public class RestXPackUsageAction extends XPackRestHandler { +public class RestXPackUsageAction extends BaseRestHandler { public RestXPackUsageAction(Settings settings, RestController controller) { super(settings); - controller.registerHandler(GET, URI_BASE + "/usage", this); + controller.registerHandler(GET, "/_xpack/usage", this); } @Override @@ -37,11 +37,11 @@ public String getName() { } @Override - public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException { + public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { final TimeValue masterTimeout = request.paramAsTime("master_timeout", MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT); - return channel -> new XPackUsageRequestBuilder(client.es()) + return channel -> new XPackUsageRequestBuilder(client) .setMasterNodeTimeout(masterTimeout) - .execute(new RestBuilderListener(channel) { + .execute(new RestBuilderListener<>(channel) { @Override public RestResponse buildResponse(XPackUsageResponse response, XContentBuilder builder) throws Exception { builder.startObject(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java index d0a086bd649f0..1d57df3b54199 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; @@ -222,7 +221,7 @@ public void onFailure(Exception e) { creationCheck.set(false); onPutPolicyFailure(policy, e); } - }, (req, listener) -> new XPackClient(client).ilmClient().putLifecyclePolicy(req, listener)); + }, (req, listener) -> client.execute(PutLifecycleAction.INSTANCE, req, listener)); }); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java index 9231bad9a8dfe..39407ef735974 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.index.engine; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; @@ -23,6 +24,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -37,9 +39,9 @@ import org.elasticsearch.search.internal.AliasFilter; import org.elasticsearch.search.internal.ShardSearchLocalRequest; import org.elasticsearch.test.ESSingleNodeTestCase; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction; +import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeIndexAction; import org.hamcrest.Matchers; import java.io.IOException; @@ -69,8 +71,7 @@ public void testCloseFreezeAndOpen() throws ExecutionException, InterruptedExcep client().prepareIndex("index", "_doc", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); client().prepareIndex("index", "_doc", "2").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); client().prepareIndex("index", "_doc", "3").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("index"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("index")).actionGet()); expectThrows(ClusterBlockException.class, () -> client().prepareIndex("index", "_doc", "4").setSource("field", "value") .setRefreshPolicy(IMMEDIATE).get()); IndicesService indexServices = getInstanceFromNode(IndicesService.class); @@ -115,8 +116,7 @@ public void testSearchAndGetAPIsAreThrottled() throws InterruptedException, IOEx for (int i = 0; i < 10; i++) { client().prepareIndex("index", "_doc", "" + i).setSource("field", "foo bar baz").get(); } - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("index"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("index")).actionGet()); int numRequests = randomIntBetween(20, 50); CountDownLatch latch = new CountDownLatch(numRequests); ActionListener listener = ActionListener.wrap(latch::countDown); @@ -159,8 +159,7 @@ public void testFreezeAndUnfreeze() throws InterruptedException, ExecutionExcept // sometimes close it assertAcked(client().admin().indices().prepareClose("index").get()); } - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("index"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("index")).actionGet()); { IndicesService indexServices = getInstanceFromNode(IndicesService.class); Index index = resolveIndex("index"); @@ -169,7 +168,8 @@ public void testFreezeAndUnfreeze() throws InterruptedException, ExecutionExcept IndexShard shard = indexService.getShard(0); assertEquals(0, shard.refreshStats().getTotal()); } - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("index").setFreeze(false))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, + new TransportFreezeIndexAction.FreezeRequest("index").setFreeze(false)).actionGet()); { IndicesService indexServices = getInstanceFromNode(IndicesService.class); Index index = resolveIndex("index"); @@ -192,13 +192,12 @@ private void assertIndexFrozen(String idx) { public void testDoubleFreeze() throws ExecutionException, InterruptedException { createIndex("test-idx", Settings.builder().put("index.number_of_shards", 2).build()); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("test-idx"))); - ExecutionException executionException = expectThrows(ExecutionException.class, - () -> xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("test-idx") + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("test-idx")).actionGet()); + ResourceNotFoundException exception = expectThrows(ResourceNotFoundException.class, + () -> client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("test-idx") .indicesOptions(new IndicesOptions(EnumSet.noneOf(IndicesOptions.Option.class), - EnumSet.of(IndicesOptions.WildcardStates.OPEN))))); - assertEquals("no index found to freeze", executionException.getCause().getMessage()); + EnumSet.of(IndicesOptions.WildcardStates.OPEN)))).actionGet()); + assertEquals("no index found to freeze", exception.getMessage()); } public void testUnfreezeClosedIndices() throws ExecutionException, InterruptedException { @@ -206,11 +205,10 @@ public void testUnfreezeClosedIndices() throws ExecutionException, InterruptedEx client().prepareIndex("idx", "_doc", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); createIndex("idx-closed", Settings.builder().put("index.number_of_shards", 1).build()); client().prepareIndex("idx-closed", "_doc", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("idx"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("idx")).actionGet()); assertAcked(client().admin().indices().prepareClose("idx-closed").get()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("idx*").setFreeze(false) - .indicesOptions(IndicesOptions.strictExpand()))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("idx*").setFreeze(false) + .indicesOptions(IndicesOptions.strictExpand())).actionGet()); ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get(); assertEquals(IndexMetaData.State.CLOSE, stateResponse.getState().getMetaData().index("idx-closed").getState()); assertEquals(IndexMetaData.State.OPEN, stateResponse.getState().getMetaData().index("idx").getState()); @@ -222,8 +220,7 @@ public void testFreezePattern() throws ExecutionException, InterruptedException client().prepareIndex("test-idx", "_doc", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); createIndex("test-idx-1", Settings.builder().put("index.number_of_shards", 1).build()); client().prepareIndex("test-idx-1", "_doc", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("test-idx"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("test-idx")).actionGet()); assertIndexFrozen("test-idx"); IndicesStatsResponse index = client().admin().indices().prepareStats("test-idx").clear().setRefresh(true).get(); @@ -232,7 +229,7 @@ public void testFreezePattern() throws ExecutionException, InterruptedException index = client().admin().indices().prepareStats("test-idx").clear().setRefresh(true).get(); assertEquals(1, index.getTotal().refresh.getTotal()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("test*"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("test*")).actionGet()); assertIndexFrozen("test-idx"); assertIndexFrozen("test-idx-1"); index = client().admin().indices().prepareStats("test-idx").clear().setRefresh(true).get(); @@ -269,8 +266,7 @@ public void testCanMatch() throws ExecutionException, InterruptedException, IOEx new AliasFilter(null, Strings.EMPTY_ARRAY), 1f, -1, null, null))); } - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("index"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("index")).actionGet()); { IndicesService indexServices = getInstanceFromNode(IndicesService.class); @@ -301,8 +297,7 @@ public void testCanMatch() throws ExecutionException, InterruptedException, IOEx public void testWriteToFrozenIndex() throws ExecutionException, InterruptedException { createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); client().prepareIndex("idx", "_doc", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("idx"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("idx")).actionGet()); assertIndexFrozen("idx"); expectThrows(ClusterBlockException.class, () -> client().prepareIndex("idx", "_doc", "2").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get()); @@ -312,9 +307,8 @@ public void testIgnoreUnavailable() throws ExecutionException, InterruptedExcept createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); createIndex("idx-close", Settings.builder().put("index.number_of_shards", 1).build()); assertAcked(client().admin().indices().prepareClose("idx-close")); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("idx*", "not_available") - .indicesOptions(IndicesOptions.fromParameters(null, "true", null, null, IndicesOptions.strictExpandOpen())))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("idx*", "not_available") + .indicesOptions(IndicesOptions.fromParameters(null, "true", null, null, IndicesOptions.strictExpandOpen()))).actionGet()); assertIndexFrozen("idx"); assertEquals(IndexMetaData.State.CLOSE, client().admin().cluster().prepareState().get().getState().metaData().index("idx-close").getState()); @@ -322,17 +316,17 @@ public void testIgnoreUnavailable() throws ExecutionException, InterruptedExcept public void testUnfreezeClosedIndex() throws ExecutionException, InterruptedException { createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("idx"))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("idx")).actionGet()); assertAcked(client().admin().indices().prepareClose("idx")); assertEquals(IndexMetaData.State.CLOSE, client().admin().cluster().prepareState().get().getState().metaData().index("idx").getState()); - expectThrows(ExecutionException.class, - () -> xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("id*").setFreeze(false) + expectThrows(IndexNotFoundException.class, + () -> client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest("id*").setFreeze(false) .indicesOptions(new IndicesOptions(EnumSet.noneOf(IndicesOptions.Option.class), - EnumSet.of(IndicesOptions.WildcardStates.OPEN))))); + EnumSet.of(IndicesOptions.WildcardStates.OPEN)))).actionGet()); // we don't resolve to closed indices - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest("idx").setFreeze(false))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, + new TransportFreezeIndexAction.FreezeRequest("idx").setFreeze(false)).actionGet()); assertEquals(IndexMetaData.State.OPEN, client().admin().cluster().prepareState().get().getState().metaData().index("idx").getState()); } @@ -345,8 +339,7 @@ public void testFreezeIndexIncreasesIndexSettingsVersion() throws ExecutionExcep final long settingsVersion = client().admin().cluster().prepareState().get() .getState().metaData().index(index).getSettingsVersion(); - XPackClient xPackClient = new XPackClient(client()); - assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest(index))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest(index)).actionGet()); assertIndexFrozen(index); assertThat(client().admin().cluster().prepareState().get().getState().metaData().index(index).getSettingsVersion(), greaterThan(settingsVersion)); @@ -374,7 +367,7 @@ public void testFreezeEmptyIndexWithTranslogOps() throws Exception { assertThat(indexService.getShard(0).getGlobalCheckpoint(), greaterThanOrEqualTo(nbNoOps - 1L)); }); - assertAcked(new XPackClient(client()).freeze(new TransportFreezeIndexAction.FreezeRequest(indexName))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest(indexName)).actionGet()); assertIndexFrozen(indexName); } @@ -390,7 +383,7 @@ public void testRecoveryState() throws ExecutionException, InterruptedException assertThat(indexResponse.status(), is(RestStatus.CREATED)); } - assertAcked(new XPackClient(client()).freeze(new TransportFreezeIndexAction.FreezeRequest(indexName))); + assertAcked(client().execute(FreezeIndexAction.INSTANCE, new TransportFreezeIndexAction.FreezeRequest(indexName)).actionGet()); assertIndexFrozen(indexName); final IndexMetaData indexMetaData = client().admin().cluster().prepareState().get().getState().metaData().index(indexName); diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index 130d6deed567f..80d4d638a0a09 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.LogManager; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; @@ -19,11 +20,10 @@ import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest.TermBoost; import org.elasticsearch.protocol.xpack.graph.Hop; import org.elasticsearch.protocol.xpack.graph.VertexRequest; +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 java.util.HashMap; @@ -38,7 +38,7 @@ /** * @see GraphExploreRequest */ -public class RestGraphAction extends XPackRestHandler { +public class RestGraphAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGraphAction.class)); public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + @@ -68,19 +68,19 @@ public RestGraphAction(Settings settings, RestController controller) { // TODO: remove deprecated endpoint in 8.0.0 controller.registerWithDeprecatedHandler( GET, "/{index}/_graph/explore", this, - GET, "/{index}" + URI_BASE + "/graph/_explore", deprecationLogger); + GET, "/{index}/_xpack/graph/_explore", deprecationLogger); // TODO: remove deprecated endpoint in 8.0.0 controller.registerWithDeprecatedHandler( POST, "/{index}/_graph/explore", this, - POST, "/{index}" + URI_BASE + "/graph/_explore", deprecationLogger); + POST, "/{index}/_xpack/graph/_explore", deprecationLogger); // TODO: remove deprecated endpoint in 8.0.0 controller.registerWithDeprecatedHandler( GET, "/{index}/{type}/_graph/explore", this, - GET, "/{index}/{type}" + URI_BASE + "/graph/_explore", deprecationLogger); + GET, "/{index}/{type}/_xpack/graph/_explore", deprecationLogger); // TODO: remove deprecated endpoint in 8.0.0 controller.registerWithDeprecatedHandler( POST, "/{index}/{type}/_graph/explore", this, - POST, "/{index}/{type}" + URI_BASE + "/graph/_explore", deprecationLogger); + POST, "/{index}/{type}/_xpack/graph/_explore", deprecationLogger); } @Override @@ -89,7 +89,7 @@ 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 { GraphExploreRequest graphRequest = new GraphExploreRequest(Strings.splitStringByCommaToArray(request.param("index"))); graphRequest.indicesOptions(IndicesOptions.fromRequest(request, graphRequest.indicesOptions())); graphRequest.routing(request.param("routing")); @@ -117,7 +117,7 @@ public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPa deprecationLogger.deprecatedAndMaybeLog("graph_with_types", TYPES_DEPRECATION_MESSAGE); graphRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); } - return channel -> client.es().execute(INSTANCE, graphRequest, new RestToXContentListener<>(channel)); + return channel -> client.execute(INSTANCE, graphRequest, new RestToXContentListener<>(channel)); } private void parseHop(XContentParser parser, Hop currentHop, GraphExploreRequest graphRequest) throws IOException { diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java index 6aab3114b7807..8f8072ef5b864 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java @@ -14,10 +14,8 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction; -import org.elasticsearch.xpack.core.ccr.client.CcrClient; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.collector.Collector; @@ -37,25 +35,25 @@ public final class StatsCollector extends Collector { private final Settings settings; private final ThreadContext threadContext; - private final CcrClient ccrClient; + private final Client client; public StatsCollector( final Settings settings, final ClusterService clusterService, final XPackLicenseState licenseState, final Client client) { - this(settings, clusterService, licenseState, new XPackClient(client).ccr(), client.threadPool().getThreadContext()); + this(settings, clusterService, licenseState, client, client.threadPool().getThreadContext()); } StatsCollector( final Settings settings, final ClusterService clusterService, final XPackLicenseState licenseState, - final CcrClient ccrClient, + final Client client, final ThreadContext threadContext) { super(TYPE, clusterService, CCR_STATS_TIMEOUT, licenseState); this.settings = settings; - this.ccrClient = ccrClient; + this.client = client; this.threadContext = threadContext; } @@ -79,7 +77,7 @@ protected Collection doCollect( final String clusterUuid = clusterUuid(clusterState); final CcrStatsAction.Request request = new CcrStatsAction.Request(); - final CcrStatsAction.Response response = ccrClient.stats(request).actionGet(getCollectionTimeout()); + final CcrStatsAction.Response response = client.execute(CcrStatsAction.INSTANCE, request).actionGet(getCollectionTimeout()); final AutoFollowStatsMonitoringDoc autoFollowStatsDoc = new AutoFollowStatsMonitoringDoc(clusterUuid, timestamp, interval, node, response.getAutoFollowStats()); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java index 855780d4836ae..be34af2850ec6 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java @@ -14,10 +14,8 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction; -import org.elasticsearch.xpack.core.ml.client.MachineLearningClient; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.collector.Collector; @@ -43,15 +41,15 @@ public class JobStatsCollector extends Collector { private final Settings settings; private final ThreadContext threadContext; - private final MachineLearningClient client; + private final Client client; public JobStatsCollector(final Settings settings, final ClusterService clusterService, final XPackLicenseState licenseState, final Client client) { - this(settings, clusterService, licenseState, new XPackClient(client).machineLearning(), client.threadPool().getThreadContext()); + this(settings, clusterService, licenseState, client, client.threadPool().getThreadContext()); } JobStatsCollector(final Settings settings, final ClusterService clusterService, - final XPackLicenseState licenseState, final MachineLearningClient client, final ThreadContext threadContext) { + final XPackLicenseState licenseState, final Client client, final ThreadContext threadContext) { super(JobStatsMonitoringDoc.TYPE, clusterService, JOB_STATS_TIMEOUT, licenseState); this.settings = settings; this.client = client; @@ -74,7 +72,7 @@ protected List doCollect(final MonitoringDoc.Node node, // fetch details about all jobs try (ThreadContext.StoredContext ignore = threadContext.stashWithOrigin(MONITORING_ORIGIN)) { final GetJobsStatsAction.Response jobs = - client.getJobsStats(new GetJobsStatsAction.Request(MetaData.ALL)) + client.execute(GetJobsStatsAction.INSTANCE, new GetJobsStatsAction.Request(MetaData.ALL)) .actionGet(getCollectionTimeout()); final long timestamp = timestamp(); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java index 12f2f77a9d40c..8661c77345591 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java @@ -40,7 +40,6 @@ import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; @@ -431,8 +430,7 @@ private boolean hasValidVersion(final Object version, final long minimumVersion) */ private void getClusterAlertsInstallationAsyncActions(final boolean indexExists, final List asyncActions, final AtomicInteger pendingResponses) { - final XPackClient xpackClient = new XPackClient(client); - final WatcherClient watcher = xpackClient.watcher(); + final WatcherClient watcher = new WatcherClient(client); final boolean canAddWatches = licenseState.isMonitoringClusterAlertsAllowed(); for (final String watchId : ClusterAlertsUtil.WATCH_IDS) { diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java index 0a1576393ba26..04faf82d8c1d1 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java @@ -8,21 +8,22 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.RestChannel; 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.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.action.MonitoringBulkRequestBuilder; import org.elasticsearch.xpack.core.monitoring.action.MonitoringBulkResponse; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; -import org.elasticsearch.xpack.core.rest.XPackRestHandler; import java.io.IOException; import java.util.Arrays; @@ -34,7 +35,7 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; -public class RestMonitoringBulkAction extends XPackRestHandler { +public class RestMonitoringBulkAction extends BaseRestHandler { public static final String MONITORING_ID = "system_id"; public static final String MONITORING_VERSION = "system_api_version"; @@ -68,7 +69,7 @@ public String getName() { } @Override - public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException { + public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { final String id = request.param(MONITORING_ID); if (Strings.isEmpty(id)) { @@ -98,27 +99,9 @@ public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient cli final long timestamp = System.currentTimeMillis(); final long intervalMillis = parseTimeValue(intervalAsString, INTERVAL).getMillis(); - final MonitoringBulkRequestBuilder requestBuilder = client.monitoring().prepareMonitoringBulk(); + final MonitoringBulkRequestBuilder requestBuilder = new MonitoringBulkRequestBuilder(client); requestBuilder.add(system, request.content(), request.getXContentType(), timestamp, intervalMillis); - return channel -> requestBuilder.execute(new RestBuilderListener(channel) { - @Override - public RestResponse buildResponse(MonitoringBulkResponse response, XContentBuilder builder) throws Exception { - builder.startObject(); - { - builder.field("took", response.getTookInMillis()); - builder.field("ignored", response.isIgnored()); - - final MonitoringBulkResponse.Error error = response.getError(); - builder.field("errors", error != null); - - if (error != null) { - builder.field("error", response.getError()); - } - } - builder.endObject(); - return new BytesRestResponse(response.status(), builder); - } - }); + return channel -> requestBuilder.execute(getRestBuilderListener(channel)); } @Override @@ -138,4 +121,26 @@ private boolean isSupportedSystemVersion(final MonitoredSystem system, final Str final List monitoredSystem = supportedApiVersions.getOrDefault(system, emptyList()); return monitoredSystem.contains(version); } + + static RestBuilderListener getRestBuilderListener(RestChannel channel) { + return new RestBuilderListener<>(channel) { + @Override + public RestResponse buildResponse(MonitoringBulkResponse response, XContentBuilder builder) throws Exception { + builder.startObject(); + { + builder.field("took", response.getTookInMillis()); + builder.field("ignored", response.isIgnored()); + + final MonitoringBulkResponse.Error error = response.getError(); + builder.field("errors", error != null); + + if (error != null) { + builder.field("error", response.getError()); + } + } + builder.endObject(); + return new BytesRestResponse(response.status(), builder); + } + }; + } } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java index 0713e26f80667..61b485e77ae27 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java @@ -6,16 +6,17 @@ package org.elasticsearch.xpack.monitoring.collector.ml; import org.elasticsearch.action.ActionFuture; +import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.xpack.core.XPackSettings; +import org.elasticsearch.xpack.core.action.util.QueryPage; +import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction.Request; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction.Response; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction.Response.JobStats; -import org.elasticsearch.xpack.core.action.util.QueryPage; -import org.elasticsearch.xpack.core.ml.client.MachineLearningClient; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; @@ -128,7 +129,7 @@ public void testDoCollect() throws Exception { whenClusterStateWithUUID(clusterUuid); final MonitoringDoc.Node node = randomMonitoringNode(random()); - final MachineLearningClient client = mock(MachineLearningClient.class); + final Client client = mock(Client.class); final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(1, 120)); @@ -143,7 +144,7 @@ public void testDoCollect() throws Exception { final ActionFuture future = (ActionFuture)mock(ActionFuture.class); final Response response = new Response(new QueryPage<>(jobStats, jobStats.size(), Job.RESULTS_FIELD)); - when(client.getJobsStats(eq(new Request(MetaData.ALL)))).thenReturn(future); + when(client.execute(eq(GetJobsStatsAction.INSTANCE), eq(new Request(MetaData.ALL)))).thenReturn(future); when(future.actionGet(timeout)).thenReturn(response); final long interval = randomNonNegativeLong(); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java index 7a4427c9f0fdc..fb79751f797e6 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java @@ -6,8 +6,7 @@ package org.elasticsearch.xpack.monitoring.rest.action; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.client.Client; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -25,22 +24,16 @@ import org.elasticsearch.rest.action.RestBuilderListener; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; -import org.elasticsearch.xpack.core.monitoring.action.MonitoringBulkRequestBuilder; import org.elasticsearch.xpack.core.monitoring.action.MonitoringBulkResponse; -import org.elasticsearch.xpack.core.monitoring.client.MonitoringClient; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils.TEMPLATE_VERSION; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -115,8 +108,7 @@ public void testUnknownSystemVersion() { public void testNoErrors() throws Exception { final MonitoringBulkResponse response = new MonitoringBulkResponse(randomLong(), false); - final FakeRestRequest request = createRestRequest(randomSystemId(), TEMPLATE_VERSION, "10s"); - final RestResponse restResponse = getRestBuilderListener(request).buildResponse(response); + final RestResponse restResponse = getRestBuilderListener().buildResponse(response); assertThat(restResponse.status(), is(RestStatus.OK)); assertThat(restResponse.content().utf8ToString(), @@ -125,8 +117,7 @@ public void testNoErrors() throws Exception { public void testNoErrorsButIgnored() throws Exception { final MonitoringBulkResponse response = new MonitoringBulkResponse(randomLong(), true); - final FakeRestRequest request = createRestRequest(randomSystemId(), TEMPLATE_VERSION, "10s"); - final RestResponse restResponse = getRestBuilderListener(request).buildResponse(response); + final RestResponse restResponse = getRestBuilderListener().buildResponse(response); assertThat(restResponse.status(), is(RestStatus.OK)); assertThat(restResponse.content().utf8ToString(), @@ -139,8 +130,7 @@ public void testWithErrors() throws Exception { final MonitoringBulkResponse response = new MonitoringBulkResponse(randomLong(), error); final String errorJson; - final FakeRestRequest request = createRestRequest(randomSystemId(), TEMPLATE_VERSION, "10s"); - final RestResponse restResponse = getRestBuilderListener(request).buildResponse(response); + final RestResponse restResponse = getRestBuilderListener().buildResponse(response); try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) { error.toXContent(builder, ToXContent.EMPTY_PARAMS); @@ -167,35 +157,18 @@ private static String randomSystemId() { } private void prepareRequest(final RestRequest restRequest) throws Exception { - getRestBuilderListener(restRequest); - } - - private RestBuilderListener getRestBuilderListener(final RestRequest restRequest) throws Exception { - final Client client = mock(Client.class); - final XPackClient xpackClient = mock(XPackClient.class); - final MonitoringClient monitoringClient = mock(MonitoringClient.class); - final AtomicReference> listenerReference = new AtomicReference<>(); - final MonitoringBulkRequestBuilder builder = new MonitoringBulkRequestBuilder(client){ - @SuppressWarnings("unchecked") - @Override - public void execute(ActionListener listener) { - listenerReference.set((RestBuilderListener)listener); - } - }; - when(monitoringClient.prepareMonitoringBulk()).thenReturn(builder); - when(xpackClient.monitoring()).thenReturn(monitoringClient); - - final CheckedConsumer consumer = action.doPrepareRequest(restRequest, xpackClient); - + final NodeClient client = mock(NodeClient.class); + final CheckedConsumer consumer = action.prepareRequest(restRequest, client); final RestChannel channel = mock(RestChannel.class); when(channel.newBuilder()).thenReturn(JsonXContent.contentBuilder()); - - // trigger/capture execution + // trigger execution consumer.accept(channel); + } - assertThat(listenerReference.get(), not(nullValue())); - - return listenerReference.get(); + private RestBuilderListener getRestBuilderListener() throws Exception { + final RestChannel channel = mock(RestChannel.class); + when(channel.newBuilder()).thenReturn(JsonXContent.contentBuilder()); + return RestMonitoringBulkAction.getRestBuilderListener(channel); } private static FakeRestRequest createRestRequest(final String systemId, final String systemApiVersion, final String interval) { diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java index c350b9a374ab2..c3921b7e7199b 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java @@ -19,7 +19,6 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.store.MockFSIndexStore; import org.elasticsearch.test.transport.MockTransportService; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.monitoring.client.MonitoringClient; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; import org.elasticsearch.xpack.core.monitoring.test.MockPainlessScriptEngine; @@ -76,7 +75,7 @@ protected Collection> nodePlugins() { } protected MonitoringClient monitoringClient() { - return randomBoolean() ? new XPackClient(client()).monitoring() : new MonitoringClient(client()); + return new MonitoringClient(client()); } @Override diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 5b11b444db3ca..5199aa6bf22f2 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -41,7 +41,6 @@ import org.elasticsearch.test.disruption.ServiceDisruptionScheme; import org.elasticsearch.test.store.MockFSIndexStore; import org.elasticsearch.test.transport.MockTransportService; -import org.elasticsearch.xpack.core.XPackClient; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.watcher.WatcherState; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; @@ -328,7 +327,7 @@ protected WatchParser watchParser() { } protected WatcherClient watcherClient() { - return randomBoolean() ? new XPackClient(client()).watcher() : new WatcherClient(client()); + return new WatcherClient(client()); } private IndexNameExpressionResolver indexNameExpressionResolver() {