Skip to content

Commit 03225b4

Browse files
committed
Merge remote-tracking branch 'es/6.x' into ccr-6.x
2 parents 7cc7cd5 + 870884f commit 03225b4

File tree

213 files changed

+5243
-2238
lines changed

Some content is hidden

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

213 files changed

+5243
-2238
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,19 @@ class BuildPlugin implements Plugin<Project> {
123123
}
124124
println " Random Testing Seed : ${project.testSeed}"
125125

126-
// enforce gradle version
127-
GradleVersion minGradle = GradleVersion.version('3.3')
128-
if (GradleVersion.current() < minGradle) {
126+
// enforce Gradle version
127+
final GradleVersion currentGradleVersion = GradleVersion.current();
128+
129+
final GradleVersion minGradle = GradleVersion.version('3.3')
130+
if (currentGradleVersion < minGradle) {
129131
throw new GradleException("${minGradle} or above is required to build elasticsearch")
130132
}
131133

134+
final GradleVersion maxGradle = GradleVersion.version('4.2')
135+
if (currentGradleVersion >= maxGradle) {
136+
throw new GradleException("${maxGradle} or above is not compatible with the elasticsearch build")
137+
}
138+
132139
// enforce Java version
133140
if (javaVersionEnum < minimumJava) {
134141
throw new GradleException("Java ${minimumJava} or above is required to build Elasticsearch")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.Header;
23+
import org.elasticsearch.action.ActionListener;
24+
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
25+
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
26+
27+
import java.io.IOException;
28+
import java.util.Collections;
29+
30+
/**
31+
* A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Indices API.
32+
*
33+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html">Indices API on elastic.co</a>
34+
*/
35+
public final class IndicesClient {
36+
private final RestHighLevelClient restHighLevelClient;
37+
38+
public IndicesClient(RestHighLevelClient restHighLevelClient) {
39+
this.restHighLevelClient = restHighLevelClient;
40+
}
41+
42+
/**
43+
* Deletes an index using the Delete Index API
44+
* <p>
45+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html">
46+
* Delete Index API on elastic.co</a>
47+
*/
48+
public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException {
49+
return restHighLevelClient.performRequestAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent,
50+
Collections.emptySet(), headers);
51+
}
52+
53+
/**
54+
* Asynchronously deletes an index using the Delete Index API
55+
* <p>
56+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html">
57+
* Delete Index API on elastic.co</a>
58+
*/
59+
public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener<DeleteIndexResponse> listener, Header... headers) {
60+
restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent,
61+
listener, Collections.emptySet(), headers);
62+
}
63+
}

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

100644100755
+16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.http.entity.ContentType;
3030
import org.apache.lucene.util.BytesRef;
3131
import org.elasticsearch.action.DocWriteRequest;
32+
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3233
import org.elasticsearch.action.bulk.BulkRequest;
3334
import org.elasticsearch.action.delete.DeleteRequest;
3435
import org.elasticsearch.action.get.GetRequest;
@@ -123,6 +124,17 @@ static Request delete(DeleteRequest deleteRequest) {
123124
return new Request(HttpDelete.METHOD_NAME, endpoint, parameters.getParams(), null);
124125
}
125126

127+
static Request deleteIndex(DeleteIndexRequest deleteIndexRequest) {
128+
String endpoint = endpoint(deleteIndexRequest.indices(), Strings.EMPTY_ARRAY, "");
129+
130+
Params parameters = Params.builder();
131+
parameters.withTimeout(deleteIndexRequest.timeout());
132+
parameters.withMasterTimeout(deleteIndexRequest.masterNodeTimeout());
133+
parameters.withIndicesOptions(deleteIndexRequest.indicesOptions());
134+
135+
return new Request(HttpDelete.METHOD_NAME, endpoint, parameters.getParams(), null);
136+
}
137+
126138
static Request info() {
127139
return new Request(HttpGet.METHOD_NAME, "/", Collections.emptyMap(), null);
128140
}
@@ -449,6 +461,10 @@ Params withFetchSourceContext(FetchSourceContext fetchSourceContext) {
449461
return this;
450462
}
451463

464+
Params withMasterTimeout(TimeValue masterTimeout) {
465+
return putParam("master_timeout", masterTimeout);
466+
}
467+
452468
Params withParent(String parent) {
453469
return putParam("parent", parent);
454470
}

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

100644100755
+19-8
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public class RestHighLevelClient implements Closeable {
176176
private final NamedXContentRegistry registry;
177177
private final CheckedConsumer<RestClient, IOException> doClose;
178178

179+
private final IndicesClient indicesClient = new IndicesClient(this);
180+
179181
/**
180182
* Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the
181183
* {@link RestClient} to be used to perform requests.
@@ -220,6 +222,15 @@ public final void close() throws IOException {
220222
doClose.accept(client);
221223
}
222224

225+
/**
226+
* Provides an {@link IndicesClient} which can be used to access the Indices API.
227+
*
228+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html">Indices API on elastic.co</a>
229+
*/
230+
public IndicesClient indices() {
231+
return indicesClient;
232+
}
233+
223234
/**
224235
* Executes a bulk request using the Bulk API
225236
*
@@ -327,7 +338,7 @@ public void updateAsync(UpdateRequest updateRequest, ActionListener<UpdateRespon
327338
}
328339

329340
/**
330-
* Deletes a document by id using the Delete api
341+
* Deletes a document by id using the Delete API
331342
*
332343
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html">Delete API on elastic.co</a>
333344
*/
@@ -337,7 +348,7 @@ public DeleteResponse delete(DeleteRequest deleteRequest, Header... headers) thr
337348
}
338349

339350
/**
340-
* Asynchronously deletes a document by id using the Delete api
351+
* Asynchronously deletes a document by id using the Delete API
341352
*
342353
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html">Delete API on elastic.co</a>
343354
*/
@@ -347,7 +358,7 @@ public void deleteAsync(DeleteRequest deleteRequest, ActionListener<DeleteRespon
347358
}
348359

349360
/**
350-
* Executes a search using the Search api
361+
* Executes a search using the Search API
351362
*
352363
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
353364
*/
@@ -356,7 +367,7 @@ public SearchResponse search(SearchRequest searchRequest, Header... headers) thr
356367
}
357368

358369
/**
359-
* Asynchronously executes a search using the Search api
370+
* Asynchronously executes a search using the Search API
360371
*
361372
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
362373
*/
@@ -365,7 +376,7 @@ public void searchAsync(SearchRequest searchRequest, ActionListener<SearchRespon
365376
}
366377

367378
/**
368-
* Executes a search using the Search Scroll api
379+
* Executes a search using the Search Scroll API
369380
*
370381
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
371382
* API on elastic.co</a>
@@ -375,7 +386,7 @@ public SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, Head
375386
}
376387

377388
/**
378-
* Asynchronously executes a search using the Search Scroll api
389+
* Asynchronously executes a search using the Search Scroll API
379390
*
380391
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
381392
* API on elastic.co</a>
@@ -386,7 +397,7 @@ public void searchScrollAsync(SearchScrollRequest searchScrollRequest, ActionLis
386397
}
387398

388399
/**
389-
* Clears one or more scroll ids using the Clear Scroll api
400+
* Clears one or more scroll ids using the Clear Scroll API
390401
*
391402
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api">
392403
* Clear Scroll API on elastic.co</a>
@@ -397,7 +408,7 @@ public ClearScrollResponse clearScroll(ClearScrollRequest clearScrollRequest, He
397408
}
398409

399410
/**
400-
* Asynchronously clears one or more scroll ids using the Clear Scroll api
411+
* Asynchronously clears one or more scroll ids using the Clear Scroll API
401412
*
402413
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api">
403414
* Clear Scroll API on elastic.co</a>

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

+9-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.elasticsearch.action.update.UpdateResponse;
4040
import org.elasticsearch.common.Strings;
4141
import org.elasticsearch.common.bytes.BytesReference;
42-
import org.elasticsearch.common.settings.Settings;
4342
import org.elasticsearch.common.unit.ByteSizeUnit;
4443
import org.elasticsearch.common.unit.ByteSizeValue;
4544
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -50,7 +49,6 @@
5049
import org.elasticsearch.script.Script;
5150
import org.elasticsearch.script.ScriptType;
5251
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
53-
import org.elasticsearch.threadpool.ThreadPool;
5452

5553
import java.io.IOException;
5654
import java.util.Collections;
@@ -614,14 +612,14 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
614612
}
615613
};
616614

617-
ThreadPool threadPool = new ThreadPool(Settings.builder().put("node.name", getClass().getName()).build());
618615
// Pull the client to a variable to work around https://bugs.eclipse.org/bugs/show_bug.cgi?id=514884
619616
RestHighLevelClient hlClient = highLevelClient();
620-
try(BulkProcessor processor = new BulkProcessor.Builder(hlClient::bulkAsync, listener, threadPool)
621-
.setConcurrentRequests(0)
622-
.setBulkSize(new ByteSizeValue(5, ByteSizeUnit.GB))
623-
.setBulkActions(nbItems + 1)
624-
.build()) {
617+
618+
try (BulkProcessor processor = BulkProcessor.builder(hlClient::bulkAsync, listener)
619+
.setConcurrentRequests(0)
620+
.setBulkSize(new ByteSizeValue(5, ByteSizeUnit.GB))
621+
.setBulkActions(nbItems + 1)
622+
.build()) {
625623
for (int i = 0; i < nbItems; i++) {
626624
String id = String.valueOf(i);
627625
boolean erroneous = randomBoolean();
@@ -631,7 +629,7 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
631629
if (opType == DocWriteRequest.OpType.DELETE) {
632630
if (erroneous == false) {
633631
assertEquals(RestStatus.CREATED,
634-
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
632+
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
635633
}
636634
DeleteRequest deleteRequest = new DeleteRequest("index", "test", id);
637635
processor.add(deleteRequest);
@@ -653,10 +651,10 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
653651

654652
} else if (opType == DocWriteRequest.OpType.UPDATE) {
655653
UpdateRequest updateRequest = new UpdateRequest("index", "test", id)
656-
.doc(new IndexRequest().source(xContentType, "id", i));
654+
.doc(new IndexRequest().source(xContentType, "id", i));
657655
if (erroneous == false) {
658656
assertEquals(RestStatus.CREATED,
659-
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
657+
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
660658
}
661659
processor.add(updateRequest);
662660
}
@@ -676,8 +674,6 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
676674
assertNull(error.get());
677675

678676
validateBulkResponses(nbItems, errors, bulkResponse, bulkRequest);
679-
680-
terminate(threadPool);
681677
}
682678

683679
private void validateBulkResponses(int nbItems, boolean[] errors, BulkResponse bulkResponse, BulkRequest bulkRequest) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.elasticsearch.ElasticsearchException;
23+
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
24+
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
25+
import org.elasticsearch.rest.RestStatus;
26+
27+
import java.io.IOException;
28+
29+
public class IndicesClientIT extends ESRestHighLevelClientTestCase {
30+
31+
public void testDeleteIndex() throws IOException {
32+
{
33+
// Delete index if exists
34+
String indexName = "test_index";
35+
createIndex(indexName);
36+
37+
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);
38+
DeleteIndexResponse deleteIndexResponse =
39+
execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync);
40+
assertTrue(deleteIndexResponse.isAcknowledged());
41+
42+
assertFalse(indexExists(indexName));
43+
}
44+
{
45+
// Return 404 if index doesn't exist
46+
String nonExistentIndex = "non_existent_index";
47+
assertFalse(indexExists(nonExistentIndex));
48+
49+
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(nonExistentIndex);
50+
51+
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
52+
() -> execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync));
53+
assertEquals(RestStatus.NOT_FOUND, exception.status());
54+
}
55+
}
56+
57+
private static void createIndex(String index) throws IOException {
58+
Response response = client().performRequest("PUT", index);
59+
60+
assertEquals(200, response.getStatusLine().getStatusCode());
61+
}
62+
63+
private static boolean indexExists(String index) throws IOException {
64+
Response response = client().performRequest("HEAD", index);
65+
66+
return response.getStatusLine().getStatusCode() == 200;
67+
}
68+
}

0 commit comments

Comments
 (0)