Skip to content

Commit 9dcf3f5

Browse files
authored
HLRC: Move commercial clients from XPackClient (#32596)
The commercial clients were improperly placed into XPackClient, which is a wrapper for the miscellaneous usage and info APIs. This commit moves them into the HLRC.
1 parent 0a83968 commit 9dcf3f5

File tree

6 files changed

+40
-35
lines changed

6 files changed

+40
-35
lines changed

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

+28-6
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ public class RestHighLevelClient implements Closeable {
205205
private final SnapshotClient snapshotClient = new SnapshotClient(this);
206206
private final TasksClient tasksClient = new TasksClient(this);
207207
private final XPackClient xPackClient = new XPackClient(this);
208+
private final WatcherClient watcherClient = new WatcherClient(this);
209+
private final LicenseClient licenseClient = new LicenseClient(this);
208210

209211
/**
210212
* Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the
@@ -296,18 +298,38 @@ public final TasksClient tasks() {
296298
}
297299

298300
/**
299-
* A wrapper for the {@link RestHighLevelClient} that provides methods for
300-
* accessing the Elastic Licensed X-Pack APIs that are shipped with the
301-
* default distribution of Elasticsearch. All of these APIs will 404 if run
302-
* against the OSS distribution of Elasticsearch.
301+
* Provides methods for accessing the Elastic Licensed X-Pack Info
302+
* and Usage APIs that are shipped with the default distribution of
303+
* Elasticsearch. All of these APIs will 404 if run against the OSS
304+
* distribution of Elasticsearch.
303305
* <p>
304-
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/xpack-api.html">
305-
* X-Pack APIs on elastic.co</a> for more information.
306+
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html">
307+
* Info APIs on elastic.co</a> for more information.
306308
*/
307309
public final XPackClient xpack() {
308310
return xPackClient;
309311
}
310312

313+
/**
314+
* Provides methods for accessing the Elastic Licensed Watcher APIs that
315+
* are shipped with the default distribution of Elasticsearch. All of
316+
* these APIs will 404 if run against the OSS distribution of Elasticsearch.
317+
* <p>
318+
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api.html">
319+
* Watcher APIs on elastic.co</a> for more information.
320+
*/
321+
public WatcherClient watcher() { return watcherClient; }
322+
323+
/**
324+
* Provides methods for accessing the Elastic Licensed Licensing APIs that
325+
* are shipped with the default distribution of Elasticsearch. All of
326+
* these APIs will 404 if run against the OSS distribution of Elasticsearch.
327+
* <p>
328+
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/licensing-apis.html">
329+
* Licensing APIs on elastic.co</a> for more information.
330+
*/
331+
public LicenseClient license() { return licenseClient; }
332+
311333
/**
312334
* Executes a bulk request using the Bulk API.
313335
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html">Bulk API on elastic.co</a>

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

-19
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,9 @@
4141
public final class XPackClient {
4242

4343
private final RestHighLevelClient restHighLevelClient;
44-
private final WatcherClient watcherClient;
45-
private final LicenseClient licenseClient;
4644

4745
XPackClient(RestHighLevelClient restHighLevelClient) {
4846
this.restHighLevelClient = restHighLevelClient;
49-
this.watcherClient = new WatcherClient(restHighLevelClient);
50-
this.licenseClient = new LicenseClient(restHighLevelClient);
51-
}
52-
53-
public WatcherClient watcher() {
54-
return watcherClient;
5547
}
5648

5749
/**
@@ -102,15 +94,4 @@ public void usageAsync(XPackUsageRequest request, RequestOptions options, Action
10294
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::xpackUsage, options,
10395
XPackUsageResponse::fromXContent, listener, emptySet());
10496
}
105-
106-
/**
107-
* A wrapper for the {@link RestHighLevelClient} that provides methods for
108-
* accessing the Elastic Licensing APIs.
109-
* <p>
110-
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/licensing-apis.html">
111-
* X-Pack APIs on elastic.co</a> for more information.
112-
*/
113-
public LicenseClient license() {
114-
return licenseClient;
115-
}
11697
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,9 @@ public void testApiNamingConventions() throws Exception {
755755
method.isAnnotationPresent(Deprecated.class));
756756
} else {
757757
//TODO xpack api are currently ignored, we need to load xpack yaml spec too
758-
if (apiName.startsWith("xpack.") == false) {
758+
if (apiName.startsWith("xpack.") == false &&
759+
apiName.startsWith("license.") == false &&
760+
apiName.startsWith("watcher.") == false) {
759761
apiNotFound.add(apiName);
760762
}
761763
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ private PutWatchResponse createWatch(String watchId) throws Exception {
4646
"}";
4747
BytesReference bytesReference = new BytesArray(json);
4848
PutWatchRequest putWatchRequest = new PutWatchRequest(watchId, bytesReference, XContentType.JSON);
49-
return highLevelClient().xpack().watcher().putWatch(putWatchRequest, RequestOptions.DEFAULT);
49+
return highLevelClient().watcher().putWatch(putWatchRequest, RequestOptions.DEFAULT);
5050
}
5151

5252
public void testDeleteWatch() throws Exception {
5353
// delete watch that exists
5454
{
5555
String watchId = randomAlphaOfLength(10);
5656
createWatch(watchId);
57-
DeleteWatchResponse deleteWatchResponse = highLevelClient().xpack().watcher().deleteWatch(new DeleteWatchRequest(watchId),
57+
DeleteWatchResponse deleteWatchResponse = highLevelClient().watcher().deleteWatch(new DeleteWatchRequest(watchId),
5858
RequestOptions.DEFAULT);
5959
assertThat(deleteWatchResponse.getId(), is(watchId));
6060
assertThat(deleteWatchResponse.getVersion(), is(2L));
@@ -64,7 +64,7 @@ public void testDeleteWatch() throws Exception {
6464
// delete watch that does not exist
6565
{
6666
String watchId = randomAlphaOfLength(10);
67-
DeleteWatchResponse deleteWatchResponse = highLevelClient().xpack().watcher().deleteWatch(new DeleteWatchRequest(watchId),
67+
DeleteWatchResponse deleteWatchResponse = highLevelClient().watcher().deleteWatch(new DeleteWatchRequest(watchId),
6868
RequestOptions.DEFAULT);
6969
assertThat(deleteWatchResponse.getId(), is(watchId));
7070
assertThat(deleteWatchResponse.getVersion(), is(1L));

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void testPutLicense() throws Exception {
6262
request.setLicenseDefinition(license); // <1>
6363
request.setAcknowledge(false); // <2>
6464

65-
PutLicenseResponse response = client.xpack().license().putLicense(request, RequestOptions.DEFAULT);
65+
PutLicenseResponse response = client.license().putLicense(request, RequestOptions.DEFAULT);
6666
//end::put-license-execute
6767

6868
//tag::put-license-response
@@ -98,7 +98,7 @@ public void onFailure(Exception e) {
9898
listener = new LatchedActionListener<>(listener, latch);
9999

100100
// tag::put-license-execute-async
101-
client.xpack().license().putLicenseAsync(
101+
client.license().putLicenseAsync(
102102
request, RequestOptions.DEFAULT, listener); // <1>
103103
// end::put-license-execute-async
104104

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void testWatcher() throws Exception {
4949
"}");
5050
PutWatchRequest request = new PutWatchRequest("my_watch_id", watch, XContentType.JSON);
5151
request.setActive(false); // <1>
52-
PutWatchResponse response = client.xpack().watcher().putWatch(request, RequestOptions.DEFAULT);
52+
PutWatchResponse response = client.watcher().putWatch(request, RequestOptions.DEFAULT);
5353
//end::x-pack-put-watch-execute
5454

5555
//tag::x-pack-put-watch-response
@@ -85,7 +85,7 @@ public void onFailure(Exception e) {
8585
listener = new LatchedActionListener<>(listener, latch);
8686

8787
// tag::x-pack-put-watch-execute-async
88-
client.xpack().watcher().putWatchAsync(request, RequestOptions.DEFAULT, listener); // <1>
88+
client.watcher().putWatchAsync(request, RequestOptions.DEFAULT, listener); // <1>
8989
// end::x-pack-put-watch-execute-async
9090

9191
assertTrue(latch.await(30L, TimeUnit.SECONDS));
@@ -94,7 +94,7 @@ public void onFailure(Exception e) {
9494
{
9595
//tag::x-pack-delete-watch-execute
9696
DeleteWatchRequest request = new DeleteWatchRequest("my_watch_id");
97-
DeleteWatchResponse response = client.xpack().watcher().deleteWatch(request, RequestOptions.DEFAULT);
97+
DeleteWatchResponse response = client.watcher().deleteWatch(request, RequestOptions.DEFAULT);
9898
//end::x-pack-delete-watch-execute
9999

100100
//tag::x-pack-delete-watch-response
@@ -125,7 +125,7 @@ public void onFailure(Exception e) {
125125
listener = new LatchedActionListener<>(listener, latch);
126126

127127
// tag::x-pack-delete-watch-execute-async
128-
client.xpack().watcher().deleteWatchAsync(request, RequestOptions.DEFAULT, listener); // <1>
128+
client.watcher().deleteWatchAsync(request, RequestOptions.DEFAULT, listener); // <1>
129129
// end::x-pack-delete-watch-execute-async
130130

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

0 commit comments

Comments
 (0)