Skip to content

Several internal improvements to internal test cluster infra #26214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ ThreadPool getThreadPool() {
public static final String CLIENT_TYPE = "transport";

final Injector injector;
final NamedWriteableRegistry namedWriteableRegistry;
protected final NamedWriteableRegistry namedWriteableRegistry;

private final List<LifecycleComponent> pluginLifecycleComponents;
private final TransportClientNodesService nodesService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public class MockSecureSettings implements SecureSettings {
private Set<String> settingNames = new HashSet<>();
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
public boolean isLoaded() {
return true;
Expand Down Expand Up @@ -94,4 +103,9 @@ private void ensureOpen() {
throw new IllegalStateException("secure settings are already closed");
}
}

public SecureSettings clone() {
ensureOpen();
return new MockSecureSettings(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,7 @@ protected void ensureClusterSizeConsistency() {
*/
protected void ensureClusterStateConsistency() throws IOException {
if (cluster() != null && cluster().size() > 0) {
final NamedWriteableRegistry namedWriteableRegistry;
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());
}
final NamedWriteableRegistry namedWriteableRegistry = cluster().getNamedWriteableRegistry();
ClusterState masterClusterState = client().admin().cluster().prepareState().all().get().getState();
byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterClusterState);
// remove local node reference
Expand Down Expand Up @@ -2192,9 +2185,13 @@ protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigC
}

protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
final List<NodeInfo> nodes = nodeInfos.getNodes();
assertFalse(nodeInfos.hasFailures());
NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get();
assertFalse(nodesInfoResponse.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<>();
for (NodeInfo node : nodes) {
if (node.getHttp() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.breaker.CircuitBreaker;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -62,7 +63,7 @@ public final class ExternalTestCluster extends TestCluster {
private static final AtomicInteger counter = new AtomicInteger();
public static final String EXTERNAL_CLUSTER_PREFIX = "external_";

private final Client client;
private final MockTransportClient client;

private final InetSocketAddress[] httpAddresses;

Expand Down Expand Up @@ -95,8 +96,7 @@ public ExternalTestCluster(Path tempDir, Settings additionalSettings, Collection
}
}
Settings clientSettings = clientSettingsBuilder.build();
TransportClient client = new MockTransportClient(clientSettings, pluginClasses);

MockTransportClient client = new MockTransportClient(clientSettings, pluginClasses);
try {
client.addTransportAddresses(transportAddresses);
NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
Expand All @@ -117,6 +117,7 @@ public ExternalTestCluster(Path tempDir, Settings additionalSettings, Collection
this.numDataNodes = dataNodes;
this.numMasterAndDataNodes = masterAndDataNodes;
this.client = client;

logger.info("Setup ExternalTestCluster [{}] made of [{}] nodes", nodeInfos.getClusterName().value(), size());
} catch (Exception e) {
client.close();
Expand Down Expand Up @@ -186,6 +187,11 @@ public Iterable<Client> getClients() {
return Collections.singleton(client);
}

@Override
public NamedWriteableRegistry getNamedWriteableRegistry() {
return client.getNamedWriteableRegistry();
}

@Override
public String getClusterName() {
return clusterName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.breaker.CircuitBreaker;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.SecureSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.Settings.Builder;
Expand Down Expand Up @@ -610,6 +612,10 @@ private NodeAndClient buildNode(int nodeId, long seed, Settings settings,
throw new IllegalArgumentException(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " must be configured");
}
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));
try {
IOUtils.close(secureSettings);
Expand Down Expand Up @@ -1964,6 +1970,11 @@ public void remove() {
};
}

@Override
public NamedWriteableRegistry getNamedWriteableRegistry() {
return getInstance(NamedWriteableRegistry.class);
}

/**
* Returns a predicate that only accepts settings of nodes with one of the given names.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.IndexTemplateMissingException;
Expand All @@ -34,6 +35,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Random;
import java.util.Set;

Expand Down Expand Up @@ -233,5 +235,9 @@ public void wipeRepositories(String... repositories) {
*/
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.elasticsearch.transport;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
Expand Down Expand Up @@ -69,4 +70,8 @@ private static Collection<Class<? extends Plugin>> addMockTransportIfMissing(Set
}
return plugins;
}

public NamedWriteableRegistry getNamedWriteableRegistry() {
return namedWriteableRegistry;
}
}