diff --git a/build.gradle b/build.gradle index 7e08f2cbf4b..0963a175e81 100644 --- a/build.gradle +++ b/build.gradle @@ -437,6 +437,14 @@ class Run extends DefaultTask { public void setDebug(boolean enabled) { project.project(':distribution').run.debug = enabled } + + @Option( + option = "data-dir", + description = "Override the base data directory used by the testcluster" + ) + public void setDataDir(String dataDirStr) { + project.project(':distribution').run.dataDir = dataDirStr + } } task run(type: Run) { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java index e85b68c6b76..f8364188fd4 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java @@ -133,7 +133,6 @@ public class ElasticsearchNode implements TestClusterConfiguration { private final Path confPathRepo; private final Path configFile; - private final Path confPathData; private final Path confPathLogs; private final Path transportPortFile; private final Path httpPortsFile; @@ -150,6 +149,7 @@ public class ElasticsearchNode implements TestClusterConfiguration { private boolean isWorkingDirConfigured = false; private String httpPort = "0"; private String transportPort = "0"; + private Path confPathData; ElasticsearchNode(String path, String name, Project project, ReaperService reaper, File workingDirBase) { this.path = path; @@ -1305,6 +1305,10 @@ public class ElasticsearchNode implements TestClusterConfiguration { this.transportPort = transportPort; } + void setDataPath(Path dataPath) { + this.confPathData = dataPath; + } + @Internal Path getEsStdoutFile() { return esStdoutFile; diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java index 2282651f6d4..07e5a6ae221 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java @@ -10,9 +10,12 @@ import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; public class RunTask extends DefaultTestClustersTask { @@ -22,6 +25,8 @@ public class RunTask extends DefaultTestClustersTask { private Boolean debug = false; + private Path dataDir = null; + @Option( option = "debug-jvm", description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch." @@ -35,6 +40,19 @@ public class RunTask extends DefaultTestClustersTask { return debug; } + @Option( + option = "data-dir", + description = "Override the base data directory used by the testcluster" + ) + public void setDataDir(String dataDirStr) { + dataDir = Paths.get(dataDirStr).toAbsolutePath(); + } + + @Input + public String getDataDir() { + return dataDir.toString(); + } + @Override public void beforeStart() { int debugPort = 5005; @@ -46,6 +64,14 @@ public class RunTask extends DefaultTestClustersTask { entry -> entry.getKey().toString().substring(CUSTOM_SETTINGS_PREFIX.length()), entry -> entry.getValue().toString() )); + boolean singleNode = getClusters().stream().flatMap(c -> c.getNodes().stream()).count() == 1; + final Function getDataPath; + if (singleNode) { + getDataPath = n -> dataDir; + } else { + getDataPath = n -> dataDir.resolve(n.getName()); + } + for (ElasticsearchCluster cluster : getClusters()) { cluster.getFirstNode().setHttpPort(String.valueOf(httpPort)); httpPort++; @@ -53,6 +79,9 @@ public class RunTask extends DefaultTestClustersTask { transportPort++; for (ElasticsearchNode node : cluster.getNodes()) { additionalSettings.forEach(node::setting); + if (dataDir != null) { + node.setDataPath(getDataPath.apply(node)); + } if (debug) { logger.lifecycle( "Running elasticsearch in debug mode, {} suspending until connected on debugPort {}",