Skip to content

Commit 8ab7e63

Browse files
committed
Merge remote-tracking branch 'elastic/6.x' into ccr-6.x
* elastic/6.x: Enable setting client path prefix to / (#30119) [DOCS] Secure settings specified per node (#31621) Build test: Thread linger Build: Fix naming conventions task (#31681) Introduce a Hashing Processor (#31087)
2 parents de00a85 + e302d80 commit 8ab7e63

File tree

19 files changed

+597
-28
lines changed

19 files changed

+597
-28
lines changed

buildSrc/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
20-
2119
import java.nio.file.Files
2220

2321
plugins {
@@ -41,6 +39,12 @@ if (project == rootProject) {
4139
buildDir = 'build-bootstrap'
4240
}
4341

42+
// Make sure :buildSrc: doesn't generate classes incompatible with RUNTIME_JAVA_HOME
43+
// We can't use BuildPlugin here, so read from file
44+
String minimumRuntimeVersion = file('src/main/resources/minimumRuntimeVersion').text.trim()
45+
targetCompatibility = minimumRuntimeVersion
46+
sourceCompatibility = minimumRuntimeVersion
47+
4448
/*****************************************************************************
4549
* Propagating version.properties to the rest of the build *
4650
*****************************************************************************/

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.elasticsearch.gradle
2020

2121
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
22-
import nebula.plugin.extraconfigurations.ProvidedBasePlugin
2322
import org.apache.tools.ant.taskdefs.condition.Os
2423
import org.eclipse.jgit.lib.Constants
2524
import org.eclipse.jgit.lib.RepositoryBuilder
@@ -58,9 +57,6 @@ import java.time.ZonedDateTime
5857
*/
5958
class BuildPlugin implements Plugin<Project> {
6059

61-
static final JavaVersion minimumRuntimeVersion = JavaVersion.VERSION_1_8
62-
static final JavaVersion minimumCompilerVersion = JavaVersion.VERSION_1_10
63-
6460
@Override
6561
void apply(Project project) {
6662
if (project.pluginManager.hasPlugin('elasticsearch.standalone-rest-test')) {
@@ -95,6 +91,12 @@ class BuildPlugin implements Plugin<Project> {
9591
/** Performs checks on the build environment and prints information about the build environment. */
9692
static void globalBuildInfo(Project project) {
9793
if (project.rootProject.ext.has('buildChecksDone') == false) {
94+
JavaVersion minimumRuntimeVersion = JavaVersion.toVersion(
95+
BuildPlugin.class.getClassLoader().getResourceAsStream("minimumRuntimeVersion").text.trim()
96+
)
97+
JavaVersion minimumCompilerVersion = JavaVersion.toVersion(
98+
BuildPlugin.class.getClassLoader().getResourceAsStream("minimumCompilerVersion").text.trim()
99+
)
98100
String compilerJavaHome = findCompilerJavaHome()
99101
String runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome)
100102
File gradleJavaHome = Jvm.current().javaHome
@@ -192,10 +194,12 @@ class BuildPlugin implements Plugin<Project> {
192194
project.rootProject.ext.runtimeJavaVersion = runtimeJavaVersionEnum
193195
project.rootProject.ext.javaVersions = javaVersions
194196
project.rootProject.ext.buildChecksDone = true
197+
project.rootProject.ext.minimumCompilerVersion = minimumCompilerVersion
198+
project.rootProject.ext.minimumRuntimeVersion = minimumRuntimeVersion
195199
}
196200

197-
project.targetCompatibility = minimumRuntimeVersion
198-
project.sourceCompatibility = minimumRuntimeVersion
201+
project.targetCompatibility = project.rootProject.ext.minimumRuntimeVersion
202+
project.sourceCompatibility = project.rootProject.ext.minimumRuntimeVersion
199203

200204
// set java home for each project, so they dont have to find it in the root project
201205
project.ext.compilerJavaHome = project.rootProject.ext.compilerJavaHome
@@ -348,7 +352,7 @@ class BuildPlugin implements Plugin<Project> {
348352
// just a self contained test-fixture configuration, likely transitive and hellacious
349353
return
350354
}
351-
configuration.resolutionStrategy {
355+
configuration.resolutionStrategy {
352356
failOnVersionConflict()
353357
}
354358
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.10
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.8

buildSrc/src/test/java/org/elasticsearch/gradle/precommit/NamingConventionsTaskIT.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.gradle.testkit.runner.BuildResult;
55
import org.gradle.testkit.runner.GradleRunner;
66
import org.gradle.testkit.runner.TaskOutcome;
7-
import org.junit.Ignore;
87

98
import java.util.Arrays;
109

@@ -21,7 +20,6 @@ public void testPluginCanBeApplied() {
2120
assertTrue(result.getOutput().contains("build plugin can be applied"));
2221
}
2322

24-
@Ignore("AwaitsFix : https://github.com/elastic/elasticsearch/issues/31665")
2523
public void testNameCheckFailsAsItShould() {
2624
BuildResult result = GradleRunner.create()
2725
.withProjectDir(getProjectDir("namingConventionsSelfTest"))
@@ -46,7 +44,6 @@ public void testNameCheckFailsAsItShould() {
4644
}
4745
}
4846

49-
@Ignore("AwaitsFix : https://github.com/elastic/elasticsearch/issues/31665")
5047
public void testNameCheckFailsAsItShouldWithMain() {
5148
BuildResult result = GradleRunner.create()
5249
.withProjectDir(getProjectDir("namingConventionsSelfTest"))

buildSrc/src/test/java/org/elasticsearch/gradle/test/BaseTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.carrotsearch.randomizedtesting.JUnit4MethodProvider;
2222
import com.carrotsearch.randomizedtesting.RandomizedRunner;
2323
import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders;
24+
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
2425
import org.junit.Assert;
2526
import org.junit.runner.RunWith;
2627

@@ -29,5 +30,6 @@
2930
JUnit4MethodProvider.class,
3031
JUnit3MethodProvider.class
3132
})
33+
@ThreadLeakLingering(linger = 5000) // wait for "Connection worker" to die
3234
public abstract class BaseTestCase extends Assert {
3335
}

client/rest/src/main/java/org/elasticsearch/client/RestClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,10 @@ static URI buildUri(String pathPrefix, String path, Map<String, String> params)
794794
Objects.requireNonNull(path, "path must not be null");
795795
try {
796796
String fullPath;
797-
if (pathPrefix != null) {
798-
if (path.startsWith("/")) {
797+
if (pathPrefix != null && pathPrefix.isEmpty() == false) {
798+
if (pathPrefix.endsWith("/") && path.startsWith("/")) {
799+
fullPath = pathPrefix.substring(0, pathPrefix.length() - 1) + path;
800+
} else if (pathPrefix.endsWith("/") || path.startsWith("/")) {
799801
fullPath = pathPrefix + path;
800802
} else {
801803
fullPath = pathPrefix + "/" + path;

client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,33 @@ public RestClientBuilder setRequestConfigCallback(RequestConfigCallback requestC
143143
* For example, if this is set to "/my/path", then any client request will become <code>"/my/path/" + endpoint</code>.
144144
* <p>
145145
* In essence, every request's {@code endpoint} is prefixed by this {@code pathPrefix}. The path prefix is useful for when
146-
* Elasticsearch is behind a proxy that provides a base path; it is not intended for other purposes and it should not be supplied in
147-
* other scenarios.
146+
* Elasticsearch is behind a proxy that provides a base path or a proxy that requires all paths to start with '/';
147+
* it is not intended for other purposes and it should not be supplied in other scenarios.
148148
*
149149
* @throws NullPointerException if {@code pathPrefix} is {@code null}.
150-
* @throws IllegalArgumentException if {@code pathPrefix} is empty, only '/', or ends with more than one '/'.
150+
* @throws IllegalArgumentException if {@code pathPrefix} is empty, or ends with more than one '/'.
151151
*/
152152
public RestClientBuilder setPathPrefix(String pathPrefix) {
153153
Objects.requireNonNull(pathPrefix, "pathPrefix must not be null");
154-
String cleanPathPrefix = pathPrefix;
155154

155+
if (pathPrefix.isEmpty()) {
156+
throw new IllegalArgumentException("pathPrefix must not be empty");
157+
}
158+
159+
String cleanPathPrefix = pathPrefix;
156160
if (cleanPathPrefix.startsWith("/") == false) {
157161
cleanPathPrefix = "/" + cleanPathPrefix;
158162
}
159163

160164
// best effort to ensure that it looks like "/base/path" rather than "/base/path/"
161-
if (cleanPathPrefix.endsWith("/")) {
165+
if (cleanPathPrefix.endsWith("/") && cleanPathPrefix.length() > 1) {
162166
cleanPathPrefix = cleanPathPrefix.substring(0, cleanPathPrefix.length() - 1);
163167

164168
if (cleanPathPrefix.endsWith("/")) {
165169
throw new IllegalArgumentException("pathPrefix is malformed. too many trailing slashes: [" + pathPrefix + "]");
166170
}
167171
}
168172

169-
if (cleanPathPrefix.isEmpty() || "/".equals(cleanPathPrefix)) {
170-
throw new IllegalArgumentException("pathPrefix must not be empty or '/': [" + pathPrefix + "]");
171-
}
172173

173174
this.pathPrefix = cleanPathPrefix;
174175
return this;

client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ public void testSetPathPrefixNull() {
180180
}
181181

182182
public void testSetPathPrefixEmpty() {
183-
assertSetPathPrefixThrows("/");
184183
assertSetPathPrefixThrows("");
185184
}
186185

client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,33 @@ public void onFailure(Exception exception) {
223223
}
224224

225225
public void testBuildUriLeavesPathUntouched() {
226+
final Map<String, String> emptyMap = Collections.emptyMap();
226227
{
227-
URI uri = RestClient.buildUri("/foo$bar", "/index/type/id", Collections.<String, String>emptyMap());
228+
URI uri = RestClient.buildUri("/foo$bar", "/index/type/id", emptyMap);
228229
assertEquals("/foo$bar/index/type/id", uri.getPath());
229230
}
230231
{
231-
URI uri = RestClient.buildUri(null, "/foo$bar/ty/pe/i/d", Collections.<String, String>emptyMap());
232+
URI uri = RestClient.buildUri("/", "/*", emptyMap);
233+
assertEquals("/*", uri.getPath());
234+
}
235+
{
236+
URI uri = RestClient.buildUri("/", "*", emptyMap);
237+
assertEquals("/*", uri.getPath());
238+
}
239+
{
240+
URI uri = RestClient.buildUri(null, "*", emptyMap);
241+
assertEquals("*", uri.getPath());
242+
}
243+
{
244+
URI uri = RestClient.buildUri("", "*", emptyMap);
245+
assertEquals("*", uri.getPath());
246+
}
247+
{
248+
URI uri = RestClient.buildUri(null, "/*", emptyMap);
249+
assertEquals("/*", uri.getPath());
250+
}
251+
{
252+
URI uri = RestClient.buildUri(null, "/foo$bar/ty/pe/i/d", emptyMap);
232253
assertEquals("/foo$bar/ty/pe/i/d", uri.getPath());
233254
}
234255
{

0 commit comments

Comments
 (0)