Skip to content

Commit 20e4303

Browse files
committed
Merge branch 'master' into ubuntu-1804
* master: Use more precise does S3 bucket exist method (elastic#34123) LLREST: Introduce a strict mode (elastic#33708) [CCR] Adjust list retryable errors (elastic#33985) Fix AggregationFactories.Builder equality and hash regarding order (elastic#34005) MINOR: Remove some deadcode in NodeEnv and Related (elastic#34133) Rest-Api-Spec: Correct spelling in filter_path description (elastic#33154) Core: Don't rely on java time for epoch seconds formatting (elastic#34086) Retry errors when fetching follower global checkpoint. (elastic#34019) Watcher: Reenable watcher stats REST tests (elastic#34107) Remove special-casing of Synonym filters in AnalysisRegistry (elastic#34034) Rename CCR APIs (elastic#34027) Fixed CCR stats api serialization issues and (elastic#33983) Support 'string'-style queries on metadata fields when reasonable. (elastic#34089) Logging: Drop Settings from security logger get calls (elastic#33940) SQL: Internal refactoring of operators as functions (elastic#34097)
2 parents 539f2e7 + 99681f9 commit 20e4303

File tree

384 files changed

+5551
-4275
lines changed

Some content is hidden

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

384 files changed

+5551
-4275
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
import org.apache.http.RequestLine;
2727
import org.apache.http.StatusLine;
2828

29+
import java.util.ArrayList;
30+
import java.util.List;
2931
import java.util.Objects;
32+
import java.util.regex.Matcher;
33+
import java.util.regex.Pattern;
3034

3135
/**
3236
* Holds an elasticsearch response. It wraps the {@link HttpResponse} returned and associates it with
@@ -96,6 +100,46 @@ public HttpEntity getEntity() {
96100
return response.getEntity();
97101
}
98102

103+
private static final Pattern WARNING_HEADER_PATTERN = Pattern.compile(
104+
"299 " + // warn code
105+
"Elasticsearch-\\d+\\.\\d+\\.\\d+(?:-(?:alpha|beta|rc)\\d+)?(?:-SNAPSHOT)?-(?:[a-f0-9]{7}|Unknown) " + // warn agent
106+
"\"((?:\t| |!|[\\x23-\\x5B]|[\\x5D-\\x7E]|[\\x80-\\xFF]|\\\\|\\\\\")*)\" " + // quoted warning value, captured
107+
// quoted RFC 1123 date format
108+
"\"" + // opening quote
109+
"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), " + // weekday
110+
"\\d{2} " + // 2-digit day
111+
"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) " + // month
112+
"\\d{4} " + // 4-digit year
113+
"\\d{2}:\\d{2}:\\d{2} " + // (two-digit hour):(two-digit minute):(two-digit second)
114+
"GMT" + // GMT
115+
"\""); // closing quote
116+
117+
/**
118+
* Returns a list of all warning headers returned in the response.
119+
*/
120+
public List<String> getWarnings() {
121+
List<String> warnings = new ArrayList<>();
122+
for (Header header : response.getHeaders("Warning")) {
123+
String warning = header.getValue();
124+
final Matcher matcher = WARNING_HEADER_PATTERN.matcher(warning);
125+
if (matcher.matches()) {
126+
warnings.add(matcher.group(1));
127+
continue;
128+
}
129+
warnings.add(warning);
130+
}
131+
return warnings;
132+
}
133+
134+
/**
135+
* Returns true if there is at least one warning header returned in the
136+
* response.
137+
*/
138+
public boolean hasWarnings() {
139+
Header[] warnings = response.getHeaders("Warning");
140+
return warnings != null && warnings.length > 0;
141+
}
142+
99143
HttpResponse getHttpResponse() {
100144
return response;
101145
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ private static String buildMessage(Response response) throws IOException {
5858
response.getStatusLine().toString()
5959
);
6060

61+
if (response.hasWarnings()) {
62+
message += "\n" + "Warnings: " + response.getWarnings();
63+
}
64+
6165
HttpEntity entity = response.getEntity();
6266
if (entity != null) {
6367
if (entity.isRepeatable() == false) {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ public class RestClient implements Closeable {
110110
private final FailureListener failureListener;
111111
private final NodeSelector nodeSelector;
112112
private volatile NodeTuple<List<Node>> nodeTuple;
113+
private final boolean strictDeprecationMode;
113114

114-
RestClient(CloseableHttpAsyncClient client, long maxRetryTimeoutMillis, Header[] defaultHeaders,
115-
List<Node> nodes, String pathPrefix, FailureListener failureListener, NodeSelector nodeSelector) {
115+
RestClient(CloseableHttpAsyncClient client, long maxRetryTimeoutMillis, Header[] defaultHeaders, List<Node> nodes, String pathPrefix,
116+
FailureListener failureListener, NodeSelector nodeSelector, boolean strictDeprecationMode) {
116117
this.client = client;
117118
this.maxRetryTimeoutMillis = maxRetryTimeoutMillis;
118119
this.defaultHeaders = Collections.unmodifiableList(Arrays.asList(defaultHeaders));
119120
this.failureListener = failureListener;
120121
this.pathPrefix = pathPrefix;
121122
this.nodeSelector = nodeSelector;
123+
this.strictDeprecationMode = strictDeprecationMode;
122124
setNodes(nodes);
123125
}
124126

@@ -296,7 +298,11 @@ public void completed(HttpResponse httpResponse) {
296298
Response response = new Response(request.getRequestLine(), node.getHost(), httpResponse);
297299
if (isSuccessfulResponse(statusCode) || ignoreErrorCodes.contains(response.getStatusLine().getStatusCode())) {
298300
onResponse(node);
299-
listener.onSuccess(response);
301+
if (strictDeprecationMode && response.hasWarnings()) {
302+
listener.onDefinitiveFailure(new ResponseException(response));
303+
} else {
304+
listener.onSuccess(response);
305+
}
300306
} else {
301307
ResponseException responseException = new ResponseException(response);
302308
if (isRetryStatus(statusCode)) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public final class RestClientBuilder {
5656
private RequestConfigCallback requestConfigCallback;
5757
private String pathPrefix;
5858
private NodeSelector nodeSelector = NodeSelector.ANY;
59+
private boolean strictDeprecationMode = false;
5960

6061
/**
6162
* Creates a new builder instance and sets the hosts that the client will send requests to.
@@ -185,6 +186,15 @@ public RestClientBuilder setNodeSelector(NodeSelector nodeSelector) {
185186
return this;
186187
}
187188

189+
/**
190+
* Whether the REST client should return any response containing at least
191+
* one warning header as a failure.
192+
*/
193+
public RestClientBuilder setStrictDeprecationMode(boolean strictDeprecationMode) {
194+
this.strictDeprecationMode = strictDeprecationMode;
195+
return this;
196+
}
197+
188198
/**
189199
* Creates a new {@link RestClient} based on the provided configuration.
190200
*/
@@ -199,7 +209,7 @@ public CloseableHttpAsyncClient run() {
199209
}
200210
});
201211
RestClient restClient = new RestClient(httpClient, maxRetryTimeout, defaultHeaders, nodes,
202-
pathPrefix, failureListener, nodeSelector);
212+
pathPrefix, failureListener, nodeSelector, strictDeprecationMode);
203213
httpClient.start();
204214
return restClient;
205215
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void run() {
115115
}
116116
nodes = Collections.unmodifiableList(nodes);
117117
failureListener = new HostsTrackingFailureListener();
118-
return new RestClient(httpClient, 10000, new Header[0], nodes, null, failureListener, nodeSelector);
118+
return new RestClient(httpClient, 10000, new Header[0], nodes, null, failureListener, nodeSelector, false);
119119
}
120120

121121
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void run() {
148148
node = new Node(new HttpHost("localhost", 9200));
149149
failureListener = new HostsTrackingFailureListener();
150150
restClient = new RestClient(httpClient, 10000, defaultHeaders,
151-
singletonList(node), null, failureListener, NodeSelector.ANY);
151+
singletonList(node), null, failureListener, NodeSelector.ANY, false);
152152
}
153153

154154
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class RestClientTests extends RestClientTestCase {
5757
public void testCloseIsIdempotent() throws IOException {
5858
List<Node> nodes = singletonList(new Node(new HttpHost("localhost", 9200)));
5959
CloseableHttpAsyncClient closeableHttpAsyncClient = mock(CloseableHttpAsyncClient.class);
60-
RestClient restClient = new RestClient(closeableHttpAsyncClient, 1_000, new Header[0], nodes, null, null, null);
60+
RestClient restClient = new RestClient(closeableHttpAsyncClient, 1_000, new Header[0], nodes, null, null, null, false);
6161
restClient.close();
6262
verify(closeableHttpAsyncClient, times(1)).close();
6363
restClient.close();
@@ -345,7 +345,7 @@ private static String assertSelectAllRejected( NodeTuple<List<Node>> nodeTuple,
345345
private static RestClient createRestClient() {
346346
List<Node> nodes = Collections.singletonList(new Node(new HttpHost("localhost", 9200)));
347347
return new RestClient(mock(CloseableHttpAsyncClient.class), randomLongBetween(1_000, 30_000),
348-
new Header[] {}, nodes, null, null, null);
348+
new Header[] {}, nodes, null, null, null, false);
349349
}
350350

351351
public void testRoundRobin() throws IOException {

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
275275
filters.put("sorani_normalization", SoraniNormalizationFilterFactory::new);
276276
filters.put("stemmer_override", requiresAnalysisSettings(StemmerOverrideTokenFilterFactory::new));
277277
filters.put("stemmer", StemmerTokenFilterFactory::new);
278+
filters.put("synonym", requiresAnalysisSettings(SynonymTokenFilterFactory::new));
279+
filters.put("synonym_graph", requiresAnalysisSettings(SynonymGraphTokenFilterFactory::new));
278280
filters.put("trim", TrimTokenFilterFactory::new);
279281
filters.put("truncate", requiresAnalysisSettings(TruncateTokenFilterFactory::new));
280282
filters.put("unique", UniqueTokenFilterFactory::new);

server/src/main/java/org/elasticsearch/index/analysis/ESSolrSynonymParser.java renamed to modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/ESSolrSynonymParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.index.analysis;
20+
package org.elasticsearch.analysis.common;
2121

2222
import org.apache.logging.log4j.Logger;
2323
import org.apache.logging.log4j.LogManager;

server/src/main/java/org/elasticsearch/index/analysis/ESWordnetSynonymParser.java renamed to modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/ESWordnetSynonymParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.index.analysis;
20+
package org.elasticsearch.analysis.common;
2121

2222
import org.apache.logging.log4j.Logger;
2323
import org.apache.logging.log4j.LogManager;

0 commit comments

Comments
 (0)