Skip to content

Commit 5a0660d

Browse files
committed
Merge branch 'master' into ccr-overview
* master: (22 commits) Introduce CCR getting started guide (elastic#35434) Correct typo in BuildPlugin exception message (elastic#35458) Correct implemented interface of ParsedReverseNested (elastic#35455) [ML] Fix find_file_structure NPE with should_trim_fields (elastic#35465) Handle OS pretty name on old OS without OS release (elastic#35453) Register remote cluster compress setting (elastic#35464) [DOCS] Clarify results_index_name description (elastic#35463) [TEST] add missing doc tests for HLRC GetRollupIndexCaps API [HLRC] Add GetRollupIndexCaps API (elastic#35102) Geo: enables coerce support in WKT polygon parser (elastic#35414) [ILM] fix retry so it picks up latest policy and executes async action (elastic#35406) Address handling of OS pretty name on some OS (elastic#35451) HLRC support for getTask (elastic#35166) upgrade to lucene-8.0.0-snapshot-6d9c714052 (elastic#35428) Add docs for CCR stats API (elastic#35439) Fix the names of CCR stats endpoints in usage API (elastic#35438) Switch to default to no build qualifier (elastic#35415) Clarify S3 repository storage class parameter (elastic#35400) SQL: Fix query translation for scripted queries (elastic#35408) [TEST] Instead of ignoring the ccr downgrade to basic license qa test avoid the assertions that check the log files, because that does not work on Windows. The rest of the test is still useful and should work on Windows CI. ...
2 parents 20c4995 + 92fef40 commit 5a0660d

File tree

125 files changed

+3396
-352
lines changed

Some content is hidden

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

125 files changed

+3396
-352
lines changed

buildSrc/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class VersionPropertiesLoader {
245245
elasticsearch
246246
)
247247
}
248-
String qualifier = systemProperties.getProperty("build.version_qualifier", "alpha1");
248+
String qualifier = systemProperties.getProperty("build.version_qualifier", "");
249249
if (qualifier.isEmpty() == false) {
250250
if (qualifier.matches("(alpha|beta|rc)\\d+") == false) {
251251
throw new IllegalStateException("Invalid qualifier: " + qualifier)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BuildPlugin implements Plugin<Project> {
6666
void apply(Project project) {
6767
if (project.pluginManager.hasPlugin('elasticsearch.standalone-rest-test')) {
6868
throw new InvalidUserDataException('elasticsearch.standalone-test, '
69-
+ 'elasticearch.standalone-rest-test, and elasticsearch.build '
69+
+ 'elasticsearch.standalone-rest-test, and elasticsearch.build '
7070
+ 'are mutually exclusive')
7171
}
7272
final String minimumGradleVersion

buildSrc/version.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
elasticsearch = 7.0.0
2-
lucene = 8.0.0-snapshot-31d7dfe6b1
2+
lucene = 8.0.0-snapshot-6d9c714052
33

44
# optional dependencies
55
spatial4j = 0.7
@@ -16,6 +16,7 @@ slf4j = 1.6.2
1616
jna = 4.5.1
1717

1818
netty = 4.1.30.Final
19+
joda = 2.10.1
1920

2021
# test dependencies
2122
randomizedrunner = 2.7.0

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

+88
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,38 @@ private <Req, Resp> Resp internalPerformRequest(Req request,
14171417
throw new IOException("Unable to parse response body for " + response, e);
14181418
}
14191419
}
1420+
1421+
/**
1422+
* Defines a helper method for requests that can 404 and in which case will return an empty Optional
1423+
* otherwise tries to parse the response body
1424+
*/
1425+
protected final <Req extends Validatable, Resp> Optional<Resp> performRequestAndParseOptionalEntity(Req request,
1426+
CheckedFunction<Req, Request, IOException> requestConverter,
1427+
RequestOptions options,
1428+
CheckedFunction<XContentParser, Resp, IOException> entityParser
1429+
) throws IOException {
1430+
Optional<ValidationException> validationException = request.validate();
1431+
if (validationException != null && validationException.isPresent()) {
1432+
throw validationException.get();
1433+
}
1434+
Request req = requestConverter.apply(request);
1435+
req.setOptions(options);
1436+
Response response;
1437+
try {
1438+
response = client.performRequest(req);
1439+
} catch (ResponseException e) {
1440+
if (RestStatus.NOT_FOUND.getStatus() == e.getResponse().getStatusLine().getStatusCode()) {
1441+
return Optional.empty();
1442+
}
1443+
throw parseResponseException(e);
1444+
}
1445+
1446+
try {
1447+
return Optional.of(parseEntity(response.getEntity(), entityParser));
1448+
} catch (Exception e) {
1449+
throw new IOException("Unable to parse response body for " + response, e);
1450+
}
1451+
}
14201452

14211453
/**
14221454
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
@@ -1538,6 +1570,62 @@ public void onFailure(Exception exception) {
15381570
}
15391571
};
15401572
}
1573+
1574+
/**
1575+
* Async request which returns empty Optionals in the case of 404s or parses entity into an Optional
1576+
*/
1577+
protected final <Req extends Validatable, Resp> void performRequestAsyncAndParseOptionalEntity(Req request,
1578+
CheckedFunction<Req, Request, IOException> requestConverter,
1579+
RequestOptions options,
1580+
CheckedFunction<XContentParser, Resp, IOException> entityParser,
1581+
ActionListener<Optional<Resp>> listener) {
1582+
Optional<ValidationException> validationException = request.validate();
1583+
if (validationException != null && validationException.isPresent()) {
1584+
listener.onFailure(validationException.get());
1585+
return;
1586+
}
1587+
Request req;
1588+
try {
1589+
req = requestConverter.apply(request);
1590+
} catch (Exception e) {
1591+
listener.onFailure(e);
1592+
return;
1593+
}
1594+
req.setOptions(options);
1595+
ResponseListener responseListener = wrapResponseListener404sOptional(response -> parseEntity(response.getEntity(),
1596+
entityParser), listener);
1597+
client.performRequestAsync(req, responseListener);
1598+
}
1599+
1600+
final <Resp> ResponseListener wrapResponseListener404sOptional(CheckedFunction<Response, Resp, IOException> responseConverter,
1601+
ActionListener<Optional<Resp>> actionListener) {
1602+
return new ResponseListener() {
1603+
@Override
1604+
public void onSuccess(Response response) {
1605+
try {
1606+
actionListener.onResponse(Optional.of(responseConverter.apply(response)));
1607+
} catch (Exception e) {
1608+
IOException ioe = new IOException("Unable to parse response body for " + response, e);
1609+
onFailure(ioe);
1610+
}
1611+
}
1612+
1613+
@Override
1614+
public void onFailure(Exception exception) {
1615+
if (exception instanceof ResponseException) {
1616+
ResponseException responseException = (ResponseException) exception;
1617+
Response response = responseException.getResponse();
1618+
if (RestStatus.NOT_FOUND.getStatus() == response.getStatusLine().getStatusCode()) {
1619+
actionListener.onResponse(Optional.empty());
1620+
} else {
1621+
actionListener.onFailure(parseResponseException(responseException));
1622+
}
1623+
} else {
1624+
actionListener.onFailure(exception);
1625+
}
1626+
}
1627+
};
1628+
}
15411629

15421630
/**
15431631
* Converts a {@link ResponseException} obtained from the low level REST client into an {@link ElasticsearchException}.

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

+38
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.elasticsearch.action.ActionListener;
2323
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
2424
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
25+
import org.elasticsearch.client.rollup.GetRollupIndexCapsRequest;
26+
import org.elasticsearch.client.rollup.GetRollupIndexCapsResponse;
2527
import org.elasticsearch.client.rollup.GetRollupJobRequest;
2628
import org.elasticsearch.client.rollup.GetRollupJobResponse;
2729
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
@@ -219,4 +221,40 @@ public void getRollupCapabilitiesAsync(GetRollupCapsRequest request, RequestOpti
219221
listener,
220222
Collections.emptySet());
221223
}
224+
225+
/**
226+
* Get the Rollup Index Capabilities of a rollup index or pattern
227+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">
228+
* the docs</a> for more.
229+
* @param request the request
230+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
231+
* @return the response
232+
* @throws IOException in case there is a problem sending the request or parsing back the response
233+
*/
234+
public GetRollupIndexCapsResponse getRollupIndexCapabilities(GetRollupIndexCapsRequest request,
235+
RequestOptions options) throws IOException {
236+
return restHighLevelClient.performRequestAndParseEntity(request,
237+
RollupRequestConverters::getRollupIndexCaps,
238+
options,
239+
GetRollupIndexCapsResponse::fromXContent,
240+
Collections.emptySet());
241+
}
242+
243+
/**
244+
* Asynchronously Get the Rollup Index Capabilities of a rollup index or pattern
245+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">
246+
* the docs</a> for more.
247+
* @param request the request
248+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
249+
* @param listener the listener to be notified upon request completion
250+
*/
251+
public void getRollupIndexCapabilitiesAsync(GetRollupIndexCapsRequest request, RequestOptions options,
252+
ActionListener<GetRollupIndexCapsResponse> listener) {
253+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
254+
RollupRequestConverters::getRollupIndexCaps,
255+
options,
256+
GetRollupIndexCapsResponse::fromXContent,
257+
listener,
258+
Collections.emptySet());
259+
}
222260
}

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

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.http.client.methods.HttpPut;
2525
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
2626
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
27+
import org.elasticsearch.client.rollup.GetRollupIndexCapsRequest;
2728
import org.elasticsearch.client.rollup.GetRollupJobRequest;
2829
import org.elasticsearch.client.rollup.PutRollupJobRequest;
2930
import org.elasticsearch.client.rollup.StartRollupJobRequest;
@@ -85,4 +86,14 @@ static Request getRollupCaps(final GetRollupCapsRequest getRollupCapsRequest) th
8586
request.setEntity(createEntity(getRollupCapsRequest, REQUEST_BODY_CONTENT_TYPE));
8687
return request;
8788
}
89+
90+
static Request getRollupIndexCaps(final GetRollupIndexCapsRequest getRollupIndexCapsRequest) throws IOException {
91+
String endpoint = new RequestConverters.EndpointBuilder()
92+
.addCommaSeparatedPathParts(getRollupIndexCapsRequest.indices())
93+
.addPathPartAsIs("_xpack", "rollup", "data")
94+
.build();
95+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
96+
request.setEntity(createEntity(getRollupIndexCapsRequest, REQUEST_BODY_CONTENT_TYPE));
97+
return request;
98+
}
8899
}

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

+31
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
2525
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
2626
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
27+
import org.elasticsearch.client.tasks.GetTaskRequest;
28+
import org.elasticsearch.client.tasks.GetTaskResponse;
2729

2830
import java.io.IOException;
31+
import java.util.Optional;
2932

3033
import static java.util.Collections.emptySet;
3134

@@ -67,6 +70,34 @@ public void listAsync(ListTasksRequest request, RequestOptions options, ActionLi
6770
restHighLevelClient.performRequestAsyncAndParseEntity(request, TasksRequestConverters::listTasks, options,
6871
ListTasksResponse::fromXContent, listener, emptySet());
6972
}
73+
74+
/**
75+
* Get a task using the Task Management API.
76+
* See
77+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
78+
* @param request the request
79+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
80+
* @return the response
81+
* @throws IOException in case there is a problem sending the request or parsing back the response
82+
*/
83+
public Optional<GetTaskResponse> get(GetTaskRequest request, RequestOptions options) throws IOException {
84+
return restHighLevelClient.performRequestAndParseOptionalEntity(request, TasksRequestConverters::getTask, options,
85+
GetTaskResponse::fromXContent);
86+
}
87+
88+
/**
89+
* Get a task using the Task Management API.
90+
* See
91+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
92+
* @param request the request
93+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
94+
* @param listener an actionlistener that takes an optional response (404s are returned as an empty Optional)
95+
*/
96+
public void getAsync(GetTaskRequest request, RequestOptions options, ActionListener<Optional<GetTaskResponse>> listener) {
97+
98+
restHighLevelClient.performRequestAsyncAndParseOptionalEntity(request, TasksRequestConverters::getTask, options,
99+
GetTaskResponse::fromXContent, listener);
100+
}
70101

71102
/**
72103
* Cancel one or more cluster tasks using the Task Management API.

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

+14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.apache.http.client.methods.HttpPost;
2424
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
2525
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
26+
import org.elasticsearch.client.RequestConverters.EndpointBuilder;
27+
import org.elasticsearch.client.tasks.GetTaskRequest;
2628

2729
final class TasksRequestConverters {
2830

@@ -54,4 +56,16 @@ static Request listTasks(ListTasksRequest listTaskRequest) {
5456
.putParam("group_by", "none");
5557
return request;
5658
}
59+
60+
static Request getTask(GetTaskRequest getTaskRequest) {
61+
String endpoint = new EndpointBuilder().addPathPartAsIs("_tasks")
62+
.addPathPartAsIs(getTaskRequest.getNodeId() + ":" + Long.toString(getTaskRequest.getTaskId()))
63+
.build();
64+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
65+
RequestConverters.Params params = new RequestConverters.Params(request);
66+
params.withTimeout(getTaskRequest.getTimeout())
67+
.withWaitForCompletion(getTaskRequest.getWaitForCompletion());
68+
return request;
69+
}
70+
5771
}

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

+1-20
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
*/
1919
package org.elasticsearch.client.rollup;
2020

21-
import org.elasticsearch.common.Strings;
22-
import org.elasticsearch.common.xcontent.ToXContent;
23-
import org.elasticsearch.common.xcontent.ToXContentObject;
24-
import org.elasticsearch.common.xcontent.XContentBuilder;
2521
import org.elasticsearch.common.xcontent.XContentParser;
2622

2723
import java.io.IOException;
@@ -30,7 +26,7 @@
3026
import java.util.Map;
3127
import java.util.Objects;
3228

33-
public class GetRollupCapsResponse implements ToXContentObject {
29+
public class GetRollupCapsResponse {
3430

3531
private final Map<String, RollableIndexCaps> jobs;
3632

@@ -42,16 +38,6 @@ public Map<String, RollableIndexCaps> getJobs() {
4238
return jobs;
4339
}
4440

45-
@Override
46-
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
47-
builder.startObject();
48-
for (Map.Entry<String, RollableIndexCaps> entry : jobs.entrySet()) {
49-
entry.getValue().toXContent(builder, params);
50-
}
51-
builder.endObject();
52-
return builder;
53-
}
54-
5541
public static GetRollupCapsResponse fromXContent(final XContentParser parser) throws IOException {
5642
Map<String, RollableIndexCaps> jobs = new HashMap<>();
5743
XContentParser.Token token = parser.nextToken();
@@ -84,9 +70,4 @@ public boolean equals(Object obj) {
8470
GetRollupCapsResponse other = (GetRollupCapsResponse) obj;
8571
return Objects.equals(jobs, other.jobs);
8672
}
87-
88-
@Override
89-
public final String toString() {
90-
return Strings.toString(this);
91-
}
9273
}

0 commit comments

Comments
 (0)