Skip to content

Commit 364484d

Browse files
committed
Merge branch 'master' into fix_54540
2 parents 589d089 + f44d86a commit 364484d

File tree

52 files changed

+1945
-883
lines changed

Some content is hidden

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

52 files changed

+1945
-883
lines changed

.ci/bwcVersions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ BWC_VERSION:
1717
- "7.6.0"
1818
- "7.6.1"
1919
- "7.6.2"
20+
- "7.6.3"
2021
- "7.7.0"
2122
- "7.8.0"
2223
- "8.0.0"

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy

Lines changed: 0 additions & 97 deletions
This file was deleted.

buildSrc/src/main/java/org/elasticsearch/gradle/SystemPropertyCommandLineArgumentProvider.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55

66
import java.util.LinkedHashMap;
77
import java.util.Map;
8+
import java.util.function.Supplier;
89
import java.util.stream.Collectors;
910

1011
public class SystemPropertyCommandLineArgumentProvider implements CommandLineArgumentProvider {
1112
private final Map<String, Object> systemProperties = new LinkedHashMap<>();
1213

14+
public void systemProperty(String key, Supplier<String> value) {
15+
systemProperties.put(key, value);
16+
}
17+
1318
public void systemProperty(String key, Object value) {
1419
systemProperties.put(key, value);
1520
}
@@ -18,7 +23,12 @@ public void systemProperty(String key, Object value) {
1823
public Iterable<String> asArguments() {
1924
return systemProperties.entrySet()
2025
.stream()
21-
.map(entry -> "-D" + entry.getKey() + "=" + entry.getValue())
26+
.map(
27+
entry -> "-D"
28+
+ entry.getKey()
29+
+ "="
30+
+ (entry.getValue() instanceof Supplier ? ((Supplier) entry.getValue()).get() : entry.getValue())
31+
)
2232
.collect(Collectors.toList());
2333
}
2434

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/Fixture.groovy renamed to buildSrc/src/main/java/org/elasticsearch/gradle/test/Fixture.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
99
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
10+
* http://www.apache.org/licenses/LICENSE-2.0
1111
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
@@ -16,7 +16,8 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.gradle.test
19+
20+
package org.elasticsearch.gradle.test;
2021

2122
/**
2223
* Any object that can produce an accompanying stop task, meant to tear down
@@ -25,6 +26,6 @@
2526
public interface Fixture {
2627

2728
/** A task which will stop this fixture. This should be used as a finalizedBy for any tasks that use the fixture. */
28-
public Object getStopTask()
29+
Object getStopTask();
2930

3031
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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.gradle.test;
21+
22+
import org.elasticsearch.gradle.SystemPropertyCommandLineArgumentProvider;
23+
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster;
24+
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask;
25+
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
26+
import org.gradle.api.Action;
27+
import org.gradle.api.DefaultTask;
28+
import org.gradle.api.NamedDomainObjectContainer;
29+
import org.gradle.api.Project;
30+
import org.gradle.api.Task;
31+
32+
public class RestIntegTestTask extends DefaultTask {
33+
34+
protected RestTestRunnerTask runner;
35+
private static final String TESTS_REST_CLUSTER = "tests.rest.cluster";
36+
private static final String TESTS_CLUSTER = "tests.cluster";
37+
private static final String TESTS_CLUSTER_NAME = "tests.clustername";
38+
39+
public RestIntegTestTask() {
40+
Project project = getProject();
41+
String name = getName();
42+
runner = project.getTasks().create(name + "Runner", RestTestRunnerTask.class);
43+
super.dependsOn(runner);
44+
@SuppressWarnings("unchecked")
45+
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = (NamedDomainObjectContainer<ElasticsearchCluster>) project
46+
.getExtensions()
47+
.getByName(TestClustersPlugin.EXTENSION_NAME);
48+
ElasticsearchCluster cluster = testClusters.create(name);
49+
runner.useCluster(cluster);
50+
runner.include("**/*IT.class");
51+
runner.systemProperty("tests.rest.load_packaged", Boolean.FALSE.toString());
52+
if (System.getProperty(TESTS_REST_CLUSTER) == null) {
53+
if (System.getProperty(TESTS_CLUSTER) != null || System.getProperty(TESTS_CLUSTER_NAME) != null) {
54+
throw new IllegalArgumentException(
55+
String.format("%s, %s, and %s must all be null or non-null", TESTS_REST_CLUSTER, TESTS_CLUSTER, TESTS_CLUSTER_NAME)
56+
);
57+
}
58+
SystemPropertyCommandLineArgumentProvider runnerNonInputProperties = (SystemPropertyCommandLineArgumentProvider) runner
59+
.getExtensions()
60+
.getByName("nonInputProperties");
61+
runnerNonInputProperties.systemProperty(TESTS_REST_CLUSTER, () -> String.join(",", cluster.getAllHttpSocketURI()));
62+
runnerNonInputProperties.systemProperty(TESTS_CLUSTER, () -> String.join(",", cluster.getAllTransportPortURI()));
63+
runnerNonInputProperties.systemProperty(TESTS_CLUSTER_NAME, cluster::getName);
64+
} else {
65+
if (System.getProperty(TESTS_CLUSTER) == null || System.getProperty(TESTS_CLUSTER_NAME) == null) {
66+
throw new IllegalArgumentException(
67+
String.format("%s, %s, and %s must all be null or non-null", TESTS_REST_CLUSTER, TESTS_CLUSTER, TESTS_CLUSTER_NAME)
68+
);
69+
}
70+
}
71+
// this must run after all projects have been configured, so we know any project
72+
// references can be accessed as a fully configured
73+
project.getGradle().projectsEvaluated(x -> {
74+
if (isEnabled() == false) {
75+
runner.setEnabled(false);
76+
}
77+
});
78+
}
79+
80+
@Override
81+
public Task dependsOn(Object... dependencies) {
82+
runner.dependsOn(dependencies);
83+
for (Object dependency : dependencies) {
84+
if (dependency instanceof Fixture) {
85+
runner.finalizedBy(((Fixture) dependency).getStopTask());
86+
}
87+
}
88+
return this;
89+
}
90+
91+
@Override
92+
public void setDependsOn(Iterable<?> dependencies) {
93+
runner.setDependsOn(dependencies);
94+
for (Object dependency : dependencies) {
95+
if (dependency instanceof Fixture) {
96+
runner.finalizedBy(((Fixture) dependency).getStopTask());
97+
}
98+
}
99+
}
100+
101+
public void runner(Action<? super RestTestRunnerTask> configure) {
102+
configure.execute(runner);
103+
}
104+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ static Request cancelTasks(CancelTasksRequest req) {
3939
params
4040
.withNodes(req.getNodes())
4141
.withActions(req.getActions());
42+
if (req.getWaitForCompletion() != null) {
43+
params.withWaitForCompletion(req.getWaitForCompletion());
44+
}
4245
request.addParameters(params.asMap());
4346
return request;
4447
}

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class CancelTasksRequest implements Validatable {
3333
private Optional<TimeValue> timeout = Optional.empty();
3434
private Optional<TaskId> parentTaskId = Optional.empty();
3535
private Optional<TaskId> taskId = Optional.empty();
36+
private Boolean waitForCompletion;
3637

3738
CancelTasksRequest(){}
3839

@@ -76,6 +77,14 @@ public Optional<TaskId> getTaskId() {
7677
return taskId;
7778
}
7879

80+
public Boolean getWaitForCompletion() {
81+
return waitForCompletion;
82+
}
83+
84+
public void setWaitForCompletion(boolean waitForCompletion) {
85+
this.waitForCompletion = waitForCompletion;
86+
}
87+
7988
@Override
8089
public boolean equals(Object o) {
8190
if (this == o) return true;
@@ -85,12 +94,13 @@ public boolean equals(Object o) {
8594
Objects.equals(getActions(), that.getActions()) &&
8695
Objects.equals(getTimeout(), that.getTimeout()) &&
8796
Objects.equals(getParentTaskId(), that.getParentTaskId()) &&
88-
Objects.equals(getTaskId(), that.getTaskId()) ;
97+
Objects.equals(getTaskId(), that.getTaskId()) &&
98+
Objects.equals(waitForCompletion, that.waitForCompletion);
8999
}
90100

91101
@Override
92102
public int hashCode() {
93-
return Objects.hash(getNodes(), getActions(), getTimeout(), getParentTaskId(), getTaskId());
103+
return Objects.hash(getNodes(), getActions(), getTimeout(), getParentTaskId(), getTaskId(), waitForCompletion);
94104
}
95105

96106
@Override
@@ -101,6 +111,7 @@ public String toString() {
101111
", timeout=" + timeout +
102112
", parentTaskId=" + parentTaskId +
103113
", taskId=" + taskId +
114+
", waitForCompletion=" + waitForCompletion +
104115
'}';
105116
}
106117

@@ -110,6 +121,7 @@ public static class Builder {
110121
private Optional<TaskId> parentTaskId = Optional.empty();
111122
private List<String> actionsFilter = new ArrayList<>();
112123
private List<String> nodesFilter = new ArrayList<>();
124+
private Boolean waitForCompletion;
113125

114126
public Builder withTimeout(TimeValue timeout){
115127
this.timeout = Optional.of(timeout);
@@ -138,13 +150,21 @@ public Builder withNodesFiltered(List<String> nodes){
138150
return this;
139151
}
140152

153+
public Builder withWaitForCompletion(boolean waitForCompletion) {
154+
this.waitForCompletion = waitForCompletion;
155+
return this;
156+
}
157+
141158
public CancelTasksRequest build() {
142159
CancelTasksRequest request = new CancelTasksRequest();
143160
timeout.ifPresent(request::setTimeout);
144161
taskId.ifPresent(request::setTaskId);
145162
parentTaskId.ifPresent(request::setParentTaskId);
146163
request.setNodes(nodesFilter);
147164
request.setActions(actionsFilter);
165+
if (waitForCompletion != null) {
166+
request.setWaitForCompletion(waitForCompletion);
167+
}
148168
return request;
149169
}
150170
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.http.client.methods.HttpGet;
2323
import org.apache.http.client.methods.HttpPost;
2424
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
25+
import org.elasticsearch.client.tasks.CancelTasksRequest;
2526
import org.elasticsearch.tasks.TaskId;
2627
import org.elasticsearch.test.ESTestCase;
2728

@@ -40,14 +41,15 @@ public void testCancelTasks() {
4041
new org.elasticsearch.client.tasks.TaskId(randomAlphaOfLength(5), randomNonNegativeLong());
4142
org.elasticsearch.client.tasks.TaskId parentTaskId =
4243
new org.elasticsearch.client.tasks.TaskId(randomAlphaOfLength(5), randomNonNegativeLong());
43-
org.elasticsearch.client.tasks.CancelTasksRequest request =
44-
new org.elasticsearch.client.tasks.CancelTasksRequest.Builder()
45-
.withTaskId(taskId)
46-
.withParentTaskId(parentTaskId)
47-
.build();
44+
CancelTasksRequest.Builder builder = new CancelTasksRequest.Builder().withTaskId(taskId).withParentTaskId(parentTaskId);
4845
expectedParams.put("task_id", taskId.toString());
4946
expectedParams.put("parent_task_id", parentTaskId.toString());
50-
Request httpRequest = TasksRequestConverters.cancelTasks(request);
47+
if (randomBoolean()) {
48+
boolean waitForCompletion = randomBoolean();
49+
builder.withWaitForCompletion(waitForCompletion);
50+
expectedParams.put("wait_for_completion", Boolean.toString(waitForCompletion));
51+
}
52+
Request httpRequest = TasksRequestConverters.cancelTasks(builder.build());
5153
assertThat(httpRequest, notNullValue());
5254
assertThat(httpRequest.getMethod(), equalTo(HttpPost.METHOD_NAME));
5355
assertThat(httpRequest.getEntity(), nullValue());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ public void testCancelTasks() throws IOException {
164164
// tag::cancel-tasks-request-filter
165165
CancelTasksRequest byTaskIdRequest = new org.elasticsearch.client.tasks.CancelTasksRequest.Builder() // <1>
166166
.withTaskId(new org.elasticsearch.client.tasks.TaskId("myNode",44L)) // <2>
167-
.build(); // <3>
167+
.withWaitForCompletion(true) // <3>
168+
.build(); // <4>
168169
// end::cancel-tasks-request-filter
169170

170171
}

0 commit comments

Comments
 (0)