Skip to content

Commit 42457b5

Browse files
committed
Merge remote-tracking branch 'elastic/master' into zen2
2 parents 70c361e + 4c2e0d7 commit 42457b5

File tree

34 files changed

+1254
-217
lines changed

34 files changed

+1254
-217
lines changed

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

Lines changed: 55 additions & 67 deletions
Large diffs are not rendered by default.

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

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,59 @@
1919

2020
package org.elasticsearch.client.ccr;
2121

22+
import org.elasticsearch.common.ParseField;
2223
import org.elasticsearch.common.unit.ByteSizeValue;
2324
import org.elasticsearch.common.unit.TimeValue;
2425
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2526
import org.elasticsearch.common.xcontent.ObjectParser;
2627
import org.elasticsearch.common.xcontent.XContentParser;
27-
import org.elasticsearch.common.xcontent.XContentParser.Token;
2828

29-
import java.io.IOException;
29+
import java.util.AbstractMap;
3030
import java.util.Collections;
31-
import java.util.HashMap;
3231
import java.util.List;
3332
import java.util.Map;
33+
import java.util.NavigableMap;
3434
import java.util.Objects;
35+
import java.util.TreeMap;
36+
import java.util.stream.Collectors;
3537

3638
public final class GetAutoFollowPatternResponse {
3739

38-
public static GetAutoFollowPatternResponse fromXContent(final XContentParser parser) throws IOException {
39-
final Map<String, Pattern> patterns = new HashMap<>();
40-
for (Token token = parser.nextToken(); token != Token.END_OBJECT; token = parser.nextToken()) {
41-
if (token == Token.FIELD_NAME) {
42-
final String name = parser.currentName();
43-
final Pattern pattern = Pattern.PARSER.parse(parser, null);
44-
patterns.put(name, pattern);
45-
}
46-
}
47-
return new GetAutoFollowPatternResponse(patterns);
40+
static final ParseField PATTERNS_FIELD = new ParseField("patterns");
41+
static final ParseField NAME_FIELD = new ParseField("name");
42+
static final ParseField PATTERN_FIELD = new ParseField("pattern");
43+
44+
private static final ConstructingObjectParser<Map.Entry<String, Pattern>, Void> ENTRY_PARSER = new ConstructingObjectParser<>(
45+
"get_auto_follow_pattern_response", args -> new AbstractMap.SimpleEntry<>((String) args[0], (Pattern) args[1]));
46+
47+
static {
48+
ENTRY_PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME_FIELD);
49+
ENTRY_PARSER.declareObject(ConstructingObjectParser.constructorArg(), Pattern.PARSER, PATTERN_FIELD);
50+
}
51+
52+
private static final ConstructingObjectParser<GetAutoFollowPatternResponse, Void> PARSER = new ConstructingObjectParser<>(
53+
"get_auto_follow_pattern_response", args -> {
54+
@SuppressWarnings("unchecked")
55+
List<Map.Entry<String, Pattern>> entries = (List<Map.Entry<String, Pattern>>) args[0];
56+
return new GetAutoFollowPatternResponse(new TreeMap<>(entries.stream()
57+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))));
58+
});
59+
60+
static {
61+
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), ENTRY_PARSER, PATTERNS_FIELD);
62+
}
63+
64+
public static GetAutoFollowPatternResponse fromXContent(final XContentParser parser) {
65+
return PARSER.apply(parser, null);
4866
}
4967

50-
private final Map<String, Pattern> patterns;
68+
private final NavigableMap<String, Pattern> patterns;
5169

52-
GetAutoFollowPatternResponse(Map<String, Pattern> patterns) {
53-
this.patterns = Collections.unmodifiableMap(patterns);
70+
GetAutoFollowPatternResponse(NavigableMap<String, Pattern> patterns) {
71+
this.patterns = Collections.unmodifiableNavigableMap(patterns);
5472
}
5573

56-
public Map<String, Pattern> getPatterns() {
74+
public NavigableMap<String, Pattern> getPatterns() {
5775
return patterns;
5876
}
5977

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727

2828
import java.io.IOException;
2929
import java.util.Collections;
30-
import java.util.HashMap;
3130
import java.util.Map;
31+
import java.util.NavigableMap;
32+
import java.util.TreeMap;
3233

3334
import static org.elasticsearch.client.ccr.PutAutoFollowPatternRequest.FOLLOW_PATTERN_FIELD;
3435
import static org.elasticsearch.client.ccr.PutAutoFollowPatternRequest.LEADER_PATTERNS_FIELD;
@@ -48,7 +49,7 @@ public void testFromXContent() throws IOException {
4849

4950
private GetAutoFollowPatternResponse createTestInstance() {
5051
int numPatterns = randomIntBetween(0, 16);
51-
Map<String, GetAutoFollowPatternResponse.Pattern> patterns = new HashMap<>(numPatterns);
52+
NavigableMap<String, GetAutoFollowPatternResponse.Pattern> patterns = new TreeMap<>();
5253
for (int i = 0; i < numPatterns; i++) {
5354
GetAutoFollowPatternResponse.Pattern pattern = new GetAutoFollowPatternResponse.Pattern(
5455
randomAlphaOfLength(4), Collections.singletonList(randomAlphaOfLength(4)), randomAlphaOfLength(4));
@@ -90,17 +91,26 @@ private GetAutoFollowPatternResponse createTestInstance() {
9091
public static void toXContent(GetAutoFollowPatternResponse response, XContentBuilder builder) throws IOException {
9192
builder.startObject();
9293
{
94+
builder.startArray(GetAutoFollowPatternResponse.PATTERNS_FIELD.getPreferredName());
9395
for (Map.Entry<String, GetAutoFollowPatternResponse.Pattern> entry : response.getPatterns().entrySet()) {
94-
builder.startObject(entry.getKey());
95-
GetAutoFollowPatternResponse.Pattern pattern = entry.getValue();
96-
builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), pattern.getRemoteCluster());
97-
builder.field(LEADER_PATTERNS_FIELD.getPreferredName(), pattern.getLeaderIndexPatterns());
98-
if (pattern.getFollowIndexNamePattern()!= null) {
99-
builder.field(FOLLOW_PATTERN_FIELD.getPreferredName(), pattern.getFollowIndexNamePattern());
96+
builder.startObject();
97+
{
98+
builder.field(GetAutoFollowPatternResponse.NAME_FIELD.getPreferredName(), entry.getKey());
99+
builder.startObject(GetAutoFollowPatternResponse.PATTERN_FIELD.getPreferredName());
100+
{
101+
GetAutoFollowPatternResponse.Pattern pattern = entry.getValue();
102+
builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), pattern.getRemoteCluster());
103+
builder.field(LEADER_PATTERNS_FIELD.getPreferredName(), pattern.getLeaderIndexPatterns());
104+
if (pattern.getFollowIndexNamePattern()!= null) {
105+
builder.field(FOLLOW_PATTERN_FIELD.getPreferredName(), pattern.getFollowIndexNamePattern());
106+
}
107+
entry.getValue().toXContentFragment(builder, ToXContent.EMPTY_PARAMS);
108+
}
109+
builder.endObject();
100110
}
101-
entry.getValue().toXContentFragment(builder, ToXContent.EMPTY_PARAMS);
102111
builder.endObject();
103112
}
113+
builder.endArray();
104114
}
105115
builder.endObject();
106116
}

docs/java-rest/high-level/execution.asciidoc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ for the +{response}+ to be returned before continuing with code execution:
1818
include-tagged::{doc-tests-file}[{api}-execute]
1919
--------------------------------------------------
2020

21+
Synchronous calls may throw an `IOException` in case of either failing to
22+
parse the REST response in the high-level REST client, the request times out
23+
or similar cases where there is no response coming back from the server.
24+
25+
In cases where the server returns a `4xx` or `5xx` error code, the high-level
26+
client tries to parse the response body error details instead and then throws
27+
a generic `ElasticsearchException` and adds the original `ResponseException` as a
28+
suppressed exception to it.
29+
2130
[id="{upid}-{api}-async"]
2231
==== Asynchronous Execution
2332

@@ -36,7 +45,8 @@ the execution completes
3645
The asynchronous method does not block and returns immediately. Once it is
3746
completed the `ActionListener` is called back using the `onResponse` method
3847
if the execution successfully completed or using the `onFailure` method if
39-
it failed.
48+
it failed. Failure scenarios and expected exceptions are the same as in the
49+
synchronous execution case.
4050

4151
A typical listener for +{api}+ looks like:
4252

@@ -45,4 +55,4 @@ A typical listener for +{api}+ looks like:
4555
include-tagged::{doc-tests-file}[{api}-execute-listener]
4656
--------------------------------------------------
4757
<1> Called when the execution is successfully completed.
48-
<2> Called when the whole +{request}+ fails.
58+
<2> Called when the whole +{request}+ fails.

docs/reference/ccr/apis/auto-follow/get-auto-follow-pattern.asciidoc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ The API returns the following result:
8787
[source,js]
8888
--------------------------------------------------
8989
{
90-
"my_auto_follow_pattern" :
91-
{
92-
"remote_cluster" : "remote_cluster",
93-
"leader_index_patterns" :
94-
[
95-
"leader_index*"
96-
],
97-
"follow_index_pattern" : "{{leader_index}}-follower"
98-
}
90+
"patterns": [
91+
{
92+
"name": "my_auto_follow_pattern",
93+
"pattern": {
94+
"remote_cluster" : "remote_cluster",
95+
"leader_index_patterns" :
96+
[
97+
"leader_index*"
98+
],
99+
"follow_index_pattern" : "{{leader_index}}-follower"
100+
}
101+
}
102+
]
99103
}
100104
--------------------------------------------------
101105
// TESTRESPONSE

docs/reference/security/reference/files.asciidoc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
[role="xpack"]
2+
[testenv="gold"]
23
[[security-files]]
3-
=== Security Files
4+
=== Security files
45

5-
{security} uses the following files:
6+
The {es} {security-features} use the following files:
67

7-
* `ES_PATH_CONF/roles.yml` defines the roles in use on the cluster
8-
(read more <<roles-management-file, here>>).
8+
* `ES_PATH_CONF/roles.yml` defines the roles in use on the cluster. See
9+
{stack-ov}/defining-roles.html[Defining roles].
910

1011
* `ES_PATH_CONF/elasticsearch-users` defines the users and their hashed passwords for
11-
the <<file-realm,`file` realm>>.
12+
the `file` realm. See <<configuring-file-realm>>.
1213

1314
* `ES_PATH_CONF/elasticsearch-users_roles` defines the user roles assignment for the
14-
the <<file-realm, `file` realm>>.
15+
the `file` realm. See <<configuring-file-realm>>.
1516

1617
* `ES_PATH_CONF/role_mapping.yml` defines the role assignments for a
1718
Distinguished Name (DN) to a role. This allows for LDAP and Active Directory
18-
groups and users and PKI users to be mapped to roles (read more
19-
<<mapping-roles, here>>).
19+
groups and users and PKI users to be mapped to roles. See
20+
{stack-ov}/mapping-roles.html[Mapping users and groups to roles].
2021

21-
* `ES_PATH_CONF/log4j2.properties` contains audit information (read more
22-
<<logging-file, here>>).
22+
* `ES_PATH_CONF/log4j2.properties` contains audit information. See
23+
{stack-ov}/audit-log-output.html[Logfile audit output].
2324

2425
[[security-files-location]]
2526

26-
IMPORTANT: Any files that {security} uses must be stored in the Elasticsearch
27-
configuration directory. Elasticsearch runs with restricted permissions
27+
IMPORTANT: Any files that the {security-features} use must be stored in the {es}
28+
configuration directory. {es} runs with restricted permissions
2829
and is only permitted to read from the locations configured in the
2930
directory layout for enhanced security.
3031

0 commit comments

Comments
 (0)