|
|
@@ -94,20 +94,12 @@ public class EnrollmentProcessTests extends PackagingTestCase {
|
|
|
waitForElasticsearch(installation);
|
|
|
final String node1ContainerId = Docker.getContainerId();
|
|
|
|
|
|
- final AtomicReference<String> enrollmentToken = new AtomicReference<>();
|
|
|
+ Docker.waitForNodeStarted(node1ContainerId);
|
|
|
|
|
|
- assertBusy(() -> {
|
|
|
- final String tokenValue = installation.executables().createEnrollmentToken.run("-s node")
|
|
|
- .stdout()
|
|
|
- .lines()
|
|
|
- .filter(line -> line.startsWith("WARNING:") == false)
|
|
|
- .findFirst()
|
|
|
- .orElseThrow(() -> new AssertionError("Failed to find any non-warning output lines"));
|
|
|
- enrollmentToken.set(tokenValue);
|
|
|
- }, 30, TimeUnit.SECONDS);
|
|
|
+ String enrollmentToken = getEnrollmentToken();
|
|
|
|
|
|
// installation refers to second node from now on
|
|
|
- installation = runAdditionalContainer(distribution(), builder().envVar("ENROLLMENT_TOKEN", enrollmentToken.get()), 9201, 9301);
|
|
|
+ installation = runAdditionalContainer(distribution(), builder().envVar("ENROLLMENT_TOKEN", enrollmentToken), 9201, 9301);
|
|
|
|
|
|
// TODO Make our packaging test methods aware of multiple installations, see https://github.com/elastic/elasticsearch/issues/79688
|
|
|
waitForElasticsearch(installation);
|
|
|
@@ -130,6 +122,34 @@ public class EnrollmentProcessTests extends PackagingTestCase {
|
|
|
removeContainer(node1ContainerId);
|
|
|
}
|
|
|
|
|
|
+ private String getEnrollmentToken() throws Exception {
|
|
|
+ final AtomicReference<String> enrollmentTokenHolder = new AtomicReference<>();
|
|
|
+
|
|
|
+ assertBusy(() -> {
|
|
|
+ // `assertBusy` only retries on assertion errors, not exceptions, and `Executable#run(String)`
|
|
|
+ // throws a `Shell.ShellException` if the command isn't successful.
|
|
|
+ final Shell.Result result = installation.executables().createEnrollmentToken.run("-s node", null, true);
|
|
|
+
|
|
|
+ if (result.isSuccess() == false) {
|
|
|
+ if (result.stdout().contains("Failed to determine the health of the cluster")) {
|
|
|
+ throw new AssertionError("Elasticsearch is not ready yet");
|
|
|
+ }
|
|
|
+ throw new Shell.ShellException(
|
|
|
+ "Command was not successful: [elasticsearch-create-enrollment-token -s node]\n result: " + result
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ final String tokenValue = result.stdout()
|
|
|
+ .lines()
|
|
|
+ .filter(line -> line.startsWith("WARNING:") == false)
|
|
|
+ .findFirst()
|
|
|
+ .orElseThrow(() -> new AssertionError("Failed to find any non-warning output lines"));
|
|
|
+ enrollmentTokenHolder.set(tokenValue);
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ return enrollmentTokenHolder.get();
|
|
|
+ }
|
|
|
+
|
|
|
private void waitForSecondNode() {
|
|
|
int retries = 60;
|
|
|
while (retries > 0) {
|