|
@@ -22,23 +22,22 @@ import org.elasticsearch.GradleServicesAdapter;
|
|
import org.elasticsearch.gradle.Distribution;
|
|
import org.elasticsearch.gradle.Distribution;
|
|
import org.elasticsearch.gradle.FileSupplier;
|
|
import org.elasticsearch.gradle.FileSupplier;
|
|
import org.elasticsearch.gradle.Version;
|
|
import org.elasticsearch.gradle.Version;
|
|
|
|
+import org.elasticsearch.gradle.http.WaitForHttpResource;
|
|
import org.gradle.api.NamedDomainObjectContainer;
|
|
import org.gradle.api.NamedDomainObjectContainer;
|
|
import org.gradle.api.Project;
|
|
import org.gradle.api.Project;
|
|
import org.gradle.api.logging.Logger;
|
|
import org.gradle.api.logging.Logger;
|
|
import org.gradle.api.logging.Logging;
|
|
import org.gradle.api.logging.Logging;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.InputStreamReader;
|
|
|
|
import java.io.UncheckedIOException;
|
|
import java.io.UncheckedIOException;
|
|
-import java.net.HttpURLConnection;
|
|
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
-import java.net.URL;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
|
|
+import java.security.GeneralSecurityException;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
@@ -75,6 +74,8 @@ public class ElasticsearchCluster implements TestClusterConfiguration {
|
|
services, artifactsExtractDir, workingDirBase
|
|
services, artifactsExtractDir, workingDirBase
|
|
)
|
|
)
|
|
);
|
|
);
|
|
|
|
+
|
|
|
|
+ addWaitForClusterHealth();
|
|
}
|
|
}
|
|
|
|
|
|
public void setNumberOfNodes(int numberOfNodes) {
|
|
public void setNumberOfNodes(int numberOfNodes) {
|
|
@@ -219,6 +220,11 @@ public class ElasticsearchCluster implements TestClusterConfiguration {
|
|
nodes.all(node -> node.extraConfigFile(destination, from));
|
|
nodes.all(node -> node.extraConfigFile(destination, from));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void user(Map<String, String> userSpec) {
|
|
|
|
+ nodes.all(node -> node.user(userSpec));
|
|
|
|
+ }
|
|
|
|
+
|
|
private void writeUnicastHostsFiles() {
|
|
private void writeUnicastHostsFiles() {
|
|
String unicastUris = nodes.stream().flatMap(node -> node.getAllTransportPortURI().stream()).collect(Collectors.joining("\n"));
|
|
String unicastUris = nodes.stream().flatMap(node -> node.getAllTransportPortURI().stream()).collect(Collectors.joining("\n"));
|
|
nodes.forEach(node -> {
|
|
nodes.forEach(node -> {
|
|
@@ -262,9 +268,6 @@ public class ElasticsearchCluster implements TestClusterConfiguration {
|
|
writeUnicastHostsFiles();
|
|
writeUnicastHostsFiles();
|
|
|
|
|
|
LOGGER.info("Starting to wait for cluster to form");
|
|
LOGGER.info("Starting to wait for cluster to form");
|
|
- addWaitForUri(
|
|
|
|
- "cluster health yellow", "/_cluster/health?wait_for_nodes=>=" + nodes.size() + "&wait_for_status=yellow"
|
|
|
|
- );
|
|
|
|
waitForConditions(waitConditions, startedAt, CLUSTER_UP_TIMEOUT, CLUSTER_UP_TIMEOUT_UNIT, this);
|
|
waitForConditions(waitConditions, startedAt, CLUSTER_UP_TIMEOUT, CLUSTER_UP_TIMEOUT_UNIT, this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -293,21 +296,25 @@ public class ElasticsearchCluster implements TestClusterConfiguration {
|
|
return getFirstNode();
|
|
return getFirstNode();
|
|
}
|
|
}
|
|
|
|
|
|
- private void addWaitForUri(String description, String uri) {
|
|
|
|
- waitConditions.put(description, (node) -> {
|
|
|
|
|
|
+ private void addWaitForClusterHealth() {
|
|
|
|
+ waitConditions.put("cluster health yellow", (node) -> {
|
|
try {
|
|
try {
|
|
- URL url = new URL("http://" + getFirstNode().getHttpSocketURI() + uri);
|
|
|
|
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
|
|
|
- con.setRequestMethod("GET");
|
|
|
|
- con.setConnectTimeout(500);
|
|
|
|
- con.setReadTimeout(500);
|
|
|
|
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
|
|
|
|
- String response = reader.lines().collect(Collectors.joining("\n"));
|
|
|
|
- LOGGER.info("{} -> {} ->\n{}", this, uri, response);
|
|
|
|
|
|
+ WaitForHttpResource wait = new WaitForHttpResource(
|
|
|
|
+ "http", getFirstNode().getHttpSocketURI(), nodes.size()
|
|
|
|
+ );
|
|
|
|
+ List<Map<String, String>> credentials = getFirstNode().getCredentials();
|
|
|
|
+ if (getFirstNode().getCredentials().isEmpty() == false) {
|
|
|
|
+ wait.setUsername(credentials.get(0).get("useradd"));
|
|
|
|
+ wait.setPassword(credentials.get(0).get("-p"));
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
|
|
+ return wait.wait(500);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
throw new IllegalStateException("Connection attempt to " + this + " failed", e);
|
|
throw new IllegalStateException("Connection attempt to " + this + " failed", e);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
+ throw new TestClustersException("Interrupted while waiting for " + this, e);
|
|
|
|
+ } catch (GeneralSecurityException e) {
|
|
|
|
+ throw new RuntimeException("security exception", e);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|