mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 22:45:04 +00:00
Several internal improvements to internal test cluster infra (#26214)
This chance adds several random test infrastructure improvements that caused issues in on-going developments but are generally useful. For instance is it impossible to restart a node with a secure setting source since we close it after the node is started. This change makes it cloneable such that we can reuse it for a restart.
This commit is contained in:
parent
93edbc0030
commit
a9169e536b
@ -235,7 +235,7 @@ public abstract class TransportClient extends AbstractClient {
|
|||||||
public static final String CLIENT_TYPE = "transport";
|
public static final String CLIENT_TYPE = "transport";
|
||||||
|
|
||||||
final Injector injector;
|
final Injector injector;
|
||||||
final NamedWriteableRegistry namedWriteableRegistry;
|
protected final NamedWriteableRegistry namedWriteableRegistry;
|
||||||
|
|
||||||
private final List<LifecycleComponent> pluginLifecycleComponents;
|
private final List<LifecycleComponent> pluginLifecycleComponents;
|
||||||
private final TransportClientNodesService nodesService;
|
private final TransportClientNodesService nodesService;
|
||||||
|
@ -38,6 +38,15 @@ public class MockSecureSettings implements SecureSettings {
|
|||||||
private Set<String> settingNames = new HashSet<>();
|
private Set<String> settingNames = new HashSet<>();
|
||||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
public MockSecureSettings() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private MockSecureSettings(MockSecureSettings source) {
|
||||||
|
secureStrings.putAll(source.secureStrings);
|
||||||
|
files.putAll(source.files);
|
||||||
|
settingNames.addAll(source.settingNames);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLoaded() {
|
public boolean isLoaded() {
|
||||||
return true;
|
return true;
|
||||||
@ -94,4 +103,9 @@ public class MockSecureSettings implements SecureSettings {
|
|||||||
throw new IllegalStateException("secure settings are already closed");
|
throw new IllegalStateException("secure settings are already closed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SecureSettings clone() {
|
||||||
|
ensureOpen();
|
||||||
|
return new MockSecureSettings(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1084,14 +1084,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||||||
*/
|
*/
|
||||||
protected void ensureClusterStateConsistency() throws IOException {
|
protected void ensureClusterStateConsistency() throws IOException {
|
||||||
if (cluster() != null && cluster().size() > 0) {
|
if (cluster() != null && cluster().size() > 0) {
|
||||||
final NamedWriteableRegistry namedWriteableRegistry;
|
final NamedWriteableRegistry namedWriteableRegistry = cluster().getNamedWriteableRegistry();
|
||||||
if (isInternalCluster()) {
|
|
||||||
// If it's internal cluster - using existing registry in case plugin registered custom data
|
|
||||||
namedWriteableRegistry = internalCluster().getInstance(NamedWriteableRegistry.class);
|
|
||||||
} else {
|
|
||||||
// If it's external cluster - fall back to the standard set
|
|
||||||
namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
|
|
||||||
}
|
|
||||||
ClusterState masterClusterState = client().admin().cluster().prepareState().all().get().getState();
|
ClusterState masterClusterState = client().admin().cluster().prepareState().all().get().getState();
|
||||||
byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterClusterState);
|
byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterClusterState);
|
||||||
// remove local node reference
|
// remove local node reference
|
||||||
@ -2192,9 +2185,13 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
|
protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
|
||||||
final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
|
NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get();
|
||||||
final List<NodeInfo> nodes = nodeInfos.getNodes();
|
assertFalse(nodesInfoResponse.hasFailures());
|
||||||
assertFalse(nodeInfos.hasFailures());
|
return createRestClient(nodesInfoResponse.getNodes(), httpClientConfigCallback, protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static RestClient createRestClient(final List<NodeInfo> nodes,
|
||||||
|
RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
|
||||||
List<HttpHost> hosts = new ArrayList<>();
|
List<HttpHost> hosts = new ArrayList<>();
|
||||||
for (NodeInfo node : nodes) {
|
for (NodeInfo node : nodes) {
|
||||||
if (node.getHttp() != null) {
|
if (node.getHttp() != null) {
|
||||||
|
@ -28,6 +28,7 @@ import org.elasticsearch.client.Client;
|
|||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.common.breaker.CircuitBreaker;
|
import org.elasticsearch.common.breaker.CircuitBreaker;
|
||||||
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.network.NetworkModule;
|
import org.elasticsearch.common.network.NetworkModule;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
@ -62,7 +63,7 @@ public final class ExternalTestCluster extends TestCluster {
|
|||||||
private static final AtomicInteger counter = new AtomicInteger();
|
private static final AtomicInteger counter = new AtomicInteger();
|
||||||
public static final String EXTERNAL_CLUSTER_PREFIX = "external_";
|
public static final String EXTERNAL_CLUSTER_PREFIX = "external_";
|
||||||
|
|
||||||
private final Client client;
|
private final MockTransportClient client;
|
||||||
|
|
||||||
private final InetSocketAddress[] httpAddresses;
|
private final InetSocketAddress[] httpAddresses;
|
||||||
|
|
||||||
@ -95,8 +96,7 @@ public final class ExternalTestCluster extends TestCluster {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Settings clientSettings = clientSettingsBuilder.build();
|
Settings clientSettings = clientSettingsBuilder.build();
|
||||||
TransportClient client = new MockTransportClient(clientSettings, pluginClasses);
|
MockTransportClient client = new MockTransportClient(clientSettings, pluginClasses);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.addTransportAddresses(transportAddresses);
|
client.addTransportAddresses(transportAddresses);
|
||||||
NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
|
NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
|
||||||
@ -117,6 +117,7 @@ public final class ExternalTestCluster extends TestCluster {
|
|||||||
this.numDataNodes = dataNodes;
|
this.numDataNodes = dataNodes;
|
||||||
this.numMasterAndDataNodes = masterAndDataNodes;
|
this.numMasterAndDataNodes = masterAndDataNodes;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
logger.info("Setup ExternalTestCluster [{}] made of [{}] nodes", nodeInfos.getClusterName().value(), size());
|
logger.info("Setup ExternalTestCluster [{}] made of [{}] nodes", nodeInfos.getClusterName().value(), size());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
client.close();
|
client.close();
|
||||||
@ -186,6 +187,11 @@ public final class ExternalTestCluster extends TestCluster {
|
|||||||
return Collections.singleton(client);
|
return Collections.singleton(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||||
|
return client.getNamedWriteableRegistry();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getClusterName() {
|
public String getClusterName() {
|
||||||
return clusterName;
|
return clusterName;
|
||||||
|
@ -51,9 +51,11 @@ import org.elasticsearch.common.Nullable;
|
|||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.breaker.CircuitBreaker;
|
import org.elasticsearch.common.breaker.CircuitBreaker;
|
||||||
import org.elasticsearch.common.io.FileSystemUtils;
|
import org.elasticsearch.common.io.FileSystemUtils;
|
||||||
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.lease.Releasables;
|
import org.elasticsearch.common.lease.Releasables;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.network.NetworkModule;
|
import org.elasticsearch.common.network.NetworkModule;
|
||||||
|
import org.elasticsearch.common.settings.MockSecureSettings;
|
||||||
import org.elasticsearch.common.settings.SecureSettings;
|
import org.elasticsearch.common.settings.SecureSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.Settings.Builder;
|
import org.elasticsearch.common.settings.Settings.Builder;
|
||||||
@ -610,6 +612,10 @@ public final class InternalTestCluster extends TestCluster {
|
|||||||
throw new IllegalArgumentException(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " must be configured");
|
throw new IllegalArgumentException(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " must be configured");
|
||||||
}
|
}
|
||||||
SecureSettings secureSettings = finalSettings.getSecureSettings();
|
SecureSettings secureSettings = finalSettings.getSecureSettings();
|
||||||
|
if (secureSettings instanceof MockSecureSettings) {
|
||||||
|
// we clone this here since in the case of a node restart we might need it again
|
||||||
|
secureSettings = ((MockSecureSettings) secureSettings).clone();
|
||||||
|
}
|
||||||
MockNode node = new MockNode(finalSettings.build(), plugins, nodeConfigurationSource.nodeConfigPath(nodeId));
|
MockNode node = new MockNode(finalSettings.build(), plugins, nodeConfigurationSource.nodeConfigPath(nodeId));
|
||||||
try {
|
try {
|
||||||
IOUtils.close(secureSettings);
|
IOUtils.close(secureSettings);
|
||||||
@ -1964,6 +1970,11 @@ public final class InternalTestCluster extends TestCluster {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||||
|
return getInstance(NamedWriteableRegistry.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a predicate that only accepts settings of nodes with one of the given names.
|
* Returns a predicate that only accepts settings of nodes with one of the given names.
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +26,7 @@ import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResp
|
|||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||||
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.index.IndexNotFoundException;
|
import org.elasticsearch.index.IndexNotFoundException;
|
||||||
import org.elasticsearch.indices.IndexTemplateMissingException;
|
import org.elasticsearch.indices.IndexTemplateMissingException;
|
||||||
@ -34,6 +35,7 @@ import org.elasticsearch.repositories.RepositoryMissingException;
|
|||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -233,5 +235,9 @@ public abstract class TestCluster implements Closeable {
|
|||||||
*/
|
*/
|
||||||
public abstract Iterable<Client> getClients();
|
public abstract Iterable<Client> getClients();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this clusters {@link NamedWriteableRegistry} this is needed to
|
||||||
|
* deserialize binary content from this cluster that might include custom named writeables
|
||||||
|
*/
|
||||||
|
public abstract NamedWriteableRegistry getNamedWriteableRegistry();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package org.elasticsearch.transport;
|
package org.elasticsearch.transport;
|
||||||
|
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.network.NetworkModule;
|
import org.elasticsearch.common.network.NetworkModule;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
@ -69,4 +70,8 @@ public class MockTransportClient extends TransportClient {
|
|||||||
}
|
}
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||||
|
return namedWriteableRegistry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user