Skip to content

Commit d329caf

Browse files
committed
Docs: Cut down on high level rest client copy-and-paste-ness (#34125)
* Anchors * includes * get settings * more * More
1 parent c8ad76b commit d329caf

File tree

9 files changed

+221
-287
lines changed

9 files changed

+221
-287
lines changed

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,8 @@
5555
import static org.hamcrest.Matchers.notNullValue;
5656

5757
/**
58-
* This class is used to generate the Java Cluster API documentation.
59-
* You need to wrap your code between two tags like:
60-
* // tag::example
61-
* // end::example
62-
*
63-
* Where example is your tag name.
64-
*
65-
* Then in the documentation, you can extract what is between tag and end tags with
66-
* ["source","java",subs="attributes,callouts,macros"]
67-
* --------------------------------------------------
68-
* include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[example]
69-
* --------------------------------------------------
70-
*
71-
* The column width of the code block is 84. If the code contains a line longer
72-
* than 84, the line will be cut and a horizontal scroll bar will be displayed.
73-
* (the code indentation of the tag is not included in the width)
58+
* Documentation for Cluster APIs in the high level java client.
59+
* Code wrapped in {@code tag} and {@code end} tags is included in the docs.
7460
*/
7561
public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase {
7662

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,63 @@
1-
[[java-rest-high-cluster-get-settings]]
1+
--
2+
:api: get-settings
3+
:request: ClusterGetSettingsRequest
4+
:response: ClusterGetSettingsResponse
5+
--
6+
7+
[id="{upid}-{api}"]
28
=== Cluster Get Settings API
39

410
The Cluster Get Settings API allows to get the cluster wide settings.
511

6-
[[java-rest-high-cluster-get-settings-request]]
12+
[id="{upid}-{api}-request"]
713
==== Cluster Get Settings Request
814

9-
A `ClusterGetSettingsRequest`:
15+
A +{request}+:
1016

1117
["source","java",subs="attributes,callouts,macros"]
1218
--------------------------------------------------
13-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-request]
19+
include-tagged::{doc-tests-file}[{api}-request]
1420
--------------------------------------------------
1521

1622
==== Optional arguments
1723
The following arguments can optionally be provided:
1824

1925
["source","java",subs="attributes,callouts,macros"]
2026
--------------------------------------------------
21-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-request-includeDefaults]
27+
include-tagged::{doc-tests-file}[{api}-request-includeDefaults]
2228
--------------------------------------------------
2329
<1> By default only those settings that were explicitly set are returned. Setting this to true also returns
2430
the default settings.
2531

2632
["source","java",subs="attributes,callouts,macros"]
2733
--------------------------------------------------
28-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-request-local]
34+
include-tagged::{doc-tests-file}[{api}-request-local]
2935
--------------------------------------------------
3036
<1> By default the request goes to the master of the cluster to get the latest results. If local is specified it gets
3137
the results from whichever node the request goes to.
3238

3339
["source","java",subs="attributes,callouts,macros"]
3440
--------------------------------------------------
35-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-request-masterTimeout]
41+
include-tagged::{doc-tests-file}[{api}-request-masterTimeout]
3642
--------------------------------------------------
3743
<1> Timeout to connect to the master node as a `TimeValue`
3844
<2> Timeout to connect to the master node as a `String`
3945

40-
[[java-rest-high-cluster-get-settings-sync]]
41-
==== Synchronous Execution
42-
43-
["source","java",subs="attributes,callouts,macros"]
44-
--------------------------------------------------
45-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-execute]
46-
--------------------------------------------------
47-
<1> Execute the request and get back the response in a `ClusterGetSettingsResponse` object.
48-
49-
[[java-rest-high-cluster-get-settings-async]]
50-
==== Asynchronous Execution
51-
52-
The asynchronous execution of a cluster get settings requires both the
53-
`ClusterGetSettingsRequest` instance and an `ActionListener` instance to be
54-
passed to the asynchronous method:
55-
56-
["source","java",subs="attributes,callouts,macros"]
57-
--------------------------------------------------
58-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-execute-async]
59-
--------------------------------------------------
60-
<1> The `ClusterGetSettingsRequest` to execute and the `ActionListener`
61-
to use when the execution completes
62-
63-
The asynchronous method does not block and returns immediately. Once it is
64-
completed the `ActionListener` is called back using the `onResponse` method
65-
if the execution successfully completed or using the `onFailure` method if
66-
it failed.
46+
include::../execution.asciidoc[]
6747

68-
A typical listener for `ClusterGetSettingsResponse` looks like:
69-
70-
["source","java",subs="attributes,callouts,macros"]
71-
--------------------------------------------------
72-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-execute-listener]
73-
--------------------------------------------------
74-
<1> Called when the execution is successfully completed. The response is
75-
provided as an argument
76-
<2> Called in case of a failure. The raised exception is provided as an argument
77-
78-
[[java-rest-high-cluster-get-settings-response]]
48+
[id="{upid}-{api}-response"]
7949
==== Cluster Get Settings Response
8050

81-
The returned `ClusterGetSettingsResponse` allows to retrieve information about the
51+
The returned +{response}+ allows to retrieve information about the
8252
executed operation as follows:
8353

8454
["source","java",subs="attributes,callouts,macros"]
8555
--------------------------------------------------
86-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-settings-response]
56+
include-tagged::{doc-tests-file}[{api}-response]
8757
--------------------------------------------------
8858
<1> Get the persistent settings.
8959
<2> Get the transient settings.
9060
<3> Get the default settings (returns empty settings if `includeDefaults` was not set to `true`).
9161
<4> Get the value as a `String` for a particular setting. The order of searching is first in `persistentSettings` then in
9262
`transientSettings` and finally, if not found in either, in `defaultSettings`.
63+
Lines changed: 34 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
[[java-rest-high-cluster-health]]
1+
--
2+
:api: health
3+
:request: ClusterHealthRequest
4+
:response: ClusterHealthResponse
5+
--
6+
7+
[id="{upid}-{api}"]
28
=== Cluster Health API
39

410
The Cluster Health API allows getting cluster health.
511

6-
[[java-rest-high-cluster-health-request]]
12+
[id="{upid}-{api}-request"]
713
==== Cluster Health Request
814

9-
A `ClusterHealthRequest`:
15+
A +{request}+:
1016

1117
["source","java",subs="attributes,callouts,macros"]
1218
--------------------------------------------------
13-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request]
19+
include-tagged::{doc-tests-file}[{api}-request]
1420
--------------------------------------------------
1521
There are no required parameters. By default, the client will check all indices and will not wait
1622
for any events.
@@ -21,14 +27,14 @@ Indices which should be checked can be passed in the constructor:
2127

2228
["source","java",subs="attributes,callouts,macros"]
2329
--------------------------------------------------
24-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-indices-ctr]
30+
include-tagged::{doc-tests-file}[{api}-request-indices-ctr]
2531
--------------------------------------------------
2632

2733
Or using the corresponding setter method:
2834

2935
["source","java",subs="attributes,callouts,macros"]
3036
--------------------------------------------------
31-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-indices-setter]
37+
include-tagged::{doc-tests-file}[{api}-request-indices-setter]
3238
--------------------------------------------------
3339

3440
==== Other parameters
@@ -37,138 +43,103 @@ Other parameters can be passed only through setter methods:
3743

3844
["source","java",subs="attributes,callouts,macros"]
3945
--------------------------------------------------
40-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-timeout]
46+
include-tagged::{doc-tests-file}[{api}-request-timeout]
4147
--------------------------------------------------
4248
<1> Timeout for the request as a `TimeValue`. Defaults to 30 seconds
4349
<2> As a `String`
4450

4551
["source","java",subs="attributes,callouts,macros"]
4652
--------------------------------------------------
47-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-master-timeout]
53+
include-tagged::{doc-tests-file}[{api}-request-master-timeout]
4854
--------------------------------------------------
4955
<1> Timeout to connect to the master node as a `TimeValue`. Defaults to the same as `timeout`
5056
<2> As a `String`
5157

5258
["source","java",subs="attributes,callouts,macros"]
5359
--------------------------------------------------
54-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wait-status]
60+
include-tagged::{doc-tests-file}[{api}-request-wait-status]
5561
--------------------------------------------------
5662
<1> The status to wait (e.g. `green`, `yellow`, or `red`). Accepts a `ClusterHealthStatus` value.
5763
<2> Using predefined method
5864

5965
["source","java",subs="attributes,callouts,macros"]
6066
--------------------------------------------------
61-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wait-events]
67+
include-tagged::{doc-tests-file}[{api}-request-wait-events]
6268
--------------------------------------------------
6369
<1> The priority of the events to wait for. Accepts a `Priority` value.
6470

6571
["source","java",subs="attributes,callouts,macros"]
6672
--------------------------------------------------
67-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-level]
73+
include-tagged::{doc-tests-file}[{api}-request-level]
6874
--------------------------------------------------
69-
<1> The level of detail of the returned health information. Accepts a `ClusterHealthRequest.Level` value.
75+
<1> The level of detail of the returned health information. Accepts a +{request}.Level+ value.
7076

7177
["source","java",subs="attributes,callouts,macros"]
7278
--------------------------------------------------
73-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wait-relocation]
79+
include-tagged::{doc-tests-file}[{api}-request-wait-relocation]
7480
--------------------------------------------------
7581
<1> Wait for 0 relocating shards. Defaults to `false`
7682

7783
["source","java",subs="attributes,callouts,macros"]
7884
--------------------------------------------------
79-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wait-initializing]
85+
include-tagged::{doc-tests-file}[{api}-request-wait-initializing]
8086
--------------------------------------------------
8187
<1> Wait for 0 initializing shards. Defaults to `false`
8288

8389
["source","java",subs="attributes,callouts,macros"]
8490
--------------------------------------------------
85-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wait-nodes]
91+
include-tagged::{doc-tests-file}[{api}-request-wait-nodes]
8692
--------------------------------------------------
8793
<1> Wait for `N` nodes in the cluster. Defaults to `0`
8894
<2> Using `>=N`, `<=N`, `>N` and `<N` notation
8995
<3> Using `ge(N)`, `le(N)`, `gt(N)`, `lt(N)` notation
9096

9197
["source","java",subs="attributes,callouts,macros"]
9298
--------------------------------------------------
93-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wait-active]
99+
include-tagged::{doc-tests-file}[{api}-request-wait-active]
94100
--------------------------------------------------
95101

96102
<1> Wait for all shards to be active in the cluster
97103
<2> Wait for `N` shards to be active in the cluster
98104

99105
["source","java",subs="attributes,callouts,macros"]
100106
--------------------------------------------------
101-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-local]
107+
include-tagged::{doc-tests-file}[{api}-request-local]
102108
--------------------------------------------------
103109
<1> Non-master node can be used for this request. Defaults to `false`
104110

105-
[[java-rest-high-cluster-health-sync]]
106-
==== Synchronous Execution
107-
108-
["source","java",subs="attributes,callouts,macros"]
109-
--------------------------------------------------
110-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-execute]
111-
--------------------------------------------------
112-
113-
[[java-rest-high-cluster-health-async]]
114-
==== Asynchronous Execution
115-
116-
The asynchronous execution of a cluster health request requires both the
117-
`ClusterHealthRequest` instance and an `ActionListener` instance to be
118-
passed to the asynchronous method:
119-
120-
["source","java",subs="attributes,callouts,macros"]
121-
--------------------------------------------------
122-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-execute-async]
123-
--------------------------------------------------
124-
<1> The `ClusterHealthRequest` to execute and the `ActionListener` to use
125-
when the execution completes
126-
127-
The asynchronous method does not block and returns immediately. Once it is
128-
completed the `ActionListener` is called back using the `onResponse` method
129-
if the execution successfully completed or using the `onFailure` method if
130-
it failed.
131-
132-
A typical listener for `ClusterHealthResponse` looks like:
133-
134-
["source","java",subs="attributes,callouts,macros"]
135-
--------------------------------------------------
136-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-execute-listener]
137-
--------------------------------------------------
138-
<1> Called when the execution is successfully completed. The response is
139-
provided as an argument
140-
<2> Called in case of a failure. The raised exception is provided as an argument
111+
include::../execution.asciidoc[]
141112

142-
[[java-rest-high-cluster-health-response]]
113+
[id="{upid}-{api}-response"]
143114
==== Cluster Health Response
144115

145-
The returned `ClusterHealthResponse` contains the next information about the
116+
The returned +{response}+ contains the next information about the
146117
cluster:
147118

148119
["source","java",subs="attributes,callouts,macros"]
149120
--------------------------------------------------
150-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-general]
121+
include-tagged::{doc-tests-file}[{api}-response-general]
151122
--------------------------------------------------
152123
<1> Name of the cluster
153124
<2> Cluster status (`green`, `yellow` or `red`)
154125

155126
["source","java",subs="attributes,callouts,macros"]
156127
--------------------------------------------------
157-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-request-status]
128+
include-tagged::{doc-tests-file}[{api}-response-request-status]
158129
--------------------------------------------------
159130
<1> Whether request was timed out while processing
160131
<2> Status of the request (`OK` or `REQUEST_TIMEOUT`). Other errors will be thrown as exceptions
161132

162133
["source","java",subs="attributes,callouts,macros"]
163134
--------------------------------------------------
164-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-nodes]
135+
include-tagged::{doc-tests-file}[{api}-response-nodes]
165136
--------------------------------------------------
166137
<1> Number of nodes in the cluster
167138
<2> Number of data nodes in the cluster
168139

169140
["source","java",subs="attributes,callouts,macros"]
170141
--------------------------------------------------
171-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-shards]
142+
include-tagged::{doc-tests-file}[{api}-response-shards]
172143
--------------------------------------------------
173144
<1> Number of active shards
174145
<2> Number of primary active shards
@@ -180,26 +151,26 @@ include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-sh
180151

181152
["source","java",subs="attributes,callouts,macros"]
182153
--------------------------------------------------
183-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-task]
154+
include-tagged::{doc-tests-file}[{api}-response-task]
184155
--------------------------------------------------
185156
<1> Maximum wait time of all tasks in the queue
186157
<2> Number of currently pending tasks
187158
<3> Number of async fetches that are currently ongoing
188159

189160
["source","java",subs="attributes,callouts,macros"]
190161
--------------------------------------------------
191-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-indices]
162+
include-tagged::{doc-tests-file}[{api}-response-indices]
192163
--------------------------------------------------
193164
<1> Detailed information about indices in the cluster
194165

195166
["source","java",subs="attributes,callouts,macros"]
196167
--------------------------------------------------
197-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-index]
168+
include-tagged::{doc-tests-file}[{api}-response-index]
198169
--------------------------------------------------
199170
<1> Detailed information about a specific index
200171

201172
["source","java",subs="attributes,callouts,macros"]
202173
--------------------------------------------------
203-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-shard-details]
174+
include-tagged::{doc-tests-file}[{api}-response-shard-details]
204175
--------------------------------------------------
205176
<1> Detailed information about a specific shard

0 commit comments

Comments
 (0)