Skip to content

Commit 465ea7b

Browse files
committed
Merge branch '7.x' into peer-recovery-retention-leases-7.x
2 parents d0f889d + 31dc5b7 commit 465ea7b

File tree

615 files changed

+29415
-5470
lines changed

Some content is hidden

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

615 files changed

+29415
-5470
lines changed

A

Whitespace-only changes.

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

+15-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.gradle.api.credentials.HttpHeaderCredentials;
3636
import org.gradle.api.file.FileTree;
3737
import org.gradle.api.plugins.ExtraPropertiesExtension;
38-
import org.gradle.api.tasks.Copy;
38+
import org.gradle.api.tasks.Sync;
3939
import org.gradle.api.tasks.TaskProvider;
4040
import org.gradle.authentication.http.HttpHeaderAuthentication;
4141

@@ -54,15 +54,19 @@
5454
*/
5555
public class DistributionDownloadPlugin implements Plugin<Project> {
5656

57-
private static final String FAKE_GROUP = "elasticsearch-distribution";
57+
private static final String FAKE_IVY_GROUP = "elasticsearch-distribution";
5858
private static final String DOWNLOAD_REPO_NAME = "elasticsearch-downloads";
5959

6060
private BwcVersions bwcVersions;
6161
private NamedDomainObjectContainer<ElasticsearchDistribution> distributionsContainer;
6262

6363
@Override
6464
public void apply(Project project) {
65-
distributionsContainer = project.container(ElasticsearchDistribution.class, name -> new ElasticsearchDistribution(name, project));
65+
distributionsContainer = project.container(ElasticsearchDistribution.class, name -> {
66+
Configuration fileConfiguration = project.getConfigurations().create("es_distro_file_" + name);
67+
Configuration extractedConfiguration = project.getConfigurations().create("es_distro_extracted_" + name);
68+
return new ElasticsearchDistribution(name, project.getObjects(), fileConfiguration, extractedConfiguration);
69+
});
6670
project.getExtensions().add("elasticsearch_distributions", distributionsContainer);
6771

6872
setupDownloadServiceRepo(project);
@@ -112,18 +116,16 @@ private void setupRootDownload(Project rootProject, ElasticsearchDistribution di
112116
String extractedConfigName = "extracted_" + downloadConfigName;
113117
final Configuration downloadConfig = configurations.create(downloadConfigName);
114118
configurations.create(extractedConfigName);
115-
Object distroDep = dependencyNotation(rootProject, distribution);
116-
rootProject.getDependencies().add(downloadConfigName, distroDep);
119+
rootProject.getDependencies().add(downloadConfigName, dependencyNotation(rootProject, distribution));
117120

118121
// add task for extraction, delaying resolving config until runtime
119122
if (distribution.getType() == Type.ARCHIVE || distribution.getType() == Type.INTEG_TEST_ZIP) {
120123
Supplier<File> archiveGetter = downloadConfig::getSingleFile;
121124
String extractDir = rootProject.getBuildDir().toPath().resolve("elasticsearch-distros").resolve(extractedConfigName).toString();
122-
TaskProvider<Copy> extractTask = rootProject.getTasks().register(extractTaskName, Copy.class, copyTask -> {
123-
copyTask.dependsOn(downloadConfig);
124-
copyTask.doFirst(t -> rootProject.delete(extractDir));
125-
copyTask.into(extractDir);
126-
copyTask.from((Callable<FileTree>)() -> {
125+
TaskProvider<Sync> extractTask = rootProject.getTasks().register(extractTaskName, Sync.class, syncTask -> {
126+
syncTask.dependsOn(downloadConfig);
127+
syncTask.into(extractDir);
128+
syncTask.from((Callable<FileTree>)() -> {
127129
File archiveFile = archiveGetter.get();
128130
String archivePath = archiveFile.toString();
129131
if (archivePath.endsWith(".zip")) {
@@ -155,12 +157,12 @@ private static void setupDownloadServiceRepo(Project project) {
155157
});
156158
ivyRepo.getAuthentication().create("header", HttpHeaderAuthentication.class);
157159
ivyRepo.patternLayout(layout -> layout.artifact("/downloads/elasticsearch/[module]-[revision](-[classifier]).[ext]"));
158-
ivyRepo.content(content -> content.includeGroup(FAKE_GROUP));
160+
ivyRepo.content(content -> content.includeGroup(FAKE_IVY_GROUP));
159161
});
160162
project.getRepositories().all(repo -> {
161163
if (repo.getName().equals(DOWNLOAD_REPO_NAME) == false) {
162164
// all other repos should ignore the special group name
163-
repo.content(content -> content.excludeGroup(FAKE_GROUP));
165+
repo.content(content -> content.excludeGroup(FAKE_IVY_GROUP));
164166
}
165167
});
166168
// TODO: need maven repo just for integ-test-zip, but only in external cases
@@ -199,7 +201,7 @@ private Object dependencyNotation(Project project, ElasticsearchDistribution dis
199201
extension = distribution.getPlatform() == Platform.WINDOWS ? "zip" : "tar.gz";
200202
classifier = distribution.getPlatform() + "-" + classifier;
201203
}
202-
return FAKE_GROUP + ":elasticsearch" + (distribution.getFlavor() == Flavor.OSS ? "-oss:" : ":")
204+
return FAKE_IVY_GROUP + ":elasticsearch" + (distribution.getFlavor() == Flavor.OSS ? "-oss:" : ":")
203205
+ distribution.getVersion() + ":" + classifier + "@" + extension;
204206
}
205207

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
package org.elasticsearch.gradle;
2121

2222
import org.gradle.api.Buildable;
23-
import org.gradle.api.Project;
2423
import org.gradle.api.artifacts.Configuration;
24+
import org.gradle.api.model.ObjectFactory;
2525
import org.gradle.api.provider.Property;
2626
import org.gradle.api.tasks.TaskDependency;
2727

@@ -107,17 +107,18 @@ public String toString() {
107107
private final Property<Flavor> flavor;
108108
private final Property<Boolean> bundledJdk;
109109

110-
ElasticsearchDistribution(String name, Project project) {
110+
ElasticsearchDistribution(String name, ObjectFactory objectFactory, Configuration fileConfiguration,
111+
Configuration extractedConfiguration) {
111112
this.name = name;
112-
this.configuration = project.getConfigurations().create("es_distro_file_" + name);
113-
this.version = project.getObjects().property(Version.class);
113+
this.configuration = fileConfiguration;
114+
this.version = objectFactory.property(Version.class);
114115
this.version.convention(Version.fromString(VersionProperties.getElasticsearch()));
115-
this.type = project.getObjects().property(Type.class);
116+
this.type = objectFactory.property(Type.class);
116117
this.type.convention(Type.ARCHIVE);
117-
this.platform = project.getObjects().property(Platform.class);
118-
this.flavor = project.getObjects().property(Flavor.class);
119-
this.bundledJdk = project.getObjects().property(Boolean.class);
120-
this.extracted = new Extracted(project.getConfigurations().create("es_distro_extracted_" + name));
118+
this.platform = objectFactory.property(Platform.class);
119+
this.flavor = objectFactory.property(Flavor.class);
120+
this.bundledJdk = objectFactory.property(Boolean.class);
121+
this.extracted = new Extracted(extractedConfiguration);
121122
}
122123

123124
public String getName() {

buildSrc/src/main/java/org/elasticsearch/gradle/http/WaitForHttpResource.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,14 @@ public boolean wait(int durationInMs) throws GeneralSecurityException, Interrupt
129129
}
130130

131131
protected void checkResource(SSLContext ssl) throws IOException {
132-
try {
133-
final HttpURLConnection connection = buildConnection(ssl);
134-
connection.connect();
135-
final Integer response = connection.getResponseCode();
136-
if (validResponseCodes.contains(response)) {
137-
logger.info("Got successful response [{}] from URL [{}]", response, url);
138-
return;
139-
} else {
140-
throw new IOException(response + " " + connection.getResponseMessage());
141-
}
142-
} catch (IOException e) {
143-
throw e;
132+
final HttpURLConnection connection = buildConnection(ssl);
133+
connection.connect();
134+
final Integer response = connection.getResponseCode();
135+
if (validResponseCodes.contains(response)) {
136+
logger.info("Got successful response [{}] from URL [{}]", response, url);
137+
return;
138+
} else {
139+
throw new IOException(response + " " + connection.getResponseMessage());
144140
}
145141
}
146142

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public ElasticsearchCluster(String path, String clusterName, Project project, Fi
7575
services, artifactsExtractDir, workingDirBase
7676
)
7777
);
78+
// configure the cluster name eagerly so nodes know about it
79+
this.nodes.all((node) -> node.defaultConfig.put("cluster.name", safeName(clusterName)));
7880

7981
addWaitForClusterHealth();
8082
}
@@ -215,12 +217,19 @@ public void setJavaHome(File javaHome) {
215217

216218
@Override
217219
public void start() {
218-
String nodeNames = nodes.stream().map(ElasticsearchNode::getName).collect(Collectors.joining(","));
220+
final String nodeNames;
221+
if (nodes.stream().map(ElasticsearchNode::getName).anyMatch( name -> name == null)) {
222+
nodeNames = null;
223+
} else {
224+
nodeNames = nodes.stream().map(ElasticsearchNode::getName).collect(Collectors.joining(","));
225+
};
219226
for (ElasticsearchNode node : nodes) {
220-
node.defaultConfig.put("cluster.name", safeName(clusterName));
221-
if (Version.fromString(node.getVersion()).getMajor() >= 7) {
222-
node.defaultConfig.put("cluster.initial_master_nodes", "[" + nodeNames + "]");
223-
node.defaultConfig.put("discovery.seed_providers", "file");
227+
if (nodeNames != null) {
228+
// Can only configure master nodes if we have node names defined
229+
if (Version.fromString(node.getVersion()).getMajor() >= 7) {
230+
node.defaultConfig.put("cluster.initial_master_nodes", "[" + nodeNames + "]");
231+
node.defaultConfig.put("discovery.seed_providers", "file");
232+
}
224233
}
225234
node.start();
226235
}
@@ -319,7 +328,6 @@ public ElasticsearchNode singleNode() {
319328

320329
private void addWaitForClusterHealth() {
321330
waitConditions.put("cluster health yellow", (node) -> {
322-
323331
try {
324332
boolean httpSslEnabled = getFirstNode().isHttpSslEnabled();
325333
WaitForHttpResource wait = new WaitForHttpResource(
@@ -328,7 +336,8 @@ private void addWaitForClusterHealth() {
328336
nodes.size()
329337
);
330338
if (httpSslEnabled) {
331-
wait.setCertificateAuthorities(getFirstNode().getHttpCertificateAuthoritiesFile());
339+
340+
getFirstNode().configureHttpWait(wait);
332341
}
333342
List<Map<String, String>> credentials = getFirstNode().getCredentials();
334343
if (getFirstNode().getCredentials().isEmpty() == false) {
@@ -337,7 +346,7 @@ private void addWaitForClusterHealth() {
337346
}
338347
return wait.wait(500);
339348
} catch (IOException e) {
340-
throw new IllegalStateException("Connection attempt to " + this + " failed", e);
349+
throw new UncheckedIOException("IO error while waiting cluster", e);
341350
} catch (InterruptedException e) {
342351
Thread.currentThread().interrupt();
343352
throw new TestClustersException("Interrupted while waiting for " + this, e);

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

+36-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.gradle.FileSupplier;
2424
import org.elasticsearch.gradle.OS;
2525
import org.elasticsearch.gradle.Version;
26+
import org.elasticsearch.gradle.http.WaitForHttpResource;
2627
import org.gradle.api.logging.Logger;
2728
import org.gradle.api.logging.Logging;
2829

@@ -581,7 +582,11 @@ public List<String> getAllTransportPortURI() {
581582
}
582583

583584
public File getServerLog() {
584-
return confPathLogs.resolve(safeName(getName()).replaceAll("-[0-9]+$", "") + "_server.json").toFile();
585+
return confPathLogs.resolve(defaultConfig.get("cluster.name") + "_server.json").toFile();
586+
}
587+
588+
public File getAuditLog() {
589+
return confPathLogs.resolve(defaultConfig.get("cluster.name") + "_audit.json").toFile();
585590
}
586591

587592
@Override
@@ -727,7 +732,10 @@ private void syncWithLinks(Path sourceRoot, Path destinationRoot) {
727732
}
728733

729734
private void createConfiguration() {
730-
defaultConfig.put("node.name", nameCustomization.apply(safeName(name)));
735+
String nodeName = nameCustomization.apply(safeName(name));
736+
if (nodeName != null) {
737+
defaultConfig.put("node.name", nodeName);
738+
}
731739
defaultConfig.put("path.repo", confPathRepo.toAbsolutePath().toString());
732740
defaultConfig.put("path.data", confPathData.toAbsolutePath().toString());
733741
defaultConfig.put("path.logs", confPathLogs.toAbsolutePath().toString());
@@ -880,12 +888,32 @@ public boolean isHttpSslEnabled() {
880888
);
881889
}
882890

883-
public File getHttpCertificateAuthoritiesFile() {
884-
if (settings.containsKey("xpack.security.http.ssl.certificate_authorities") == false) {
885-
throw new TestClustersException("Can't get certificates authority file, not configured for " + this);
891+
void configureHttpWait(WaitForHttpResource wait) {
892+
if (settings.containsKey("xpack.security.http.ssl.certificate_authorities")) {
893+
wait.setCertificateAuthorities(
894+
getConfigDir()
895+
.resolve(settings.get("xpack.security.http.ssl.certificate_authorities").get().toString())
896+
.toFile()
897+
);
898+
}
899+
if (settings.containsKey("xpack.security.http.ssl.certificate")) {
900+
wait.setCertificateAuthorities(
901+
getConfigDir()
902+
.resolve(settings.get("xpack.security.http.ssl.certificate").get().toString())
903+
.toFile()
904+
);
905+
}
906+
if (settings.containsKey("xpack.security.http.ssl.keystore.path")) {
907+
wait.setTrustStoreFile(
908+
getConfigDir()
909+
.resolve(settings.get("xpack.security.http.ssl.keystore.path").get().toString())
910+
.toFile()
911+
);
912+
}
913+
if (keystoreSettings.containsKey("xpack.security.http.ssl.keystore.secure_password")) {
914+
wait.setTrustStorePassword(
915+
keystoreSettings.get("xpack.security.http.ssl.keystore.secure_password").get().toString()
916+
);
886917
}
887-
return getConfigDir()
888-
.resolve(settings.get("xpack.security.http.ssl.certificate_authorities").get().toString())
889-
.toFile();
890918
}
891919
}

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClusterConfiguration.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ default void waitForConditions(
122122
} catch (TestClustersException e) {
123123
throw e;
124124
} catch (Exception e) {
125-
throw e;
125+
lastException = e;
126126
}
127127
}
128128
if (conditionMet == false) {
@@ -131,7 +131,17 @@ default void waitForConditions(
131131
if (lastException == null) {
132132
throw new TestClustersException(message);
133133
} else {
134-
throw new TestClustersException(message + message, lastException);
134+
String extraCause = "";
135+
Throwable cause = lastException;
136+
int ident = 2;
137+
while (cause != null) {
138+
if (cause.getMessage() != null && cause.getMessage().isEmpty() == false) {
139+
extraCause += "\n" + " " + cause.getMessage();
140+
ident += 2;
141+
}
142+
cause = cause.getCause();
143+
}
144+
throw new TestClustersException(message + extraCause, lastException);
135145
}
136146
}
137147
logger.info(

client/rest-high-level/build.gradle

+9-19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
apply plugin: 'elasticsearch.testclusters'
1920
apply plugin: 'elasticsearch.build'
2021
apply plugin: 'elasticsearch.rest-test'
2122
apply plugin: 'nebula.maven-base-publish'
@@ -95,14 +96,15 @@ forbiddenApisMain {
9596
File nodeCert = file("./testnode.crt")
9697
File nodeTrustStore = file("./testnode.jks")
9798

98-
integTestRunner {
99+
integTest.runner {
99100
systemProperty 'tests.rest.cluster.username', System.getProperty('tests.rest.cluster.username', 'test_user')
100101
systemProperty 'tests.rest.cluster.password', System.getProperty('tests.rest.cluster.password', 'test-password')
101102
}
102103

103-
integTestCluster {
104+
testClusters.integTest {
105+
distribution = "DEFAULT"
104106
systemProperty 'es.scripting.update.ctx_in_params', 'false'
105-
setting 'reindex.remote.whitelist', ['"[::1]:*"', '"127.0.0.1:*"']
107+
setting 'reindex.remote.whitelist', '[ "[::1]:*", "127.0.0.1:*" ]'
106108
setting 'xpack.license.self_generated.type', 'trial'
107109
setting 'xpack.security.enabled', 'true'
108110
setting 'xpack.security.authc.token.enabled', 'true'
@@ -111,22 +113,10 @@ integTestCluster {
111113
setting 'xpack.security.http.ssl.certificate_authorities', 'testnode.crt'
112114
setting 'xpack.security.transport.ssl.truststore.path', 'testnode.jks'
113115
setting 'indices.lifecycle.poll_interval', '1000ms'
114-
keystoreSetting 'xpack.security.transport.ssl.truststore.secure_password', 'testnode'
115-
setupCommand 'setupDummyUser',
116-
'bin/elasticsearch-users',
117-
'useradd', System.getProperty('tests.rest.cluster.username', 'test_user'),
118-
'-p', System.getProperty('tests.rest.cluster.password', 'test-password'),
119-
'-r', 'superuser'
116+
keystore 'xpack.security.transport.ssl.truststore.secure_password', 'testnode'
117+
user username: System.getProperty('tests.rest.cluster.username', 'test_user'),
118+
password: System.getProperty('tests.rest.cluster.password', 'test-password')
119+
120120
extraConfigFile nodeCert.name, nodeCert
121121
extraConfigFile nodeTrustStore.name, nodeTrustStore
122-
waitCondition = { node, ant ->
123-
File tmpFile = new File(node.cwd, 'wait.success')
124-
ant.get(src: "http://${node.httpUri()}/_cluster/health?wait_for_nodes=>=${numNodes}&wait_for_status=yellow",
125-
dest: tmpFile.toString(),
126-
username: System.getProperty('tests.rest.cluster.username', 'test_user'),
127-
password: System.getProperty('tests.rest.cluster.password', 'test-password'),
128-
ignoreerrors: true,
129-
retries: 10)
130-
return tmpFile.exists()
131-
}
132122
}

0 commit comments

Comments
 (0)