Skip to content

Commit 89f9eff

Browse files
committed
Merge branch 'master' into pr/37940
* master: Expose retention leases in shard stats (elastic#37991) Make primary terms fields private in index shard (elastic#38036) ML: Add reason field in JobTaskState (elastic#38029) Log flush_stats and commit_stats in testMaybeFlush HLRC: Fix strict setting exception handling (elastic#37247) Test: Enable strict deprecation on all tests (elastic#36558) Removes typed calls from YAML REST tests (elastic#37611) Switch default time format for ingest from Joda to Java for v7 (elastic#37934) Remove deprecated Plugin#onModule extension points (elastic#37866) Geo: Fix Empty Geometry Collection Handling (elastic#37978)
2 parents edba50d + 6500b0c commit 89f9eff

File tree

297 files changed

+2205
-2657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+2205
-2657
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,15 +1671,16 @@ protected final ElasticsearchStatusException parseResponseException(ResponseExce
16711671
Response response = responseException.getResponse();
16721672
HttpEntity entity = response.getEntity();
16731673
ElasticsearchStatusException elasticsearchException;
1674+
RestStatus restStatus = RestStatus.fromCode(response.getStatusLine().getStatusCode());
1675+
16741676
if (entity == null) {
16751677
elasticsearchException = new ElasticsearchStatusException(
1676-
responseException.getMessage(), RestStatus.fromCode(response.getStatusLine().getStatusCode()), responseException);
1678+
responseException.getMessage(), restStatus, responseException);
16771679
} else {
16781680
try {
16791681
elasticsearchException = parseEntity(entity, BytesRestResponse::errorFromXContent);
16801682
elasticsearchException.addSuppressed(responseException);
16811683
} catch (Exception e) {
1682-
RestStatus restStatus = RestStatus.fromCode(response.getStatusLine().getStatusCode());
16831684
elasticsearchException = new ElasticsearchStatusException("Unable to parse response body", restStatus, responseException);
16841685
elasticsearchException.addSuppressed(e);
16851686
}
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.apache.http.HttpHost;
23+
import org.apache.http.ProtocolVersion;
24+
import org.apache.http.RequestLine;
25+
import org.apache.http.client.methods.HttpGet;
26+
import org.apache.http.message.BasicRequestLine;
27+
import org.apache.http.message.BasicStatusLine;
28+
import org.elasticsearch.test.ESTestCase;
29+
import org.junit.Before;
30+
31+
import java.io.IOException;
32+
import java.util.Collections;
33+
import java.util.List;
34+
35+
import static org.hamcrest.Matchers.equalTo;
36+
import static org.mockito.Matchers.any;
37+
import static org.mockito.Mockito.doThrow;
38+
import static org.mockito.Mockito.mock;
39+
import static org.mockito.Mockito.when;
40+
41+
public class MockRestHighLevelTests extends ESTestCase {
42+
private RestHighLevelClient client;
43+
private static final List<String> WARNINGS = Collections.singletonList("Some Warning");
44+
45+
@Before
46+
private void setupClient() throws IOException {
47+
final RestClient mockClient = mock(RestClient.class);
48+
final Response mockResponse = mock(Response.class);
49+
50+
when(mockResponse.getHost()).thenReturn(new HttpHost("localhost", 9200));
51+
when(mockResponse.getWarnings()).thenReturn(WARNINGS);
52+
53+
ProtocolVersion protocol = new ProtocolVersion("HTTP", 1, 1);
54+
when(mockResponse.getStatusLine()).thenReturn(new BasicStatusLine(protocol, 200, "OK"));
55+
56+
RequestLine requestLine = new BasicRequestLine(HttpGet.METHOD_NAME, "/_blah", protocol);
57+
when(mockResponse.getRequestLine()).thenReturn(requestLine);
58+
59+
WarningFailureException expectedException = new WarningFailureException(mockResponse);
60+
doThrow(expectedException).when(mockClient).performRequest(any());
61+
62+
client = new RestHighLevelClient(mockClient, RestClient::close, Collections.emptyList());
63+
}
64+
65+
public void testWarningFailure() {
66+
WarningFailureException exception = expectThrows(WarningFailureException.class,
67+
() -> client.info(RequestOptions.DEFAULT));
68+
assertThat(exception.getMessage(), equalTo("method [GET], host [http://localhost:9200], URI [/_blah], " +
69+
"status line [HTTP/1.1 200 OK]"));
70+
assertNull(exception.getCause());
71+
assertThat(exception.getResponse().getWarnings(), equalTo(WARNINGS));
72+
}
73+
}

client/rest/src/main/java/org/elasticsearch/client/ResponseException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
public final class ResponseException extends IOException {
3434

35-
private Response response;
35+
private final Response response;
3636

3737
public ResponseException(Response response) throws IOException {
3838
super(buildMessage(response));
@@ -49,7 +49,7 @@ public ResponseException(Response response) throws IOException {
4949
this.response = e.getResponse();
5050
}
5151

52-
private static String buildMessage(Response response) throws IOException {
52+
static String buildMessage(Response response) throws IOException {
5353
String message = String.format(Locale.ROOT,
5454
"method [%s], host [%s], URI [%s], status line [%s]",
5555
response.getRequestLine().getMethod(),

client/rest/src/main/java/org/elasticsearch/client/RestClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public void completed(HttpResponse httpResponse) {
301301
if (isSuccessfulResponse(statusCode) || ignoreErrorCodes.contains(response.getStatusLine().getStatusCode())) {
302302
onResponse(node);
303303
if (thisWarningsHandler.warningsShouldFailRequest(response.getWarnings())) {
304-
listener.onDefinitiveFailure(new ResponseException(response));
304+
listener.onDefinitiveFailure(new WarningFailureException(response));
305305
} else {
306306
listener.onSuccess(response);
307307
}
@@ -686,6 +686,9 @@ Response get() throws IOException {
686686
* like the asynchronous API. We wrap the exception so that the caller's
687687
* signature shows up in any exception we throw.
688688
*/
689+
if (exception instanceof WarningFailureException) {
690+
throw new WarningFailureException((WarningFailureException) exception);
691+
}
689692
if (exception instanceof ResponseException) {
690693
throw new ResponseException((ResponseException) exception);
691694
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 java.io.IOException;
23+
24+
import static org.elasticsearch.client.ResponseException.buildMessage;
25+
26+
/**
27+
* This exception is used to indicate that one or more {@link Response#getWarnings()} exist
28+
* and is typically used when the {@link RestClient} is set to fail by setting
29+
* {@link RestClientBuilder#setStrictDeprecationMode(boolean)} to `true`.
30+
*/
31+
// This class extends RuntimeException in order to deal with wrapping that is done in FutureUtils on exception.
32+
// if the exception is not of type ElasticsearchException or RuntimeException it will be wrapped in a UncategorizedExecutionException
33+
public final class WarningFailureException extends RuntimeException {
34+
35+
private final Response response;
36+
37+
public WarningFailureException(Response response) throws IOException {
38+
super(buildMessage(response));
39+
this.response = response;
40+
}
41+
42+
/**
43+
* Wrap a {@linkplain WarningFailureException} with another one with the current
44+
* stack trace. This is used during synchronous calls so that the caller
45+
* ends up in the stack trace of the exception thrown.
46+
*/
47+
WarningFailureException(WarningFailureException e) {
48+
super(e.getMessage(), e);
49+
this.response = e.getResponse();
50+
}
51+
52+
/**
53+
* Returns the {@link Response} that caused this exception to be thrown.
54+
*/
55+
public Response getResponse() {
56+
return response;
57+
}
58+
}

client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ private void assertDeprecationWarnings(List<String> warningHeaderTexts, List<Str
421421
if (expectFailure) {
422422
try {
423423
restClient.performRequest(request);
424-
fail("expected ResponseException from warnings");
424+
fail("expected WarningFailureException from warnings");
425425
return;
426-
} catch (ResponseException e) {
426+
} catch (WarningFailureException e) {
427427
if (false == warningBodyTexts.isEmpty()) {
428428
assertThat(e.getMessage(), containsString("\nWarnings: " + warningBodyTexts));
429429
}

libs/geo/src/main/java/org/elasticsearch/geo/utils/WellKnownText.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public Void visit(MultiLine multiLine) {
121121

122122
@Override
123123
public Void visit(MultiPoint multiPoint) {
124+
if (multiPoint.isEmpty()) {
125+
sb.append(EMPTY);
126+
return null;
127+
}
124128
// walk through coordinates:
125129
sb.append(LPAREN);
126130
visitPoint(multiPoint.get(0).getLon(), multiPoint.get(0).getLat());

modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/20_empty_bucket.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@
22
"Empty Bucket Aggregation":
33
- do:
44
indices.create:
5+
include_type_name: false
56
index: empty_bucket_idx
67
body:
78
settings:
89
number_of_shards: "3"
910
mappings:
10-
test:
11-
"properties":
12-
"value":
13-
"type": "integer"
14-
"val1":
15-
"type": "double"
11+
"properties":
12+
"value":
13+
"type": "integer"
14+
"val1":
15+
"type": "double"
1616

1717
- do:
1818
index:
1919
index: empty_bucket_idx
20-
type: test
2120
id: 1
2221
body: { "value": 0, "val1": 3.1 }
2322

2423
- do:
2524
index:
2625
index: empty_bucket_idx
27-
type: test
2826
id: 2
2927
body: { "value": 2, "val1": -3.1 }
3028

modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/30_single_value_field.yml

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ setup:
33

44
- do:
55
indices.create:
6+
include_type_name: false
67
index: test
78
body:
89
settings:
910
number_of_shards: 3
1011
number_of_routing_shards: 3
1112
mappings:
12-
test:
13-
"properties":
14-
"val1":
15-
"type": "double"
16-
"val2":
17-
"type": "double"
18-
"val3":
19-
"type": "double"
13+
"properties":
14+
"val1":
15+
"type": "double"
16+
"val2":
17+
"type": "double"
18+
"val3":
19+
"type": "double"
2020

2121
- do:
2222
indices.create:
@@ -28,91 +28,76 @@ setup:
2828
- do:
2929
index:
3030
index: test
31-
type: test
3231
id: 1
3332
body: { "val1": 1.9, "val2": 3.1, "val3": 2.3 }
3433
- do:
3534
index:
3635
index: test
37-
type: test
3836
id: 2
3937
body: { "val1": -5.2, "val2": -3.4, "val3": 2.3}
4038
- do:
4139
index:
4240
index: test
43-
type: test
4441
id: 3
4542
body: { "val1": -5.2, "val3": 2.3}
4643
- do:
4744
index:
4845
index: test
49-
type: test
5046
id: 4
5147
body: { "val1": 18.3, "val2": 104.4, "val3": 2.3}
5248
- do:
5349
index:
5450
index: test
55-
type: test
5651
id: 5
5752
body: { "val1": -53.2, "val2": -322.4, "val3": 2.3}
5853
- do:
5954
index:
6055
index: test
61-
type: test
6256
id: 6
6357
body: { "val1": -578.9, "val2": 69.9, "val3": 2.3}
6458
- do:
6559
index:
6660
index: test
67-
type: test
6861
id: 7
6962
body: { "val1": 16.2, "val2": 17.2, "val3": 2.3}
7063
- do:
7164
index:
7265
index: test
73-
type: test
7466
id: 8
7567
body: { "val1": -4222.63, "val2": 316.44, "val3": 2.3}
7668
- do:
7769
index:
7870
index: test
79-
type: test
8071
id: 9
8172
body: { "val1": -59999.55, "val2": -3163.4, "val3": 2.3}
8273
- do:
8374
index:
8475
index: test
85-
type: test
8676
id: 10
8777
body: { "val1": 782.7, "val2": 789.7, "val3": 2.3}
8878
- do:
8979
index:
9080
index: test
91-
type: test
9281
id: 11
9382
body: { "val1": -1.2, "val2": 6.3, "val3": 2.3}
9483
- do:
9584
index:
9685
index: test
97-
type: test
9886
id: 12
9987
body: { "val1": 0, "val2": 1.11, "val3": 2.3}
10088
- do:
10189
index:
10290
index: test
103-
type: test
10491
id: 13
10592
body: { "val1": 0.1, "val2": 0.92, "val3": 2.3}
10693
- do:
10794
index:
10895
index: test
109-
type: test
11096
id: 14
11197
body: { "val1": 0.12, "val2": -82.4, "val3": 2.3}
11298
- do:
11399
index:
114100
index: test
115-
type: test
116101
id: 15
117102
body: { "val1": 98.2, "val2": 32.4, "val3": 2.3}
118103

0 commit comments

Comments
 (0)