|
|
@ -2,21 +2,11 @@ package org.xbib.elx.transport.test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import org.elasticsearch.ElasticsearchTimeoutException;
|
|
|
|
|
|
|
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
|
|
|
|
|
|
|
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
|
|
|
|
|
|
|
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|
|
|
|
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction;
|
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction;
|
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
|
|
|
|
|
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
|
|
|
|
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
|
|
|
|
|
|
|
import org.elasticsearch.client.support.AbstractClient;
|
|
|
|
|
|
|
|
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
|
|
|
|
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
|
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
|
|
|
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
|
|
|
|
|
|
import org.elasticsearch.node.Node;
|
|
|
|
import org.elasticsearch.node.Node;
|
|
|
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
|
|
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
|
|
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
|
|
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
|
|
@ -66,10 +56,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|
|
|
Helper helper = extensionContext.getParent().isPresent() ?
|
|
|
|
Helper helper = extensionContext.getParent().isPresent() ?
|
|
|
|
extensionContext.getParent().get().getStore(ns).getOrComputeIfAbsent(key + count.get(), key -> create(), Helper.class) : null;
|
|
|
|
extensionContext.getParent().get().getStore(ns).getOrComputeIfAbsent(key + count.get(), key -> create(), Helper.class) : null;
|
|
|
|
Objects.requireNonNull(helper);
|
|
|
|
Objects.requireNonNull(helper);
|
|
|
|
logger.info("starting cluster with helper " + helper + " at " + helper.getHome());
|
|
|
|
|
|
|
|
helper.startNode();
|
|
|
|
helper.startNode();
|
|
|
|
helper.greenHealth();
|
|
|
|
|
|
|
|
logger.info("cluster name = {}", helper.clusterName());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -122,8 +109,6 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|
|
|
|
|
|
|
|
|
|
|
Node node;
|
|
|
|
Node node;
|
|
|
|
|
|
|
|
|
|
|
|
AbstractClient client;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setHome(String home) {
|
|
|
|
void setHome(String home) {
|
|
|
|
this.home = home;
|
|
|
|
this.home = home;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -140,26 +125,21 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|
|
|
return cluster;
|
|
|
|
return cluster;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Settings getNodeSettings() {
|
|
|
|
Settings getClientSettings() {
|
|
|
|
return Settings.builder()
|
|
|
|
|
|
|
|
.put("cluster.name", getClusterName())
|
|
|
|
|
|
|
|
.put("path.home", getHome())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Settings getTransportSettings() {
|
|
|
|
|
|
|
|
return Settings.builder()
|
|
|
|
return Settings.builder()
|
|
|
|
.put("cluster.name", cluster)
|
|
|
|
.put("cluster.name", cluster)
|
|
|
|
.put("path.home", getHome())
|
|
|
|
.put("path.home", getHome())
|
|
|
|
.put("host", host)
|
|
|
|
.put("host", host)
|
|
|
|
.put("port", port)
|
|
|
|
.put("port", port)
|
|
|
|
|
|
|
|
.put("cluster.target_health", "YELLOW")
|
|
|
|
|
|
|
|
.put("cluster.target_health_timeout", "1m")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void startNode() {
|
|
|
|
void startNode() {
|
|
|
|
buildNode().start();
|
|
|
|
buildNode().start();
|
|
|
|
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
|
|
|
|
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
|
|
|
|
NodesInfoResponse response = client.execute(NodesInfoAction.INSTANCE, nodesInfoRequest).actionGet();
|
|
|
|
NodesInfoResponse response = node.client().execute(NodesInfoAction.INSTANCE, nodesInfoRequest).actionGet();
|
|
|
|
Object obj = response.iterator().next().getTransport().getAddress()
|
|
|
|
Object obj = response.iterator().next().getTransport().getAddress()
|
|
|
|
.publishAddress();
|
|
|
|
.publishAddress();
|
|
|
|
if (obj instanceof InetSocketTransportAddress) {
|
|
|
|
if (obj instanceof InetSocketTransportAddress) {
|
|
|
@ -180,48 +160,26 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node buildNode() {
|
|
|
|
Node buildNode() {
|
|
|
|
String id = "1";
|
|
|
|
|
|
|
|
Settings nodeSettings = Settings.builder()
|
|
|
|
Settings nodeSettings = Settings.builder()
|
|
|
|
.put(getNodeSettings())
|
|
|
|
.put("cluster.name", getClusterName())
|
|
|
|
.put("node.name", id)
|
|
|
|
.put("path.home", getHome())
|
|
|
|
|
|
|
|
.put("name", getClusterName() + "-name-server") // for threadpool setting
|
|
|
|
|
|
|
|
.put("node.name", getClusterName() + "-server")
|
|
|
|
|
|
|
|
.put("node.master", "true")
|
|
|
|
|
|
|
|
.put("node.data", "true")
|
|
|
|
|
|
|
|
.put("node.client", "false")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
node = new MockNode(nodeSettings);
|
|
|
|
this.node = new MockNode(nodeSettings);
|
|
|
|
client = (AbstractClient) node.client();
|
|
|
|
|
|
|
|
return node;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void closeNodes() {
|
|
|
|
void closeNodes() {
|
|
|
|
if (client != null) {
|
|
|
|
|
|
|
|
logger.info("closing client");
|
|
|
|
|
|
|
|
client.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node != null) {
|
|
|
|
if (node != null) {
|
|
|
|
logger.info("closing node");
|
|
|
|
logger.info("closing node");
|
|
|
|
node.close();
|
|
|
|
node.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void greenHealth() throws IOException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ClusterHealthResponse healthResponse = client.execute(ClusterHealthAction.INSTANCE,
|
|
|
|
|
|
|
|
new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN)
|
|
|
|
|
|
|
|
.timeout(TimeValue.timeValueSeconds(30))).actionGet();
|
|
|
|
|
|
|
|
if (healthResponse != null && healthResponse.isTimedOut()) {
|
|
|
|
|
|
|
|
throw new IOException("cluster state is " + healthResponse.getStatus().name()
|
|
|
|
|
|
|
|
+ ", from here on, everything will fail!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ElasticsearchTimeoutException e) {
|
|
|
|
|
|
|
|
throw new IOException("cluster does not respond to health request, cowardly refusing to continue");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String clusterName() {
|
|
|
|
|
|
|
|
ClusterStateRequest clusterStateRequest = new ClusterStateRequest().all();
|
|
|
|
|
|
|
|
ClusterStateResponse clusterStateResponse =
|
|
|
|
|
|
|
|
client.execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet();
|
|
|
|
|
|
|
|
return clusterStateResponse.getClusterName().value();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz").toCharArray();
|
|
|
|
private static final char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz").toCharArray();
|
|
|
|
|
|
|
|
|
|
|
|
private static final Random random = new SecureRandom();
|
|
|
|
private static final Random random = new SecureRandom();
|
|
|
|