Add cliSetup command to test clusters configuration (#50414)
This commit adds a cliSetup command that can be used to run arbitrary bin scripts to setup a test cluster. This is the same as what was previously called setupCommands in cluster formation tasks. closes #50382
This commit is contained in:
parent
20eba1e410
commit
1f6c1df58e
|
@ -179,6 +179,11 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
|
|||
nodes.all(each -> each.keystore(key, valueSupplier));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cliSetup(String binTool, CharSequence... args) {
|
||||
nodes.all(each -> each.cliSetup(binTool, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setting(String key, String value) {
|
||||
nodes.all(each -> each.setting(key, value));
|
||||
|
|
|
@ -124,6 +124,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
final LazyPropertyMap<String, CharSequence> settings = new LazyPropertyMap<>("Settings", this);
|
||||
private final LazyPropertyMap<String, CharSequence> keystoreSettings = new LazyPropertyMap<>("Keystore", this);
|
||||
private final LazyPropertyMap<String, File> keystoreFiles = new LazyPropertyMap<>("Keystore files", this, FileEntry::new);
|
||||
private final LazyPropertyList<CliEntry> cliSetup = new LazyPropertyList<>("CLI setup commands", this);
|
||||
private final LazyPropertyMap<String, CharSequence> systemProperties = new LazyPropertyMap<>("System properties", this);
|
||||
private final LazyPropertyMap<String, CharSequence> environment = new LazyPropertyMap<>("Environment", this);
|
||||
private final LazyPropertyList<CharSequence> jvmArgs = new LazyPropertyList<>("JVM arguments", this);
|
||||
|
@ -300,6 +301,11 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
keystoreFiles.put(key, valueSupplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cliSetup(String binTool, CharSequence... args) {
|
||||
cliSetup.add(new CliEntry(binTool, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setting(String key, String value) {
|
||||
settings.put(key, value);
|
||||
|
@ -471,6 +477,14 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
));
|
||||
}
|
||||
|
||||
if (cliSetup.isEmpty() == false) {
|
||||
logToProcessStdout("Running " + cliSetup.size() + " setup commands");
|
||||
|
||||
for (CliEntry entry : cliSetup) {
|
||||
runElasticsearchBinScript(entry.executable, entry.args);
|
||||
}
|
||||
}
|
||||
|
||||
logToProcessStdout("Starting Elasticsearch process");
|
||||
startElasticsearchProcess();
|
||||
}
|
||||
|
@ -592,7 +606,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
credentials.add(cred);
|
||||
}
|
||||
|
||||
private void runElasticsearchBinScriptWithInput(String input, String tool, String... args) {
|
||||
private void runElasticsearchBinScriptWithInput(String input, String tool, CharSequence... args) {
|
||||
if (
|
||||
Files.exists(getDistroDir().resolve("bin").resolve(tool)) == false &&
|
||||
Files.exists(getDistroDir().resolve("bin").resolve(tool + ".bat")) == false
|
||||
|
@ -611,12 +625,12 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
.supply()
|
||||
);
|
||||
spec.args(
|
||||
OS.<List<String>>conditional()
|
||||
OS.<List<CharSequence>>conditional()
|
||||
.onWindows(() -> {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
ArrayList<CharSequence> result = new ArrayList<>();
|
||||
result.add("/c");
|
||||
result.add("bin\\" + tool + ".bat");
|
||||
for (String arg : args) {
|
||||
for (CharSequence arg : args) {
|
||||
result.add(arg);
|
||||
}
|
||||
return result;
|
||||
|
@ -632,7 +646,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
private void runElasticsearchBinScript(String tool, String... args) {
|
||||
private void runElasticsearchBinScript(String tool, CharSequence... args) {
|
||||
runElasticsearchBinScriptWithInput("", tool, args);
|
||||
}
|
||||
|
||||
|
@ -1169,6 +1183,11 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
return keystoreFiles.getNormalizedCollection();
|
||||
}
|
||||
|
||||
@Nested
|
||||
public List<?> getCliSetup() {
|
||||
return cliSetup.getNormalizedCollection();
|
||||
}
|
||||
|
||||
@Nested
|
||||
public List<?> getSettings() {
|
||||
return settings.getNormalizedCollection();
|
||||
|
@ -1340,4 +1359,24 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CliEntry {
|
||||
private String executable;
|
||||
private CharSequence[] args;
|
||||
|
||||
CliEntry(String executable, CharSequence[] args) {
|
||||
this.executable = executable;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Input
|
||||
public String getExecutable() {
|
||||
return executable;
|
||||
}
|
||||
|
||||
@Input
|
||||
public CharSequence[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,8 @@ public interface TestClusterConfiguration {
|
|||
|
||||
void keystore(String key, FileSupplier valueSupplier);
|
||||
|
||||
void cliSetup(String binTool, CharSequence... args);
|
||||
|
||||
void setting(String key, String value);
|
||||
|
||||
void setting(String key, String value, PropertyNormalization normalization);
|
||||
|
|
Loading…
Reference in New Issue