Skip to content

Commit dcbb115

Browse files
authored
HLRest: Move xPackInfo() to xPack().info() (#31905)
Originally I put the X-Pack info object into the top level rest client object. I did that because we thought we'd like to squash `xpack` from the name of the X-Pack APIs now that it is part of the default distribution. We still kind of want to do that, but at least for now we feel like it is better to keep the high level rest client aligned with the other language clients like C# and Python. This shifts the X-Pack info API to align with its json spec file. Relates to #31870
1 parent e85bb73 commit dcbb115

File tree

15 files changed

+103
-46
lines changed

15 files changed

+103
-46
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@
6666
import org.elasticsearch.index.rankeval.RankEvalRequest;
6767
import org.elasticsearch.index.rankeval.RankEvalResponse;
6868
import org.elasticsearch.plugins.spi.NamedXContentProvider;
69-
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
70-
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
7169
import org.elasticsearch.rest.BytesRestResponse;
7270
import org.elasticsearch.rest.RestStatus;
7371
import org.elasticsearch.script.mustache.MultiSearchTemplateRequest;
@@ -204,6 +202,7 @@ public class RestHighLevelClient implements Closeable {
204202
private final IngestClient ingestClient = new IngestClient(this);
205203
private final SnapshotClient snapshotClient = new SnapshotClient(this);
206204
private final TasksClient tasksClient = new TasksClient(this);
205+
private final XPackClient xPackClient = new XPackClient(this);
207206

208207
/**
209208
* Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the
@@ -294,6 +293,19 @@ public final TasksClient tasks() {
294293
return tasksClient;
295294
}
296295

296+
/**
297+
* A wrapper for the {@link RestHighLevelClient} that provides methods for
298+
* accessing the Elastic Licensed X-Pack APIs that are shipped with the
299+
* default distribution of Elasticsearch. All of these APIs will 404 if run
300+
* against the OSS distribution of Elasticsearch.
301+
* <p>
302+
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/xpack-api.html">
303+
* X-Pack APIs on elastic.co</a> for more information.
304+
*/
305+
public final XPackClient xpack() {
306+
return xPackClient;
307+
}
308+
297309
/**
298310
* Executes a bulk request using the Bulk API.
299311
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html">Bulk API on elastic.co</a>
@@ -794,34 +806,6 @@ public final void fieldCapsAsync(FieldCapabilitiesRequest fieldCapabilitiesReque
794806
FieldCapabilitiesResponse::fromXContent, listener, emptySet());
795807
}
796808

797-
/**
798-
* Fetch information about X-Pack from the cluster if it is installed.
799-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html">
800-
* the docs</a> for more.
801-
* @param request the request
802-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
803-
* @return the response
804-
* @throws IOException in case there is a problem sending the request or parsing back the response
805-
*/
806-
public XPackInfoResponse xPackInfo(XPackInfoRequest request, RequestOptions options) throws IOException {
807-
return performRequestAndParseEntity(request, RequestConverters::xPackInfo, options,
808-
XPackInfoResponse::fromXContent, emptySet());
809-
}
810-
811-
/**
812-
* Fetch information about X-Pack from the cluster if it is installed.
813-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html">
814-
* the docs</a> for more.
815-
* @param request the request
816-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
817-
* @param listener the listener to be notified upon request completion
818-
*/
819-
public void xPackInfoAsync(XPackInfoRequest request, RequestOptions options,
820-
ActionListener<XPackInfoResponse> listener) {
821-
performRequestAsyncAndParseEntity(request, RequestConverters::xPackInfo, options,
822-
XPackInfoResponse::fromXContent, listener, emptySet());
823-
}
824-
825809
protected final <Req extends ActionRequest, Resp> Resp performRequestAndParseEntity(Req request,
826810
CheckedFunction<Req, Request, IOException> requestConverter,
827811
RequestOptions options,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client;
21+
22+
import org.elasticsearch.action.ActionListener;
23+
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
24+
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
25+
26+
import java.io.IOException;
27+
28+
import static java.util.Collections.emptySet;
29+
30+
/**
31+
* A wrapper for the {@link RestHighLevelClient} that provides methods for
32+
* accessing the Elastic Licensed X-Pack APIs that are shipped with the
33+
* default distribution of Elasticsearch. All of these APIs will 404 if run
34+
* against the OSS distribution of Elasticsearch.
35+
* <p>
36+
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/xpack-api.html">
37+
* X-Pack APIs on elastic.co</a> for more information.
38+
*/
39+
public final class XPackClient {
40+
private final RestHighLevelClient restHighLevelClient;
41+
42+
XPackClient(RestHighLevelClient restHighLevelClient) {
43+
this.restHighLevelClient = restHighLevelClient;
44+
}
45+
46+
/**
47+
* Fetch information about X-Pack from the cluster.
48+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html">
49+
* the docs</a> for more.
50+
* @param request the request
51+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
52+
* @return the response
53+
* @throws IOException in case there is a problem sending the request or parsing back the response
54+
*/
55+
public XPackInfoResponse info(XPackInfoRequest request, RequestOptions options) throws IOException {
56+
return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::xPackInfo, options,
57+
XPackInfoResponse::fromXContent, emptySet());
58+
}
59+
60+
/**
61+
* Asynchronously fetch information about X-Pack from the cluster.
62+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html">
63+
* the docs</a> for more.
64+
* @param request the request
65+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
66+
* @param listener the listener to be notified upon request completion
67+
*/
68+
public void infoAsync(XPackInfoRequest request, RequestOptions options,
69+
ActionListener<XPackInfoResponse> listener) {
70+
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::xPackInfo, options,
71+
XPackInfoResponse::fromXContent, listener, emptySet());
72+
}
73+
}

client/rest-high-level/src/test/java/org/elasticsearch/client/PingAndInfoIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
import org.apache.http.client.methods.HttpGet;
2323
import org.elasticsearch.action.main.MainResponse;
24-
import org.elasticsearch.protocol.license.LicenseStatus;
2524
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
2625
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
2726
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo.FeatureSet;
27+
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
2828

2929
import java.io.IOException;
3030
import java.util.EnumSet;
@@ -60,7 +60,7 @@ public void testXPackInfo() throws IOException {
6060
XPackInfoRequest request = new XPackInfoRequest();
6161
request.setCategories(EnumSet.allOf(XPackInfoRequest.Category.class));
6262
request.setVerbose(true);
63-
XPackInfoResponse info = highLevelClient().xPackInfo(request, RequestOptions.DEFAULT);
63+
XPackInfoResponse info = highLevelClient().xpack().info(request, RequestOptions.DEFAULT);
6464

6565
MainResponse mainResponse = highLevelClient().info(RequestOptions.DEFAULT);
6666

@@ -89,7 +89,7 @@ public void testXPackInfo() throws IOException {
8989
}
9090

9191
public void testXPackInfoEmptyRequest() throws IOException {
92-
XPackInfoResponse info = highLevelClient().xPackInfo(new XPackInfoRequest(), RequestOptions.DEFAULT);
92+
XPackInfoResponse info = highLevelClient().xpack().info(new XPackInfoRequest(), RequestOptions.DEFAULT);
9393

9494
/*
9595
* The default in the transport client is non-verbose and returning

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MiscellaneousDocumentationIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void testXPackInfo() throws Exception {
8686
XPackInfoRequest.Category.BUILD,
8787
XPackInfoRequest.Category.LICENSE,
8888
XPackInfoRequest.Category.FEATURES));
89-
XPackInfoResponse response = client.xPackInfo(request, RequestOptions.DEFAULT);
89+
XPackInfoResponse response = client.xpack().info(request, RequestOptions.DEFAULT);
9090
//end::x-pack-info-execute
9191

9292
//tag::x-pack-info-response
@@ -122,7 +122,7 @@ public void onFailure(Exception e) {
122122
listener = new LatchedActionListener<>(listener, latch);
123123

124124
// tag::x-pack-info-execute-async
125-
client.xPackInfoAsync(request, RequestOptions.DEFAULT, listener); // <1>
125+
client.xpack().infoAsync(request, RequestOptions.DEFAULT, listener); // <1>
126126
// end::x-pack-info-execute-async
127127

128128
assertTrue(latch.await(30L, TimeUnit.SECONDS));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.elasticsearch.common.xcontent.XContentFactory;
3030
import org.elasticsearch.common.xcontent.XContentParser;
3131
import org.elasticsearch.common.xcontent.XContentType;
32-
import org.elasticsearch.protocol.license.LicenseStatus;
32+
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
3333

3434
/**
3535
* Data structure for license. Use {@link Builder} to build a license.

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/action/TransportXPackInfoActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import org.elasticsearch.common.settings.Settings;
1111
import org.elasticsearch.license.License;
1212
import org.elasticsearch.license.LicenseService;
13-
import org.elasticsearch.protocol.license.LicenseStatus;
1413
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
1514
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
1615
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo.FeatureSet;
16+
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
1717
import org.elasticsearch.tasks.Task;
1818
import org.elasticsearch.test.ESTestCase;
1919
import org.elasticsearch.transport.Transport;

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/MlRemoteLicenseChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import org.elasticsearch.common.Strings;
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
1515
import org.elasticsearch.license.License;
16-
import org.elasticsearch.protocol.license.LicenseStatus;
1716
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
1817
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
18+
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
1919
import org.elasticsearch.transport.ActionNotFoundTransportException;
2020
import org.elasticsearch.transport.RemoteClusterAware;
2121
import org.elasticsearch.xpack.core.action.XPackInfoAction;

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/MlRemoteLicenseCheckerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import org.elasticsearch.common.Strings;
1212
import org.elasticsearch.common.settings.Settings;
1313
import org.elasticsearch.common.util.concurrent.ThreadContext;
14-
import org.elasticsearch.protocol.license.LicenseStatus;
1514
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
15+
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
1616
import org.elasticsearch.test.ESTestCase;
1717
import org.elasticsearch.threadpool.ThreadPool;
1818
import org.elasticsearch.xpack.core.action.XPackInfoAction;

x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/XPackInfoResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.elasticsearch.common.xcontent.ToXContentObject;
3232
import org.elasticsearch.common.xcontent.XContentBuilder;
3333
import org.elasticsearch.common.xcontent.XContentParser;
34-
import org.elasticsearch.protocol.license.LicenseStatus;
34+
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
3535

3636
import java.io.IOException;
3737
import java.util.ArrayList;

x-pack/protocol/src/main/java/org/elasticsearch/protocol/license/LicenseStatus.java renamed to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/license/LicenseStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.protocol.license;
19+
package org.elasticsearch.protocol.xpack.license;
2020

2121
import java.io.IOException;
2222

0 commit comments

Comments
 (0)