Skip to content

Commit

Permalink
Add cliSetup command to test clusters configuration (#50414)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rjernst committed Jan 7, 2020
1 parent 20eba1e commit 1f6c1df
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public void keystore(String key, FileSupplier valueSupplier) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -300,6 +301,11 @@ public void keystore(String key, FileSupplier valueSupplier) {
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);
Expand Down Expand Up @@ -471,6 +477,14 @@ public synchronized void start() {
));
}

if (cliSetup.isEmpty() == false) {
logToProcessStdout("Running " + cliSetup.size() + " setup commands");

for (CliEntry entry : cliSetup) {
runElasticsearchBinScript(entry.executable, entry.args);
}
}

logToProcessStdout("Starting Elasticsearch process");
startElasticsearchProcess();
}
Expand Down Expand Up @@ -592,7 +606,7 @@ public void user(Map<String, String> userSpec) {
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
Expand All @@ -611,12 +625,12 @@ private void runElasticsearchBinScriptWithInput(String input, String tool, Strin
.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;
Expand All @@ -632,7 +646,7 @@ private void runElasticsearchBinScriptWithInput(String input, String tool, Strin
}
}

private void runElasticsearchBinScript(String tool, String... args) {
private void runElasticsearchBinScript(String tool, CharSequence... args) {
runElasticsearchBinScriptWithInput("", tool, args);
}

Expand Down Expand Up @@ -1169,6 +1183,11 @@ public List<?> getKeystoreFiles() {
return keystoreFiles.getNormalizedCollection();
}

@Nested
public List<?> getCliSetup() {
return cliSetup.getNormalizedCollection();
}

@Nested
public List<?> getSettings() {
return settings.getNormalizedCollection();
Expand Down Expand Up @@ -1340,4 +1359,24 @@ public File getFile() {
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1f6c1df

Please sign in to comment.