Skip to content

Commit 50f48e5

Browse files
committed
Merge remote-tracking branch 'es/master' into ccr
* es/master: (97 commits) Clarify requirements of strict date formats. (#29090) Clarify that dates are always rendered as strings. (#29093) Compilation fix for #29067 [Docs] Fix link to Grok patterns (#29088) Store offsets in index prefix fields when stored in the parent field (#29067) Fix starting on Windows from another drive (#29086) Use removeTask instead of finishTask in PersistentTasksClusterService (#29055) Added minimal docs for reindex api in java-api docs Allow overriding JVM options in Windows service (#29044) Clarify how to set compiler and runtime JDKs (#29101) CLI: Close subcommands in MultiCommand (#28954) TEST: write ops should execute under shard permit (#28966) [DOCS] Add X-Pack upgrade details (#29038) Revert "Improve error message for installing plugin (#28298)" Docs: HighLevelRestClient#exists (#29073) Validate regular expressions in dynamic templates. (#29013) [Tests] Fix GetResultTests and DocumentFieldTests failures (#29083) Reenable LiveVersionMapTests.testRamBytesUsed on Java 9. (#29063) Mute failing GetResultTests and DocumentFieldTests Improve error message for installing plugin (#28298) ...
2 parents bfd587d + 0755ff4 commit 50f48e5

File tree

597 files changed

+8583
-6203
lines changed

Some content is hidden

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

597 files changed

+8583
-6203
lines changed

TESTING.asciidoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ The REST tests are run automatically when executing the "./gradlew check" comman
270270
REST tests use the following command:
271271

272272
---------------------------------------------------------------------------
273-
./gradlew :distribution:integ-test-zip:integTest \
273+
./gradlew :distribution:archives:integ-test-zip:integTest \
274274
-Dtests.class="org.elasticsearch.test.rest.*Yaml*IT"
275275
---------------------------------------------------------------------------
276276

277277
A specific test case can be run with
278278

279279
---------------------------------------------------------------------------
280-
./gradlew :distribution:integ-test-zip:integTest \
280+
./gradlew :distribution:archives:integ-test-zip:integTest \
281281
-Dtests.class="org.elasticsearch.test.rest.*Yaml*IT" \
282282
-Dtests.method="test {p0=cat.shards/10_basic/Help}"
283283
---------------------------------------------------------------------------
@@ -407,7 +407,7 @@ destructive. When working with a single package it's generally faster to run its
407407
tests in a tighter loop than Gradle provides. In one window:
408408

409409
--------------------------------
410-
./gradlew :distribution:rpm:assemble
410+
./gradlew :distribution:packages:rpm:assemble
411411
--------------------------------
412412

413413
and in another window:

benchmarks/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ shadowJar {
8585
classifier = 'benchmarks'
8686
}
8787

88+
runShadow {
89+
executable = new File(project.runtimeJavaHome, 'bin/java')
90+
}
91+
8892
// alias the shadowJar and runShadow tasks to abstract from the concrete plugin that we are using and provide a more consistent interface
8993
task jmhJar(
9094
dependsOn: shadowJar,

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

+10-6
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,22 @@ class BuildPlugin implements Plugin<Project> {
140140

141141
final GradleVersion minGradle = GradleVersion.version('4.3')
142142
if (currentGradleVersion < minGradle) {
143-
throw new GradleException("${minGradle} or above is required to build elasticsearch")
143+
throw new GradleException("${minGradle} or above is required to build Elasticsearch")
144144
}
145145

146146
// enforce Java version
147147
if (compilerJavaVersionEnum < minimumCompilerVersion) {
148-
throw new GradleException("Java ${minimumCompilerVersion} or above is required to build Elasticsearch")
148+
final String message =
149+
"the environment variable JAVA_HOME must be set to a JDK installation directory for Java ${minimumCompilerVersion}" +
150+
" but is [${compilerJavaHome}] corresponding to [${compilerJavaVersionEnum}]"
151+
throw new GradleException(message)
149152
}
150153

151154
if (runtimeJavaVersionEnum < minimumRuntimeVersion) {
152-
throw new GradleException("Java ${minimumRuntimeVersion} or above is required to run Elasticsearch")
155+
final String message =
156+
"the environment variable RUNTIME_JAVA_HOME must be set to a JDK installation directory for Java ${minimumRuntimeVersion}" +
157+
" but is [${runtimeJavaHome}] corresponding to [${runtimeJavaVersionEnum}]"
158+
throw new GradleException(message)
153159
}
154160

155161
project.rootProject.ext.compilerJavaHome = compilerJavaHome
@@ -558,7 +564,7 @@ class BuildPlugin implements Plugin<Project> {
558564
return {
559565
jvm "${project.runtimeJavaHome}/bin/java"
560566
parallelism System.getProperty('tests.jvms', 'auto')
561-
ifNoTests 'fail'
567+
ifNoTests System.getProperty('tests.ifNoTests', 'fail')
562568
onNonEmptyWorkDirectory 'wipe'
563569
leaveTemporary true
564570

@@ -582,8 +588,6 @@ class BuildPlugin implements Plugin<Project> {
582588
systemProperty 'tests.task', path
583589
systemProperty 'tests.security.manager', 'true'
584590
systemProperty 'jna.nosys', 'true'
585-
// default test sysprop values
586-
systemProperty 'tests.ifNoTests', 'fail'
587591
// TODO: remove setting logging level via system property
588592
systemProperty 'tests.logger.level', 'WARN'
589593
for (Map.Entry<String, String> property : System.properties.entrySet()) {

buildSrc/src/main/resources/forbidden/es-all-signatures.txt

+2
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ java.nio.channels.SocketChannel#connect(java.net.SocketAddress)
4848
# org.elasticsearch.common.Booleans#parseBoolean(java.lang.String) directly on the string.
4949
@defaultMessage use org.elasticsearch.common.Booleans#parseBoolean(java.lang.String)
5050
java.lang.Boolean#getBoolean(java.lang.String)
51+
52+
org.apache.lucene.util.IOUtils @ use @org.elasticsearch.core.internal.io instead

buildSrc/src/main/resources/forbidden/es-server-signatures.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ java.util.concurrent.Executors#privilegedThreadFactory()
2929
java.lang.Character#codePointBefore(char[],int) @ Implicit start offset is error-prone when the char[] is a buffer and the first chars are random chars
3030
java.lang.Character#codePointAt(char[],int) @ Implicit end offset is error-prone when the char[] is a buffer and the last chars are random chars
3131

32-
java.io.StringReader#<init>(java.lang.String) @ Use FastStringReader instead
33-
3432
@defaultMessage Reference management is tricky, leave it to SearcherManager
3533
org.apache.lucene.index.IndexReader#decRef()
3634
org.apache.lucene.index.IndexReader#incRef()
@@ -135,3 +133,17 @@ java.time.OffsetDateTime#withYear(int)
135133
java.time.zone.ZoneRules#getStandardOffset(java.time.Instant)
136134
java.time.zone.ZoneRules#getDaylightSavings(java.time.Instant)
137135
java.time.zone.ZoneRules#isDaylightSavings(java.time.Instant)
136+
137+
@defaultMessage Use logger methods with non-Object parameter
138+
org.apache.logging.log4j.Logger#trace(java.lang.Object)
139+
org.apache.logging.log4j.Logger#trace(java.lang.Object, java.lang.Throwable)
140+
org.apache.logging.log4j.Logger#debug(java.lang.Object)
141+
org.apache.logging.log4j.Logger#debug(java.lang.Object, java.lang.Throwable)
142+
org.apache.logging.log4j.Logger#info(java.lang.Object)
143+
org.apache.logging.log4j.Logger#info(java.lang.Object, java.lang.Throwable)
144+
org.apache.logging.log4j.Logger#warn(java.lang.Object)
145+
org.apache.logging.log4j.Logger#warn(java.lang.Object, java.lang.Throwable)
146+
org.apache.logging.log4j.Logger#error(java.lang.Object)
147+
org.apache.logging.log4j.Logger#error(java.lang.Object, java.lang.Throwable)
148+
org.apache.logging.log4j.Logger#fatal(java.lang.Object)
149+
org.apache.logging.log4j.Logger#fatal(java.lang.Object, java.lang.Throwable)

buildSrc/src/main/resources/plugin-descriptor.properties

-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,3 @@ extended.plugins=${extendedPlugins}
4343
#
4444
# 'has.native.controller': whether or not the plugin has a native controller
4545
has.native.controller=${hasNativeController}
46-
#
47-
# 'requires.keystore': whether or not the plugin needs the elasticsearch keystore be created
48-
requires.keystore=${requiresKeystore}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException {
328328
}
329329
metadata.endObject();
330330

331-
BytesRef metadataSource = metadata.bytes().toBytesRef();
331+
BytesRef metadataSource = BytesReference.bytes(metadata).toBytesRef();
332332
content.write(metadataSource.bytes, metadataSource.offset, metadataSource.length);
333333
content.write(separator);
334334
}
@@ -343,7 +343,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException {
343343
LoggingDeprecationHandler.INSTANCE, indexSource, indexXContentType)) {
344344
try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) {
345345
builder.copyCurrentStructure(parser);
346-
source = builder.bytes().toBytesRef();
346+
source = BytesReference.bytes(builder).toBytesRef();
347347
}
348348
}
349349
} else if (opType == DocWriteRequest.OpType.UPDATE) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ public void testBulk() throws IOException {
617617
bulkRequest.add(deleteRequest);
618618

619619
} else {
620-
BytesReference source = XContentBuilder.builder(xContentType.xContent()).startObject().field("id", i).endObject().bytes();
620+
BytesReference source = BytesReference.bytes(XContentBuilder.builder(xContentType.xContent())
621+
.startObject().field("id", i).endObject());
621622
if (opType == DocWriteRequest.OpType.INDEX) {
622623
IndexRequest indexRequest = new IndexRequest("index", "test", id).source(source, xContentType);
623624
if (erroneous) {

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737
import org.elasticsearch.action.main.MainRequest;
3838
import org.elasticsearch.action.main.MainResponse;
3939
import org.elasticsearch.action.support.PlainActionFuture;
40-
import org.elasticsearch.client.Request;
41-
import org.elasticsearch.client.Response;
42-
import org.elasticsearch.client.ResponseListener;
43-
import org.elasticsearch.client.RestClient;
44-
import org.elasticsearch.client.RestHighLevelClient;
4540
import org.elasticsearch.cluster.ClusterName;
4641
import org.elasticsearch.common.SuppressForbidden;
4742
import org.elasticsearch.common.xcontent.XContentHelper;
@@ -162,7 +157,7 @@ private Response mockPerformRequest(Header httpHeader) throws IOException {
162157
ProtocolVersion protocol = new ProtocolVersion("HTTP", 1, 1);
163158
when(mockResponse.getStatusLine()).thenReturn(new BasicStatusLine(protocol, 200, "OK"));
164159

165-
MainResponse response = new MainResponse(httpHeader.getValue(), Version.CURRENT, ClusterName.DEFAULT, "_na", Build.CURRENT, true);
160+
MainResponse response = new MainResponse(httpHeader.getValue(), Version.CURRENT, ClusterName.DEFAULT, "_na", Build.CURRENT);
166161
BytesRef bytesRef = XContentHelper.toXContent(response, XContentType.JSON, false).toBytesRef();
167162
when(mockResponse.getEntity()).thenReturn(new ByteArrayEntity(bytesRef.bytes, ContentType.APPLICATION_JSON));
168163

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.elasticsearch.action.search.ShardSearchFailure;
5656
import org.elasticsearch.cluster.ClusterName;
5757
import org.elasticsearch.common.CheckedFunction;
58+
import org.elasticsearch.common.bytes.BytesReference;
5859
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
5960
import org.elasticsearch.common.xcontent.ToXContent;
6061
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -163,7 +164,7 @@ public void testPingSocketTimeout() throws IOException {
163164
public void testInfo() throws IOException {
164165
Header[] headers = randomHeaders(random(), "Header");
165166
MainResponse testInfo = new MainResponse("nodeName", Version.CURRENT, new ClusterName("clusterName"), "clusterUuid",
166-
Build.CURRENT, true);
167+
Build.CURRENT);
167168
mockResponse(testInfo);
168169
MainResponse receivedInfo = restHighLevelClient.info(headers);
169170
assertEquals(testInfo, receivedInfo);
@@ -272,7 +273,7 @@ private static HttpEntity createBinaryEntity(XContentBuilder xContentBuilder, Co
272273
builder.startObject();
273274
builder.field("field", "value");
274275
builder.endObject();
275-
return new ByteArrayEntity(builder.bytes().toBytesRef().bytes, contentType);
276+
return new ByteArrayEntity(BytesReference.bytes(builder).toBytesRef().bytes, contentType);
276277
}
277278
}
278279

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.action.search.SearchRequest;
3535
import org.elasticsearch.action.search.SearchResponse;
3636
import org.elasticsearch.action.search.SearchScrollRequest;
37+
import org.elasticsearch.common.Strings;
3738
import org.elasticsearch.common.unit.TimeValue;
3839
import org.elasticsearch.common.xcontent.XContentBuilder;
3940
import org.elasticsearch.index.query.MatchQueryBuilder;
@@ -478,7 +479,7 @@ public void testSearchScroll() throws Exception {
478479

479480
for (int i = 0; i < 100; i++) {
480481
XContentBuilder builder = jsonBuilder().startObject().field("field", i).endObject();
481-
HttpEntity entity = new NStringEntity(builder.string(), ContentType.APPLICATION_JSON);
482+
HttpEntity entity = new NStringEntity(Strings.toString(builder), ContentType.APPLICATION_JSON);
482483
client().performRequest(HttpPut.METHOD_NAME, "test/type1/" + Integer.toString(i), Collections.emptyMap(), entity);
483484
}
484485
client().performRequest(HttpPost.METHOD_NAME, "/test/_refresh");

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

+45-2
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ public void testUpdate() throws Exception {
266266
assertSame(indexResponse.status(), RestStatus.CREATED);
267267

268268
XContentType xContentType = XContentType.JSON;
269-
String script = XContentBuilder.builder(xContentType.xContent())
269+
String script = Strings.toString(XContentBuilder.builder(xContentType.xContent())
270270
.startObject()
271271
.startObject("script")
272272
.field("lang", "painless")
273273
.field("code", "ctx._source.field += params.count")
274274
.endObject()
275-
.endObject().string();
275+
.endObject());
276276
HttpEntity body = new NStringEntity(script, ContentType.create(xContentType.mediaType()));
277277
Response response = client().performRequest(HttpPost.METHOD_NAME, "/_scripts/increment-field", emptyMap(), body);
278278
assertEquals(response.getStatusLine().getStatusCode(), RestStatus.OK.getStatus());
@@ -932,6 +932,49 @@ public void onFailure(Exception e) {
932932
}
933933
}
934934

935+
public void testExists() throws Exception {
936+
RestHighLevelClient client = highLevelClient();
937+
// tag::exists-request
938+
GetRequest getRequest = new GetRequest(
939+
"posts", // <1>
940+
"doc", // <2>
941+
"1"); // <3>
942+
getRequest.fetchSourceContext(new FetchSourceContext(false)); // <4>
943+
getRequest.storedFields("_none_"); // <5>
944+
// end::exists-request
945+
{
946+
// tag::exists-execute
947+
boolean exists = client.exists(getRequest);
948+
// end::exists-execute
949+
assertFalse(exists);
950+
}
951+
{
952+
// tag::exists-execute-listener
953+
ActionListener<Boolean> listener = new ActionListener<Boolean>() {
954+
@Override
955+
public void onResponse(Boolean exists) {
956+
// <1>
957+
}
958+
959+
@Override
960+
public void onFailure(Exception e) {
961+
// <2>
962+
}
963+
};
964+
// end::exists-execute-listener
965+
966+
// Replace the empty listener by a blocking listener in test
967+
final CountDownLatch latch = new CountDownLatch(1);
968+
listener = new LatchedActionListener<>(listener, latch);
969+
970+
// tag::exists-execute-async
971+
client.existsAsync(getRequest, listener); // <1>
972+
// end::exists-execute-async
973+
974+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
975+
}
976+
}
977+
935978
public void testBulkProcessor() throws InterruptedException {
936979
RestHighLevelClient client = highLevelClient();
937980
{

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.client.Response;
3434
import org.elasticsearch.client.RestHighLevelClient;
3535
import org.elasticsearch.cluster.health.ClusterHealthStatus;
36+
import org.elasticsearch.common.Strings;
3637
import org.elasticsearch.common.settings.Settings;
3738
import org.elasticsearch.common.xcontent.XContentFactory;
3839
import org.elasticsearch.common.xcontent.XContentHelper;
@@ -75,7 +76,7 @@ public void testCreateIndex() throws IOException {
7576
.put(SETTING_NUMBER_OF_REPLICAS, 0)
7677
.build();
7778

78-
String payload = XContentFactory.jsonBuilder() // <2>
79+
String payload = Strings.toString(XContentFactory.jsonBuilder() // <2>
7980
.startObject()
8081
.startObject("settings") // <3>
8182
.value(indexSettings)
@@ -89,7 +90,7 @@ public void testCreateIndex() throws IOException {
8990
.endObject()
9091
.endObject()
9192
.endObject()
92-
.endObject().string();
93+
.endObject());
9394

9495
HttpEntity entity = new NStringEntity(payload, ContentType.APPLICATION_JSON); // <5>
9596

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MainDocumentationIT.java renamed to client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MiscellaneousDocumentationIT.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,17 @@
3131
import java.io.IOException;
3232

3333
/**
34-
* This class is used to generate the Java Main API documentation.
35-
* You need to wrap your code between two tags like:
36-
* // tag::example[]
37-
* // end::example[]
38-
*
39-
* Where example is your tag name.
40-
*
41-
* Then in the documentation, you can extract what is between tag and end tags with
42-
* ["source","java",subs="attributes,callouts,macros"]
43-
* --------------------------------------------------
44-
* include-tagged::{doc-tests}/MainDocumentationIT.java[example]
45-
* --------------------------------------------------
34+
* Documentation for miscellaneous APIs in the high level java client.
35+
* Code wrapped in {@code tag} and {@code end} tags is included in the docs.
4636
*/
47-
public class MainDocumentationIT extends ESRestHighLevelClientTestCase {
37+
public class MiscellaneousDocumentationIT extends ESRestHighLevelClientTestCase {
4838

4939
public void testMain() throws IOException {
5040
RestHighLevelClient client = highLevelClient();
5141
{
5242
//tag::main-execute
5343
MainResponse response = client.info();
5444
//end::main-execute
55-
assertTrue(response.isAvailable());
5645
//tag::main-response
5746
ClusterName clusterName = response.getClusterName(); // <1>
5847
String clusterUuid = response.getClusterUuid(); // <2>
@@ -68,6 +57,14 @@ public void testMain() throws IOException {
6857
}
6958
}
7059

60+
public void testPing() throws IOException {
61+
RestHighLevelClient client = highLevelClient();
62+
//tag::ping-execute
63+
boolean response = client.ping();
64+
//end::ping-execute
65+
assertTrue(response);
66+
}
67+
7168
public void testInitializationFromClientBuilder() throws IOException {
7269
//tag::rest-high-level-client-init
7370
RestHighLevelClient client = new RestHighLevelClient(

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

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
7777
import static org.elasticsearch.index.query.QueryBuilders.typeQuery;
7878
import static org.elasticsearch.index.query.QueryBuilders.wildcardQuery;
79+
import static org.elasticsearch.index.query.QueryBuilders.wrapperQuery;
7980
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.exponentialDecayFunction;
8081
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.randomFunction;
8182

@@ -449,4 +450,11 @@ public void testWildcard() {
449450
"k?mch*"); // <2>
450451
// end::wildcard
451452
}
453+
454+
public void testWrapper() {
455+
// tag::wrapper
456+
String query = "{\"term\": {\"user\": \"kimchy\"}}"; // <1>
457+
wrapperQuery(query);
458+
// end::wrapper
459+
}
452460
}

0 commit comments

Comments
 (0)