Skip to content

Commit 47bcb56

Browse files
authored
Docs: Cut down on high level rest client copy-and-paste-ness (#34125)
* Anchors * includes * get settings * more * More
1 parent 68b42f7 commit 47bcb56

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,139 +43,104 @@ 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
Default value is `cluster`.
7177

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

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

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

9298
["source","java",subs="attributes,callouts,macros"]
9399
--------------------------------------------------
94-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wait-active]
100+
include-tagged::{doc-tests-file}[{api}-request-wait-active]
95101
--------------------------------------------------
96102

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

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

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

143-
[[java-rest-high-cluster-health-response]]
114+
[id="{upid}-{api}-response"]
144115
==== Cluster Health Response
145116

146-
The returned `ClusterHealthResponse` contains the next information about the
117+
The returned +{response}+ contains the next information about the
147118
cluster:
148119

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

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

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

170141
["source","java",subs="attributes,callouts,macros"]
171142
--------------------------------------------------
172-
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-shards]
143+
include-tagged::{doc-tests-file}[{api}-response-shards]
173144
--------------------------------------------------
174145
<1> Number of active shards
175146
<2> Number of primary active shards
@@ -181,26 +152,26 @@ include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-response-sh
181152

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

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

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

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

0 commit comments

Comments
 (0)