Skip to content

Commit

Permalink
[7.17] Fixes for module projects in new tests clusters and auto secur…
Browse files Browse the repository at this point in the history
…ity config (#92533) (#92582)

* Fixes for module projects in new tests clusters and auto security config (#92533)

Fix an issue where the build cannot resolve a module dependency for the
current module project. Also add partial support for security auto-
configuration in test clusters.
# Conflicts:
#	build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java
#	modules/aggregations/build.gradle
#	modules/aggs-matrix-stats/src/yamlRestTest/java/org/elasticsearch/search/aggregations/matrix/MatrixStatsClientYamlTestSuiteIT.java
#	test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalClusterHandle.java

* Post-merge fixes

* Spotless
  • Loading branch information
mark-vieira committed Dec 28, 2022
1 parent b5c0d05 commit 223786c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ private FileTree getDistributionFiles(ElasticsearchDistribution distribution, Ac
}

private void registerConfigurationInputs(Task task, Configuration configuration) {
task.getInputs()
.files(providerFactory.provider(() -> configuration.getAsFileTree().filter(f -> f.getName().endsWith(".jar"))))
.withPropertyName(configuration.getName() + "-classpath")
.withNormalizer(ClasspathNormalizer.class);

task.getInputs()
.files(providerFactory.provider(() -> configuration.getAsFileTree().filter(f -> f.getName().endsWith(".jar") == false)))
.withPropertyName(configuration.getName() + "-files")
.withPathSensitivity(PathSensitivity.RELATIVE);

task.getInputs()
.files(providerFactory.provider(() -> configuration.getAsFileTree().filter(f -> f.getName().endsWith(".jar"))))
.withPropertyName(configuration.getName() + "-classpath")
.withNormalizer(ClasspathNormalizer.class);
}

private void registerDistributionInputs(Task task, ElasticsearchDistribution distribution) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public Map<String, String> get(LocalNodeSpec nodeSpec) {
settings.put("node.portsfile", "true");
settings.put("http.port", "0");
settings.put("transport.port", "0");
settings.put("network.host", "_local_");

if (nodeSpec.getDistributionType() == DistributionType.DEFAULT) {
// Disable deprecation indexing which is enabled by default in 7.16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void installPlugins() {
+ project
+ "':\n\n"
+ "dependencies {\n"
+ " clusterModules "
+ " clusterPlugins "
+ "project(':plugins:"
+ pluginName
+ "')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class LocalClusterHandle implements ClusterHandle {
private static final Logger LOGGER = LogManager.getLogger(LocalClusterHandle.class);
Expand Down Expand Up @@ -124,13 +125,19 @@ private void waitUntilReady() {
try {
Retry.retryUntilTrue(CLUSTER_UP_TIMEOUT, Duration.ZERO, () -> {
Node node = nodes.get(0);
String scheme = node.getSpec().isSettingTrue("xpack.security.http.ssl.enabled") ? "https" : "http";
boolean securityEnabled = Boolean.parseBoolean(node.getSpec().getSetting("xpack.security.enabled", "true"));
boolean sslEnabled = Boolean.parseBoolean(node.getSpec().getSetting("xpack.security.http.ssl.enabled", "false"));
boolean securityAutoConfigured = isSecurityAutoConfigured(node);
String scheme = securityEnabled && (sslEnabled || securityAutoConfigured) ? "https" : "http";
WaitForHttpResource wait = new WaitForHttpResource(scheme, node.getHttpAddress(), nodes.size());
if (node.getSpec().getUsers().isEmpty() == false) {
User credentials = node.getSpec().getUsers().get(0);
wait.setUsername(credentials.getUsername());
wait.setPassword(credentials.getPassword());
}
if (securityAutoConfigured) {
wait.setCertificateAuthorities(node.getWorkingDir().resolve("config/certs/http_ca.crt").toFile());
}
return wait.wait(500);
});
} catch (TimeoutException e) {
Expand All @@ -140,6 +147,15 @@ private void waitUntilReady() {
}
}

private boolean isSecurityAutoConfigured(Node node) {
Path configFile = node.getWorkingDir().resolve("config").resolve("elasticsearch.yml");
try (Stream<String> lines = Files.lines(configFile)) {
return lines.anyMatch(l -> l.contains("BEGIN SECURITY AUTO CONFIGURATION"));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private void writeUnicastHostsFile() {
String transportUris = execute(() -> nodes.parallelStream().map(Node::getTransportEndpoint).collect(Collectors.joining("\n")));
nodes.forEach(node -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public boolean isSecurityEnabled() {
);
}

public boolean isSettingTrue(String setting) {
return Boolean.parseBoolean(resolveSettings().getOrDefault(setting, "false"));
public String getSetting(String setting, String defaultValue) {
return resolveSettings().getOrDefault(setting, defaultValue);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DistributionDescriptor resolve(Version version, DistributionType type) {
+ "':\n\n"
+ "tasks.named('"
+ taskName
+ "').configure {\n"
+ "') {\n"
+ " usesDefaultDistribution()\n"
+ "}"
);
Expand Down

0 comments on commit 223786c

Please sign in to comment.