Skip to content

Commit efcb9a3

Browse files
committed
Merge branch 'master' into ccr
* master: [DOCS] Omit shard failures assertion for incompatible responses (#31430) [DOCS] Move licensing APIs to docs (#31445) Add Delete Snapshot High Level REST API Remove QueryCachingPolicy#ALWAYS_CACHE (#31451) [Docs] Extend Homebrew installation instructions (#28902) Choose JVM options ergonomically [Docs] Mention ip_range datatypes on ip type page (#31416) Multiplexing token filter (#31208) Fix use of time zone in date_histogram rewrite (#31407) Core: Remove index name resolver from base TransportAction (#31002) [DOCS] Fixes code snippet testing for machine learning (#31189) [DOCS] Removed and params from MLT. Closes #28128 (#31370) Security: fix joining cluster with production license (#31341) Unify http channels and exception handling (#31379) [DOCS] Moves the info API to docs (#31121) Preserve response headers on cluster update task (#31421) [DOCS] Add code snippet testing for more ML APIs (#31404) Do not preallocate bytes for channel buffer (#31400) Docs: Advice for reindexing many indices (#31279) Mute HttpExporterTests#testHttpExporterShutdown test Tracked by #31433 Docs: Add note about removing prepareExecute from the java client (#31401) Make release notes ignore the `>test-failure` label. (#31309)
2 parents c74cd30 + 6ebe6e3 commit efcb9a3

File tree

264 files changed

+2322
-1281
lines changed

Some content is hidden

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

264 files changed

+2322
-1281
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.gradle.api.tasks.OutputDirectory
2727

2828
import java.nio.file.Files
2929
import java.nio.file.Path
30-
import java.util.regex.Matcher
3130

3231
/**
3332
* Generates REST tests for each snippet marked // TEST.
@@ -100,6 +99,14 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
10099
return snippet.language == 'js' || snippet.curl
101100
}
102101

102+
/**
103+
* Certain requests should not have the shard failure check because the
104+
* format of the response is incompatible i.e. it is not a JSON object.
105+
*/
106+
static shouldAddShardFailureCheck(String path) {
107+
return path.startsWith('_cat') == false && path.startsWith('_xpack/ml/datafeeds/') == false
108+
}
109+
103110
/**
104111
* Converts Kibana's block quoted strings into standard JSON. These
105112
* {@code """} delimited strings can be embedded in CONSOLE and can
@@ -309,13 +316,11 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
309316
* no shard succeeds. But we need to fail the tests on all of these
310317
* because they mean invalid syntax or broken queries or something
311318
* else that we don't want to teach people to do. The REST test
312-
* framework doesn't allow us to has assertions in the setup
313-
* section so we have to skip it there. We also have to skip _cat
314-
* actions because they don't return json so we can't is_false
315-
* them. That is ok because they don't have this
316-
* partial-success-is-success thing.
319+
* framework doesn't allow us to have assertions in the setup
320+
* section so we have to skip it there. We also omit the assertion
321+
* from APIs that don't return a JSON object
317322
*/
318-
if (false == inSetup && false == path.startsWith('_cat')) {
323+
if (false == inSetup && shouldAddShardFailureCheck(path)) {
319324
current.println(" - is_false: _shards.failures")
320325
}
321326
}

buildSrc/src/test/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTaskTest.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
package org.elasticsearch.gradle.doc
2121

22-
import org.elasticsearch.gradle.doc.SnippetsTask.Snippet
23-
import org.gradle.api.InvalidUserDataException
24-
22+
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.shouldAddShardFailureCheck
2523
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.replaceBlockQuote
2624

2725
class RestTestFromSnippetsTaskTest extends GroovyTestCase {
@@ -47,4 +45,10 @@ class RestTestFromSnippetsTaskTest extends GroovyTestCase {
4745
assertEquals("\"foo\": \"bort\\n baz\"",
4846
replaceBlockQuote("\"foo\": \"\"\"bort\n baz\"\"\""));
4947
}
48+
49+
void testIsDocWriteRequest() {
50+
assertTrue(shouldAddShardFailureCheck("doc-index/_search"));
51+
assertFalse(shouldAddShardFailureCheck("_cat"))
52+
assertFalse(shouldAddShardFailureCheck("_xpack/ml/datafeeds/datafeed-id/_preview"));
53+
}
5054
}

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/TransportNoopBulkAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.action.support.ActionFilters;
2828
import org.elasticsearch.action.support.HandledTransportAction;
2929
import org.elasticsearch.action.update.UpdateResponse;
30-
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
3130
import org.elasticsearch.common.inject.Inject;
3231
import org.elasticsearch.common.settings.Settings;
3332
import org.elasticsearch.index.shard.ShardId;
@@ -40,8 +39,8 @@ public class TransportNoopBulkAction extends HandledTransportAction<BulkRequest,
4039

4140
@Inject
4241
public TransportNoopBulkAction(Settings settings, ThreadPool threadPool, TransportService transportService,
43-
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
44-
super(settings, NoopBulkAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, BulkRequest::new);
42+
ActionFilters actionFilters) {
43+
super(settings, NoopBulkAction.NAME, threadPool, transportService, actionFilters, BulkRequest::new);
4544
}
4645

4746
@Override

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/TransportNoopSearchAction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.elasticsearch.action.search.ShardSearchFailure;
2525
import org.elasticsearch.action.support.ActionFilters;
2626
import org.elasticsearch.action.support.HandledTransportAction;
27-
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
2827
import org.elasticsearch.common.inject.Inject;
28+
import org.elasticsearch.common.io.stream.Writeable;
2929
import org.elasticsearch.common.settings.Settings;
3030
import org.elasticsearch.search.aggregations.InternalAggregations;
3131
import org.elasticsearch.search.SearchHit;
@@ -40,10 +40,10 @@
4040

4141
public class TransportNoopSearchAction extends HandledTransportAction<SearchRequest, SearchResponse> {
4242
@Inject
43-
public TransportNoopSearchAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters
44-
actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
45-
super(settings, NoopSearchAction.NAME, threadPool, transportService, actionFilters, SearchRequest::new,
46-
indexNameExpressionResolver);
43+
public TransportNoopSearchAction(Settings settings, ThreadPool threadPool, TransportService transportService,
44+
ActionFilters actionFilters) {
45+
super(settings, NoopSearchAction.NAME, threadPool, transportService, actionFilters,
46+
(Writeable.Reader<SearchRequest>) SearchRequest::new);
4747
}
4848

4949
@Override

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
4040
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
4141
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
42+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
4243
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
4344
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
4445
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
@@ -844,6 +845,18 @@ static Request verifyRepository(VerifyRepositoryRequest verifyRepositoryRequest)
844845
return request;
845846
}
846847

848+
static Request deleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest) {
849+
String endpoint = new EndpointBuilder().addPathPartAsIs("_snapshot")
850+
.addPathPart(deleteSnapshotRequest.repository())
851+
.addPathPart(deleteSnapshotRequest.snapshot())
852+
.build();
853+
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
854+
855+
Params parameters = new Params(request);
856+
parameters.withMasterTimeout(deleteSnapshotRequest.masterNodeTimeout());
857+
return request;
858+
}
859+
847860
static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
848861
String endpoint = new EndpointBuilder().addPathPartAsIs("_template").addPathPart(putIndexTemplateRequest.name()).build();
849862
Request request = new Request(HttpPut.METHOD_NAME, endpoint);

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
2929
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
3030
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
31+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
32+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse;
3133

3234
import java.io.IOException;
3335

@@ -161,4 +163,34 @@ public void verifyRepositoryAsync(VerifyRepositoryRequest verifyRepositoryReques
161163
restHighLevelClient.performRequestAsyncAndParseEntity(verifyRepositoryRequest, RequestConverters::verifyRepository, options,
162164
VerifyRepositoryResponse::fromXContent, listener, emptySet());
163165
}
166+
167+
/**
168+
* Deletes a snapshot.
169+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
170+
* API on elastic.co</a>
171+
*
172+
* @param deleteSnapshotRequest the request
173+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
174+
* @return the response
175+
* @throws IOException in case there is a problem sending the request or parsing back the response
176+
*/
177+
public DeleteSnapshotResponse delete(DeleteSnapshotRequest deleteSnapshotRequest, RequestOptions options) throws IOException {
178+
return restHighLevelClient.performRequestAndParseEntity(deleteSnapshotRequest, RequestConverters::deleteSnapshot, options,
179+
DeleteSnapshotResponse::fromXContent, emptySet());
180+
}
181+
182+
/**
183+
* Asynchronously deletes a snapshot.
184+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
185+
* API on elastic.co</a>
186+
*
187+
* @param deleteSnapshotRequest the request
188+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
189+
* @param listener the listener to be notified upon request completion
190+
*/
191+
public void deleteAsync(DeleteSnapshotRequest deleteSnapshotRequest, RequestOptions options,
192+
ActionListener<DeleteSnapshotResponse> listener) {
193+
restHighLevelClient.performRequestAsyncAndParseEntity(deleteSnapshotRequest, RequestConverters::deleteSnapshot, options,
194+
DeleteSnapshotResponse::fromXContent, listener, emptySet());
195+
}
164196
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
3838
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
3939
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
40+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
4041
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
4142
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
4243
import org.elasticsearch.action.admin.indices.alias.Alias;
@@ -1857,6 +1858,25 @@ public void testVerifyRepository() {
18571858
assertThat(expectedParams, equalTo(request.getParameters()));
18581859
}
18591860

1861+
public void testDeleteSnapshot() {
1862+
Map<String, String> expectedParams = new HashMap<>();
1863+
String repository = randomIndicesNames(1, 1)[0];
1864+
String snapshot = "snapshot-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);
1865+
1866+
String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/%s", repository, snapshot);
1867+
1868+
DeleteSnapshotRequest deleteSnapshotRequest = new DeleteSnapshotRequest();
1869+
deleteSnapshotRequest.repository(repository);
1870+
deleteSnapshotRequest.snapshot(snapshot);
1871+
setRandomMasterTimeout(deleteSnapshotRequest, expectedParams);
1872+
1873+
Request request = RequestConverters.deleteSnapshot(deleteSnapshotRequest);
1874+
assertThat(endpoint, equalTo(request.getEndpoint()));
1875+
assertThat(HttpDelete.METHOD_NAME, equalTo(request.getMethod()));
1876+
assertThat(expectedParams, equalTo(request.getParameters()));
1877+
assertNull(request.getEntity());
1878+
}
1879+
18601880
public void testPutTemplateRequest() throws Exception {
18611881
Map<String, String> names = new HashMap<>();
18621882
names.put("log", "log");

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
2929
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
3030
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
31+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
32+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse;
3133
import org.elasticsearch.common.xcontent.XContentType;
3234
import org.elasticsearch.repositories.fs.FsRepository;
3335
import org.elasticsearch.rest.RestStatus;
3436

3537
import java.io.IOException;
38+
import java.util.Locale;
3639

3740
import static org.hamcrest.Matchers.equalTo;
3841

@@ -46,6 +49,13 @@ private PutRepositoryResponse createTestRepository(String repository, String typ
4649
highLevelClient().snapshot()::createRepositoryAsync);
4750
}
4851

52+
private Response createTestSnapshot(String repository, String snapshot) throws IOException {
53+
Request createSnapshot = new Request("put", String.format(Locale.ROOT, "_snapshot/%s/%s", repository, snapshot));
54+
createSnapshot.addParameter("wait_for_completion", "true");
55+
return highLevelClient().getLowLevelClient().performRequest(createSnapshot);
56+
}
57+
58+
4959
public void testCreateRepository() throws IOException {
5060
PutRepositoryResponse response = createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}");
5161
assertTrue(response.isAcknowledged());
@@ -108,4 +118,21 @@ public void testVerifyRepository() throws IOException {
108118
highLevelClient().snapshot()::verifyRepositoryAsync);
109119
assertThat(response.getNodes().size(), equalTo(1));
110120
}
121+
122+
public void testDeleteSnapshot() throws IOException {
123+
String repository = "test_repository";
124+
String snapshot = "test_snapshot";
125+
126+
PutRepositoryResponse putRepositoryResponse = createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}");
127+
assertTrue(putRepositoryResponse.isAcknowledged());
128+
129+
Response putSnapshotResponse = createTestSnapshot(repository, snapshot);
130+
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
131+
assertEquals(200, putSnapshotResponse.getStatusLine().getStatusCode());
132+
133+
DeleteSnapshotRequest request = new DeleteSnapshotRequest(repository, snapshot);
134+
DeleteSnapshotResponse response = execute(request, highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync);
135+
136+
assertTrue(response.isAcknowledged());
137+
}
111138
}

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
3030
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
3131
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
32+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
33+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse;
3234
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
35+
import org.elasticsearch.client.Request;
3336
import org.elasticsearch.client.RequestOptions;
37+
import org.elasticsearch.client.Response;
3438
import org.elasticsearch.client.RestHighLevelClient;
3539
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
3640
import org.elasticsearch.common.settings.Settings;
@@ -41,6 +45,7 @@
4145
import java.io.IOException;
4246
import java.util.HashMap;
4347
import java.util.List;
48+
import java.util.Locale;
4449
import java.util.Map;
4550
import java.util.concurrent.CountDownLatch;
4651
import java.util.concurrent.TimeUnit;
@@ -69,6 +74,8 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
6974

7075
private static final String repositoryName = "test_repository";
7176

77+
private static final String snapshotName = "test_snapshot";
78+
7279
public void testSnapshotCreateRepository() throws IOException {
7380
RestHighLevelClient client = highLevelClient();
7481

@@ -360,10 +367,76 @@ public void onFailure(Exception e) {
360367
}
361368
}
362369

370+
public void testSnapshotDeleteSnapshot() throws IOException {
371+
RestHighLevelClient client = highLevelClient();
372+
373+
createTestRepositories();
374+
createTestSnapshots();
375+
376+
// tag::delete-snapshot-request
377+
DeleteSnapshotRequest request = new DeleteSnapshotRequest(repositoryName);
378+
request.snapshot(snapshotName);
379+
// end::delete-snapshot-request
380+
381+
// tag::delete-snapshot-request-masterTimeout
382+
request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1>
383+
request.masterNodeTimeout("1m"); // <2>
384+
// end::delete-snapshot-request-masterTimeout
385+
386+
// tag::delete-snapshot-execute
387+
DeleteSnapshotResponse response = client.snapshot().delete(request, RequestOptions.DEFAULT);
388+
// end::delete-snapshot-execute
389+
390+
// tag::delete-snapshot-response
391+
boolean acknowledged = response.isAcknowledged(); // <1>
392+
// end::delete-snapshot-response
393+
assertTrue(acknowledged);
394+
}
395+
396+
public void testSnapshotDeleteSnapshotAsync() throws InterruptedException {
397+
RestHighLevelClient client = highLevelClient();
398+
{
399+
DeleteSnapshotRequest request = new DeleteSnapshotRequest();
400+
401+
// tag::delete-snapshot-execute-listener
402+
ActionListener<DeleteSnapshotResponse> listener =
403+
new ActionListener<DeleteSnapshotResponse>() {
404+
@Override
405+
public void onResponse(DeleteSnapshotResponse deleteSnapshotResponse) {
406+
// <1>
407+
}
408+
409+
@Override
410+
public void onFailure(Exception e) {
411+
// <2>
412+
}
413+
};
414+
// end::delete-snapshot-execute-listener
415+
416+
// Replace the empty listener by a blocking listener in test
417+
final CountDownLatch latch = new CountDownLatch(1);
418+
listener = new LatchedActionListener<>(listener, latch);
419+
420+
// tag::delete-snapshot-execute-async
421+
client.snapshot().deleteAsync(request, RequestOptions.DEFAULT, listener); // <1>
422+
// end::delete-snapshot-execute-async
423+
424+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
425+
}
426+
}
427+
363428
private void createTestRepositories() throws IOException {
364429
PutRepositoryRequest request = new PutRepositoryRequest(repositoryName);
365430
request.type(FsRepository.TYPE);
366431
request.settings("{\"location\": \".\"}", XContentType.JSON);
367432
assertTrue(highLevelClient().snapshot().createRepository(request, RequestOptions.DEFAULT).isAcknowledged());
368433
}
434+
435+
private void createTestSnapshots() throws IOException {
436+
Request createSnapshot = new Request("put", String.format(Locale.ROOT, "_snapshot/%s/%s", repositoryName, snapshotName));
437+
createSnapshot.addParameter("wait_for_completion", "true");
438+
Response response = highLevelClient().getLowLevelClient().performRequest(createSnapshot);
439+
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
440+
assertEquals(200, response.getStatusLine().getStatusCode());
441+
}
369442
}

dev-tools/es_release_notes.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
">enhancement", ">bug", ">regression", ">upgrade"
3333
);
3434
my %Ignore = map { $_ => 1 }
35-
( ">non-issue", ">refactoring", ">docs", ">test", ":Core/Build" );
35+
( ">non-issue", ">refactoring", ">docs", ">test", ">test-failure", ":Core/Build" );
3636

3737
my %Group_Labels = (
3838
'>breaking' => 'Breaking changes',

0 commit comments

Comments
 (0)